Skip to content

Commit a13e850

Browse files
committed
examples: add the GlanceListImages example
This patch introduces a new example for the glance module. The example authenticates to a known keystone instance to query the catalog and retrieve the "image" (glance) services list. Then it connects to the first glance instance and retrieves the list of the available images. Signed-off-by: Federico Simoncelli <[email protected]>
1 parent 7df3ff3 commit a13e850

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

openstack-examples/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
<artifactId>ceilometer-client</artifactId>
3535
<version>2.0.0-SNAPSHOT</version>
3636
</dependency>
37+
<dependency>
38+
<groupId>org.openstack</groupId>
39+
<artifactId>glance-client</artifactId>
40+
<version>2.0.0-SNAPSHOT</version>
41+
</dependency>
3742
<dependency>
3843
<groupId>org.openstack</groupId>
3944
<artifactId>jersey2-connector</artifactId>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.openstack.examples.glance;
2+
3+
import org.openstack.connector.JaxRs20Connector;
4+
import org.openstack.examples.ExamplesConfiguration;
5+
import org.openstack.glance.GlanceClient;
6+
import org.openstack.glance.api.ListImages;
7+
import org.openstack.glance.model.Image;
8+
import org.openstack.glance.model.Images;
9+
import org.openstack.keystone.KeystoneClient;
10+
import org.openstack.keystone.api.Authenticate;
11+
import org.openstack.keystone.api.ListTenants;
12+
import org.openstack.keystone.model.Access;
13+
import org.openstack.keystone.model.Tenants;
14+
import org.openstack.keystone.utils.KeystoneUtils;
15+
16+
public class GlanceListImages {
17+
18+
/**
19+
* @param args
20+
*/
21+
public static void main(String[] args) {
22+
JaxRs20Connector connector = new JaxRs20Connector();
23+
24+
KeystoneClient keystone = new KeystoneClient(
25+
ExamplesConfiguration.KEYSTONE_AUTH_URL, connector);
26+
27+
Access access = keystone.execute(Authenticate.withPasswordCredentials(
28+
ExamplesConfiguration.KEYSTONE_USERNAME,
29+
ExamplesConfiguration.KEYSTONE_PASSWORD));
30+
keystone.token(access.getToken().getId());
31+
32+
Tenants tenants = keystone.execute(new ListTenants());
33+
34+
if (tenants.getList().size() > 0) {
35+
access = keystone.execute(Authenticate.withToken(
36+
access.getToken().getId()).withTenantId(
37+
tenants.getList().get(0).getId()));
38+
39+
GlanceClient client = new GlanceClient(
40+
KeystoneUtils.findEndpointURL(access.getServiceCatalog(),
41+
"image", null, "public"), connector);
42+
43+
Images images = client.execute(new ListImages(false));
44+
45+
for (Image image : images) {
46+
System.out.println(image);
47+
}
48+
} else {
49+
System.out.println("No tenants found!");
50+
}
51+
}
52+
53+
}

0 commit comments

Comments
 (0)