Search in sources :

Example 1 with CreateNetworkAnswer

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

the class BrocadeVcsGuestNetworkGuru method implement.

@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
    Network implemented = super.implement(network, offering, dest, context);
    int vlanTag = Integer.parseInt(BroadcastDomainType.getValue(implemented.getBroadcastUri()));
    //get physical network id
    Long physicalNetworkId = network.getPhysicalNetworkId();
    List<BrocadeVcsDeviceVO> devices = _brocadeVcsDao.listByPhysicalNetwork(physicalNetworkId);
    if (devices.isEmpty()) {
        s_logger.error("No Brocade VCS Switch on physical network " + physicalNetworkId);
        return null;
    }
    for (BrocadeVcsDeviceVO brocadeVcsDevice : devices) {
        HostVO brocadeVcsHost = _hostDao.findById(brocadeVcsDevice.getHostId());
        // create createNetworkCmd instance and agentMgr execute it.
        CreateNetworkCommand cmd = new CreateNetworkCommand(vlanTag, network.getId(), context.getDomain().getName() + "-" + context.getAccount().getAccountName());
        CreateNetworkAnswer answer = (CreateNetworkAnswer) _agentMgr.easySend(brocadeVcsHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("CreateNetworkCommand failed");
            s_logger.error("Unable to create network " + network.getId());
            return null;
        }
    }
    // Persist the network-vlan mapping from db
    BrocadeVcsNetworkVlanMappingVO brocadeVcsNetworkVlanMapping = new BrocadeVcsNetworkVlanMappingVO(network.getId(), vlanTag);
    _brocadeVcsNetworkVlanDao.persist(brocadeVcsNetworkVlanMapping);
    return implemented;
}
Also used : Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) CreateNetworkAnswer(com.cloud.agent.api.CreateNetworkAnswer) BrocadeVcsNetworkVlanMappingVO(com.cloud.network.BrocadeVcsNetworkVlanMappingVO) CreateNetworkCommand(com.cloud.agent.api.CreateNetworkCommand) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO)

Example 2 with CreateNetworkAnswer

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

the class BrocadeVcsResourceTest method testCreateNetworkApi.

@Test
public void testCreateNetworkApi() throws ConfigurationException, BrocadeVcsApiException {
    resource.configure("BrocadeVcsResource", parameters);
    when(api.createNetwork(VLAN_ID, NETWORK_ID)).thenReturn(true);
    final CreateNetworkCommand cmd = new CreateNetworkCommand(VLAN_ID, NETWORK_ID, "owner");
    final CreateNetworkAnswer answer = (CreateNetworkAnswer) resource.executeRequest(cmd);
    //verify(api).createNetwork(VLAN_ID, NETWORK_ID);
    assertTrue(answer.getResult());
}
Also used : CreateNetworkAnswer(com.cloud.agent.api.CreateNetworkAnswer) CreateNetworkCommand(com.cloud.agent.api.CreateNetworkCommand) Test(org.junit.Test)

Example 3 with CreateNetworkAnswer

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

the class BrocadeVcsResourceTest method testCreateNetworkApiException.

@Test
public void testCreateNetworkApiException() throws ConfigurationException, BrocadeVcsApiException {
    resource.configure("BrocadeVcsResource", parameters);
    when(api.createNetwork(VLAN_ID, NETWORK_ID)).thenThrow(new BrocadeVcsApiException());
    final CreateNetworkCommand cmd = new CreateNetworkCommand(VLAN_ID, NETWORK_ID, "owner");
    final CreateNetworkAnswer answer = (CreateNetworkAnswer) resource.executeRequest(cmd);
    assertFalse(answer.getResult());
}
Also used : CreateNetworkAnswer(com.cloud.agent.api.CreateNetworkAnswer) CreateNetworkCommand(com.cloud.agent.api.CreateNetworkCommand) BrocadeVcsApiException(com.cloud.network.brocade.BrocadeVcsApiException) Test(org.junit.Test)

Example 4 with CreateNetworkAnswer

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

the class BrocadeVcsResourceTest method testRetries.

@Test
public void testRetries() throws ConfigurationException, BrocadeVcsApiException {
    resource.configure("BrocadeVcsResource", parameters);
    when(api.createNetwork(VLAN_ID, NETWORK_ID)).thenThrow(new BrocadeVcsApiException()).thenThrow(new BrocadeVcsApiException()).thenReturn(true);
    final CreateNetworkCommand cmd = new CreateNetworkCommand(VLAN_ID, NETWORK_ID, "owner");
    final CreateNetworkAnswer answer = (CreateNetworkAnswer) resource.executeRequest(cmd);
    assertTrue(answer.getResult());
}
Also used : CreateNetworkAnswer(com.cloud.agent.api.CreateNetworkAnswer) CreateNetworkCommand(com.cloud.agent.api.CreateNetworkCommand) BrocadeVcsApiException(com.cloud.network.brocade.BrocadeVcsApiException) Test(org.junit.Test)

Example 5 with CreateNetworkAnswer

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

the class BrocadeVcsGuestNetworkGuruTest method testImplementFail.

@Test
public void testImplementFail() throws InsufficientVirtualNetworkCapacityException, URISyntaxException {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VCS" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
    mock(DeploymentPlan.class);
    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"));
    final DeployDestination dest = mock(DeployDestination.class);
    final DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).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);
    final List<BrocadeVcsDeviceVO> devices = mock(List.class);
    when(devices.isEmpty()).thenReturn(true);
    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);
    when(guestGuru.implement(network, offering, dest, res)).thenReturn(network);
    final CreateNetworkAnswer answer = mock(CreateNetworkAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    final Network implementednetwork = guru.implement(network, offering, dest, res);
    assertTrue(implementednetwork == null);
    verify(agentmgr, times(0)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) URI(java.net.URI) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) ReservationContext(com.cloud.vm.ReservationContext) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) CreateNetworkAnswer(com.cloud.agent.api.CreateNetworkAnswer) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Aggregations

CreateNetworkAnswer (com.cloud.agent.api.CreateNetworkAnswer)6 Test (org.junit.Test)5 CreateNetworkCommand (com.cloud.agent.api.CreateNetworkCommand)4 HostVO (com.cloud.host.HostVO)3 BrocadeVcsDeviceVO (com.cloud.network.BrocadeVcsDeviceVO)3 Network (com.cloud.network.Network)3 DataCenter (com.cloud.dc.DataCenter)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 NetworkOffering (com.cloud.offering.NetworkOffering)2 Account (com.cloud.user.Account)2 ReservationContext (com.cloud.vm.ReservationContext)2 URI (java.net.URI)2 BrocadeVcsNetworkVlanMappingVO (com.cloud.network.BrocadeVcsNetworkVlanMappingVO)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 ArrayList (java.util.ArrayList)1