@Override
  public NodeMetadata apply(final VirtualGuest from) {

    // convert the result object to a jclouds NodeMetadata
    NodeMetadataBuilder builder = new NodeMetadataBuilder();
    builder.ids(from.getId() + "");
    builder.name(from.getHostname());
    builder.hostname(from.getHostname());
    builder.status(serverStateToNodeStatus.get(from.getPowerState().getKeyName()));

    // These are null for 'bad' guest orders in the HALTED state.
    if (from.getPrimaryIpAddress() != null)
      builder.publicAddresses(ImmutableSet.<String>of(from.getPrimaryIpAddress()));
    if (from.getPrimaryBackendIpAddress() != null)
      builder.privateAddresses(ImmutableSet.<String>of(from.getPrimaryBackendIpAddress()));
    return builder.build();
  }
 @Override
 @Consumes(MediaType.APPLICATION_JSON)
 public VirtualGuest expected() {
   return VirtualGuest.builder()
       .id(416700)
       .accountId(93750)
       .billingItemId(7184019)
       .createDate(
           new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-01T11:47:35-08:00"))
       .metricPollDate(
           new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T02:32:00-08:00"))
       .dedicatedAccountHostOnly(true)
       .domain("me.org")
       .fullyQualifiedDomainName("node1703810489.me.org")
       .hostname("node1703810489")
       .maxCpu(1)
       .maxCpuUnits("CORE")
       .maxMemory(1024)
       .modifyDate(
           new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T03:18:12-08:00"))
       .primaryBackendIpAddress("10.37.102.195")
       .primaryIpAddress("173.192.29.187")
       .startCpus(1)
       .statusId(1001)
       .uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8")
       .operatingSystem(
           OperatingSystem.builder()
               .id(913824)
               .passwords(
                   Password.builder().id(729122).username("root").password("KnJqhC2l").build())
               .build())
       .datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build())
       // TODO: maybe powerState can be flattened like billingItemId
       .powerState(new PowerState(VirtualGuest.State.PAUSED))
       .build();
 }
 @Override
 @Consumes(MediaType.APPLICATION_JSON)
 public ContainerVirtualGuestConfiguration expected() {
   return ContainerVirtualGuestConfiguration.builder()
       .blockDevices(
           ContainerVirtualGuestConfigurationOption.builder()
               .productItemPrice(
                   ProductItemPrice.builder()
                       .hourlyRecurringFee(0)
                       .recurringFee("0")
                       .item(ProductItem.builder().description("25 GB (SAN)").build())
                       .build())
               .template(
                   VirtualGuest.builder()
                       .blockDevices(
                           VirtualGuestBlockDevice.builder()
                               .device("0")
                               .diskImage(VirtualDiskImage.builder().capacity(25).build())
                               .build())
                       .localDiskFlag(false)
                       .build())
               .build())
       .datacenters(
           ContainerVirtualGuestConfigurationOption.builder()
               .template(
                   VirtualGuest.builder()
                       .datacenter(Datacenter.builder().name("ams01").build())
                       .build())
               .build())
       .memory(
           ContainerVirtualGuestConfigurationOption.builder()
               .productItemPrice(
                   ProductItemPrice.builder()
                       .hourlyRecurringFee(.02f)
                       .recurringFee("14")
                       .item(ProductItem.builder().description("1 GB").build())
                       .build())
               .template(VirtualGuest.builder().maxMemory(1024).build())
               .build())
       .networkComponents(
           ContainerVirtualGuestConfigurationOption.builder()
               .productItemPrice(
                   ProductItemPrice.builder()
                       .hourlyRecurringFee(0)
                       .recurringFee("0")
                       .item(
                           ProductItem.builder()
                               .description("10 Mbps Public & Private Networks")
                               .build())
                       .build())
               .template(
                   VirtualGuest.builder()
                       .networkComponents(
                           VirtualGuestNetworkComponent.builder().maxSpeed(10).build())
                       .build())
               .build())
       .operatingSystems(
           ContainerVirtualGuestConfigurationOption.builder()
               .productItemPrice(
                   ProductItemPrice.builder()
                       .hourlyRecurringFee(0)
                       .recurringFee("0")
                       .item(
                           ProductItem.builder()
                               .description("CentOS 6.x - Minimal Install (64 bit)")
                               .build())
                       .build())
               .template(
                   VirtualGuest.builder().operatingSystemReferenceCode("CENTOS_6_64").build())
               .build())
       .processors(
           ContainerVirtualGuestConfigurationOption.builder()
               .productItemPrice(
                   ProductItemPrice.builder()
                       .hourlyRecurringFee(.022f)
                       .recurringFee("15")
                       .item(ProductItem.builder().description("1 x 2.0 GHz Core").build())
                       .build())
               .template(VirtualGuest.builder().startCpus(1).build())
               .build())
       .build();
 }
 @Override
 public NodeMetadata apply(VirtualGuest from) {
   NodeMetadataBuilder builder = new NodeMetadataBuilder();
   builder.ids(from.getId() + "");
   builder.name(from.getHostname());
   builder.hostname(from.getFullyQualifiedDomainName());
   if (from.getDatacenter() != null) {
     builder.location(
         from(locations.get())
             .firstMatch(LocationPredicates.idEquals(from.getDatacenter().getName()))
             .orNull());
   }
   builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getHostname()));
   builder.hardware(virtualGuestToHardware.apply(from));
   Image image = virtualGuestToImage.apply(from);
   if (image != null) {
     builder.imageId(image.getId());
     builder.operatingSystem(image.getOperatingSystem());
   }
   if (from.getPowerState() != null) {
     builder.status(serverStateToNodeStatus.get(from.getPowerState().getKeyName()));
   }
   if (from.getPrimaryIpAddress() != null)
     builder.publicAddresses(ImmutableSet.of(from.getPrimaryIpAddress()));
   if (from.getPrimaryBackendIpAddress() != null)
     builder.privateAddresses(ImmutableSet.of(from.getPrimaryBackendIpAddress()));
   // TODO simplify once we move domain classes to AutoValue
   if (from.getOperatingSystem() != null
       && from.getOperatingSystem().getPasswords() != null
       && !from.getOperatingSystem().getPasswords().isEmpty()) {
     Password password = getBestPassword(from.getOperatingSystem().getPasswords(), from);
     builder.credentials(
         LoginCredentials.builder()
             .identity(password.getUsername())
             .credential(password.getPassword())
             .build());
   }
   if (from.getTagReferences() != null && !from.getTagReferences().isEmpty()) {
     List<String> tags = Lists.newArrayList();
     for (TagReference tagReference : from.getTagReferences()) {
       if (tagReference != null) {
         tags.add(tagReference.getTag().getName());
       }
     }
     builder.tags(tags);
   }
   return builder.build();
 }