Examples of CloudStackUserVm


Examples of com.cloud.stack.models.CloudStackUserVm

            List<CloudStackUserVm> vmList = getApi().listVirtualMachines(null, null, true, null, null, null, null,
                    request.getInstanceId(), null, null, null, null, null, null, null, null, null);
            if (vmList == null || vmList.size() == 0) {
                throw new Exception("Instance not found");
            }
            CloudStackUserVm cloudVm = vmList.get(0);

            CloudStackInfoResponse resp = getApi().enableStaticNat(cloudIp.getId(), cloudVm.getId());
            if (resp != null) {
                return resp.getSuccess();
            }
        } catch(Exception e) {
            logger.error( "EC2 AssociateAddress - ", e);
View Full Code Here

Examples of com.cloud.stack.models.CloudStackUserVm

            // -> send reboot requests for each found VM
            for (EC2Instance vm : vms) {
                if (vm.getState().equalsIgnoreCase( "Destroyed" )) continue;

                CloudStackUserVm resp = getApi().rebootVirtualMachine(vm.getId());
                if (logger.isDebugEnabled())
                    logger.debug("Rebooting VM " + resp.getId() + " job " + resp.getJobId());
            }

            // -> if some specified VMs where not found we have to tell the caller
            if (instanceSet.length != vms.length)
                throw new Exception("One or more instanceIds do not exist, other instances rebooted.");
View Full Code Here

Examples of com.cloud.stack.models.CloudStackUserVm

                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());
                    break;
View Full Code Here

Examples of com.cloud.stack.models.CloudStackUserVm

                if (vm.getState().equalsIgnoreCase( "Running" ) || vm.getState().equalsIgnoreCase( "Destroyed" )) {
                    instances.addInstance(vm);
                    continue;
                }

                CloudStackUserVm resp = getApi().startVirtualMachine(vm.getId());
                if(resp != null){
                    vm.setState(resp.getState());
                    if(logger.isDebugEnabled())
                        logger.debug("Starting VM " + vm.getId() + " job " + resp.getJobId());
                }
                instances.addInstance(vm);
            }
        } catch( Exception e ) {
            logger.error( "EC2 StartInstances - ", e);
View Full Code Here

Examples of com.cloud.stack.models.CloudStackUserVm

            virtualMachines = previousState.getInstanceSet();

            // -> send stop requests for each item
            for (EC2Instance vm : virtualMachines) {
                vm.setPreviousState( vm.getState());
                CloudStackUserVm resp = null;
                if (request.getDestroyInstances()) {
                    if (vm.getState().equalsIgnoreCase( "Destroyed" )) {
                        instances.addInstance(vm);
                        continue;
                    }
                    resp = getApi().destroyVirtualMachine(vm.getId());
                    if(logger.isDebugEnabled())
                        logger.debug("Destroying VM " + vm.getId() + " job " + resp.getJobId());
                } else {
                    if (vm.getState().equalsIgnoreCase("Stopped") || vm.getState().equalsIgnoreCase("Destroyed")) {
                        instances.addInstance(vm);
                        continue;
                    }
                    resp = getApi().stopVirtualMachine(vm.getId(), forced);
                    if(logger.isDebugEnabled())
                        logger.debug("Stopping VM " + vm.getId() + " job " + resp.getJobId());
                }
                if (resp != null) {
                    vm.setState(resp.getState());
                    instances.addInstance(vm);
                }
            }
        } catch( Exception e ) {
            logger.error( "EC2 StopInstances - ", e);
View Full Code Here

Examples of com.cloud.stack.models.CloudStackUserVm

            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());
                status = (userVm != null);
            }
        } catch (Exception e) {
            logger.error("ModifyInstanceAttribute - ", e);
View Full Code Here

Examples of com.cloud.stack.models.CloudStackUserVm

     * @return
     * @throws Exception
     */
    private boolean stopVirtualMachine( String instanceId) throws Exception {
        try {
            CloudStackUserVm resp = getApi().stopVirtualMachine(instanceId, false);
            if (logger.isDebugEnabled())
                logger.debug("Stopping VM " + instanceId );
            return resp != null;
        } catch(Exception e) {
            logger.error( "StopVirtualMachine - ", e);
View Full Code Here

Examples of com.cloud.stack.models.CloudStackUserVm

     * @return
     * @throws Exception
     */
    private boolean startVirtualMachine( String instanceId ) throws Exception {
        try {
            CloudStackUserVm resp = getApi().startVirtualMachine(instanceId);
            if (logger.isDebugEnabled())
                logger.debug("Starting VM " + instanceId );
            return resp != null;
        } catch(Exception e) {
            logger.error("StartVirtualMachine - ", e);
View Full Code Here

Examples of com.cloud.stack.models.CloudStackUserVm

      CloudStackClient client = new CloudStackClient("192.168.130.22", 8080, false);

    CloudStackCommand command = new CloudStackCommand("startVirtualMachine");
    command.setParam("id", "246446");
    try {
      CloudStackUserVm vm = client.call(command, API_KEY, SECRET_KEY, true, "startvirtualmachineresponse", "virtualmachine", CloudStackUserVm.class);
      Assert.assertTrue(vm.getId() == "246446");
    } catch(Exception e) {
      logger.error("Unexpected exception ", e);
    }
    }
View Full Code Here

Examples of com.cloud.stack.models.CloudStackUserVm

        CloudStackClient client = new CloudStackClient("192.168.130.22", 8080, false);

        CloudStackCommand command = new CloudStackCommand("startVirtualMachine");
        command.setParam("id", "246446");
        try {
            CloudStackUserVm vm = client.call(command, API_KEY, SECRET_KEY, true, "startvirtualmachineresponse", "virtualmachine", CloudStackUserVm.class);
            Assert.assertTrue(vm.getId() == "246446");
        } catch (Exception e) {
            logger.error("Unexpected exception ", e);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.