Search in sources :

Example 6 with BrocadeVcsDeviceVO

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

the class ListBrocadeVcsDevicesCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
    try {
        List<BrocadeVcsDeviceVO> brocadeDevices = brocadeVcsElementService.listBrocadeVcsDevices(this);
        ListResponse<BrocadeVcsDeviceResponse> response = new ListResponse<BrocadeVcsDeviceResponse>();
        List<BrocadeVcsDeviceResponse> brocadeDevicesResponse = new ArrayList<BrocadeVcsDeviceResponse>();
        if (brocadeDevices != null && !brocadeDevices.isEmpty()) {
            for (BrocadeVcsDeviceVO brocadeDeviceVO : brocadeDevices) {
                BrocadeVcsDeviceResponse brocadeDeviceResponse = brocadeVcsElementService.createBrocadeVcsDeviceResponse(brocadeDeviceVO);
                brocadeDevicesResponse.add(brocadeDeviceResponse);
            }
        }
        response.setResponses(brocadeDevicesResponse);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : BrocadeVcsDeviceResponse(com.cloud.api.response.BrocadeVcsDeviceResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO)

Example 7 with BrocadeVcsDeviceVO

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

the class BrocadeVcsGuestNetworkGuru method reserve.

@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    super.reserve(nic, network, vm, dest, context);
    DataCenter dc = _dcDao.findById(network.getDataCenterId());
    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 AssociateMacToNetworkCmd instance and agentMgr execute it.
        AssociateMacToNetworkCommand cmd = new AssociateMacToNetworkCommand(network.getId(), interfaceMac, context.getDomain().getName() + "-" + context.getAccount().getAccountName());
        AssociateMacToNetworkAnswer answer = (AssociateMacToNetworkAnswer) _agentMgr.easySend(brocadeVcsHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            s_logger.error("AssociateMacToNetworkCommand failed");
            throw new InsufficientVirtualNetworkCapacityException("Unable to associate mac " + interfaceMac + " to network " + network.getId(), DataCenter.class, dc.getId());
        }
    }
}
Also used : AssociateMacToNetworkAnswer(com.cloud.agent.api.AssociateMacToNetworkAnswer) DataCenter(com.cloud.dc.DataCenter) AssociateMacToNetworkCommand(com.cloud.agent.api.AssociateMacToNetworkCommand) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO)

Example 8 with BrocadeVcsDeviceVO

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

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

the class BrocadeVcsElement method deleteBrocadeVcsDevice.

@Override
public boolean deleteBrocadeVcsDevice(DeleteBrocadeVcsDeviceCmd 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 " + brocadeVcsDevice);
    }
    // Find the physical network we work for
    Long physicalNetworkId = brocadeVcsDevice.getPhysicalNetworkId();
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork != null) {
        // Lets see if there are networks that use us
        // Find the brocade networks on this physical network
        List<NetworkVO> networkList = _networkDao.listByPhysicalNetwork(physicalNetworkId);
        if (networkList != null) {
            // Networks with broadcast type vcs are ours
            for (NetworkVO network : networkList) {
                if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Vcs) {
                    if ((network.getState() != Network.State.Shutdown) && (network.getState() != Network.State.Destroy)) {
                        throw new CloudRuntimeException("This Brocade VCS Switch can not be deleted as there are one or more logical networks provisioned by cloudstack.");
                    }
                }
            }
        }
    }
    HostVO brocadeHost = _hostDao.findById(brocadeVcsDevice.getHostId());
    Long hostId = brocadeHost.getId();
    brocadeHost.setResourceState(ResourceState.Maintenance);
    _hostDao.update(hostId, brocadeHost);
    _resourceMgr.deleteHost(hostId, false, false);
    _brocadeVcsDao.remove(brocadeDeviceId);
    return true;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO)

Example 10 with BrocadeVcsDeviceVO

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

the class BrocadeVcsElement method listBrocadeVcsDevices.

@Override
public List<BrocadeVcsDeviceVO> listBrocadeVcsDevices(ListBrocadeVcsDevicesCmd cmd) {
    Long physicalNetworkId = cmd.getPhysicalNetworkId();
    Long brocadeVcsDeviceId = cmd.getBrocadeVcsDeviceId();
    List<BrocadeVcsDeviceVO> responseList = new ArrayList<BrocadeVcsDeviceVO>();
    if (physicalNetworkId == null && brocadeVcsDeviceId == null) {
        throw new InvalidParameterValueException("Either physical network Id or brocade vcs switch Id must be specified");
    }
    if (brocadeVcsDeviceId != null) {
        BrocadeVcsDeviceVO brocadeVcsDevice = _brocadeVcsDao.findById(brocadeVcsDeviceId);
        if (brocadeVcsDevice == null) {
            throw new InvalidParameterValueException("Could not find Brocade VCS Switch with id: " + brocadeVcsDeviceId);
        }
        responseList.add(brocadeVcsDevice);
    } else {
        PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
        if (physicalNetwork == null) {
            throw new InvalidParameterValueException("Could not find a physical network with id: " + physicalNetworkId);
        }
        responseList = _brocadeVcsDao.listByPhysicalNetwork(physicalNetworkId);
    }
    return responseList;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) 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