use of com.cloud.vm.VirtualMachineProfile.Param in project cloudstack by apache.
the class NetScalerVMManagerImpl method deployNsVpx.
@Override
public Map<String, Object> deployNsVpx(Account owner, DeployDestination dest, DeploymentPlan plan, long svcOffId, long templateId) throws InsufficientCapacityException {
VMTemplateVO template = _templateDao.findById(templateId);
long id = _vmDao.getNextInSequence(Long.class, "id");
Account systemAcct = _accountMgr.getSystemAccount();
if (template == null) {
s_logger.error(" Unable to find the NS VPX template");
throw new CloudRuntimeException("Unable to find the Template" + templateId);
}
long dataCenterId = dest.getDataCenter().getId();
DataCenterVO dc = _dcDao.findById(dest.getDataCenter().getId());
String nxVpxName = VirtualMachineName.getSystemVmName(id, "Vpx", NetScalerLbVmNamePrefix);
// using 2GB and 2CPU offering
ServiceOfferingVO vpxOffering = _serviceOfferingDao.findById(svcOffId);
if (vpxOffering.getRamSize() < 2048 && vpxOffering.getCpu() < 2) {
throw new InvalidParameterValueException("Specified Service Offering :" + vpxOffering.getUuid() + " NS Vpx cannot be deployed. Min 2GB Ram and 2 CPU are required");
}
long userId = CallContext.current().getCallingUserId();
// TODO change the os bits from 142 103 to the actual guest of bits
if (template.getGuestOSId() != 103) {
throw new InvalidParameterValueException("Specified Template " + template.getUuid() + " not suitable for NS VPX Deployment. Please register the template with guest os type as unknow(64-bit)");
}
NetworkVO defaultNetwork = null;
NetworkVO defaultPublicNetwork = null;
if (dc.getNetworkType() == NetworkType.Advanced && dc.isSecurityGroupEnabled()) {
List<NetworkVO> networks = _networkDao.listByZoneSecurityGroup(dataCenterId);
if (networks == null || networks.size() == 0) {
throw new CloudRuntimeException("Can not found security enabled network in SG Zone " + dc);
}
defaultNetwork = networks.get(0);
} else {
TrafficType defaultTrafficType = TrafficType.Management;
List<NetworkVO> defaultNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, defaultTrafficType);
TrafficType publicTrafficType = TrafficType.Public;
List<NetworkVO> publicNetworks = _networkDao.listByZoneAndTrafficType(dataCenterId, publicTrafficType);
// api should never allow this situation to happen
if (defaultNetworks.size() != 1) {
throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
}
if (publicNetworks.size() != 1) {
throw new CloudRuntimeException("Found " + defaultNetworks.size() + " networks of type " + defaultTrafficType + " when expect to find 1");
}
defaultPublicNetwork = publicNetworks.get(0);
defaultNetwork = defaultNetworks.get(0);
}
LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(4);
NicProfile defaultNic = new NicProfile();
defaultNic.setDefaultNic(true);
defaultNic.setDeviceId(0);
networks.put(_networkMgr.setupNetwork(_accountMgr.getSystemAccount(), _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), new ArrayList<NicProfile>());
NicProfile defaultNic1 = new NicProfile();
defaultNic1.setDefaultNic(false);
defaultNic1.setDeviceId(1);
NicProfile defaultNic2 = new NicProfile();
defaultNic2.setDefaultNic(false);
defaultNic2.setDeviceId(2);
defaultNic2.setIPv4Address("");
defaultNic2.setIPv4Gateway("");
defaultNic2.setIPv4Netmask("");
String macAddress = _networkDao.getNextAvailableMacAddress(defaultPublicNetwork.getId(), null);
defaultNic2.setMacAddress(macAddress);
networks.put(_networkMgr.setupNetwork(_accountMgr.getSystemAccount(), _networkOfferingDao.findByUniqueName(NetworkOffering.SystemPublicNetwork), plan, null, null, false).get(0), new ArrayList<NicProfile>(Arrays.asList(defaultNic2)));
networks.put(_networkMgr.setupNetwork(_accountMgr.getSystemAccount(), _networkOfferingDao.findByUniqueName(NetworkOffering.SystemControlNetwork), plan, null, null, false).get(0), new ArrayList<NicProfile>());
long physicalNetworkId = _networkModel.findPhysicalNetworkId(dataCenterId, _networkOfferingDao.findById(defaultPublicNetwork.getNetworkOfferingId()).getTags(), TrafficType.Public);
// Validate physical network
PhysicalNetwork physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
if (physicalNetwork == null) {
throw new InvalidParameterValueException("Unable to find physical network with id: " + physicalNetworkId + " and tag: " + _networkOfferingDao.findById(defaultPublicNetwork.getNetworkOfferingId()).getTags());
}
String guestvnet = physicalNetwork.getVnetString();
final List<VlanVO> vlans = _vlanDao.listByZone(dataCenterId);
List<String> pvlan = new ArrayList<String>();
for (final VlanVO vlan : vlans) {
pvlan.add(vlan.getVlanTag());
}
long netScalerProvider = getNetScalerLbProviderId(physicalNetworkId);
DomainRouterVO nsVpx = new DomainRouterVO(id, vpxOffering.getId(), netScalerProvider, nxVpxName, template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), userId, false, RedundantState.UNKNOWN, false, false, VirtualMachine.Type.NetScalerVm, null);
nsVpx.setRole(Role.NETSCALER_VM);
nsVpx = _routerDao.persist(nsVpx);
VMInstanceVO vmVO = _vmDao.findVMByHostName(nxVpxName);
_itMgr.allocate(nxVpxName, template, vpxOffering, networks, plan, template.getHypervisorType());
Map<Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
try {
if (vmVO != null) {
startNsVpx(vmVO, params);
} else {
throw new NullPointerException();
}
} catch (StorageUnavailableException e) {
e.printStackTrace();
} catch (ConcurrentOperationException e) {
e.printStackTrace();
} catch (ResourceUnavailableException e) {
e.printStackTrace();
}
vmVO = _vmDao.findByUuid(nsVpx.getUuid());
Map<String, Object> deployResponse = new HashMap<String, Object>();
deployResponse.put("vm", vmVO);
deployResponse.put("guestvlan", guestvnet);
deployResponse.put("publicvlan", pvlan);
return deployResponse;
}
use of com.cloud.vm.VirtualMachineProfile.Param in project cloudstack by apache.
the class LoadBalanceRuleHandlerTest method testStart.
@Test
public void testStart() throws Exception {
DomainRouterVO elbVmMock = mock(DomainRouterVO.class);
String uuid = "uuid";
when(elbVmMock.getUuid()).thenReturn(uuid);
long id = 1L;
when(elbVmMock.getId()).thenReturn(id);
Map<Param, Object> params = new HashMap<Param, Object>();
params.put(mock(Param.class), new Object());
loadBalanceRuleHandler.start(elbVmMock, params);
verify(virtualMachineManagerMock, times(1)).start(uuid, params);
verify(domainRouterDaoMock, times(1)).findById(id);
}
use of com.cloud.vm.VirtualMachineProfile.Param in project cloudstack by apache.
the class LoadBalanceRuleHandlerTest method testStartWhenElbVmIsNull.
@Test(expected = NullPointerException.class)
public void testStartWhenElbVmIsNull() throws Exception {
DomainRouterVO elbVm = null;
Map<Param, Object> params = new HashMap<Param, Object>();
loadBalanceRuleHandler.start(elbVm, params);
}
use of com.cloud.vm.VirtualMachineProfile.Param in project cloudstack by apache.
the class LoadBalanceRuleHandlerTest method testStartWhenParamsIsEmpty.
@Test
public void testStartWhenParamsIsEmpty() throws Exception {
DomainRouterVO elbVmMock = mock(DomainRouterVO.class);
String uuid = "uuid";
when(elbVmMock.getUuid()).thenReturn(uuid);
long id = 1L;
when(elbVmMock.getId()).thenReturn(id);
Map<Param, Object> params = new HashMap<Param, Object>();
loadBalanceRuleHandler.start(elbVmMock, params);
verify(virtualMachineManagerMock, times(1)).start(uuid, params);
verify(domainRouterDaoMock, times(1)).findById(id);
}
use of com.cloud.vm.VirtualMachineProfile.Param in project cosmic by MissionCriticalCloud.
the class VirtualNetworkApplianceManagerImpl method startRouter.
@Override
public VirtualRouter startRouter(final long routerId, final boolean reprogramNetwork) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
final Account caller = CallContext.current().getCallingAccount();
final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
// verify parameters
DomainRouterVO router = _routerDao.findById(routerId);
if (router == null) {
throw new InvalidParameterValueException("Unable to find router by id " + routerId + ".");
}
_accountMgr.checkAccess(caller, null, true, router);
final Account owner = _accountMgr.getAccount(router.getAccountId());
// Check if all networks are implemented for the domR; if not -
// implement them
final Zone zone = zoneRepository.findOne(router.getDataCenterId());
HostPodVO pod = null;
if (router.getPodIdToDeployIn() != null) {
pod = _podDao.findById(router.getPodIdToDeployIn());
}
final DeployDestination dest = new DeployDestination(zone, pod, null, null);
final ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
final List<NicVO> nics = _nicDao.listByVmId(routerId);
for (final NicVO nic : nics) {
if (!_networkMgr.startNetwork(nic.getNetworkId(), dest, context)) {
s_logger.warn("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
throw new CloudRuntimeException("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
}
}
// After start network, check if it's already running
router = _routerDao.findById(routerId);
if (router.getState() == VirtualMachine.State.Running) {
return router;
}
final UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
final Map<Param, Object> params = new HashMap<>();
if (reprogramNetwork) {
params.put(Param.ReProgramGuestNetworks, true);
} else {
params.put(Param.ReProgramGuestNetworks, false);
}
final VirtualRouter virtualRouter = _nwHelper.startVirtualRouter(router, user, caller, params);
if (virtualRouter == null) {
throw new CloudRuntimeException("Failed to start router with id " + routerId);
}
return virtualRouter;
}
Aggregations