use of org.openstack.model.image.Image in project platformlayer by platformlayer.
the class GlanceImageStore method findImages.
@Override
public List<CloudImage> findImages(List<Tag> tags) throws OpsException {
List<CloudImage> matches = Lists.newArrayList();
OpenstackImageClient glanceClient = getOpenstackImageClient();
Iterable<Image> images;
try {
images = glanceClient.root().images().list(true);
} catch (OpenstackException e) {
throw new OpsException("Error listing images", e);
}
for (Image image : images) {
boolean match = true;
for (Tag tag : tags) {
match = false;
String tagKey = tag.getKey();
String tagValue = tag.getValue();
boolean checked = false;
if (ImageFormat.isImageFormatTag(tag)) {
ImageFormat format = ImageFormat.fromTag(tag);
// if ("qcow2".equals(tagValue)) {
// format = ImageFormat.DiskQcow2;
// } else {
// throw new UnsupportedOperationException("Unknown glance disk_format: " + tagValue);
// }
//
// Tag mappedTag = format.toTag();
//
// match = Objects.equal(mappedTag.getValue().getDiskFormat(), glanceDiskFormat);
// checked = true;
String glanceDiskFormat = mapToGlanceDiskFormat(format);
if (glanceDiskFormat != null) {
match = Objects.equal(image.getDiskFormat(), glanceDiskFormat);
checked = true;
}
}
if (!checked) {
for (Entry<String, Object> meta : image.getProperties().asMap().entrySet()) {
if (Objects.equal(tagKey, meta.getKey())) {
String content = (String) meta.getValue();
// OS BUG #885044: Content contains whitespace
content = content.trim();
if (content.equals(tagValue)) {
match = true;
}
}
}
}
if (!match) {
break;
}
}
if (match) {
matches.add(new GlanceImage(image));
}
}
return matches;
}
Aggregations