Cluster cluster = new Cluster(); cluster.setId(entity.get("clusterid", String.class, Integer.class).toString()); cluster.setName(entity.get("name")); cluster.setDescription(entity.get("description")); cluster.setMemoryPolicy(new MemoryPolicy()); cluster.getMemoryPolicy().setOverCommit(new MemoryOverCommit()); cluster.getMemoryPolicy().getOverCommit().setPercent(entity.get("maxhostmemoryovercommit", Integer.class)); cluster.setSchedulingPolicy(parseSchedulingPolicy(entity)); cluster.setVersion(entity.get("compatibilityversion", Version.class)); cluster.setCpu(cpu); cluster.setDataCenter(dataCenter);
static String getClusterArg(StringBuilder buf, Host host) { String clusterArg = ""; if (host.isSetCluster()) { if (host.getCluster().isSetId()) { clusterArg = " -hostclusterid " + PowerShellUtils.escape(host.getCluster().getId()); } else if (host.getCluster().isSetName()) { buf.append("$c = select-cluster -searchtext "); buf.append(PowerShellUtils.escape("name=" + host.getCluster().getName())); buf.append(";"); clusterArg = " -hostclusterid $c.ClusterId"; } } return clusterArg; } }
public void updateModel(Cluster cluster) { // update writable fields only if (cluster.isSetName()) { getModel().setName(cluster.getName()); } if (cluster.isSetDescription()) { getModel().setDescription(cluster.getDescription()); } if (cluster.isSetCpu()) { CPU cpu = new CPU(); cpu.setId(cluster.getCpu().getId()); getModel().setCpu(cpu); } if (cluster.isSetDataCenter()) { DataCenter dataCenter = new DataCenter(); dataCenter.setId(cluster.getDataCenter().getId()); getModel().setDataCenter(dataCenter); } }
protected String getClusterVariable(StringBuilder buf, Cluster cluster) { if (cluster.isSetId()) { buf.append("$cluster = select-cluster | ? { $_.clusterid -eq " + PowerShellUtils.escape(cluster.getId()) + " }; "); } else { buf.append("$cluster = select-cluster -searchtext "); buf.append(PowerShellUtils.escape("name=" + cluster.getName())); buf.append("; "); } return "$cluster"; }
private static VmPool lookupClusterId(PowerShellPool shellPool, PowerShellParser parser, VmPool pool) { StringBuilder buf = new StringBuilder(); buf.append("select-cluster -searchtext "); buf.append(PowerShellUtils.escape("name = " + pool.getCluster().getName())); Cluster cluster = new Cluster(); cluster.setId(PowerShellClusterResource.runAndParseSingle(shellPool, parser, buf.toString()).getId()); pool.setCluster(cluster); return pool; }
if (cluster.isSetVersion() && cluster.getVersion().isSetMajor() && cluster.getVersion().isSetMinor()) { Version v = cluster.getVersion(); buf.append("if ("); buf.append("$v.major -eq " + Integer.toString(v.getMajor())); buf.append(" -clustername " + PowerShellUtils.escape(cluster.getName())); if (cluster.getDescription() != null) { buf.append(" -clusterdescription " + PowerShellUtils.escape(cluster.getDescription())); buf.append(" -clustercpuname " + PowerShellUtils.escape(cluster.getCpu().getId())); if (cluster.isSetMemoryPolicy() && cluster.getMemoryPolicy().isSetOverCommit() && cluster.getMemoryPolicy().getOverCommit().isSetPercent()) { buf.append(" -maxmemoryovercommit " + Integer.toString(cluster.getMemoryPolicy().getOverCommit().getPercent())); if (cluster.isSetSchedulingPolicy() && cluster.getSchedulingPolicy().isSetPolicy()) { policy = SchedulingPolicyType.fromValue(cluster.getSchedulingPolicy().getPolicy()); SchedulingPolicyThresholds thresholds = cluster.getSchedulingPolicy().getThresholds(); UriBuilder uriBuilder = getUriInfo().getAbsolutePathBuilder().path(cluster.getId());
public void updateModel(VmPool pool) { // update writable fields only if (pool.isSetName()) { getModel().setName(pool.getName()); } if (pool.isSetDescription()) { getModel().setDescription(pool.getDescription()); } if (pool.isSetCluster() && pool.getCluster().isSetId()) { getModel().setCluster(new Cluster()); getModel().getCluster().setId(pool.getCluster().getId()); } if (pool.isSetTemplate() && pool.getTemplate().isSetId()) { getModel().setTemplate(new Template()); getModel().getTemplate().setId(pool.getTemplate().getId()); } }
public void populate() { synchronized (clusters) { while (clusters.size() < 2) { MockClusterResource resource = new MockClusterResource(allocateId(Cluster.class), getExecutor(), this); resource.getModel().setName("cluster" + resource.getModel().getId()); CPU cpu = new CPU(); cpu.setId((clusters.size() % 2) == 0 ? "Intel Xeon" : "AMD Opteron G1"); resource.getModel().setCpu(cpu); DataCenter dataCenter = new DataCenter(); dataCenter.setId(resource.getModel().getId()); resource.getModel().setDataCenter(dataCenter); clusters.put(resource.getModel().getId(), resource); } } }
public static List<VmPool> parse(PowerShellParser parser, String output) { List<VmPool> ret = new ArrayList<VmPool>(); for (PowerShellParser.Entity entity : parser.parse(output)) { VmPool pool = new VmPool(); pool.setId(entity.get("vmpoolid", String.class, Integer.class).toString()); pool.setName(entity.get("name")); pool.setDescription(entity.get("description")); pool.setSize(entity.get("vmcount", Integer.class)); Cluster cluster = new Cluster(); cluster.setName(entity.get("cluster")); pool.setCluster(cluster); Template template = new Template(); template.setName(entity.get("template")); pool.setTemplate(template); ret.add(pool); } return ret; } }
public void updateModel(VM vm) { // update writable fields only if (vm.isSetName()) { getModel().setName(vm.getName()); } if (vm.isSetDescription()) { getModel().setDescription(vm.getDescription()); } if (vm.isSetCluster()) { Cluster cluster = new Cluster(); cluster.setId(vm.getCluster().getId()); getModel().setCluster(cluster); } }
private static Cluster querySupportedVersions(PowerShellPool pool, PowerShellParser parser, Cluster cluster) { String command = "get-clustercompatibilityversions -clusterid " + PowerShellUtils.escape(cluster.getId()); List<Version> supported = PowerShellVersion.parse(parser, PowerShellCmd.runCommand(pool, command)); if (!supported.isEmpty()) { cluster.setSupportedVersions(new SupportedVersions()); for (Version v : supported) { cluster.getSupportedVersions().getVersions().add(v); } } return cluster; }
private String getDataCenterArg(StringBuilder buf, Cluster cluster) { String arg = ""; if (cluster.isSetDataCenter()) { if (cluster.getDataCenter().isSetId()) { arg = PowerShellUtils.escape(cluster.getDataCenter().getId()); } else if (cluster.getDataCenter().isSetName()) { buf.append("$d = select-datacenter -searchtext "); buf.append(PowerShellUtils.escape("name=" + cluster.getDataCenter().getName())); buf.append("; "); arg = "$d.datacenterid"; } } return arg; } }
if (cluster.getName() != null) { buf.append("$c.name = " + PowerShellUtils.escape(cluster.getName()) + "; "); if (cluster.getCpu() != null) { buf.append("$c.cpuname = " + PowerShellUtils.escape(cluster.getCpu().getId()) + "; "); if (cluster.getDescription() != null) { buf.append("$c.description = " + PowerShellUtils.escape(cluster.getDescription()) + "; "); if (cluster.isSetVersion() && cluster.getVersion().isSetMajor() && cluster.getVersion().isSetMinor()) { Version v = cluster.getVersion(); buf.append("foreach ($v in get-clustercompatibilityversions -clusterid "); buf.append(PowerShellUtils.escape(cluster.getId())); buf.append(") { "); buf.append("if ("); if (cluster.isSetMemoryPolicy() && cluster.getMemoryPolicy().isSetOverCommit() && cluster.getMemoryPolicy().getOverCommit().isSetPercent()) { buf.append("$c.maxhostmemoryovercommit = "); buf.append(Integer.toString(cluster.getMemoryPolicy().getOverCommit().getPercent())); buf.append("; "); if (cluster.isSetSchedulingPolicy() && cluster.getSchedulingPolicy().isSetPolicy()) { policy = SchedulingPolicyType.valueOf(cluster.getSchedulingPolicy().getPolicy());
protected Template getModel() { Template model = new Template(); model.setName(name); model.setVm(new VM()); model.getVm().setName(vm); model.setCluster(new Cluster()); model.getCluster().setName(cluster); if (memory != -1) { model.setMemory(memory * 1024 * 1024L); } if (sockets != -1 || cores != -1) { model.setCpu(new CPU()); model.getCpu().setTopology(new CpuTopology()); if (sockets != -1) { model.getCpu().getTopology().setSockets(sockets); } if (cores != -1) { model.getCpu().getTopology().setCores(cores); } } if (boot != null) { model.setOs(getOs()); } return model; }
public void populate() { synchronized (pools) { while (pools.size() < 3) { MockVmPoolResource resource = new MockVmPoolResource(allocateId(VmPool.class), getExecutor(), this); VmPool pool = resource.getModel(); pool.setName("pool" + resource.getModel().getId()); pool.setDescription("test pool " + resource.getModel().getId()); Template template = new Template(); template.setId(resource.getModel().getId()); resource.getModel().setTemplate(template); Cluster cluster = new Cluster(); cluster.setId(resource.getModel().getId()); resource.getModel().setCluster(cluster); pools.put(pool.getId(), resource); } } }
protected VM getModel() { VM model = new VM(); model.setName(name); model.setTemplate(new Template()); model.getTemplate().setName(template); model.setCluster(new Cluster()); model.getCluster().setName(cluster); if (memory != -1) { model.setMemory(memory * 1024 * 1024L); } if (sockets != -1 || cores != -1) { model.setCpu(new CPU()); model.getCpu().setTopology(new CpuTopology()); if (sockets != -1) { model.getCpu().getTopology().setSockets(sockets); } if (cores != -1) { model.getCpu().getTopology().setCores(cores); } } if (boot != null) { model.setOs(getOs()); } return model; }