use of org.apache.cloudstack.network.contrail.model.VirtualMachineModel in project cloudstack by apache.
the class ContrailElementImpl method release.
@Override
public boolean release(Network network, NicProfile nicProfile, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
if (network.getTrafficType() == TrafficType.Guest) {
return true;
} else if (!_manager.isManagedPhysicalNetwork(network)) {
s_logger.debug("release ignore network " + network.getId());
return true;
}
NicVO nic = _nicDao.findById(nicProfile.getId());
assert nic != null;
VirtualMachineModel vmModel = _manager.getDatabase().lookupVirtualMachine(vm.getUuid());
if (vmModel == null) {
s_logger.debug("vm " + vm.getInstanceName() + " not in local database");
return true;
}
VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid());
if (vmiModel != null) {
try {
vmiModel.destroy(_manager.getModelController());
} catch (IOException ex) {
s_logger.warn("virtual-machine-interface delete", ex);
}
vmModel.removeSuccessor(vmiModel);
}
if (!vmModel.hasDescendents()) {
_manager.getDatabase().getVirtualMachines().remove(vmModel);
try {
vmModel.delete(_manager.getModelController());
} catch (IOException e) {
return false;
}
}
return true;
}
use of org.apache.cloudstack.network.contrail.model.VirtualMachineModel in project cloudstack by apache.
the class ServerDBSyncImpl method createVirtualMachine.
public void createVirtualMachine(VMInstanceVO dbVm, StringBuffer syncLogMesg) throws IOException {
syncLogMesg.append("VM# DB: " + dbVm.getInstanceName() + "/" + dbVm.getUuid() + "; VNC: none; action: create\n");
VirtualMachineModel vmModel = new VirtualMachineModel(dbVm, dbVm.getUuid());
vmModel.build(_manager.getModelController(), dbVm);
buildNicResources(vmModel, dbVm, syncLogMesg);
if (_rwMode) {
try {
vmModel.update(_manager.getModelController());
} catch (InternalErrorException ex) {
s_logger.warn("create virtual-machine", ex);
return;
}
_manager.getDatabase().getVirtualMachines().add(vmModel);
syncLogMesg.append("VM# VNC: " + dbVm.getUuid() + " created\n");
}
}
use of org.apache.cloudstack.network.contrail.model.VirtualMachineModel in project cloudstack by apache.
the class ServerDBSyncImpl method equalVirtualMachine.
public Boolean equalVirtualMachine(VMInstanceVO dbVm, VirtualMachine vncVm, StringBuffer syncLogMsg) {
syncLogMsg.append("VM# DB: " + dbVm.getInstanceName() + "/" + dbVm.getUuid() + "; VNC: " + vncVm.getUuid() + "; action: equal; DB VM State: " + dbVm.getState() + "\n");
VirtualMachineModel vmModel = new VirtualMachineModel(dbVm, dbVm.getUuid());
vmModel.build(_manager.getModelController(), dbVm);
if (vmModel.isActive()) {
try {
buildNicResources(vmModel, dbVm, syncLogMsg);
} catch (IOException ex) {
s_logger.warn("build nic information for " + dbVm.getInstanceName(), ex);
}
}
VirtualMachineModel current = _manager.getDatabase().lookupVirtualMachine(vncVm.getUuid());
if (_rwMode) {
if (current != null) {
_manager.getDatabase().getVirtualMachines().remove(current);
}
_manager.getDatabase().getVirtualMachines().add(vmModel);
try {
vmModel.update(_manager.getModelController());
} catch (Exception ex) {
s_logger.warn("update virtual-machine", ex);
}
} else {
//compare
if (current != null && current.compare(_manager.getModelController(), vmModel) == false) {
syncLogMsg.append("VM # DB: " + dbVm.getInstanceName() + "; VNC: " + vncVm.getName() + "; attributes differ\n");
return false;
}
}
return true;
}
Aggregations