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 (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); } } }
@Override public VmPool update(VmPool pool) { validateUpdate(pool); StringBuilder buf = new StringBuilder(); buf.append("$v = get-vmpool -vmpoolid " + PowerShellUtils.escape(getId()) + ";"); if (pool.getName() != null) { buf.append("$v.name = " + PowerShellUtils.escape(pool.getName()) + ";"); } if (pool.getDescription() != null) { buf.append("$v.description = " + PowerShellUtils.escape(pool.getDescription()) + ";"); } if (pool.getSize() != null) { buf.append("$v.vmcount = " + pool.getSize() + ";"); } buf.append("update-vmpool -vmpoolobject $v"); return addLinks(runAndParseSingle(buf.toString())); }
if (pool.getTemplate().isSetId()) { templateArg = PowerShellUtils.escape(pool.getTemplate().getId()); } else { buf.append("$t = select-template -searchtext "); buf.append(PowerShellUtils.escape("name=" + pool.getTemplate().getName())); buf.append(";"); templateArg = "$t.TemplateId"; if (pool.getCluster().isSetId()) { clusterArg = PowerShellUtils.escape(pool.getCluster().getId()); } else { buf.append("$c = select-cluster -searchtext "); buf.append(PowerShellUtils.escape("name=" + pool.getCluster().getName())); buf.append(";"); clusterArg = "$c.ClusterId"; buf.append(" -vmpoolname " + PowerShellUtils.escape(pool.getName())); if (pool.getDescription() != null) { buf.append(" -vmpooldescription " + PowerShellUtils.escape(pool.getDescription())); if (pool.getSize() != null) { buf.append(" -numofvms " + pool.getSize()); UriBuilder uriBuilder = getUriInfo().getAbsolutePathBuilder().path(pool.getId());
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; } }
private static VmPool lookupTemplateId(PowerShellPool shellPool, PowerShellParser parser, VmPool pool) { StringBuilder buf = new StringBuilder(); buf.append("select-template -searchtext "); buf.append(PowerShellUtils.escape("name = " + pool.getTemplate().getName())); Template template = new Template(); template.setId(PowerShellTemplateResource.runAndParseSingle(shellPool, parser, buf.toString()).getId()); pool.setTemplate(template); return pool; }
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; }
System.out.println(" VM pool: " + model.getVmPool().getName());
public static VmPool addLinks(UriInfo uriInfo, PowerShellPool shellPool, PowerShellParser parser, VmPool pool) { pool = lookupClusterId(shellPool, parser, pool); if (pool.getTemplate() != null) { pool = lookupTemplateId(shellPool, parser, pool); } return LinkHelper.addLinks(uriInfo, pool); }