Search in sources :

Example 1 with Param

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;
}
Also used : Account(com.cloud.user.Account) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) VMTemplateVO(com.cloud.storage.VMTemplateVO) ArrayList(java.util.ArrayList) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) LinkedHashMap(java.util.LinkedHashMap) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) List(java.util.List) ArrayList(java.util.ArrayList) VlanVO(com.cloud.dc.VlanVO) TrafficType(com.cloud.network.Networks.TrafficType) DataCenterVO(com.cloud.dc.DataCenterVO) NetworkVO(com.cloud.network.dao.NetworkVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicProfile(com.cloud.vm.NicProfile) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) Param(com.cloud.vm.VirtualMachineProfile.Param) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 2 with Param

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);
}
Also used : HashMap(java.util.HashMap) Param(com.cloud.vm.VirtualMachineProfile.Param) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 3 with Param

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);
}
Also used : HashMap(java.util.HashMap) Param(com.cloud.vm.VirtualMachineProfile.Param) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 4 with Param

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);
}
Also used : HashMap(java.util.HashMap) Param(com.cloud.vm.VirtualMachineProfile.Param) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 5 with Param

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;
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) HashMap(java.util.HashMap) Zone(com.cloud.db.model.Zone) TimeZone(java.util.TimeZone) HostPodVO(com.cloud.dc.HostPodVO) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) UserVO(com.cloud.user.UserVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DeployDestination(com.cloud.deploy.DeployDestination) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Param(com.cloud.vm.VirtualMachineProfile.Param) NicVO(com.cloud.vm.NicVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

DomainRouterVO (com.cloud.vm.DomainRouterVO)7 Param (com.cloud.vm.VirtualMachineProfile.Param)7 HashMap (java.util.HashMap)6 Test (org.junit.Test)4 Account (com.cloud.user.Account)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 HostPodVO (com.cloud.dc.HostPodVO)2 DeployDestination (com.cloud.deploy.DeployDestination)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 User (com.cloud.user.User)2 UserVO (com.cloud.user.UserVO)2 NicVO (com.cloud.vm.NicVO)2 ReservationContext (com.cloud.vm.ReservationContext)2 ReservationContextImpl (com.cloud.vm.ReservationContextImpl)2 Zone (com.cloud.db.model.Zone)1 DataCenter (com.cloud.dc.DataCenter)1 DataCenterVO (com.cloud.dc.DataCenterVO)1 VlanVO (com.cloud.dc.VlanVO)1 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1