@Override
  public Set<? extends Location> get() {
    Set<? extends Location> regionsOrJustProvider = regionToProviderOrJustProvider.get();
    Set<String> zoneIds = zoneIdsSupplier.get();
    if (zoneIds.size() == 0) return regionsOrJustProvider;
    Map<String, Location> zoneIdToParent =
        setParentOfZoneToRegionOrProvider(zoneIds, regionsOrJustProvider);
    Map<String, Supplier<Set<String>>> isoCodesById = isoCodesByIdSupplier.get();

    Builder<Location> locations = ImmutableSet.builder();
    if (!Iterables.all(regionsOrJustProvider, LocationPredicates.isProvider()))
      locations.addAll(regionsOrJustProvider);
    for (Map.Entry<String, Location> entry : zoneIdToParent.entrySet()) {
      String zoneId = entry.getKey();
      Location parent = entry.getValue();
      LocationBuilder builder =
          new LocationBuilder()
              .scope(LocationScope.ZONE)
              .id(zoneId)
              .description(zoneId)
              .parent(parent);
      if (isoCodesById.containsKey(zoneId)) builder.iso3166Codes(isoCodesById.get(zoneId).get());
      // be cautious.. only inherit iso codes if the parent is a region
      // regions may be added dynamically, and we prefer to inherit an
      // empty set of codes from a region, then a provider, whose code
      // are likely hard-coded.
      else if (parent.getScope() == LocationScope.REGION)
        builder.iso3166Codes(parent.getIso3166Codes());
      locations.add(builder.build());
    }
    return locations.build();
  }
 protected Builder<Location> buildJustProviderOrVDCs() {
   Builder<Location> locations = ImmutableSet.builder();
   Location provider = Iterables.getOnlyElement(super.get());
   if (orgNameToResource.get().size() == 0) return locations.add(provider);
   else
     for (ReferenceType org : orgNameToResource.get().values()) {
       LocationBuilder builder =
           new LocationBuilder()
               .scope(LocationScope.REGION)
               .id(org.getHref().toASCIIString())
               .description((org.getName()))
               .parent(provider);
       if (isoCodesById.containsKey(org.getHref().toASCIIString()))
         builder.iso3166Codes(isoCodesById.get(org.getHref().toASCIIString()));
       Location orgL = builder.build();
       for (ReferenceType vdc : orgNameToVDCResource.get().get(org.getName()).getVDCs().values()) {
         builder =
             new LocationBuilder()
                 .scope(LocationScope.ZONE)
                 .id(vdc.getHref().toASCIIString())
                 .description((vdc.getName()))
                 .parent(orgL);
         if (isoCodesById.containsKey(vdc.getHref().toASCIIString()))
           builder.iso3166Codes(isoCodesById.get(vdc.getHref().toASCIIString()));
         locations.add(builder.build());
       }
     }
   return locations;
 }
  @Override
  public NodeMetadata apply(@Nullable IMachine vm) {

    NodeMetadataBuilder nodeMetadataBuilder = new NodeMetadataBuilder();
    String s = vm.getName();
    nodeMetadataBuilder.name(s);

    // TODO Set up location properly
    LocationBuilder locationBuilder = new LocationBuilder();
    locationBuilder.description("");
    locationBuilder.id("");
    locationBuilder.scope(LocationScope.HOST);
    nodeMetadataBuilder.location(locationBuilder.build());

    HardwareBuilder hardwareBuilder = new HardwareBuilder();
    hardwareBuilder.ram(vm.getMemorySize().intValue());

    // TODO: Get more processor information
    Set<Processor> processors = new HashSet<Processor>();
    for (int i = 0; i < vm.getCPUCount(); i++) {
      Processor processor = new Processor(1, 0);
      processors.add(processor);
    }
    hardwareBuilder.processors(processors);

    // TODO: How to get this?
    hardwareBuilder.is64Bit(false);

    nodeMetadataBuilder.hostname(vm.getName());
    nodeMetadataBuilder.loginPort(18083);

    MachineState vmState = vm.getState();
    NodeState nodeState = machineToNodeState.get(vmState);
    if (nodeState == null) nodeState = NodeState.UNRECOGNIZED;
    nodeMetadataBuilder.state(nodeState);

    logger.debug("Setting virtualbox node to: " + nodeState + " from machine state: " + vmState);

    INetworkAdapter networkAdapter = vm.getNetworkAdapter(0l);
    if (networkAdapter != null) {
      String bridgedInterface = networkAdapter.getBridgedInterface();
      System.out.println("Interface: " + bridgedInterface);
    }

    // nodeMetadataBuilder.imageId("");
    // nodeMetadataBuilder.group("");

    nodeMetadataBuilder.id(vm.getId());
    return nodeMetadataBuilder.build();
  }