Search in sources :

Example 16 with BrocadeVcsDeviceVO

use of com.cloud.network.BrocadeVcsDeviceVO 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 17 with BrocadeVcsDeviceVO

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

the class BrocadeVcsGuestNetworkGuru method deallocate.

@Override
public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) {
    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 DisassociateMacFromNetworkCmd instance and agentMgr execute it.
        DisassociateMacFromNetworkCommand cmd = new DisassociateMacFromNetworkCommand(network.getId(), interfaceMac);
        DisassociateMacFromNetworkAnswer answer = (DisassociateMacFromNetworkAnswer) _agentMgr.easySend(brocadeVcsHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("DisassociateMacFromNetworkCommand failed");
            s_logger.error("Unable to disassociate mac " + interfaceMac + " from network " + network.getId());
            return;
        }
    }
    super.deallocate(network, nic, vm);
}
Also used : DisassociateMacFromNetworkCommand(com.cloud.agent.api.DisassociateMacFromNetworkCommand) DisassociateMacFromNetworkAnswer(com.cloud.agent.api.DisassociateMacFromNetworkAnswer) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO)

Example 18 with BrocadeVcsDeviceVO

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

the class BrocadeVcsElement method listBrocadeVcsDeviceNetworks.

@Override
public List<? extends Network> listBrocadeVcsDeviceNetworks(ListBrocadeVcsDeviceNetworksCmd cmd) {
    Long brocadeDeviceId = cmd.getBrocadeVcsDeviceId();
    BrocadeVcsDeviceVO brocadeVcsDevice = _brocadeVcsDao.findById(brocadeDeviceId);
    if (brocadeVcsDevice == null) {
        throw new InvalidParameterValueException("Could not find a Brocade VCS Switch with id " + brocadeDeviceId);
    }
    // Find the physical network we work for
    Long physicalNetworkId = brocadeVcsDevice.getPhysicalNetworkId();
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        // No such physical network, so no provisioned networks
        return Collections.emptyList();
    }
    // Find the brocade networks on this physical network
    List<NetworkVO> networkList = _networkDao.listByPhysicalNetwork(physicalNetworkId);
    if (networkList == null) {
        return Collections.emptyList();
    }
    // Networks with broadcast type vcs are ours
    List<NetworkVO> responseList = new ArrayList<NetworkVO>();
    for (NetworkVO network : networkList) {
        if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Vcs) {
            responseList.add(network);
        }
    }
    return responseList;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO)

Aggregations

BrocadeVcsDeviceVO (com.cloud.network.BrocadeVcsDeviceVO)18 HostVO (com.cloud.host.HostVO)13 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)12 NetworkVO (com.cloud.network.dao.NetworkVO)10 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 DeployDestination (com.cloud.deploy.DeployDestination)4 Domain (com.cloud.domain.Domain)4 BrocadeVcsNetworkVlanMappingVO (com.cloud.network.BrocadeVcsNetworkVlanMappingVO)4 NetworkOffering (com.cloud.offering.NetworkOffering)4 Account (com.cloud.user.Account)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 NicProfile (com.cloud.vm.NicProfile)4 ReservationContext (com.cloud.vm.ReservationContext)4 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)4 URI (java.net.URI)4 AssociateMacToNetworkAnswer (com.cloud.agent.api.AssociateMacToNetworkAnswer)3 CreateNetworkAnswer (com.cloud.agent.api.CreateNetworkAnswer)3 DisassociateMacFromNetworkAnswer (com.cloud.agent.api.DisassociateMacFromNetworkAnswer)3