Search in sources :

Example 1 with DeleteNetworkCommand

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

the class BrocadeVcsResourceTest method testDeleteNetworkApiException.

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

Example 2 with DeleteNetworkCommand

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

the class BrocadeVcsGuestNetworkGuru method trash.

@Override
public boolean trash(Network network, NetworkOffering offering) {
    int vlanTag = 0;
    // Get the network-vlan mapping from db
    BrocadeVcsNetworkVlanMappingVO brocadeVcsNetworkVlanMapping = _brocadeVcsNetworkVlanDao.findByNetworkId(network.getId());
    if (brocadeVcsNetworkVlanMapping != null) {
        vlanTag = brocadeVcsNetworkVlanMapping.getVlanId();
    } else {
        s_logger.error("Not able to find vlanId for network " + network.getId());
        return false;
    }
    List<BrocadeVcsDeviceVO> devices = _brocadeVcsDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No Brocade VCS Switch on physical network " + network.getPhysicalNetworkId());
        return false;
    }
    for (BrocadeVcsDeviceVO brocadeVcsDevice : devices) {
        HostVO brocadeVcsHost = _hostDao.findById(brocadeVcsDevice.getHostId());
        // create deleteNetworkCmd instance and agentMgr execute it.
        DeleteNetworkCommand cmd = new DeleteNetworkCommand(vlanTag, network.getId());
        DeleteNetworkAnswer answer = (DeleteNetworkAnswer) _agentMgr.easySend(brocadeVcsHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("DeleteNetworkCommand failed");
            s_logger.error("Unable to delete network " + network.getId());
            return false;
        }
    }
    // Remove the network-vlan mapping from db
    _brocadeVcsNetworkVlanDao.remove(brocadeVcsNetworkVlanMapping.getId());
    return super.trash(network, offering);
}
Also used : DeleteNetworkAnswer(com.cloud.agent.api.DeleteNetworkAnswer) DeleteNetworkCommand(com.cloud.agent.api.DeleteNetworkCommand) BrocadeVcsNetworkVlanMappingVO(com.cloud.network.BrocadeVcsNetworkVlanMappingVO) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO)

Example 3 with DeleteNetworkCommand

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

the class BrocadeVcsResourceTest method testDeleteNetworkApi.

@Test
public void testDeleteNetworkApi() throws ConfigurationException, BrocadeVcsApiException {
    resource.configure("BrocadeVcsResource", parameters);
    when(api.deleteNetwork(VLAN_ID, NETWORK_ID)).thenReturn(true);
    final DeleteNetworkCommand cmd = new DeleteNetworkCommand(VLAN_ID, NETWORK_ID);
    final DeleteNetworkAnswer answer = (DeleteNetworkAnswer) resource.executeRequest(cmd);
    assertTrue(answer.getResult());
}
Also used : DeleteNetworkAnswer(com.cloud.agent.api.DeleteNetworkAnswer) DeleteNetworkCommand(com.cloud.agent.api.DeleteNetworkCommand) Test(org.junit.Test)

Aggregations

DeleteNetworkAnswer (com.cloud.agent.api.DeleteNetworkAnswer)3 DeleteNetworkCommand (com.cloud.agent.api.DeleteNetworkCommand)3 Test (org.junit.Test)2 HostVO (com.cloud.host.HostVO)1 BrocadeVcsDeviceVO (com.cloud.network.BrocadeVcsDeviceVO)1 BrocadeVcsNetworkVlanMappingVO (com.cloud.network.BrocadeVcsNetworkVlanMappingVO)1 BrocadeVcsApiException (com.cloud.network.brocade.BrocadeVcsApiException)1