protected boolean namedCluster(VmPool pool) { return pool.getCluster().isSetName() && !pool.getCluster().isSetId(); }
protected boolean namedCluster(Vm vm) { return vm.isSetCluster() && vm.getCluster().isSetName() && !vm.getCluster().isSetId(); }
protected boolean namedCluster(Template template) { return template.isSetCluster() && template.getCluster().isSetName() && !template.getCluster().isSetId(); }
private Guid getTargetClusterId(Action action) { if (action.isSetCluster() && action.getCluster().isSetId()) { return asGuid(action.getCluster().getId()); } // means use the cluster of the provided host return null; }
protected Guid getClusterId(Action action) { if (action.getCluster().isSetId()) { return asGuid(action.getCluster().getId()); } else { return lookupClusterIdByName(action.getCluster().getName()); } }
@Override public Response add(CpuProfile cpuProfile) { if (!cpuProfile.isSetCluster() || !cpuProfile.getCluster().isSetId()) { cpuProfile.setCluster(new Cluster()); cpuProfile.getCluster().setId(clusterId); } return super.add(cpuProfile); }
protected Guid getClusterId(Action action) { if (action.getCluster().isSetId()) { return asGuid(action.getCluster().getId()); } else { Cluster cluster = lookupClusterByName(action.getCluster().getName()); return cluster != null ? cluster.getId() : null; } }
private void updateIncomingId(QuotaClusterLimit incoming, Quota entity) { if (incoming.isSetCluster() && incoming.getCluster().isSetId()) { incoming.setId(incoming.getCluster().getId()); } else { incoming.setId(entity.getId().toString()); } }
private Guid getClusterId(Host host) { if (host.isSetCluster()) { org.ovirt.engine.api.model.Cluster cluster = host.getCluster(); if (cluster.isSetId()) { return asGuid(cluster.getId()); } if (cluster.isSetName()) { return getClusterIdByName(cluster.getName()); } } return getClusterIdByName(DEFAULT_NAME); }
protected Guid lookupClusterId(Host host) { return host.getCluster().isSetId() ? asGuid(host.getCluster().getId()) : lookupClusterByName(host.getCluster().getName()).getId(); }
private Host setCluster(Host host, org.ovirt.engine.api.model.Cluster cluster) { if (cluster.isSetId()) { host.setCluster(cluster); } else { host.setCluster(new org.ovirt.engine.api.model.Cluster()); host.getCluster().setId(lookupClusterByName(cluster.getName()).getId().toString()); } return host; }
private Guid getClusterId(ExternalVmImport vmImport) { if (vmImport.getCluster().isSetId()) { return asGuid(vmImport.getCluster().getId()); } else /* if (vmImport.getCluster().isSetName()) */ { String clusterName = vmImport.getCluster().getName(); Cluster cluster = getEntity(Cluster.class, QueryType.GetClusterByName, new NameQueryParameters(clusterName), clusterName, true); return cluster.getId(); } }
protected Guid lookupClusterId(Vm vm) { return vm.getCluster().isSetId() ? asGuid(vm.getCluster().getId()) : getEntity(Cluster.class, QueryType.GetClusterByName, new NameQueryParameters(vm.getCluster().getName()), "Cluster: name=" + vm.getCluster().getName()).getId(); }
@Mapping(from = QuotaClusterLimit.class, to = org.ovirt.engine.core.common.businessentities.Quota.class) public static org.ovirt.engine.core.common.businessentities.Quota map(QuotaClusterLimit model, org.ovirt.engine.core.common.businessentities.Quota template) { org.ovirt.engine.core.common.businessentities.Quota entity = template != null ? template : new org.ovirt.engine.core.common.businessentities.Quota(); QuotaCluster quotaCluster = new QuotaCluster(); if (model.isSetVcpuLimit()) { quotaCluster.setVirtualCpu(model.getVcpuLimit()); } if (model.isSetMemoryLimit()) { double limit = model.getMemoryLimit(); quotaCluster.setMemSizeMB( (limit < 0) ? -1 : (long) (limit * 1024) ); } // specific cluster if (model.isSetCluster() && model.getCluster().isSetId()) { quotaCluster.setClusterId(GuidUtils.asGuid(model.getCluster().getId())); entity.getQuotaClusters().add(quotaCluster); } else { // global entity.setGlobalQuotaCluster(quotaCluster); } return entity; } }
@Mapping(from = Permission.class, to = VdcObjectType.class) public static VdcObjectType map(Permission p, VdcObjectType template) { return p.isSetDataCenter() && p.getDataCenter().isSetId() ? VdcObjectType.StoragePool : p.isSetCluster() && p.getCluster().isSetId() ? VdcObjectType.Cluster : p.isSetHost() && p.getHost().isSetId() ? VdcObjectType.VDS : p.isSetStorageDomain() && p.getStorageDomain().isSetId() ? VdcObjectType.Storage : p.isSetVm() && p.getVm().isSetId() ? VdcObjectType.VM : p.isSetVmPool() && p.getVmPool().isSetId() ? VdcObjectType.VmPool : p.isSetTemplate() && p.getTemplate().isSetId() ? VdcObjectType.VmTemplate : template; }
@Override public Host update(Host incoming) { QueryIdResolver<Guid> hostResolver = new QueryIdResolver<>(QueryType.GetVdsByVdsId, IdQueryParameters.class); VDS entity = getEntity(hostResolver, true); BackendExternalProviderHelper.completeExternalNetworkProviderConfigurations(this, incoming.getExternalNetworkProviderConfigurations()); // if fence agents list is null set it to null in entity if(incoming.getAgents() == null) { entity.setFenceAgents(null); } if (incoming.isSetCluster() && (incoming.getCluster().isSetId() || incoming.getCluster().isSetName())) { Guid clusterId = lookupClusterId(incoming); if (!clusterId.equals(entity.getClusterId())) { performAction(ActionType.ChangeVDSCluster, new ChangeVDSClusterParameters(clusterId, guid)); // After changing the cluster with the specialized command we need to reload the entity, so that it // contains the new cluster id. If we don't do this the next command will think that we are trying // to change the cluster, and it will explicitly refuse to perform the update. entity = getEntity(hostResolver, true); } } Host host = performUpdate(incoming, entity, map(entity), hostResolver, ActionType.UpdateVds, new UpdateParametersProvider()); return host; }
@Mapping(from = VmPool.class, to = VmStatic.class) public static VmStatic map(VmPool model, VmStatic template) { VmStatic entity = template != null ? template : new VmStatic(); if (model.getVm() != null) { entity = VmMapper.map(model.getVm(), entity); } entity.setName(model.getName()); entity.setDescription(model.getDescription()); if (model.isSetTemplate() && model.getTemplate().isSetId()) { entity.setVmtGuid(GuidUtils.asGuid(model.getTemplate().getId())); } if (model.isSetCluster() && model.getCluster().isSetId()) { entity.setClusterId(GuidUtils.asGuid(model.getCluster().getId())); } if (model.isSetUseLatestTemplateVersion()) { entity.setUseLatestVersion(model.isUseLatestTemplateVersion()); } return entity; }
@Mapping(from = CpuProfile.class, to = org.ovirt.engine.core.common.businessentities.profiles.CpuProfile.class) public static org.ovirt.engine.core.common.businessentities.profiles.CpuProfile map(CpuProfile model, org.ovirt.engine.core.common.businessentities.profiles.CpuProfile template) { org.ovirt.engine.core.common.businessentities.profiles.CpuProfile entity = template != null ? template : new org.ovirt.engine.core.common.businessentities.profiles.CpuProfile(); if (model.isSetId()) { entity.setId(GuidUtils.asGuid(model.getId())); } if (model.isSetName()) { entity.setName(model.getName()); } if (model.isSetDescription()) { entity.setDescription(model.getDescription()); } if (model.isSetCluster() && model.getCluster().isSetId()) { entity.setClusterId(GuidUtils.asGuid(model.getCluster().getId())); } if (model.isSetQos() && model.getQos().isSetId()) { entity.setQosId(GuidUtils.asGuid(model.getQos().getId())); } return entity; }
@Override public Response approve(Action action) { if (action.isSetCluster() && (action.getCluster().isSetId() || action.getCluster().isSetName())) { update(setCluster(get(), action.getCluster())); } ApproveVdsParameters params = new ApproveVdsParameters(guid); params = (ApproveVdsParameters) getMapper (Action.class, VdsOperationActionParameters.class).map(action, params); // Set pk authentication as default params.setAuthMethod(VdsOperationActionParameters.AuthenticationMethod.PublicKey); if (action.isSetRootPassword()) { params.setAuthMethod(VdsOperationActionParameters.AuthenticationMethod.Password); params.setRootPassword(action.getRootPassword()); } else if (action.isSetSsh() && action.getSsh().isSetAuthenticationMethod()) { if (action.getSsh().getAuthenticationMethod() == SshAuthenticationMethod.PASSWORD) { params.setAuthMethod(VdsOperationActionParameters.AuthenticationMethod.Password); if (action.getSsh().isSetUser() && action.getSsh().getUser().isSetPassword()) { params.setPassword(action.getSsh().getUser().getPassword()); } } } // by default activate the host after approval boolean activate = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, BackendHostsResource.ACTIVATE, true, true); params.setActivateHost(activate); return doAction(ActionType.ApproveVds, params, action); }
@Mapping(from = Permission.class, to = Guid.class) public static Guid map(Permission p, Guid template) { return p.isSetDataCenter() && p.getDataCenter().isSetId() ? GuidUtils.asGuid(p.getDataCenter().getId()) : p.isSetCluster() && p.getCluster().isSetId() ? GuidUtils.asGuid(p.getCluster().getId()) : p.isSetHost() && p.getHost().isSetId() ? GuidUtils.asGuid(p.getHost().getId()) : p.isSetStorageDomain() && p.getStorageDomain().isSetId() ? GuidUtils.asGuid(p.getStorageDomain().getId()) : p.isSetVm() && p.getVm().isSetId() ? GuidUtils.asGuid(p.getVm().getId()) : p.isSetVmPool() && p.getVmPool().isSetId() ? GuidUtils.asGuid(p.getVmPool().getId()) : p.isSetTemplate() && p.getTemplate().isSetId() ? GuidUtils.asGuid(p.getTemplate().getId()) : template; }