Search in sources :

Example 66 with DataCenter

use of com.cloud.dc.DataCenter in project CloudStack-archive by CloudStack-extras.

the class UpdateZoneCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("Zone Id: " + getId());
    DataCenter result = _configService.editZone(this);
    if (result != null) {
        ZoneResponse response = _responseGenerator.createZoneResponse(result, false);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update zone; internal error.");
    }
}
Also used : ZoneResponse(com.cloud.api.response.ZoneResponse) DataCenter(com.cloud.dc.DataCenter) ServerApiException(com.cloud.api.ServerApiException)

Example 67 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class OpendaylightGuestNetworkGuru method design.

@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
    PhysicalNetworkVO physnet = physicalNetworkDao.findById(plan.getPhysicalNetworkId());
    DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    if (!canHandle(offering, dc.getNetworkType(), physnet)) {
        s_logger.debug("Refusing to design this network");
        return null;
    }
    List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physnet.getId());
    if (devices.isEmpty()) {
        s_logger.error("No Controller on physical network " + physnet.getName());
        return null;
    }
    s_logger.debug("Controller " + devices.get(0).getUuid() + " found on physical network " + physnet.getId());
    s_logger.debug("Physical isolation type is ODL, asking GuestNetworkGuru to design this network");
    NetworkVO networkObject = (NetworkVO) super.design(offering, plan, userSpecified, owner);
    if (networkObject == null) {
        return null;
    }
    // Override the broadcast domain type
    networkObject.setBroadcastDomainType(BroadcastDomainType.OpenDaylight);
    return networkObject;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DataCenter(com.cloud.dc.DataCenter) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) OpenDaylightControllerVO(org.apache.cloudstack.network.opendaylight.dao.OpenDaylightControllerVO)

Example 68 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method getLbAutoScaleVmGroup.

private LbAutoScaleVmGroup getLbAutoScaleVmGroup(AutoScaleVmGroupVO vmGroup, String currentState, LoadBalancerVO lb) {
    long lbNetworkId = lb.getNetworkId();
    String lbName = lb.getName();
    List<AutoScaleVmGroupPolicyMapVO> vmGroupPolicyMapList = _autoScaleVmGroupPolicyMapDao.listByVmGroupId(vmGroup.getId());
    List<LbAutoScalePolicy> autoScalePolicies = new ArrayList<LbAutoScalePolicy>();
    for (AutoScaleVmGroupPolicyMapVO vmGroupPolicyMap : vmGroupPolicyMapList) {
        AutoScalePolicy autoScalePolicy = _autoScalePolicyDao.findById(vmGroupPolicyMap.getPolicyId());
        List<AutoScalePolicyConditionMapVO> autoScalePolicyConditionMapList = _autoScalePolicyConditionMapDao.listByAll(autoScalePolicy.getId(), null);
        List<LbCondition> lbConditions = new ArrayList<LbCondition>();
        for (AutoScalePolicyConditionMapVO autoScalePolicyConditionMap : autoScalePolicyConditionMapList) {
            Condition condition = _conditionDao.findById(autoScalePolicyConditionMap.getConditionId());
            Counter counter = _counterDao.findById(condition.getCounterid());
            lbConditions.add(new LbCondition(counter, condition));
        }
        autoScalePolicies.add(new LbAutoScalePolicy(autoScalePolicy, lbConditions));
    }
    AutoScaleVmProfile autoScaleVmProfile = _autoScaleVmProfileDao.findById(vmGroup.getProfileId());
    Long autoscaleUserId = autoScaleVmProfile.getAutoScaleUserId();
    User user = _userDao.findByIdIncludingRemoved(autoscaleUserId);
    String apiKey = user.getApiKey();
    String secretKey = user.getSecretKey();
    String csUrl = ApiServiceConfiguration.ApiServletPath.value();
    String zoneId = _dcDao.findById(autoScaleVmProfile.getZoneId()).getUuid();
    String domainId = _domainDao.findById(autoScaleVmProfile.getDomainId()).getUuid();
    String serviceOfferingId = _offeringsDao.findById(autoScaleVmProfile.getServiceOfferingId()).getUuid();
    String templateId = _templateDao.findById(autoScaleVmProfile.getTemplateId()).getUuid();
    String vmName = "AutoScale-LB-" + lbName;
    String lbNetworkUuid = null;
    DataCenter zone = _entityMgr.findById(DataCenter.class, vmGroup.getZoneId());
    if (zone == null) {
        // This should never happen, but still a cautious check
        s_logger.warn("Unable to find zone while packaging AutoScale Vm Group, zoneid: " + vmGroup.getZoneId());
        throw new InvalidParameterValueException("Unable to find zone");
    } else {
        if (zone.getNetworkType() == NetworkType.Advanced) {
            NetworkVO lbNetwork = _networkDao.findById(lbNetworkId);
            lbNetworkUuid = lbNetwork.getUuid();
        }
    }
    if (apiKey == null) {
        throw new InvalidParameterValueException("apiKey for user: " + user.getUsername() + " is empty. Please generate it");
    }
    if (secretKey == null) {
        throw new InvalidParameterValueException("secretKey for user: " + user.getUsername() + " is empty. Please generate it");
    }
    if (csUrl == null || csUrl.contains("localhost")) {
        throw new InvalidParameterValueException("Global setting endpointe.url has to be set to the Management Server's API end point");
    }
    LbAutoScaleVmProfile lbAutoScaleVmProfile = new LbAutoScaleVmProfile(autoScaleVmProfile, apiKey, secretKey, csUrl, zoneId, domainId, serviceOfferingId, templateId, vmName, lbNetworkUuid);
    return new LbAutoScaleVmGroup(vmGroup, autoScalePolicies, lbAutoScaleVmProfile, currentState);
}
Also used : Condition(com.cloud.network.as.Condition) LbCondition(com.cloud.network.lb.LoadBalancingRule.LbCondition) AutoScaleVmGroupPolicyMapVO(com.cloud.network.as.AutoScaleVmGroupPolicyMapVO) NetworkVO(com.cloud.network.dao.NetworkVO) User(com.cloud.user.User) LbAutoScaleVmProfile(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile) ArrayList(java.util.ArrayList) LbAutoScalePolicy(com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy) LbAutoScaleVmProfile(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmProfile) AutoScaleVmProfile(com.cloud.network.as.AutoScaleVmProfile) Counter(com.cloud.network.as.Counter) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) LbAutoScalePolicy(com.cloud.network.lb.LoadBalancingRule.LbAutoScalePolicy) AutoScalePolicy(com.cloud.network.as.AutoScalePolicy) LbCondition(com.cloud.network.lb.LoadBalancingRule.LbCondition) LbAutoScaleVmGroup(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup) AutoScalePolicyConditionMapVO(com.cloud.network.as.AutoScalePolicyConditionMapVO)

