Search in sources :

Example 1 with AssociateMacToNetworkAnswer

use of com.cloud.agent.api.AssociateMacToNetworkAnswer 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 AssociateMacToNetworkAnswer

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

the class BrocadeVcsResource method executeRequest.

private Answer executeRequest(AssociateMacToNetworkCommand cmd, int numRetries) {
    try {
        String mac = macReformat64To32(cmd.getInterfaceMac());
        boolean result = _brocadeVcsApi.associateMacToNetwork(cmd.getNetworkId(), mac);
        return new AssociateMacToNetworkAnswer(cmd, result, "Association of mac " + cmd.getInterfaceMac() + " to network " + cmd.getNetworkId() + " done");
    } catch (BrocadeVcsApiException e) {
        if (numRetries > 0) {
            return retry(cmd, --numRetries);
        } else {
            return new AssociateMacToNetworkAnswer(cmd, e);
        }
    }
}
Also used : AssociateMacToNetworkAnswer(com.cloud.agent.api.AssociateMacToNetworkAnswer) BrocadeVcsApiException(com.cloud.network.brocade.BrocadeVcsApiException)

Example 3 with AssociateMacToNetworkAnswer

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

the class BrocadeVcsGuestNetworkGuruTest method testReserve.

@Test
public void testReserve() throws InsufficientVirtualNetworkCapacityException, URISyntaxException, InsufficientAddressCapacityException {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getBroadcastUri()).thenReturn(new URI("vlan://14"));
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    final NicProfile nic = mock(NicProfile.class);
    when(nic.getMacAddress()).thenReturn("macaddress");
    when(nic.getReservationStrategy()).thenReturn(ReservationStrategy.Start);
    final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
    final DeployDestination dest = mock(DeployDestination.class);
    final DataCenterVO dc = mock(DataCenterVO.class);
    when(dest.getDataCenter()).thenReturn(dc);
    when(dcdao.findById((long) anyInt())).thenReturn(dc);
    final HostVO brocadeHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
    when(brocadeHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
    when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
    List<BrocadeVcsDeviceVO> devices = new ArrayList();
    devices.add(brocadeDevice);
    when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    final AssociateMacToNetworkAnswer answer = mock(AssociateMacToNetworkAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    guru.reserve(nic, network, vmProfile, dest, res);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) ArrayList(java.util.ArrayList) NicProfile(com.cloud.vm.NicProfile) URI(java.net.URI) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) ReservationContext(com.cloud.vm.ReservationContext) AssociateMacToNetworkAnswer(com.cloud.agent.api.AssociateMacToNetworkAnswer) DeployDestination(com.cloud.deploy.DeployDestination) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 4 with AssociateMacToNetworkAnswer

use of com.cloud.agent.api.AssociateMacToNetworkAnswer 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 5 with AssociateMacToNetworkAnswer

use of com.cloud.agent.api.AssociateMacToNetworkAnswer 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)6 Test (org.junit.Test)4 AssociateMacToNetworkCommand (com.cloud.agent.api.AssociateMacToNetworkCommand)3 HostVO (com.cloud.host.HostVO)3 BrocadeVcsDeviceVO (com.cloud.network.BrocadeVcsDeviceVO)3 DataCenterVO (com.cloud.dc.DataCenterVO)2 DeployDestination (com.cloud.deploy.DeployDestination)2 Domain (com.cloud.domain.Domain)2 BrocadeVcsApiException (com.cloud.network.brocade.BrocadeVcsApiException)2 NetworkVO (com.cloud.network.dao.NetworkVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 Account (com.cloud.user.Account)2 NicProfile (com.cloud.vm.NicProfile)2 ReservationContext (com.cloud.vm.ReservationContext)2 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)2 URI (java.net.URI)2 DataCenter (com.cloud.dc.DataCenter)1 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1 ArrayList (java.util.ArrayList)1