use of net.juniper.contrail.api.types.VirtualMachine 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 net.juniper.contrail.api.types.VirtualMachine in project cloudstack by apache.
the class ServerDBSyncImpl method syncVirtualMachine.
/*
* Virtual Machine Synchronization methods
*/
public boolean syncVirtualMachine() {
final ApiConnector api = _manager.getApiConnector();
try {
List<VMInstanceVO> vmDbList = _vmInstanceDao.listAll();
@SuppressWarnings("unchecked") List<VirtualMachine> vncVmList = (List<VirtualMachine>) api.list(VirtualMachine.class, null);
s_logger.debug("sync VM: CS size: " + vmDbList.size() + " VNC size: " + vncVmList.size());
return _dbSync.syncGeneric(VirtualMachine.class, vmDbList, vncVmList);
} catch (Exception ex) {
s_logger.warn("sync virtual-machines", ex);
}
return false;
}
use of net.juniper.contrail.api.types.VirtualMachine in project cloudstack by apache.
the class VirtualMachineModel method update.
@Override
public void update(ModelController controller) throws InternalErrorException, IOException {
assert _initialized;
ApiConnector api = controller.getApiAccessor();
VirtualMachine vm = _vm;
if (vm == null) {
_vm = vm = (VirtualMachine) api.findById(VirtualMachine.class, _uuid);
if (vm == null) {
vm = new VirtualMachine();
if (_projectId != null) {
Project project;
try {
project = (Project) api.findById(Project.class, _projectId);
} catch (IOException ex) {
s_logger.debug("project read", ex);
throw new CloudRuntimeException("Failed to read project", ex);
}
vm.setParent(project);
}
vm.setName(_instanceName);
vm.setUuid(_uuid);
}
}
if (_serviceModel != null) {
vm.setServiceInstance(_serviceModel.getServiceInstance());
}
if (_vm == null) {
try {
api.create(vm);
} catch (Exception ex) {
s_logger.debug("virtual-machine create", ex);
throw new CloudRuntimeException("Failed to create virtual-machine", ex);
}
_vm = vm;
} else {
try {
api.update(vm);
} catch (IOException ex) {
s_logger.warn("virtual-machine update", ex);
throw new CloudRuntimeException("Unable to update virtual-machine object", ex);
}
}
for (ModelObject successor : successors()) {
successor.update(controller);
}
}
Aggregations