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());
}
}
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());
}
}
}
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;
}
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;
}
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;
}
Aggregations