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