Package org.apache.cloudstack.network.contrail.model

Examples of org.apache.cloudstack.network.contrail.model.VirtualMachineModel


        return comparator;
    }

    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);
View Full Code Here


    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;
View Full Code Here

        VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
        /* Network must have been implemented */
        assert vnModel != null;

        VirtualMachineModel vmModel = _manager.getDatabase().lookupVirtualMachine(vm.getUuid());
        if (vmModel == null) {
            VMInstanceVO vmVo = (VMInstanceVO)vm.getVirtualMachine();
            vmModel = new VirtualMachineModel(vmVo, vm.getUuid());
            vmModel.setProperties(_manager.getModelController(), vmVo);
        }

        VMInterfaceModel vmiModel = vmModel.getVMInterface(nicVO.getUuid());
        if (vmiModel == null) {
            vmiModel = new VMInterfaceModel(nicVO.getUuid());
            vmiModel.addToVirtualMachine(vmModel);
            vmiModel.addToVirtualNetwork(vnModel);
        }
        try {
            vmiModel.build(_manager.getModelController(), (VMInstanceVO)vm.getVirtualMachine(), nicVO);
            vmiModel.setActive();
        } catch (IOException ex) {
            s_logger.error("virtual-machine-interface set", ex);
            return;
        }

        InstanceIpModel ipModel = vmiModel.getInstanceIp();
        if (ipModel == null) {
            ipModel = new InstanceIpModel(vm.getInstanceName(), nic.getDeviceId());
            ipModel.addToVMInterface(vmiModel);
        } else {
            s_logger.debug("Reuse existing instance-ip object on " + ipModel.getName());
        }
        if (nic.getIp4Address() != null) {
            s_logger.debug("Nic using existing IP address " + nic.getIp4Address());
            ipModel.setAddress(nic.getIp4Address());
        }

        try {
            vmModel.update(_manager.getModelController());
        } catch (Exception ex) {
            s_logger.warn("virtual-machine update", ex);
            return;
        }

View Full Code Here

    public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) {
        s_logger.debug("deallocate NicProfile " + nic.getId() + " on " + network.getName());
        NicVO nicVO = _nicDao.findById(nic.getId());
        assert nicVO != null;

        VirtualMachineModel vmModel = _manager.getDatabase().lookupVirtualMachine(vm.getUuid());
        if (vmModel == null) {
            return;
        }
        VMInterfaceModel vmiModel = vmModel.getVMInterface(nicVO.getUuid());
        if (vmiModel == null) {
            return;
        }
        try {
            vmiModel.destroy(_manager.getModelController());
        } catch (IOException ex) {
            return;
        }
        vmModel.removeSuccessor(vmiModel);

        if (!vmModel.hasDescendents()) {
            _manager.getDatabase().getVirtualMachines().remove(vmModel);
            try {
                vmModel.delete(_manager.getModelController());
            } catch (IOException ex) {
                s_logger.warn("virtual-machine delete", ex);
                return;
            }
        }
View Full Code Here

    public TreeSet<VirtualMachineModel> getVirtualMachines() {
        return _vmTable;
    }

    public VirtualMachineModel lookupVirtualMachine(String uuid) {
        VirtualMachineModel vmKey = new VirtualMachineModel(null, uuid);
        VirtualMachineModel current = _vmTable.ceiling(vmKey);
        if (current != null && current.getUuid().equals(uuid)) {
            return current;
        }
        return null;
    }
View Full Code Here

            // There is no notification after a physical network is associated with the VRouter NetworkOffering
            // this may be the first time we see this network.
            return false;
        }

        VirtualMachineModel vmModel = _manager.getDatabase().lookupVirtualMachine(vm.getUuid());
        if (vmModel == null) {
            VMInstanceVO vmVo = (VMInstanceVO)vm.getVirtualMachine();
            vmModel = new VirtualMachineModel(vmVo, vm.getUuid());
            vmModel.setProperties(_manager.getModelController(), vmVo);
        }

        NicVO nic = _nicDao.findById(nicProfile.getId());
        assert nic != null;

        VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid());
        if (vmiModel == null) {
            vmiModel = new VMInterfaceModel(nic.getUuid());
            vmiModel.addToVirtualMachine(vmModel);
            vmiModel.addToVirtualNetwork(vnModel);
        }

        try {
            vmiModel.build(_manager.getModelController(), (VMInstanceVO)vm.getVirtualMachine(), nic);
        } catch (IOException ex) {
            s_logger.warn("vm interface set", ex);
            return false;
        }

        InstanceIpModel ipModel = vmiModel.getInstanceIp();
        if (ipModel == null) {
            ipModel = new InstanceIpModel(vm.getInstanceName(), nic.getDeviceId());
            ipModel.addToVMInterface(vmiModel);
        }
        ipModel.setAddress(nicProfile.getIp4Address());

        try {
            vmModel.update(_manager.getModelController());
        } catch (Exception ex) {
            s_logger.warn("virtual-machine-update", ex);
            return false;
        }
        _manager.getDatabase().getVirtualMachines().add(vmModel);
