@Override
 public NodeMetadata createNodeWithGroupEncodedIntoNameThenStoreCredentials(
     String group, String name, Template template, Map<String, Credentials> credentialStore) {
   NodeMetadataBuilder builder = new NodeMetadataBuilder();
   String id = idProvider.get() + "";
   builder.ids(id);
   builder.name(name);
   // using a predictable name so tests will pass
   builder.hostname(group);
   builder.tags(template.getOptions().getTags());
   builder.group(group);
   builder.location(location.get());
   builder.imageId(template.getImage().getId());
   builder.operatingSystem(template.getImage().getOperatingSystem());
   builder.state(NodeState.PENDING);
   builder.publicAddresses(ImmutableSet.<String>of(publicIpPrefix + id));
   builder.privateAddresses(ImmutableSet.<String>of(privateIpPrefix + id));
   Credentials creds = template.getOptions().getOverridingCredentials();
   if (creds == null) creds = new Credentials(null, null);
   if (creds.identity == null) creds = creds.toBuilder().identity("root").build();
   if (creds.credential == null) creds = creds.toBuilder().credential(passwordPrefix + id).build();
   builder.credentials(creds);
   NodeMetadata node = builder.build();
   credentialStore.put("node#" + node.getId(), node.getCredentials());
   nodes.put(node.getId(), node);
   StubComputeServiceDependenciesModule.setState(node, NodeState.RUNNING, 100);
   return node;
 }
 @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();
 }