Example 69 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class CommandSetupHelper method findDefaultDnsIp.

private NicVO findDefaultDnsIp(final long userVmId) {
    final NicVO defaultNic = _nicDao.findDefaultNicForVM(userVmId);
    // check if DNS provider is the domR
    if (!_networkModel.isProviderSupportServiceInNetwork(defaultNic.getNetworkId(), Service.Dns, Provider.VirtualRouter)) {
        return null;
    }
    final NetworkOffering offering = _networkOfferingDao.findById(_networkDao.findById(defaultNic.getNetworkId()).getNetworkOfferingId());
    if (offering.getRedundantRouter()) {
        return findGatewayIp(userVmId);
    }
    final DataCenter dc = _dcDao.findById(_networkModel.getNetwork(defaultNic.getNetworkId()).getDataCenterId());
    final boolean isZoneBasic = dc.getNetworkType() == NetworkType.Basic;
    // find domR's nic in the network
    NicVO domrDefaultNic;
    if (isZoneBasic) {
        domrDefaultNic = _nicDao.findByNetworkIdTypeAndGateway(defaultNic.getNetworkId(), VirtualMachine.Type.DomainRouter, defaultNic.getIPv4Gateway());
    } else {
        domrDefaultNic = _nicDao.findByNetworkIdAndType(defaultNic.getNetworkId(), VirtualMachine.Type.DomainRouter);
    }
    return domrDefaultNic;
}
Also used : DataCenter(com.cloud.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) NicVO(com.cloud.vm.NicVO)

Example 70 with DataCenter

use of com.cloud.dc.DataCenter in project cloudstack by apache.

the class UserVmManagerImpl method createVirtualMachine.

