Search in sources :

Example 1 with CreateNetworkCommand

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

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

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

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

Aggregations

CreateNetworkAnswer (com.cloud.agent.api.CreateNetworkAnswer)4 CreateNetworkCommand (com.cloud.agent.api.CreateNetworkCommand)4 Test (org.junit.Test)3 BrocadeVcsApiException (com.cloud.network.brocade.BrocadeVcsApiException)2 HostVO (com.cloud.host.HostVO)1 BrocadeVcsDeviceVO (com.cloud.network.BrocadeVcsDeviceVO)1 BrocadeVcsNetworkVlanMappingVO (com.cloud.network.BrocadeVcsNetworkVlanMappingVO)1 Network (com.cloud.network.Network)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1