"namingConvention").createWithoutPrefix();
}
@Override
public NodeMetadata apply(VServerMetadata from) {
NodeMetadataBuilder builder = new NodeMetadataBuilder();
builder.ids(from.getId());
builder.name(from.getName());
builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from
.getName()));
if (from.getStatus() == null)
System.out.println("status null for: " + from.getId() + ": "
+ from.getName());
builder.status(vServerToStatus.get(from.getStatus()));
builder.privateAddresses(ImmutableSet.<String> of());
builder.publicAddresses(ImmutableSet.<String> of());
//
// if (from.getIps() != null) {
//
// builder.publicAddresses(Collections2.transform(from.getIps(),
// new Function<PublicIP, String>() {
//
// @Override
// public String apply(PublicIP input) {
// return input.getAddress();
// }
//
// }));
// }
if (from.getServer() != null) {
builder.imageId(from.getServer().getDiskimageId());
builder.hardware(parseHardware(from.getServer().getType()));
LoginCredentials.Builder credentialsBuilder = LoginCredentials
.builder().password(from.getInitialPassword());
Image image = parseImage(from.getServer());
// image will not be found if server was created a while back and
// the image has since been destroyed or discontinued (like an old
// CentOS version)
if (image != null) {
builder.operatingSystem(image.getOperatingSystem());
String user = image.getDefaultCredentials().getUser();
credentialsBuilder.identity(user);
}
builder.credentials(credentialsBuilder.build());
if (from.getServer() instanceof VServerWithVNICs) {
VServerWithVNICs server = (VServerWithVNICs) from.getServer();
builder.location(parseLocation(server));
List<String> ips = Lists.newArrayList();
if (server.getVnics() != null && server.getVnics().iterator().next().getPrivateIp() != null) {
ips.add(server.getVnics().iterator().next().getPrivateIp());
}
builder.privateAddresses(ips);
}
}
if (from.getTemplate() != null) {
// when creating a new node
builder.location(from.getTemplate().getLocation());
}
return builder.build();
}