@Override
public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, StorageUnavailableException, ResourceAllocationException {
    //Verify that all objects exist before passing them to the service
    Account owner = _accountService.getActiveAccountById(cmd.getEntityOwnerId());
    verifyDetails(cmd.getDetails());
    Long zoneId = cmd.getZoneId();
    DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
    if (zone == null) {
        throw new InvalidParameterValueException("Unable to find zone by id=" + zoneId);
    }
    Long serviceOfferingId = cmd.getServiceOfferingId();
    ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
    if (serviceOffering == null) {
        throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
    }
    Long templateId = cmd.getTemplateId();
    if (!serviceOffering.isDynamic()) {
        for (String detail : cmd.getDetails().keySet()) {
            if (detail.equalsIgnoreCase("cpuNumber") || detail.equalsIgnoreCase("cpuSpeed") || detail.equalsIgnoreCase("memory")) {
                throw new InvalidParameterValueException("cpuNumber or cpuSpeed or memory should not be specified for static service offering");
            }
        }
    }
    VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
    // Make sure a valid template ID was specified
    if (template == null) {
        throw new InvalidParameterValueException("Unable to use template " + templateId);
    }
    Long diskOfferingId = cmd.getDiskOfferingId();
    DiskOffering diskOffering = null;
    if (diskOfferingId != null) {
        diskOffering = _entityMgr.findById(DiskOffering.class, diskOfferingId);
        if (diskOffering == null) {
            throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
        }
    }
    if (!zone.isLocalStorageEnabled()) {
        if (serviceOffering.getUseLocalStorage()) {
            throw new InvalidParameterValueException("Zone is not configured to use local storage but service offering " + serviceOffering.getName() + " uses it");
        }
        if (diskOffering != null && diskOffering.getUseLocalStorage()) {
            throw new InvalidParameterValueException("Zone is not configured to use local storage but disk offering " + diskOffering.getName() + " uses it");
        }
    }
    String ipAddress = cmd.getIpAddress();
    String ip6Address = cmd.getIp6Address();
    String name = cmd.getName();
    String displayName = cmd.getDisplayName();
    UserVm vm = null;
    IpAddresses addrs = new IpAddresses(ipAddress, ip6Address);
    Long size = cmd.getSize();
    String group = cmd.getGroup();
    String userData = cmd.getUserData();
    String sshKeyPairName = cmd.getSSHKeyPairName();
    Boolean displayVm = cmd.getDisplayVm();
    String keyboard = cmd.getKeyboard();
    if (zone.getNetworkType() == NetworkType.Basic) {
        if (cmd.getNetworkIds() != null) {
            throw new InvalidParameterValueException("Can't specify network Ids in Basic zone");
        } else {
            vm = createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(cmd), owner, name, displayName, diskOfferingId, size, group, cmd.getHypervisor(), cmd.getHttpMethod(), userData, sshKeyPairName, cmd.getIpToNetworkMap(), addrs, displayVm, keyboard, cmd.getAffinityGroupIdList(), cmd.getDetails(), cmd.getCustomId());
        }
    } else {
        if (zone.isSecurityGroupEnabled()) {
            vm = createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, cmd.getNetworkIds(), getSecurityGroupIdList(cmd), owner, name, displayName, diskOfferingId, size, group, cmd.getHypervisor(), cmd.getHttpMethod(), userData, sshKeyPairName, cmd.getIpToNetworkMap(), addrs, displayVm, keyboard, cmd.getAffinityGroupIdList(), cmd.getDetails(), cmd.getCustomId());
        } else {
            if (cmd.getSecurityGroupIdList() != null && !cmd.getSecurityGroupIdList().isEmpty()) {
                throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone");
            }
            vm = createAdvancedVirtualMachine(zone, serviceOffering, template, cmd.getNetworkIds(), owner, name, displayName, diskOfferingId, size, group, cmd.getHypervisor(), cmd.getHttpMethod(), userData, sshKeyPairName, cmd.getIpToNetworkMap(), addrs, displayVm, keyboard, cmd.getAffinityGroupIdList(), cmd.getDetails(), cmd.getCustomId());
        }
    }
    return vm;
}
Also used : IpAddresses(com.cloud.network.Network.IpAddresses) Account(com.cloud.user.Account) UserVm(com.cloud.uservm.UserVm) DataCenter(com.cloud.dc.DataCenter) DiskOffering(com.cloud.offering.DiskOffering) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServiceOffering(com.cloud.offering.ServiceOffering)

Aggregations

DataCenter (com.cloud.dc.DataCenter)144 Account (com.cloud.user.Account)50 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)37 NetworkVO (com.cloud.network.dao.NetworkVO)33 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)32 Network (com.cloud.network.Network)30 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)27 ArrayList (java.util.ArrayList)27 DeployDestination (com.cloud.deploy.DeployDestination)25 NetworkOffering (com.cloud.offering.NetworkOffering)23 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)17 IPAddressVO (com.cloud.network.dao.IPAddressVO)17 DB (com.cloud.utils.db.DB)17 Domain (com.cloud.domain.Domain)16 ReservationContext (com.cloud.vm.ReservationContext)16 HostVO (com.cloud.host.HostVO)15 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)13 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)13 PhysicalNetwork (com.cloud.network.PhysicalNetwork)11 ServiceOffering (com.cloud.offering.ServiceOffering)11