Search in sources :

Example 1 with UserVmResponse

use of com.cloud.api.response.UserVmResponse in project CloudStack-archive by CloudStack-extras.

the class KeystoreTest method testUuid.

/*    
    public void testKeystoreSave() throws Exception {
    	KeystoreVO ksVo;
    	
        ComponentLocator locator = ComponentLocator.getCurrentLocator();

        KeystoreDao ksDao = locator.getDao(KeystoreDao.class);
        ksDao.save("CPVMCertificate", "CPVMCertificate", "KeyForCertificate", "realhostip.com");
        ksVo = ksDao.findByName("CPVMCertificate");
        assertTrue(ksVo != null);
        assertTrue(ksVo.getCertificate().equals("CPVMCertificate"));
        assertTrue(ksVo.getKey().equals("KeyForCertificate"));
        assertTrue(ksVo.getDomainSuffix().equals("realhostip.com"));
        
        ksDao.save("CPVMCertificate", "CPVMCertificate Again", "KeyForCertificate Again", "again.realhostip.com");
        
        ksVo = ksDao.findByName("CPVMCertificate");
        assertTrue(ksVo != null);
        assertTrue(ksVo.getCertificate().equals("CPVMCertificate Again"));
        assertTrue(ksVo.getKey().equals("KeyForCertificate Again"));
        assertTrue(ksVo.getDomainSuffix().equals("again.realhostip.com"));
        
        ksDao.expunge(ksVo.getId());
    }
    
    public void testStripeKey() throws Exception {
    	Pattern regex = Pattern.compile("(^[\\-]+[^\\-]+[\\-]+[\\n]?)([^\\-]+)([\\-]+[^\\-]+[\\-]+$)");
    	Matcher m = regex.matcher("-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAm4bLUORp9oM65GV9XrPrbs+K563DjUR1M8mP1HaE+Y4lX5pk\nvQjC/xoEqSs5pxDDWXAkoexvxij8A4AWcsKU1Q+ep2E+GcytBoz8XINGvgb8cQNn\n/4PlVWKp7j5SDDNCfleYvmiRn8k6P4mxVJOHKzwb/IwQcKghyqAF1w==\n-----END RSA PRIVATE KEY-----");
    	if(m.find()) {
    		String content = m.group(2);
    		assertTrue(content.startsWith("MIIEpAIBAAKCAQE"));
    		assertTrue(content.endsWith("KghyqAF1w==\n"));
    	} else {
    		assertTrue(false);
    	}
    }
    
    public void testKeystoreManager() throws Exception {
        ComponentLocator locator = ComponentLocator.getCurrentLocator();
        
        KeystoreManagerImpl ksMgr = ComponentLocator.inject(KeystoreManagerImpl.class);
        assertTrue(ksMgr.configure("TaskManager", new HashMap<String, Object>()));
        assertTrue(ksMgr.start());
        
        ksMgr.saveCertificate("CPVMCertificate", certContent, keyContent, "realhostip.com");
        
        byte[] ksBits = ksMgr.getKeystoreBits("CPVMCertificate", "realhostip", "vmops.com");
        assertTrue(ksBits != null);
        
        try {
        	KeyStore ks = CertificateHelper.loadKeystore(ksBits, "vmops.com");
        	assertTrue(ks != null);
        } catch(Exception e) {
        	assertTrue(false);
        }

        KeystoreDao ksDao = locator.getDao(KeystoreDao.class);
        KeystoreVO ksVo = ksDao.findByName("CPVMCertificate");
        ksDao.expunge(ksVo.getId());
    }
*/
public void testUuid() {
    UserVmResponse vm = new UserVmResponse();
    vm.setId(3L);
    /*    	
    	vm.setAccountName("admin");
    	vm.setName("i-2-3-KY");
    	vm.setDisplayName("i-2-3-KY");
    	vm.setDomainId(1L);
    	vm.setDomainName("ROOT");
    	vm.setCreated(new Date());
    	vm.setState("Running");
    	vm.setZoneId(1L);
    	vm.setZoneName("KY");
    	vm.setHostId(1L);
    	
    	vm.setObjectName("virtualmachine");
*/
    String result = ApiSerializerHelper.toSerializedStringOld(vm);
    // String result = "com.cloud.api.response.UserVmResponse/virtualmachine/{\"id\":{\"_tableName\":\"vm_instance\",\"_value\":3},\"name\":\"i-2-3-KY\",\"displayname\":\"i-2-3-KY\",\"account\":\"admin\",\"projectid\":{\"_tableName\":\"projects\"},\"domainid\":{\"_tableName\":\"domain\",\"_value\":1},\"domain\":\"ROOT\",\"created\":\"2011-11-02T21:54:07-0700\",\"state\":\"Running\",\"haenable\":false,\"groupid\":{\"_tableName\":\"instance_group\"},\"zoneid\":{\"_tableName\":\"data_center\",\"_value\":1},\"zonename\":\"KY\",\"hostid\":{\"_tableName\":\"host\",\"_value\":1},\"hostname\":\"xenserver-basic\",\"templateid\":{\"_tableName\":\"vm_template\",\"_value\":2},\"templatename\":\"CentOS 5.3(64-bit) no GUI (XenServer)\",\"templatedisplaytext\":\"CentOS 5.3(64-bit) no GUI (XenServer)\",\"passwordenabled\":false,\"isoid\":{\"_tableName\":\"vm_template\"},\"serviceofferingid\":{\"_tableName\":\"disk_offering\",\"_value\":7},\"serviceofferingname\":\"Small Instance\",\"cpunumber\":1,\"cpuspeed\":500,\"memory\":512,\"guestosid\":{\"_tableName\":\"guest_os\",\"_value\":12},\"rootdeviceid\":0,\"rootdevicetype\":\"NetworkFilesystem\",\"securitygroup\":[],\"jobid\":{\"_tableName\":\"async_job\"},\"nic\":[{\"id\":7,\"networkid\":200,\"netmask\":\"255.255.255.0\",\"gateway\":\"10.1.1.1\",\"ipaddress\":\"10.1.1.116\",\"isolationuri\":\"vlan://1699\",\"broadcasturi\":\"vlan://1699\",\"traffictype\":\"Guest\",\"type\":\"Virtual\",\"isdefault\":true,\"macaddress\":\"02:00:39:a7:00:01\"}],\"hypervisor\":\"XenServer\"}";
    System.out.println(result);
    //Object obj = ApiSerializerHelper.fromSerializedString(result);
    AlertResponse alert = new AlertResponse();
    alert.setId(100L);
    alert.setDescription("Hello");
    result = ApiSerializerHelper.toSerializedStringOld(alert);
    System.out.println(result);
    ApiSerializerHelper.fromSerializedString(result);
}
Also used : AlertResponse(com.cloud.api.response.AlertResponse) UserVmResponse(com.cloud.api.response.UserVmResponse)

