Search in sources :

Example 6 with VirtualMachineModel

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;
}
Also used : VMInterfaceModel(org.apache.cloudstack.network.contrail.model.VMInterfaceModel) VirtualMachineModel(org.apache.cloudstack.network.contrail.model.VirtualMachineModel) IOException(java.io.IOException) NicVO(com.cloud.vm.NicVO)

Example 7 with VirtualMachineModel

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");
    }
}
Also used : VirtualMachineModel(org.apache.cloudstack.network.contrail.model.VirtualMachineModel) InternalErrorException(com.cloud.exception.InternalErrorException)

Example 8 with VirtualMachineModel

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;
}
Also used : VirtualMachineModel(org.apache.cloudstack.network.contrail.model.VirtualMachineModel) IOException(java.io.IOException) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException)

Aggregations

VirtualMachineModel (org.apache.cloudstack.network.contrail.model.VirtualMachineModel)8 IOException (java.io.IOException)6 NicVO (com.cloud.vm.NicVO)4 VMInterfaceModel (org.apache.cloudstack.network.contrail.model.VMInterfaceModel)4 VirtualNetworkModel (org.apache.cloudstack.network.contrail.model.VirtualNetworkModel)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 InternalErrorException (com.cloud.exception.InternalErrorException)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 VMInstanceVO (com.cloud.vm.VMInstanceVO)2 InstanceIpModel (org.apache.cloudstack.network.contrail.model.InstanceIpModel)2 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 ApiConnector (net.juniper.contrail.api.ApiConnector)1 MacAddressesType (net.juniper.contrail.api.types.MacAddressesType)1 ServiceInstance (net.juniper.contrail.api.types.ServiceInstance)1 VirtualMachineInterface (net.juniper.contrail.api.types.VirtualMachineInterface)1 ServiceInstanceModel (org.apache.cloudstack.network.contrail.model.ServiceInstanceModel)1