@Override
  public Iterable<VM> listNodes() {
    Builder<VM> builder = ImmutableSet.builder();
    for (Resource org1 : client.listOrgs()) {
      Org org = client.getBrowsingClient().getOrg(org1.getId());
      for (Resource vdc : org.getVDCs()) {
        VDC VDC = client.getBrowsingClient().getVDCInOrg(org.getId(), vdc.getId());
        for (Resource vApp :
            Iterables.filter(
                VDC.getResourceEntities(),
                new Predicate<Resource>() {

                  @Override
                  public boolean apply(Resource arg0) {
                    return VCloudMediaType.VAPP_XML.equals(arg0.getType());
                  }
                })) {
          builder.add(
              client
                  .getBrowsingClient()
                  .getVMInVDC(org.getId(), vdc.getId(), vApp.getId(), withPowerState()));
        }
      }
    }
    return builder.build();
  }
 @Override
 public Iterable<Network> listLocations() {
   Builder<Network> builder = ImmutableSet.builder();
   for (Resource org1 : client.listOrgs()) {
     Org org = client.getBrowsingClient().getOrg(org1.getId());
     for (Resource vdc : org.getVDCs()) {
       VDC VDC = client.getBrowsingClient().getVDCInOrg(org.getId(), vdc.getId());
       // optionally constrain locations
       if (email != null && VDC.getDescription().indexOf(email) != -1) continue;
       for (Resource network : VDC.getAvailableNetworks()) {
         builder.add(
             client
                 .getBrowsingClient()
                 .getNetworkInVDC(org.getId(), vdc.getId(), network.getId()));
       }
     }
   }
   return builder.build();
 }
  @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);
    }
  }
 @Override
 public void suspendNode(String id) {
   taskTester.apply(
       client.getServiceManagementClient().powerOffVM(URI.create(checkNotNull(id, "id"))).getId());
 }
 @Override
 public void destroyNode(String id) {
   taskTester.apply(client.getVMClient().removeVM(URI.create(checkNotNull(id, "id"))).getId());
 }
 @Override
 public VM getNode(String id) {
   return client.getBrowsingClient().getVM(URI.create(checkNotNull(id, "id")), withPowerState());
 }
 @Override
 public Iterable<CIMOperatingSystem> listImages() {
   return client.listPredefinedOperatingSystems();
 }
Example #8
0
 private Task refresh(String taskId) {
   return client.getBrowsingClient().getTask(taskId);
 }