private void validate(APIAttachL3NetworkToVmMsg msg) { VmInstanceVO vmInstanceVO = Q.New(VmInstanceVO.class).eq(VmInstanceVO_.uuid, msg.getVmInstanceUuid()).find(); if (vmInstanceVO.getType().equals(ApplianceVmConstant.APPLIANCE_VM_TYPE)){ validateIpRangeOverlapWithVm(msg.getL3NetworkUuid(), msg.getVmInstanceUuid()); } }
void passThrough(VmInstanceMessage msg) { VmInstanceVO vo = dbf.findByUuid(msg.getVmInstanceUuid(), VmInstanceVO.class); if (vo == null && allowedMessageAfterSoftDeletion.contains(msg.getClass())) { VmInstanceEO eo = dbf.findByUuid(msg.getVmInstanceUuid(), VmInstanceEO.class); vo = ObjectUtils.newAndCopy(eo, VmInstanceVO.class); } if (vo == null) { String err = String.format("Cannot find VmInstance[uuid:%s], it may have been deleted", msg.getVmInstanceUuid()); bus.replyErrorByMessageType((Message) msg, err); return; } VmInstanceFactory factory = getVmInstanceFactory(VmInstanceType.valueOf(vo.getType())); VmInstance vm = factory.getVmInstance(vo); vm.handleMessage((Message) msg); }
private void validate(APIAttachVmNicToVmMsg msg) { VmInstanceVO vmInstanceVO = dbf.findByUuid(msg.getVmInstanceUuid(), VmInstanceVO.class); String type = vmInstanceVO.getType(); VmInstanceState state = vmInstanceVO.getState(); if (!VmInstanceState.Running.equals(state) && !VmInstanceState.Stopped.equals(state)) { throw new ApiMessageInterceptionException(operr("unable to attach a L3 network. The vm[uuid: %s] is not Running or Stopped; the current state is %s", msg.getVmInstanceUuid(), state)); } VmNicVO vmNicVO = dbf.findByUuid(msg.getVmNicUuid(), VmNicVO.class); boolean exist = Q.New(VmNicVO.class) .eq(VmNicVO_.l3NetworkUuid, vmNicVO.getL3NetworkUuid()) .eq(VmNicVO_.vmInstanceUuid, msg.getVmInstanceUuid()) .isExists(); if (exist) { throw new ApiMessageInterceptionException(operr("unable to attach a L3 network. The L3 network[uuid:%s] is already attached to the vm[uuid: %s]", vmNicVO.getL3NetworkUuid(), msg.getVmInstanceUuid())); } L3NetworkVO l3NetworkVO = dbf.findByUuid(vmNicVO.getL3NetworkUuid(), L3NetworkVO.class); L3NetworkState l3state = l3NetworkVO.getState(); boolean system = l3NetworkVO.isSystem(); if (l3state == L3NetworkState.Disabled) { throw new ApiMessageInterceptionException(operr("unable to attach a L3 network. The L3 network[uuid:%s] is disabled", l3NetworkVO.getUuid())); } if (VmInstanceConstant.USER_VM_TYPE.equals(type) && system) { throw new ApiMessageInterceptionException(operr("unable to attach a L3 network. The L3 network[uuid:%s] is a system network and vm is a user vm", l3NetworkVO.getUuid())); } }
protected VmInstanceInventory(VmInstanceVO vo) { this.setUuid(vo.getUuid()); this.setName(vo.getName()); this.setDescription(vo.getDescription()); this.setZoneUuid(vo.getZoneUuid()); this.setClusterUuid(vo.getClusterUuid()); this.setImageUuid(vo.getImageUuid()); this.setHostUuid(vo.getHostUuid()); this.setLastHostUuid(vo.getLastHostUuid()); this.setInstanceOfferingUuid(vo.getInstanceOfferingUuid()); this.setType(vo.getType()); this.setHypervisorType(vo.getHypervisorType()); this.setCreateDate(vo.getCreateDate()); this.setLastOpDate(vo.getLastOpDate()); this.setState(vo.getState().toString()); this.setRootVolumeUuid(vo.getRootVolumeUuid()); this.setAllVolumes(VolumeInventory.valueOf(vo.getAllVolumes())); this.setVmNics(VmNicInventory.valueOf(vo.getVmNics())); this.setVmCdRoms(VmCdRomInventory.valueOf(vo.getVmCdRoms())); this.setInternalId(vo.getInternalId()); this.setDefaultL3NetworkUuid(vo.getDefaultL3NetworkUuid()); this.setCpuNum(vo.getCpuNum()); this.setCpuSpeed(vo.getCpuSpeed()); this.setMemorySize(vo.getMemorySize()); this.setAllocatorStrategy(vo.getAllocatorStrategy()); this.setPlatform(vo.getPlatform()); }