@Transactional(readOnly = true) private void validate(APIDetachL3NetworkFromVmMsg msg) { String sql = "select vm.uuid, vm.state from VmInstanceVO vm, VmNicVO nic where vm.uuid = nic.vmInstanceUuid and nic.uuid = :uuid"; TypedQuery<Tuple> q = dbf.getEntityManager().createQuery(sql, Tuple.class); q.setParameter("uuid", msg.getVmNicUuid()); Tuple t = q.getSingleResult(); String vmUuid = t.get(0, String.class); VmInstanceState state = t.get(1, VmInstanceState.class); if (!VmInstanceState.Running.equals(state) && !VmInstanceState.Stopped.equals(state)) { throw new ApiMessageInterceptionException(operr("unable to detach a L3 network. The vm[uuid: %s] is not Running or Stopped; the current state is %s", msg.getVmInstanceUuid(), state)); } msg.setVmInstanceUuid(vmUuid); msg.l3Uuid = Q.New(VmNicVO.class).eq(VmNicVO_.uuid, msg.getVmNicUuid()).select(VmNicVO_.l3NetworkUuid).findValue(); }
@Override protected void scripts() { VmInstanceVO vo = findByUuid(msg.getVmInstanceUuid(), VmInstanceVO.class); if (vo.getState().equals(VmInstanceState.Running) && vo.getHostUuid().equals(msg.getHostUuid())) { throw new ApiMessageInterceptionException(argerr( "the vm[uuid:%s] is already on host[uuid:%s]", msg.getVmInstanceUuid(), msg.getHostUuid() )); } } }.execute();
if (vmInstanceVO.getState().equals(VmInstanceState.Created)) { return; } else if (!vmInstanceVO.getState().equals(VmInstanceState.Stopped) && !vmInstanceVO.getState().equals(VmInstanceState.Running) && !vmInstanceVO.getState().equals(VmInstanceState.Paused) && !vmInstanceVO.getState().equals(VmInstanceState.Starting)) { throw new ApiMessageInterceptionException(err(VmErrors.NOT_IN_CORRECT_STATE, "Incorrect VM State.VM[uuid:%s] current state:%s. ", if (vmInstanceVO.getState().equals(VmInstanceState.Running) || vmInstanceVO.getState().equals(VmInstanceState.Paused)) { checkRunningVMQuotaForChangeResourceOwner(vmInstanceUuid, resourceTargetOwnerAccountUuid, currentAccountUuid, pairs);
private void validate(final APICreateVmCdRomMsg msg) { VmInstanceVO vo = dbf.findByUuid(msg.getVmInstanceUuid(), VmInstanceVO.class); if (!vo.getState().equals(VmInstanceState.Stopped)) { throw new ApiMessageInterceptionException(argerr( "Can not create CD-ROM for vm[uuid:%s] which is in state[%s] ", msg.getVmInstanceUuid(), vo.getState().toString())); } }
@Override public VirtualRouterVmInventory call() { VirtualRouterVmVO vr = findVR(); if (vr != null && !VmInstanceState.Running.equals(vr.getState())) { throw new OperationFailureException(operr("virtual router[uuid:%s] for l3 network[uuid:%s] is not in Running state, current state is %s. We don't have HA feature now(it's coming soon), please restart it from UI and then try starting this vm again", vr.getUuid(), l3Nw.getUuid(), vr.getState())); } return vr == null ? null : new VirtualRouterVmInventory(vr); } }.call();
@Transactional(readOnly = true) private List<VolumeVO> getAttachableVolume(String accountUuid) { if (!self.getState().equals(VmInstanceState.Stopped) && self.getPlatform().equals(ImagePlatform.Other.toString())) { return Collections.emptyList();
@Override protected void scripts() { VmInstanceVO vo = Q.New(VmInstanceVO.class).eq(VmInstanceVO_.uuid, msg.getVmInstanceUuid()).find(); InstanceOfferingVO instanceOfferingVO = Q.New(InstanceOfferingVO.class).eq(InstanceOfferingVO_.uuid, msg.getInstanceOfferingUuid()).find(); if (!VmGlobalConfig.NUMA.value(Boolean.class) && !VmInstanceState.Stopped.equals(vo.getState())) { throw new ApiMessageInterceptionException(argerr( "the VM cannot do online cpu/memory update because it is not of NUMA architecture. Please stop the VM then do the cpu/memory update again" )); } if (!VmInstanceState.Stopped.equals(vo.getState()) && !VmInstanceState.Running.equals(vo.getState())) { throw new OperationFailureException(operr("The state of vm[uuid:%s] is %s. Only these state[%s] is allowed to update cpu or memory.", vo.getUuid(), vo.getState(), StringUtils.join(list(VmInstanceState.Running, VmInstanceState.Stopped), ","))); } if (VmInstanceState.Stopped.equals(vo.getState())) { return; } if (instanceOfferingVO.getCpuNum() < vo.getCpuNum() || instanceOfferingVO.getMemorySize() < vo.getMemorySize()) { throw new ApiMessageInterceptionException(argerr( "can't decrease capacity when vm[uuid:%s] is running", vo.getUuid() )); } } }.execute();
} else if (VmInstanceState.Stopped.toString().equals(state) && self.getState().equals(VmInstanceState.Destroying)) { changeVmStateInDb(VmInstanceStateEvent.destroyed); } else if (VmInstanceState.Stopped.toString().equals(state)) {
if (!VmGlobalConfig.NUMA.value(Boolean.class) && !VmInstanceState.Stopped.equals(vmState)) { throw new ApiMessageInterceptionException(argerr( "the VM cannot do online cpu/memory update because it is not of NUMA architecture. Please stop the VM then do the cpu/memory update again" if (!VmInstanceState.Stopped.equals(vo.getState()) && !VmInstanceState.Running.equals(vo.getState())) { throw new OperationFailureException(operr("The state of vm[uuid:%s] is %s. Only these state[%s] is allowed to update cpu or memory.", vo.getUuid(), vo.getState(), if (VmInstanceState.Stopped.equals(vmState)) { return;
if (deletionPolicy == VmInstanceDeletionPolicy.KeepVolume && self.getState().equals(VmInstanceState.Destroyed)) { completion.success(); return;
VmInstanceState state = t.get(1, VmInstanceState.class); 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));
if (appvm.getState().equals(VmInstanceState.Stopped)) { logger.debug(String.format("appliance vm[uuid: %s] current state is [%s], skip before detach nic", appvm.getUuid(), appvm.getStatus()));
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())); } }