Search in sources :

Example 1 with BrocadeVcsNetworkVlanMappingVO

use of com.cloud.network.BrocadeVcsNetworkVlanMappingVO 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 BrocadeVcsNetworkVlanMappingVO

use of com.cloud.network.BrocadeVcsNetworkVlanMappingVO in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testTrashFail.

@Test
public void testTrashFail() {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getDataCenterId()).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);
    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 BrocadeVcsNetworkVlanMappingVO mapping = mock(BrocadeVcsNetworkVlanMappingVO.class);
    when(mapping.getVlanId()).thenReturn(14);
    when(vcsmapdao.findByNetworkId(anyLong())).thenReturn(mapping);
    when(vcsmapdao.remove(anyLong())).thenReturn(true);
    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 boolean result = guru.trash(network, offering);
    assertTrue(result == false);
    verify(agentmgr, times(0)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) BrocadeVcsNetworkVlanMappingVO(com.cloud.network.BrocadeVcsNetworkVlanMappingVO) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) Test(org.junit.Test)

Example 3 with BrocadeVcsNetworkVlanMappingVO

use of com.cloud.network.BrocadeVcsNetworkVlanMappingVO in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testTrash.

@Test
public void testTrash() {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getDataCenterId()).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);
    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 BrocadeVcsNetworkVlanMappingVO mapping = mock(BrocadeVcsNetworkVlanMappingVO.class);
    when(mapping.getVlanId()).thenReturn(14);
    when(vcsmapdao.findByNetworkId(anyLong())).thenReturn(mapping);
    final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
    when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
    final List<BrocadeVcsDeviceVO> devices = new ArrayList();
    devices.add(brocadeDevice);
    when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
    final DeleteNetworkAnswer answer = mock(DeleteNetworkAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    when(vcsdao.remove((long) anyInt())).thenReturn(true);
    final boolean result = guru.trash(network, offering);
    assertTrue(result == true);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DeleteNetworkAnswer(com.cloud.agent.api.DeleteNetworkAnswer) NetworkOffering(com.cloud.offering.NetworkOffering) BrocadeVcsNetworkVlanMappingVO(com.cloud.network.BrocadeVcsNetworkVlanMappingVO) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) Test(org.junit.Test)

Example 4 with BrocadeVcsNetworkVlanMappingVO

use of com.cloud.network.BrocadeVcsNetworkVlanMappingVO 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)

Aggregations

HostVO (com.cloud.host.HostVO)4 BrocadeVcsDeviceVO (com.cloud.network.BrocadeVcsDeviceVO)4 BrocadeVcsNetworkVlanMappingVO (com.cloud.network.BrocadeVcsNetworkVlanMappingVO)4 DeleteNetworkAnswer (com.cloud.agent.api.DeleteNetworkAnswer)2 NetworkVO (com.cloud.network.dao.NetworkVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 NetworkOffering (com.cloud.offering.NetworkOffering)2 Test (org.junit.Test)2 CreateNetworkAnswer (com.cloud.agent.api.CreateNetworkAnswer)1 CreateNetworkCommand (com.cloud.agent.api.CreateNetworkCommand)1 DeleteNetworkCommand (com.cloud.agent.api.DeleteNetworkCommand)1 Network (com.cloud.network.Network)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 ArrayList (java.util.ArrayList)1