use of com.cloud.network.BrocadeVcsDeviceVO in project cloudstack by apache.
the class AddBrocadeVcsDeviceCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
BrocadeVcsDeviceVO brocadeVcsDeviceVO = brocadeVcsElementService.addBrocadeVcsDevice(this);
if (brocadeVcsDeviceVO != null) {
BrocadeVcsDeviceResponse response = brocadeVcsElementService.createBrocadeVcsDeviceResponse(brocadeVcsDeviceVO);
response.setObjectName("brocadevcsdevice");
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Brocade VCS Switch due to internal error.");
}
} 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 BrocadeVcsElement method addBrocadeVcsDevice.
@Override
@DB
public BrocadeVcsDeviceVO addBrocadeVcsDevice(AddBrocadeVcsDeviceCmd cmd) {
ServerResource resource = new BrocadeVcsResource();
final String deviceName = Network.Provider.BrocadeVcs.getName();
NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
if (networkDevice == null) {
throw new CloudRuntimeException("No network device found for " + deviceName);
}
final Long physicalNetworkId = cmd.getPhysicalNetworkId();
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
if (physicalNetwork == null) {
throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
}
long zoneId = physicalNetwork.getDataCenterId();
final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
if (ntwkSvcProvider == null) {
throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "to add this device");
} else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
}
Map<String, String> params = new HashMap<String, String>();
params.put("guid", UUID.randomUUID().toString());
params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
params.put("name", "Brocade VCS - " + cmd.getHost());
params.put("ip", cmd.getHost());
params.put("adminuser", cmd.getUsername());
params.put("adminpass", cmd.getPassword());
Map<String, Object> hostdetails = new HashMap<String, Object>();
hostdetails.putAll(params);
try {
resource.configure(cmd.getHost(), hostdetails);
final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params);
if (host != null) {
return Transaction.execute(new TransactionCallback<BrocadeVcsDeviceVO>() {
@Override
public BrocadeVcsDeviceVO doInTransaction(TransactionStatus status) {
BrocadeVcsDeviceVO brocadeVcsDevice = new BrocadeVcsDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
_brocadeVcsDao.persist(brocadeVcsDevice);
DetailVO detail = new DetailVO(host.getId(), "brocadevcsdeviceid", String.valueOf(brocadeVcsDevice.getId()));
_hostDetailsDao.persist(detail);
return brocadeVcsDevice;
}
});
} else {
throw new CloudRuntimeException("Failed to add Brocade VCS Switch due to internal error.");
}
} catch (ConfigurationException e) {
throw new CloudRuntimeException(e.getMessage());
}
}
use of com.cloud.network.BrocadeVcsDeviceVO 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());
}
use of com.cloud.network.BrocadeVcsDeviceVO in project cloudstack by apache.
the class BrocadeVcsGuestNetworkGuruTest method testReserve.
@Test
public void testReserve() throws InsufficientVirtualNetworkCapacityException, URISyntaxException, InsufficientAddressCapacityException {
final NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getBroadcastUri()).thenReturn(new URI("vlan://14"));
when(network.getDataCenterId()).thenReturn(NETWORK_ID);
final NicProfile nic = mock(NicProfile.class);
when(nic.getMacAddress()).thenReturn("macaddress");
when(nic.getReservationStrategy()).thenReturn(ReservationStrategy.Start);
final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
final DeployDestination dest = mock(DeployDestination.class);
final DataCenterVO dc = mock(DataCenterVO.class);
when(dest.getDataCenter()).thenReturn(dc);
when(dcdao.findById((long) anyInt())).thenReturn(dc);
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 BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
List<BrocadeVcsDeviceVO> devices = new ArrayList();
devices.add(brocadeDevice);
when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
final Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
final Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
final ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
final AssociateMacToNetworkAnswer answer = mock(AssociateMacToNetworkAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
guru.reserve(nic, network, vmProfile, dest, res);
verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
use of com.cloud.network.BrocadeVcsDeviceVO 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());
}
Aggregations