Example 2 with UserVmResponse

use of com.cloud.api.response.UserVmResponse in project CloudStack-archive by CloudStack-extras.

the class RebootVMCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException {
    UserContext.current().setEventDetails("Vm Id: " + getId());
    UserVm result;
    if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
        result = _bareMetalVmService.rebootVirtualMachine(this);
    } else {
        result = _userVmService.rebootVirtualMachine(this);
    }
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to reboot vm instance");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) UserVmResponse(com.cloud.api.response.UserVmResponse)

Example 3 with UserVmResponse

use of com.cloud.api.response.UserVmResponse in project CloudStack-archive by CloudStack-extras.

the class RecoverVMCmd method execute.

@Override
public void execute() throws ResourceAllocationException {
    UserVm result = _userVmService.recoverVirtualMachine(this);
    if (result != null) {
        UserVmResponse recoverVmResponse = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
        recoverVmResponse.setResponseName(getCommandName());
        this.setResponseObject(recoverVmResponse);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to recover vm");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) UserVmResponse(com.cloud.api.response.UserVmResponse)

Example 4 with UserVmResponse

use of com.cloud.api.response.UserVmResponse in project CloudStack-archive by CloudStack-extras.

the class UpdateVMCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("Vm Id: " + getId());
    UserVm result = _userVmService.updateVirtualMachine(this);
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update vm");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) UserVmResponse(com.cloud.api.response.UserVmResponse)

Example 5 with UserVmResponse

use of com.cloud.api.response.UserVmResponse in project CloudStack-archive by CloudStack-extras.

the class UpgradeVMCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("Vm Id: " + getId());
    ServiceOffering serviceOffering = _configService.getServiceOffering(serviceOfferingId);
    if (serviceOffering == null) {
        throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
    }
    UserVm result = _userVmService.upgradeVirtualMachine(this);
    if (result != null) {
        UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", result).get(0);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to upgrade vm");
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) ServerApiException(com.cloud.api.ServerApiException) ServiceOffering(com.cloud.offering.ServiceOffering) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UserVmResponse(com.cloud.api.response.UserVmResponse)

Aggregations

UserVmResponse (com.cloud.api.response.UserVmResponse)15 ServerApiException (com.cloud.api.ServerApiException)14 UserVm (com.cloud.uservm.UserVm)14 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 AlertResponse (com.cloud.api.response.AlertResponse)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 ManagementServerException (com.cloud.exception.ManagementServerException)1 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)1 VirtualMachineMigrationException (com.cloud.exception.VirtualMachineMigrationException)1 Host (com.cloud.host.Host)1 ServiceOffering (com.cloud.offering.ServiceOffering)1 StoragePool (com.cloud.storage.StoragePool)1 ExecutionException (com.cloud.utils.exception.ExecutionException)1 VirtualMachine (com.cloud.vm.VirtualMachine)1