use of com.cloud.uservm.UserVm in project CloudStack-archive by CloudStack-extras.
the class AttachIsoCmd method execute.
@Override
public void execute() {
UserContext.current().setEventDetails("Vm Id: " + getVirtualMachineId() + " ISO Id: " + getId());
boolean result = _templateService.attachIso(id, virtualMachineId);
if (result) {
UserVm userVm = _responseGenerator.findUserVmById(virtualMachineId);
if (userVm != null) {
UserVmResponse response = _responseGenerator.createUserVmResponse("virtualmachine", userVm).get(0);
response.setResponseName(DeployVMCmd.getResultObjectName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to attach iso");
}
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to attach iso");
}
}
use of com.cloud.uservm.UserVm in project cloudstack by apache.
the class NetworkProviderTest method dbSyncTest.
@Test
public void dbSyncTest() {
Network network = lookupTestNetwork("test-db-only-net");
if (network == null) {
network = createTestNetwork("test-db-only-net");
}
UserVm vm = _server.createVM("test-db-only-vm", network);
try {
createFloatingIp(network, vm);
} catch (Exception e) {
fail("unable to create floating ip");
}
/* reset ApiServer objects to default config only, so above created objects
* exists only in cludstack db but not in api server
*/
((ApiConnectorMock) _api).initConfig();
/* reset model cached objects */
_contrailMgr.getDatabase().initDb();
/* Create one object of each type directly in api-server - these objects does not exist in cloudstack */
net.juniper.contrail.api.types.Domain domain = new net.juniper.contrail.api.types.Domain();
domain.setName("test-vnc-only-domain--1");
domain.setUuid(UUID.randomUUID().toString());
try {
assertTrue(_api.create(domain));
} catch (IOException ex) {
fail(ex.getMessage());
}
Project project = new Project();
project.setName("test-vnc-only-project-1");
project.setUuid(UUID.randomUUID().toString());
project.setParent(domain);
try {
assertTrue(_api.create(project));
} catch (IOException ex) {
fail(ex.getMessage());
}
VirtualNetwork net = new VirtualNetwork();
net.setName("test-vnc-only-net-1");
net.setUuid(UUID.randomUUID().toString());
net.setParent(project);
NetworkIpam ipam = null;
try {
// Find default-network-ipam
String ipam_id = _api.findByName(NetworkIpam.class, null, "default-network-ipam");
assertNotNull(ipam_id);
ipam = (NetworkIpam) _api.findById(NetworkIpam.class, ipam_id);
assertNotNull(ipam);
} catch (IOException ex) {
fail(ex.getMessage());
}
VnSubnetsType subnet = new VnSubnetsType();
subnet.addIpamSubnets(new SubnetType("10.0.2.0", 24), "10.0.2.254");
net.addNetworkIpam(ipam, subnet);
VirtualMachine vncVm = new VirtualMachine();
vncVm.setName("test-vnc-only-vm-1");
try {
assertTrue(_api.create(vncVm));
} catch (IOException ex) {
fail(ex.getMessage());
}
VirtualMachineInterface vmi = new VirtualMachineInterface();
vmi.setParent(vncVm);
vmi.setName("test-vnc-only-vmi-1");
try {
assertTrue(_api.create(vmi));
assertTrue(_api.create(net));
} catch (IOException ex) {
fail(ex.getMessage());
}
InstanceIp ip_obj = new InstanceIp();
ip_obj.setName(net.getName() + ":0");
ip_obj.setVirtualNetwork(net);
ip_obj.setVirtualMachineInterface(vmi);
try {
assertTrue(_api.create(ip_obj));
// Must perform a GET in order to update the object contents.
assertTrue(_api.read(ip_obj));
assertNotNull(ip_obj.getAddress());
} catch (IOException ex) {
fail(ex.getMessage());
}
//now db sync
if (_dbSync.syncAll(DBSyncGeneric.SYNC_MODE_UPDATE) == ServerDBSync.SYNC_STATE_OUT_OF_SYNC) {
s_logger.info("# Cloudstack DB & VNC are out of sync - resync done");
}
if (_dbSync.syncAll(DBSyncGeneric.SYNC_MODE_CHECK) == ServerDBSync.SYNC_STATE_OUT_OF_SYNC) {
s_logger.info("# Cloudstack DB & VNC are still out of sync");
fail("DB Sync failed");
}
}
use of com.cloud.uservm.UserVm in project cloudstack by apache.
the class UserVmJoinDaoImpl method newUserVmView.
@Override
public List<UserVmJoinVO> newUserVmView(UserVm... userVms) {
Hashtable<Long, UserVm> userVmDataHash = new Hashtable<Long, UserVm>();
for (UserVm vm : userVms) {
if (!userVmDataHash.containsKey(vm.getId())) {
userVmDataHash.put(vm.getId(), vm);
}
}
Set<Long> vmIdSet = userVmDataHash.keySet();
List<UserVmJoinVO> uvms = searchByIds(vmIdSet.toArray(new Long[vmIdSet.size()]));
// populate transit password field from UserVm
if (uvms != null) {
for (UserVmJoinVO uvm : uvms) {
UserVm v = userVmDataHash.get(uvm.getId());
uvm.setPassword(v.getPassword());
}
}
return uvms;
}
use of com.cloud.uservm.UserVm in project cloudstack by apache.
the class ScaleVMCmdTest method testCreateSuccess.
@Test
public void testCreateSuccess() {
UserVmService userVmService = Mockito.mock(UserVmService.class);
UserVm userVm = Mockito.mock(UserVm.class);
try {
Mockito.when(userVmService.upgradeVirtualMachine(scaleVMCmd)).thenReturn(userVm);
} catch (Exception e) {
Assert.fail("Received exception when success expected " + e.getMessage());
}
ResponseGenerator responseGenerator = Mockito.mock(ResponseGenerator.class);
scaleVMCmd._responseGenerator = responseGenerator;
UserVmResponse userVmResponse = Mockito.mock(UserVmResponse.class);
//List<UserVmResponse> list = Mockito.mock(UserVmResponse.class);
//list.add(userVmResponse);
//LinkedList<UserVmResponse> mockedList = Mockito.mock(LinkedList.class);
//Mockito.when(mockedList.get(0)).thenReturn(userVmResponse);
List<UserVmResponse> list = new LinkedList<UserVmResponse>();
list.add(userVmResponse);
Mockito.when(responseGenerator.createUserVmResponse(ResponseView.Restricted, "virtualmachine", userVm)).thenReturn(list);
scaleVMCmd._userVmService = userVmService;
scaleVMCmd.execute();
}
use of com.cloud.uservm.UserVm in project cloudstack by apache.
the class VirtualMachineModel method build.
/**
* Resynchronize internal state from the cloudstack DB object.
* @param instance
*/
public void build(ModelController controller, VMInstanceVO instance) {
setProperties(controller, instance);
UserVm userVm = controller.getVmDao().findById(instance.getId());
if (userVm != null && userVm.getUserData() != null) {
s_logger.debug("vm " + instance.getInstanceName() + " user data: " + userVm.getUserData());
final Gson json = new Gson();
Map<String, String> kvmap = json.fromJson(userVm.getUserData(), new TypeToken<Map<String, String>>() {
}.getType());
//Renamed "data" to "serviceUuid" because it's clearer.
String serviceUuid = kvmap.get("service-instance");
if (serviceUuid != null) {
/*
* UUID.fromString() does not validate an UUID properly. I tried, for example, informing less digits in the UUID, where 12 were expected,
* and the UUID.fromstring() did not thrown the exception as expected. However, if you try UUID.fromString("aaa") it breaks, but if you try
* UUID.fromString("3dd4fa6e-2899-4429-b818-d34fe8df5") it doesn't (the last portion should have 12, instead of 9 digits).
*
* In other fix I added the validate UUID method to the UuidUtil classes.
*/
if (UuidUtils.validateUUID(serviceUuid)) {
/* link the object with the service instance */
buildServiceInstance(controller, serviceUuid);
} else {
// Throw a CloudRuntimeException in case the UUID is not valid.
String message = "Invalid UUID ({0}) given for the service-instance for VM {1}.";
message = MessageFormat.format(message, instance.getId(), serviceUuid);
s_logger.warn(message);
throw new CloudRuntimeException(message);
}
}
}
}
Aggregations