コード例 #1
0
  @Override
  public NodeAndInitialCredentials<VM> createNodeWithGroupEncodedIntoName(
      String tag, String name, Template template) {
    String networkTierName = template.getLocation().getId();
    String vpdcId = template.getLocation().getParent().getId();
    String billingSiteId = template.getLocation().getParent().getParent().getId();

    VMSpec.Builder specBuilder = VMSpec.builder();
    specBuilder.name(name);
    specBuilder.networkTierName(networkTierName);
    specBuilder.operatingSystem(
        CIMOperatingSystem.class.cast(template.getImage().getOperatingSystem()));
    specBuilder.processorCount(template.getHardware().getProcessors().size());
    specBuilder.memoryInGig(template.getHardware().getRam() / 1024);

    for (Volume volume : template.getHardware().getVolumes()) {
      if (volume.isBootDevice())
        specBuilder.bootDeviceName(volume.getDevice()).bootDiskSize(volume.getSize().intValue());
      else specBuilder.addDataDrive(volume.getDevice(), volume.getSize().intValue());
    }

    Task task = client.getVMClient().addVMIntoVDC(billingSiteId, vpdcId, specBuilder.build());
    // make sure there's no error
    if (task.getError() != null)
      throw new RuntimeException("cloud not add vm: " + task.getError().toString());

    if (taskTester.apply(task.getId())) {
      try {
        VM returnVal = this.getNode(task.getResult().getHref().toASCIIString());
        return new NodeAndInitialCredentials<VM>(returnVal, returnVal.getId(), null);
      } finally {
        // TODO: get the credentials relevant to the billingSiteId/Org
        // credentialStore.put(id, new Credentials(orgId, orgUser));
      }
    } else {
      throw new RuntimeException("task timed out: " + task);
    }
  }
コード例 #2
0
 @Override
 public void destroyNode(String id) {
   taskTester.apply(client.getVMClient().removeVM(URI.create(checkNotNull(id, "id"))).getId());
 }