Package com.cloud.bridge.model

Examples of com.cloud.bridge.model.CloudStackServiceOfferingVO


            //find CS service Offering ID
            String instanceType = "m1.small";
            if(request.getInstanceType() != null){
                instanceType = request.getInstanceType();
            }
            CloudStackServiceOfferingVO svcOffering = getCSServiceOfferingId(instanceType);
            if(svcOffering == null){
                logger.info("No ServiceOffering found to be defined by name, please contact the administrator "+instanceType );
                throw new Exception("instanceType not found");
            }

            // zone stuff
            String zoneId = toZoneId(request.getZoneName(), null);

            List<CloudStackZone> zones = getApi().listZones(null, null, zoneId, null);
            if (zones == null || zones.size() == 0) {
                logger.info("EC2 RunInstances - zone [" + request.getZoneName() + "] not found!");
                throw new Exception("zone not found");
            }
            // we choose first zone?
            CloudStackZone zone = zones.get(0);

            // network
            //CloudStackNetwork network = findNetwork(zone);

            // for EC2 security groups either a group ID or a group name is accepted
            String[] sgIdList = request.getSecurityGroupIdSet();
            String[] sgNameList = request.getSecurityGroupNameSet();
            if (sgIdList.length != 0 && sgNameList.length != 0)
                throw new EC2ServiceException(ClientError.InvalidParameterCombination,
                        " for EC2 groups either a group ID or a group name is accepted");

            if (sgIdList.length != 0)
                groupIds = constructList(sgIdList);
            if (sgNameList.length != 0)
                groupNames = constructList(sgNameList);

            // now actually deploy the vms
            for( int i=0; i < createInstances; i++ ) {
                try{
                    CloudStackUserVm resp = getApi().deployVirtualMachine(svcOffering.getId(),
                            request.getTemplateId(), zoneId, null, null, null, null,
                            null, null, null, request.getKeyName(), null, null,
                            groupIds, groupNames, request.getSize().longValue(), request.getUserData());
                    EC2Instance vm = new EC2Instance();
                    vm.setId(resp.getId().toString());
                    vm.setName(resp.getName());
                    vm.setZoneName(resp.getZoneName());
                    vm.setTemplateId(resp.getTemplateId().toString());
                    if (resp.getSecurityGroupList() != null && resp.getSecurityGroupList().size() > 0) {
                        List<CloudStackSecurityGroup> securityGroupList = resp.getSecurityGroupList();
                        for (CloudStackSecurityGroup securityGroup : securityGroupList) {
                            EC2SecurityGroup param = new EC2SecurityGroup();
                            param.setId(securityGroup.getId());
                            param.setName(securityGroup.getName());
                            vm.addGroupName(param);
                        }
                    }
                    vm.setState(resp.getState());
                    vm.setCreated(resp.getCreated());
                    List <CloudStackNic> nicList = resp.getNics();
                    for (CloudStackNic nic : nicList) {
                        if (nic.getIsDefault()) {
                            vm.setPrivateIpAddress(nic.getIpaddress());
                            break;
                        }
                    }
                    vm.setIpAddress(resp.getIpAddress());
                    vm.setAccountName(resp.getAccountName());
                    vm.setDomainId(resp.getDomainId());
                    vm.setHypervisor( mapToAmazonHypervisorType(resp.getHypervisor()) );
                    vm.setServiceOffering( svcOffering.getName());
                    vm.setKeyPairName(resp.getKeyPairName());
                    instances.addInstance(vm);
                    countCreated++;
                }catch(Exception e){
                    logger.error("Failed to deploy VM number: "+ (i+1) +" due to error: "+e.getMessage());
View Full Code Here


                throw new Exception("Cannot modify, instance should be in stopped state");
            }

            if (request.getInstanceType() != null) {
                String instanceType = request.getInstanceType();
                CloudStackServiceOfferingVO svcOffering = getCSServiceOfferingId(instanceType);
                if (svcOffering == null)
                    throw new Exception("instanceType not found");
                CloudStackUserVm userVm = getApi().changeServiceForVirtualMachine(instanceId, svcOffering.getId());
                status = (userVm != null);
            }
            if (status != false && request.getUserData() != null) {
                CloudStackUserVm userVm = getApi().updateVirtualMachine(instanceId, null, null, null,
                        null, request.getUserData());
View Full Code Here

     * @throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException
     */
    private String serviceOfferingIdToInstanceType( String serviceOfferingId ) throws Exception {
        try{

            CloudStackServiceOfferingVO offering =  scvoDao.getSvcOfferingById(serviceOfferingId);
            if(offering == null){
                logger.warn( "No instanceType match for serviceOfferingId: [" + serviceOfferingId + "]" );
                return "m1.small";
            }
            return offering.getName();
        }
        catch(Exception e) {
            logger.error( "Error while retrieving ServiceOffering information by id - ", e);
            throw new Exception( e.getMessage() != null ? e.getMessage() : e.toString() );
        }
View Full Code Here

     * @throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException
     */
    private String serviceOfferingIdToInstanceType(String serviceOfferingId) throws Exception {
        try {

            CloudStackServiceOfferingVO offering = scvoDao.getSvcOfferingById(serviceOfferingId);
            if (offering == null) {
                logger.warn("No instanceType match for serviceOfferingId: [" + serviceOfferingId + "]");
                return "m1.small";
            }
            return offering.getName();
        } catch (Exception e) {
            logger.error("Error while retrieving ServiceOffering information by id - ", e);
            throw new Exception(e.getMessage() != null ? e.getMessage() : e.toString());
        }
    }
View Full Code Here

            //find CS service Offering ID
            String instanceType = "m1.small";
            if(request.getInstanceType() != null){
                instanceType = request.getInstanceType();
            }
            CloudStackServiceOfferingVO svcOffering = getCSServiceOfferingId(instanceType);
            if(svcOffering == null){
                logger.info("No ServiceOffering found to be defined by name, please contact the administrator "+instanceType );
                throw new EC2ServiceException(ClientError.Unsupported, "instanceType: [" + instanceType + "] not found!");
            }

            // zone stuff
            String zoneId = toZoneId(request.getZoneName(), null);

            List<CloudStackZone> zones = getApi().listZones(null, null, zoneId, null);
            if (zones == null || zones.size() == 0) {
                logger.info("EC2 RunInstances - zone [" + request.getZoneName() + "] not found!");
                throw new EC2ServiceException(ClientError.InvalidZone_NotFound, "ZoneId [" + request.getZoneName() + "] not found!");
            }
            // we choose first zone?
            CloudStackZone zone = zones.get(0);

            // network
            CloudStackNetwork network = findNetwork(zone);

            // now actually deploy the vms
            for( int i=0; i < createInstances; i++ ) {
                try{
                    CloudStackUserVm resp = getApi().deployVirtualMachine(svcOffering.getId(),
                            request.getTemplateId(), zoneId, null, null, null, null,
                            null, null, null, request.getKeyName(), null, (network != null ? network.getId() : null),
                            null, constructList(request.getGroupSet()), request.getSize().longValue(), request.getUserData());
                    EC2Instance vm = new EC2Instance();
                    vm.setId(resp.getId().toString());
                    vm.setName(resp.getName());
                    vm.setZoneName(resp.getZoneName());
                    vm.setTemplateId(resp.getTemplateId().toString());
                    if (resp.getSecurityGroupList() != null && resp.getSecurityGroupList().size() > 0) {
                        List<CloudStackSecurityGroup> securityGroupList = resp.getSecurityGroupList();
                        for (CloudStackSecurityGroup securityGroup : securityGroupList) {
                            EC2SecurityGroup param = new EC2SecurityGroup();
                            param.setId(securityGroup.getId());
                            param.setName(securityGroup.getName());
                            vm.addGroupName(param);
                        }
                    }
                    vm.setState(resp.getState());
                    vm.setCreated(resp.getCreated());
                    List <CloudStackNic> nicList = resp.getNics();
                    for (CloudStackNic nic : nicList) {
                        if (nic.getIsDefault()) {
                            vm.setPrivateIpAddress(nic.getIpaddress());
                            break;
                        }
                    }
                    vm.setIpAddress(resp.getIpAddress());
                    vm.setAccountName(resp.getAccountName());
                    vm.setDomainId(resp.getDomainId());
                    vm.setHypervisor(resp.getHypervisor());
                    vm.setServiceOffering( svcOffering.getName());
                    vm.setKeyPairName(resp.getKeyPairName());
                    instances.addInstance(vm);
                    countCreated++;
                }catch(Exception e){
                    logger.error("Failed to deploy VM number: "+ (i+1) +" due to error: "+e.getMessage());
View Full Code Here

     * @throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException
     */
    private String serviceOfferingIdToInstanceType( String serviceOfferingId ){ 
        try{

            CloudStackServiceOfferingVO offering =  scvoDao.getSvcOfferingById(serviceOfferingId);
            if(offering == null){
                logger.warn( "No instanceType match for serviceOfferingId: [" + serviceOfferingId + "]" );
                return "m1.small";
            }
            return offering.getName();
        }
        catch(Exception e) {
            logger.error( "sError while retrieving ServiceOffering information by id - ", e);
            throw new EC2ServiceException(ServerError.InternalError, e.getMessage());
        }
View Full Code Here

      //find CS service Offering ID
      String instanceType = "m1.small";
      if(request.getInstanceType() != null){
          instanceType = request.getInstanceType();
      }
      CloudStackServiceOfferingVO svcOffering = getCSServiceOfferingId(instanceType);
      if(svcOffering == null){
          logger.info("No ServiceOffering found to be defined by name, please contact the administrator "+instanceType );
          throw new EC2ServiceException(ClientError.Unsupported, "instanceType: [" + instanceType + "] not found!");
      }
     
      // zone stuff
      String zoneId = toZoneId(request.getZoneName(), null);
     
      List<CloudStackZone> zones = getApi().listZones(null, null, zoneId, null);
      if (zones == null || zones.size() == 0) {
        logger.info("EC2 RunInstances - zone [" + request.getZoneName() + "] not found!");
        throw new EC2ServiceException(ClientError.InvalidZone_NotFound, "ZoneId [" + request.getZoneName() + "] not found!");
      }
      // we choose first zone?
      CloudStackZone zone = zones.get(0);

      // network
      CloudStackNetwork network = findNetwork(zone);

      // now actually deploy the vms
      for( int i=0; i < createInstances; i++ ) {
        CloudStackUserVm resp = getApi().deployVirtualMachine(svcOffering.getId(),
            request.getTemplateId(), zoneId, null, null, null, null,
            null, null, null, request.getKeyName(), null, (network != null ? network.getId() : null),
            null, constructList(request.getGroupSet()), request.getSize().longValue(), request.getUserData());
        EC2Instance vm = new EC2Instance();
        vm.setId(resp.getId().toString());
        vm.setName(resp.getName());
        vm.setZoneName(resp.getZoneName());
        vm.setTemplateId(resp.getTemplateId().toString());
        if (resp.getSecurityGroupList() != null && resp.getSecurityGroupList().size() > 0) {
          // TODO, we have a list of security groups, just return the first one?
                    List<CloudStackSecurityGroup> securityGroupList = resp.getSecurityGroupList();
                    for (CloudStackSecurityGroup securityGroup : securityGroupList) {
                        vm.addGroupName(securityGroup.getName());
                    }
                }
        vm.setState(resp.getState());
        vm.setCreated(resp.getCreated());
                List <CloudStackNic> nicList = resp.getNics();
                for (CloudStackNic nic : nicList) {
                    if (nic.getIsDefault()) {
                        vm.setPrivateIpAddress(nic.getIpaddress());
                        break;
                    }
                }
                vm.setIpAddress(resp.getIpAddress());
        vm.setAccountName(resp.getAccountName());
        vm.setDomainId(resp.getDomainId());
        vm.setHypervisor(resp.getHypervisor());
        vm.setServiceOffering( svcOffering.getName());
                vm.setKeyPairName(resp.getKeyPairName());
        instances.addInstance(vm);
        countCreated++;
      }       
View Full Code Here

   * @throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException
   */
  private String serviceOfferingIdToInstanceType( String serviceOfferingId ){ 
        try{
           
            CloudStackServiceOfferingVO offering =  scvoDao.getSvcOfferingById(serviceOfferingId); //dao.getSvcOfferingById(serviceOfferingId);
            if(offering == null){
                logger.warn( "No instanceType match for serviceOfferingId: [" + serviceOfferingId + "]" );
                return "m1.small";
            }
            return offering.getName();
        }
        catch(Exception e) {
            logger.error( "sError while retrieving ServiceOffering information by id - ", e);
            throw new EC2ServiceException(ServerError.InternalError, e.getMessage());
        }
View Full Code Here

            //find CS service Offering ID
            String instanceType = "m1.small";
            if(request.getInstanceType() != null){
                instanceType = request.getInstanceType();
            }
            CloudStackServiceOfferingVO svcOffering = getCSServiceOfferingId(instanceType);
            if(svcOffering == null){
                logger.info("No ServiceOffering found to be defined by name, please contact the administrator "+instanceType );
                throw new Exception("instanceType not found");
            }

            // zone stuff
            String zoneId = toZoneId(request.getZoneName(), null);

            List<CloudStackZone> zones = getApi().listZones(null, null, zoneId, null);
            if (zones == null || zones.size() == 0) {
                logger.info("EC2 RunInstances - zone [" + request.getZoneName() + "] not found!");
                throw new Exception("zone not found");
            }
            // we choose first zone?
            CloudStackZone zone = zones.get(0);

            // network
            //CloudStackNetwork network = findNetwork(zone);

            // for EC2 security groups either a group ID or a group name is accepted
            String[] sgIdList = request.getSecurityGroupIdSet();
            String[] sgNameList = request.getSecurityGroupNameSet();
            if (sgIdList.length != 0 && sgNameList.length != 0)
                throw new EC2ServiceException(ClientError.InvalidParameterCombination,
                        " for EC2 groups either a group ID or a group name is accepted");

            if (sgIdList.length != 0)
                groupIds = constructList(sgIdList);
            if (sgNameList.length != 0)
                groupNames = constructList(sgNameList);

            // now actually deploy the vms
            for( int i=0; i < createInstances; i++ ) {
                try{
                    CloudStackUserVm resp = getApi().deployVirtualMachine(svcOffering.getId(),
                            request.getTemplateId(), zoneId, null, null, null, null,
                            null, null, null, request.getKeyName(), null, null,
                            groupIds, groupNames, request.getSize().longValue(), request.getUserData());
                    EC2Instance vm = new EC2Instance();
                    vm.setId(resp.getId().toString());
                    vm.setName(resp.getName());
                    vm.setZoneName(resp.getZoneName());
                    vm.setTemplateId(resp.getTemplateId().toString());
                    if (resp.getSecurityGroupList() != null && resp.getSecurityGroupList().size() > 0) {
                        List<CloudStackSecurityGroup> securityGroupList = resp.getSecurityGroupList();
                        for (CloudStackSecurityGroup securityGroup : securityGroupList) {
                            EC2SecurityGroup param = new EC2SecurityGroup();
                            param.setId(securityGroup.getId());
                            param.setName(securityGroup.getName());
                            vm.addGroupName(param);
                        }
                    }
                    vm.setState(resp.getState());
                    vm.setCreated(resp.getCreated());
                    List <CloudStackNic> nicList = resp.getNics();
                    for (CloudStackNic nic : nicList) {
                        if (nic.getIsDefault()) {
                            vm.setPrivateIpAddress(nic.getIpaddress());
                            break;
                        }
                    }
                    vm.setIpAddress(resp.getIpAddress());
                    vm.setAccountName(resp.getAccountName());
                    vm.setDomainId(resp.getDomainId());
                    vm.setHypervisor( mapToAmazonHypervisorType(resp.getHypervisor()) );
                    vm.setServiceOffering( svcOffering.getName());
                    vm.setKeyPairName(resp.getKeyPairName());
                    instances.addInstance(vm);
                    countCreated++;
                }catch(Exception e){
                    logger.error("Failed to deploy VM number: "+ (i+1) +" due to error: "+e.getMessage());
View Full Code Here

                throw new Exception("Cannot modify, instance should be in stopped state");
            }

            if (request.getInstanceType() != null) {
                String instanceType = request.getInstanceType();
                CloudStackServiceOfferingVO svcOffering = getCSServiceOfferingId(instanceType);
                if (svcOffering == null)
                    throw new Exception("instanceType not found");
                CloudStackUserVm userVm = getApi().changeServiceForVirtualMachine(instanceId, svcOffering.getId());
                status = (userVm != null);
            }
            if (status != false && request.getUserData() != null) {
                CloudStackUserVm userVm = getApi().updateVirtualMachine(instanceId, null, null, null,
                        null, request.getUserData());
View Full Code Here

TOP

Related Classes of com.cloud.bridge.model.CloudStackServiceOfferingVO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.