Search in sources :

Example 1 with AssociateMacToNetworkCommand

use of com.cloud.agent.api.AssociateMacToNetworkCommand in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuru method reserve.

@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    super.reserve(nic, network, vm, dest, context);
    DataCenter dc = _dcDao.findById(network.getDataCenterId());
    String interfaceMac = nic.getMacAddress();
    List<BrocadeVcsDeviceVO> devices = _brocadeVcsDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No Brocade VCS Switch on physical network " + network.getPhysicalNetworkId());
        return;
    }
    for (BrocadeVcsDeviceVO brocadeVcsDevice : devices) {
        HostVO brocadeVcsHost = _hostDao.findById(brocadeVcsDevice.getHostId());
        // create AssociateMacToNetworkCmd instance and agentMgr execute it.
        AssociateMacToNetworkCommand cmd = new AssociateMacToNetworkCommand(network.getId(), interfaceMac, context.getDomain().getName() + "-" + context.getAccount().getAccountName());
        AssociateMacToNetworkAnswer answer = (AssociateMacToNetworkAnswer) _agentMgr.easySend(brocadeVcsHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("AssociateMacToNetworkCommand failed");
            throw new InsufficientVirtualNetworkCapacityException("Unable to associate mac " + interfaceMac + " to network " + network.getId(), DataCenter.class, dc.getId());
        }
    }
}
Also used : AssociateMacToNetworkAnswer(com.cloud.agent.api.AssociateMacToNetworkAnswer) DataCenter(com.cloud.dc.DataCenter) AssociateMacToNetworkCommand(com.cloud.agent.api.AssociateMacToNetworkCommand) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO)

Example 2 with AssociateMacToNetworkCommand

use of com.cloud.agent.api.AssociateMacToNetworkCommand in project cloudstack by apache.

the class BrocadeVcsResourceTest method testAssociateMacToNetworkApiException.

@Test
public void testAssociateMacToNetworkApiException() throws ConfigurationException, BrocadeVcsApiException {
    resource.configure("BrocadeVcsResource", parameters);
    when(api.associateMacToNetwork(NETWORK_ID, MAC_ADDRESS_32)).thenThrow(new BrocadeVcsApiException());
    final AssociateMacToNetworkCommand cmd = new AssociateMacToNetworkCommand(NETWORK_ID, MAC_ADDRESS_64, "owner");
    final AssociateMacToNetworkAnswer answer = (AssociateMacToNetworkAnswer) resource.executeRequest(cmd);
    assertFalse(answer.getResult());
}
Also used : AssociateMacToNetworkAnswer(com.cloud.agent.api.AssociateMacToNetworkAnswer) AssociateMacToNetworkCommand(com.cloud.agent.api.AssociateMacToNetworkCommand) BrocadeVcsApiException(com.cloud.network.brocade.BrocadeVcsApiException) Test(org.junit.Test)

Example 3 with AssociateMacToNetworkCommand

use of com.cloud.agent.api.AssociateMacToNetworkCommand in project cloudstack by apache.

the class BrocadeVcsResourceTest method testAssociateMacToNetworkApi.

@Test
public void testAssociateMacToNetworkApi() throws ConfigurationException, BrocadeVcsApiException {
    resource.configure("BrocadeVcsResource", parameters);
    when(api.associateMacToNetwork(NETWORK_ID, MAC_ADDRESS_32)).thenReturn(true);
    final AssociateMacToNetworkCommand cmd = new AssociateMacToNetworkCommand(NETWORK_ID, MAC_ADDRESS_64, "owner");
    final AssociateMacToNetworkAnswer answer = (AssociateMacToNetworkAnswer) resource.executeRequest(cmd);
    assertTrue(answer.getResult());
}
Also used : AssociateMacToNetworkAnswer(com.cloud.agent.api.AssociateMacToNetworkAnswer) AssociateMacToNetworkCommand(com.cloud.agent.api.AssociateMacToNetworkCommand) Test(org.junit.Test)

Aggregations

AssociateMacToNetworkAnswer (com.cloud.agent.api.AssociateMacToNetworkAnswer)3 AssociateMacToNetworkCommand (com.cloud.agent.api.AssociateMacToNetworkCommand)3 Test (org.junit.Test)2 DataCenter (com.cloud.dc.DataCenter)1 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1 HostVO (com.cloud.host.HostVO)1 BrocadeVcsDeviceVO (com.cloud.network.BrocadeVcsDeviceVO)1 BrocadeVcsApiException (com.cloud.network.brocade.BrocadeVcsApiException)1