public class GoogleComputeEngineImageToImage implements Function<Image, org.jclouds.compute.domain.Image> {
@Override
public org.jclouds.compute.domain.Image apply(Image image) {
ImageBuilder builder = new ImageBuilder()
.id(image.getName())
.name(image.getName())
.providerId(image.getId())
.description(image.getDescription().orNull())
.status(Status.AVAILABLE)
.uri(image.getSelfLink());
List<String> splits = Lists.newArrayList(image.getName().split("-"));
OperatingSystem.Builder osBuilder = defaultOperatingSystem(image);
if (splits == null || splits.size() == 0 || splits.size() < 3) {
return builder.operatingSystem(osBuilder.build()).build();
}
OsFamily family = OsFamily.fromValue(splits.get(0));
if (family != OsFamily.UNRECOGNIZED) {
osBuilder.family(family);
}
String version = on(".").join(limit(skip(splits, 1), splits.size() - 2));
osBuilder.version(version);
if (image.getDeprecated().isPresent()) {
builder.userMetadata(ImmutableMap.of("deprecatedState", image.getDeprecated().get().getState().orNull()));
}
builder.version(getLast(splits));
return builder.operatingSystem(osBuilder.build()).build();
}