@Override public VM update(VM incoming) { validateEnums(VM.class, incoming); validateParameters(incoming); if (incoming.isSetCluster() && (incoming.getCluster().isSetId() || incoming.getCluster().isSetName())) { Guid clusterId = lookupClusterId(incoming); if (!clusterId.toString().equals(get().getCluster().getId())) { performAction( VdcActionType.ChangeVMCluster, new ChangeVMClusterParameters(clusterId, guid)); } } if (!isFiltered()) { if (incoming.isSetPlacementPolicy()) { parent.validateAndUpdateHostsInPlacementPolicy(incoming.getPlacementPolicy()); } } else { incoming.setPlacementPolicy(null); } VM vm = performUpdate( incoming, new QueryIdResolver<Guid>(VdcQueryType.GetVmByVmId, IdQueryParameters.class), VdcActionType.UpdateVm, new UpdateParametersProvider()); if (vm != null) { DisplayHelper.adjustDisplayData(this, vm); removeRestrictedInfo(vm); } return vm; }
private RunVmOnceParams createRunVmOnceParams(VM vm) { RunVmOnceParams params = map( vm, map( map( getEntity( entityType, VdcQueryType.GetVmByVmId, new IdQueryParameters(guid), id, true), new VM()), new RunVmOnceParams(guid))); if (vm.isSetPlacementPolicy()) { Set<Guid> hostsGuidsSet = parent.validateAndUpdateHostsInPlacementPolicy(vm.getPlacementPolicy()); if (hostsGuidsSet.size() > 0) { // take the arbitrary first host for run destination params.setDestinationVdsId(hostsGuidsSet.iterator().next()); } } if (vm.isSetInitialization() && vm.getInitialization().isSetCloudInit()) { CloudInit cloudInit = vm.getInitialization().getCloudInit(); // currently only 'root' user is supported, alert the user if other user sent if (cloudInit.isSetAuthorizedKeys()) { for (AuthorizedKey authKey : cloudInit.getAuthorizedKeys().getAuthorizedKeys()) { if (!"root".equals(authKey.getUser().getUserName())) { throw new WebApplicationException( Response.status(Response.Status.BAD_REQUEST) .entity("Currently only the user 'root' is supported for authorized keys") .build()); } } } params.setInitializationType(InitializationType.CloudInit); params.setVmInit(getMapper(CloudInit.class, VmInit.class).map(cloudInit, null)); } return params; }