View Full Code Here

        }

        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;
            }
        }
View Full Code Here

        ServiceVirtualMachine svm = createServiceVM(zone, owner, template, serviceOffering, svmName, siObj, left, right);

        s_logger.debug("created VMInstance " + svm.getUuid());

        // 3. Create the virtual-machine model and push the update.
        VirtualMachineModel instanceModel = new VirtualMachineModel(svm, svm.getUuid());
        _manager.getDatabase().getVirtualMachines().add(instanceModel);
        try {
            instanceModel.setServiceInstance(_manager.getModelController(), svm, serviceModel);
            instanceModel.update(_manager.getModelController());
        } catch (Exception ex) {
            s_logger.warn("service virtual-machine update", ex);
            throw new CloudRuntimeException(ex);
        }
View Full Code Here

    public TreeSet<VirtualMachineModel> getVirtualMachines() {
        return _vmTable;
    }
   
    public VirtualMachineModel lookupVirtualMachine(String uuid) {
        VirtualMachineModel vmKey = new VirtualMachineModel(null, uuid);
        VirtualMachineModel current = _vmTable.ceiling(vmKey);
        if (current != null && current.getUuid().equals(uuid)) {
            return current;
        }
        return null;
    }
View Full Code Here

          // There is no notification after a physical network is associated with the VRouter NetworkOffering
          // this may be the first time we see this network.
          return false;
      }

      VirtualMachineModel vmModel = _manager.getDatabase().lookupVirtualMachine(vm.getUuid());
      if (vmModel == null) {
          VMInstanceVO vmVo = (VMInstanceVO) vm.getVirtualMachine();
          vmModel = new VirtualMachineModel(vmVo, vm.getUuid());
          vmModel.setProperties(_manager.getModelController(), vmVo);
      }

      NicVO nic = _nicDao.findById(nicProfile.getId());
      assert nic != null;

      VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid());
      if (vmiModel == null) {
          vmiModel = new VMInterfaceModel(nic.getUuid());
          vmiModel.addToVirtualMachine(vmModel)
                vmiModel.addToVirtualNetwork(vnModel);         
      }
     
      try {
          vmiModel.build(_manager.getModelController(), (VMInstanceVO) vm.getVirtualMachine(), nic);
      } catch (IOException ex) {
          s_logger.warn("vm interface set", ex);
          return false;
      }

      InstanceIpModel ipModel = vmiModel.getInstanceIp();
      if (ipModel == null) {
          ipModel = new InstanceIpModel(vm.getInstanceName(), nic.getDeviceId());
          ipModel.addToVMInterface(vmiModel);
      }
      ipModel.setAddress(nicProfile.getIp4Address());

      try {
          vmModel.update(_manager.getModelController());
      } catch (Exception ex) {
          s_logger.warn("virtual-machine-update", ex);
          return false;
      }
      _manager.getDatabase().getVirtualMachines().add(vmModel);  
View Full Code Here

TOP

Related Classes of org.apache.cloudstack.network.contrail.model.VirtualMachineModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.