diff options
14 files changed, 498 insertions, 498 deletions
diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/ExamplesConfiguration.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/ExamplesConfiguration.java index 0d034e8..2fa2f5f 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/ExamplesConfiguration.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/ExamplesConfiguration.java @@ -23,28 +23,28 @@ import com.woorea.openstack.keystone.model.Tenant; public class ExamplesConfiguration { - public static final String KEYSTONE_AUTH_URL = "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v3"; - - public static final String KEYSTONE_USERNAME = ""; - - public static final String KEYSTONE_PASSWORD = ""; - - public static final String KEYSTONE_ENDPOINT = "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v3"; - - public static final String TENANT_NAME = "admin"; + public static final String KEYSTONE_AUTH_URL = "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v3"; + + public static final String KEYSTONE_USERNAME = ""; + + public static final String KEYSTONE_PASSWORD = ""; + + public static final String KEYSTONE_ENDPOINT = "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v3"; + + public static final String TENANT_NAME = "admin"; - public static final String NOVA_ENDPOINT = "http://compute/v2"; - - public static final String CEILOMETER_ENDPOINT = ""; - - public static void main(String[] args) { - Keystone client = new Keystone(KEYSTONE_ENDPOINT); - client.setTokenProvider(new OpenStackSimpleTokenProvider("secret0")); - client.tenants().delete("36c481aec1d54fc49190c92c3ef6840a").execute(); - Tenant tenant = client.tenants().create(new Tenant("new_api")).execute(); - System.out.println(tenant); - System.out.println(client.tenants().list().execute()); - client.tenants().delete(tenant.getId()).execute(); - } - + public static final String NOVA_ENDPOINT = "http://compute/v2"; + + public static final String CEILOMETER_ENDPOINT = ""; + + public static void main(String[] args) { + Keystone client = new Keystone(KEYSTONE_ENDPOINT); + client.setTokenProvider(new OpenStackSimpleTokenProvider("secret0")); + client.tenants().delete("36c481aec1d54fc49190c92c3ef6840a").execute(); + Tenant tenant = client.tenants().create(new Tenant("new_api")).execute(); + System.out.println(tenant); + System.out.println(client.tenants().list().execute()); + client.tenants().delete(tenant.getId()).execute(); + } + } diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListFlavors.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListFlavors.java index 8b449e9..25b196c 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListFlavors.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListFlavors.java @@ -29,39 +29,39 @@ import com.woorea.openstack.nova.model.Flavors; public class NovaListFlavors { - /** - * @param args - */ - public static void main(String[] args) { - Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); - Access access = keystone.tokens().authenticate( - new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) - .execute(); - - //use the token in the following requests - keystone.token(access.getToken().getId()); - - Tenants tenants = keystone.tenants().list().execute(); - - //try to exchange token using the first tenant - if(tenants.getList().size() > 0) { - - access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute(); - - //NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), access.getToken().getId()); - Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(tenants.getList().get(0).getId())); - novaClient.token(access.getToken().getId()); - //novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024); - - Flavors flavors = novaClient.flavors().list(true).execute(); - for(Flavor flavor : flavors) { - System.out.println(flavor); - } - - } else { - System.out.println("No tenants found!"); - } - - } + /** + * @param args + */ + public static void main(String[] args) { + Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); + Access access = keystone.tokens().authenticate( + new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) + .execute(); + + //use the token in the following requests + keystone.token(access.getToken().getId()); + + Tenants tenants = keystone.tenants().list().execute(); + + //try to exchange token using the first tenant + if(tenants.getList().size() > 0) { + + access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute(); + + //NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), access.getToken().getId()); + Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(tenants.getList().get(0).getId())); + novaClient.token(access.getToken().getId()); + //novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024); + + Flavors flavors = novaClient.flavors().list(true).execute(); + for(Flavor flavor : flavors) { + System.out.println(flavor); + } + + } else { + System.out.println("No tenants found!"); + } + + } } diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListImages.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListImages.java index 37cd70f..1f7a431 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListImages.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListImages.java @@ -28,41 +28,41 @@ import com.woorea.openstack.nova.model.Image; import com.woorea.openstack.nova.model.Images; public class NovaListImages { - - /** - * @param args - */ - public static void main(String[] args) { - - Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); - Access access = keystone.tokens().authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)).execute(); - - //use the token in the following requests - keystone.token(access.getToken().getId()); - - Tenants tenants = keystone.tenants().list().execute(); - - //try to exchange token using the first tenant - if(tenants.getList().size() > 0) { - - access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())) - .withTenantId(tenants.getList().get(0).getId()) - .execute(); - - //NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), access.getToken().getId()); - Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(tenants.getList().get(0).getId())); - novaClient.token(access.getToken().getId()); - //novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024); - - Images images = novaClient.images().list(true).execute(); - for(Image image : images) { - System.out.println(image); - } - - } else { - System.out.println("No tenants found!"); - } - - } + + /** + * @param args + */ + public static void main(String[] args) { + + Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); + Access access = keystone.tokens().authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)).execute(); + + //use the token in the following requests + keystone.token(access.getToken().getId()); + + Tenants tenants = keystone.tenants().list().execute(); + + //try to exchange token using the first tenant + if(tenants.getList().size() > 0) { + + access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())) + .withTenantId(tenants.getList().get(0).getId()) + .execute(); + + //NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), access.getToken().getId()); + Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(tenants.getList().get(0).getId())); + novaClient.token(access.getToken().getId()); + //novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024); + + Images images = novaClient.images().list(true).execute(); + for(Image image : images) { + System.out.println(image); + } + + } else { + System.out.println("No tenants found!"); + } + + } } diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListServers.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListServers.java index 58faf69..0331a62 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListServers.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListServers.java @@ -26,29 +26,29 @@ import com.woorea.openstack.nova.model.Server; import com.woorea.openstack.nova.model.Servers; public class NovaListServers { - - /** - * @param args - */ - public static void main(String[] args) { - Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); - Access access = keystone.tokens().authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) - .withTenantName("demo") - .execute(); - - //use the token in the following requests - keystone.token(access.getToken().getId()); - - //NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), access.getToken().getId()); - Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(access.getToken().getTenant().getId())); - novaClient.token(access.getToken().getId()); - //novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024); - - Servers servers = novaClient.servers().list(true).execute(); - for(Server server : servers) { - System.out.println(server); - } - - } + + /** + * @param args + */ + public static void main(String[] args) { + Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); + Access access = keystone.tokens().authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) + .withTenantName("demo") + .execute(); + + //use the token in the following requests + keystone.token(access.getToken().getId()); + + //NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), access.getToken().getId()); + Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(access.getToken().getTenant().getId())); + novaClient.token(access.getToken().getId()); + //novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024); + + Servers servers = novaClient.servers().list(true).execute(); + for(Server server : servers) { + System.out.println(server); + } + + } } diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaStopStartServer.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaStopStartServer.java index d113d21..dfc5f06 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaStopStartServer.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaStopStartServer.java @@ -25,32 +25,32 @@ import com.woorea.openstack.nova.api.ServersResource; import com.woorea.openstack.nova.model.Servers; public class NovaStopStartServer { - public static void main(String[] args) throws InterruptedException { - Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); - Access access = keystone.tokens().authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) - .withTenantName(ExamplesConfiguration.TENANT_NAME) - .execute(); - - //use the token in the following requests - keystone.token(access.getToken().getId()); - - Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(access.getToken().getTenant().getId())); - novaClient.token(access.getToken().getId()); - - Servers servers = novaClient.servers().list(true).execute(); - if(servers.getList().size() > 0) { - - // Server has to be in activated state. - ServersResource.StopServer stopServer = novaClient.servers().stop(servers.getList().get(0).getId()); - stopServer.endpoint(ExamplesConfiguration.NOVA_ENDPOINT); - stopServer.execute(); - - // Wait until server shutdown. Or 400 error occurs. - Thread.sleep(5000); - - ServersResource.StartServer startServer = novaClient.servers().start(servers.getList().get(0).getId()); - startServer.endpoint(ExamplesConfiguration.NOVA_ENDPOINT); - startServer.execute(); - } - } + public static void main(String[] args) throws InterruptedException { + Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); + Access access = keystone.tokens().authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) + .withTenantName(ExamplesConfiguration.TENANT_NAME) + .execute(); + + //use the token in the following requests + keystone.token(access.getToken().getId()); + + Nova novaClient = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat("/").concat(access.getToken().getTenant().getId())); + novaClient.token(access.getToken().getId()); + + Servers servers = novaClient.servers().list(true).execute(); + if(servers.getList().size() > 0) { + + // Server has to be in activated state. + ServersResource.StopServer stopServer = novaClient.servers().stop(servers.getList().get(0).getId()); + stopServer.endpoint(ExamplesConfiguration.NOVA_ENDPOINT); + stopServer.execute(); + + // Wait until server shutdown. Or 400 error occurs. + Thread.sleep(5000); + + ServersResource.StartServer startServer = novaClient.servers().start(servers.getList().get(0).getId()); + startServer.endpoint(ExamplesConfiguration.NOVA_ENDPOINT); + startServer.execute(); + } + } } diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/glance/GlanceListImages.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/glance/GlanceListImages.java index 1e9802a..f0eef65 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/glance/GlanceListImages.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/glance/GlanceListImages.java @@ -33,67 +33,67 @@ import java.io.IOException; public class GlanceListImages { - protected static String IMAGE_CONTENT = "Hello World!"; - - /** - * @param args - */ - public static void main(String[] args) { - KeystoneTokenProvider keystone = new KeystoneTokenProvider( - ExamplesConfiguration.KEYSTONE_AUTH_URL, - ExamplesConfiguration.KEYSTONE_USERNAME, - ExamplesConfiguration.KEYSTONE_PASSWORD); - - Access access = keystone.getAccessByTenant(ExamplesConfiguration.TENANT_NAME); - - Service glanceService = null; - - for (Service service : access.getServiceCatalog()) { - if (service.getType().equals("image")) { - glanceService = service; - break; - } - } - - if (glanceService == null) { - throw new RuntimeException("Glance service not found"); - } - - for (Endpoint endpoint : glanceService.getEndpoints()) { - Glance glance = new Glance(endpoint.getPublicURL() + "/v1"); - glance.setTokenProvider(keystone - .getProviderByTenant(ExamplesConfiguration.TENANT_NAME)); - - // Creating a new image - Image newImage = new Image(); - newImage.setDiskFormat("raw"); - newImage.setContainerFormat("bare"); - newImage.setName("os-java-glance-test"); - newImage = glance.images().create(newImage).execute(); - - // Uploading image - ImageUpload uploadImage = new ImageUpload(newImage); - uploadImage.setInputStream(new ByteArrayInputStream(IMAGE_CONTENT.getBytes())); - glance.images().upload(newImage.getId(), uploadImage).execute(); - - // Downloading the image and displaying the image content - try { - byte[] imgContent = new byte[IMAGE_CONTENT.length()]; - ImageDownload downloadImage = glance.images().download(newImage.getId()).execute(); - downloadImage.getInputStream().read(imgContent, 0, imgContent.length); - System.out.println(new String(imgContent)); - } catch (IOException e) { - e.printStackTrace(); - } - - Images images = glance.images().list(false).execute(); - - for (Image image : images) { - System.out.println(glance.images().show(image.getId()).execute()); - } - - glance.images().delete(newImage.getId()).execute(); - } - } + protected static String IMAGE_CONTENT = "Hello World!"; + + /** + * @param args + */ + public static void main(String[] args) { + KeystoneTokenProvider keystone = new KeystoneTokenProvider( + ExamplesConfiguration.KEYSTONE_AUTH_URL, + ExamplesConfiguration.KEYSTONE_USERNAME, + ExamplesConfiguration.KEYSTONE_PASSWORD); + + Access access = keystone.getAccessByTenant(ExamplesConfiguration.TENANT_NAME); + + Service glanceService = null; + + for (Service service : access.getServiceCatalog()) { + if (service.getType().equals("image")) { + glanceService = service; + break; + } + } + + if (glanceService == null) { + throw new RuntimeException("Glance service not found"); + } + + for (Endpoint endpoint : glanceService.getEndpoints()) { + Glance glance = new Glance(endpoint.getPublicURL() + "/v1"); + glance.setTokenProvider(keystone + .getProviderByTenant(ExamplesConfiguration.TENANT_NAME)); + + // Creating a new image + Image newImage = new Image(); + newImage.setDiskFormat("raw"); + newImage.setContainerFormat("bare"); + newImage.setName("os-java-glance-test"); + newImage = glance.images().create(newImage).execute(); + + // Uploading image + ImageUpload uploadImage = new ImageUpload(newImage); + uploadImage.setInputStream(new ByteArrayInputStream(IMAGE_CONTENT.getBytes())); + glance.images().upload(newImage.getId(), uploadImage).execute(); + + // Downloading the image and displaying the image content + try { + byte[] imgContent = new byte[IMAGE_CONTENT.length()]; + ImageDownload downloadImage = glance.images().download(newImage.getId()).execute(); + downloadImage.getInputStream().read(imgContent, 0, imgContent.length); + System.out.println(new String(imgContent)); + } catch (IOException e) { + e.printStackTrace(); + } + + Images images = glance.images().list(false).execute(); + + for (Image image : images) { + System.out.println(glance.images().show(image.getId()).execute()); + } + + glance.images().delete(newImage.getId()).execute(); + } + } } diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/keystone/KeystoneCreateTenant.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/keystone/KeystoneCreateTenant.java index 34bd13d..5ef94cb 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/keystone/KeystoneCreateTenant.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/keystone/KeystoneCreateTenant.java @@ -26,27 +26,27 @@ import com.woorea.openstack.keystone.model.authentication.UsernamePassword; public class KeystoneCreateTenant { - /** - * @param args - */ - public static void main(String[] args) { - Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); - //access with unscoped token - Access access = keystone.tokens().authenticate( - new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) - .execute(); + /** + * @param args + */ + public static void main(String[] args) { + Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); + //access with unscoped token + Access access = keystone.tokens().authenticate( + new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) + .execute(); - access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantName("admin").execute(); + access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantName("admin").execute(); - Tenant tenant = new Tenant(); - tenant.setName("benn.cs"); - tenant.setDescription("benn.cs"); - tenant.setEnabled(true); - //Get the adminURL client and use the token got above - keystone = new Keystone("http://keystone.x.org/v2.0"); - keystone.token(access.getToken().getId()); - tenant = keystone.tenants().create(tenant).execute(); - System.out.println(tenant); - keystone.tenants().delete(tenant.getId()); - } + Tenant tenant = new Tenant(); + tenant.setName("benn.cs"); + tenant.setDescription("benn.cs"); + tenant.setEnabled(true); + //Get the adminURL client and use the token got above + keystone = new Keystone("http://keystone.x.org/v2.0"); + keystone.token(access.getToken().getId()); + tenant = keystone.tenants().create(tenant).execute(); + System.out.println(tenant); + keystone.tenants().delete(tenant.getId()); + } } diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/keystone/KeystoneCreateUser.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/keystone/KeystoneCreateUser.java index 0b9392c..e99d1ce 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/keystone/KeystoneCreateUser.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/keystone/KeystoneCreateUser.java @@ -26,29 +26,29 @@ import com.woorea.openstack.keystone.model.authentication.UsernamePassword; public class KeystoneCreateUser { - /** - * @param args - */ - public static void main(String[] args) { - Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); - //access with unscoped token - Access access = keystone.tokens() - .authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) - .withTenantName("admin") - .execute(); + /** + * @param args + */ + public static void main(String[] args) { + Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); + //access with unscoped token + Access access = keystone.tokens() + .authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) + .withTenantName("admin") + .execute(); - User user = new User(); - user.setEmail("luis@woorea.es"); - user.setUsername("luis.gervaso"); - user.setPassword("password.0"); - user.setName("Luis"); - user.setEnabled(Boolean.TRUE); + User user = new User(); + user.setEmail("luis@woorea.es"); + user.setUsername("luis.gervaso"); + user.setPassword("password.0"); + user.setName("Luis"); + user.setEnabled(Boolean.TRUE); - keystone = new Keystone("http://keystone.x.org/v2.0"); - keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); - //keystone.enableLogging(Logger.getLogger("keystone"), 10000); - user = keystone.users().create(user).execute(); - System.out.println(user); - keystone.users().delete(user.getId()).execute(); - } + keystone = new Keystone("http://keystone.x.org/v2.0"); + keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); + //keystone.enableLogging(Logger.getLogger("keystone"), 10000); + user = keystone.users().create(user).execute(); + System.out.println(user); + keystone.users().delete(user.getId()).execute(); + } } diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/metering/v2/TestAll.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/metering/v2/TestAll.java index 279775a..bdb20c0 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/metering/v2/TestAll.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/metering/v2/TestAll.java @@ -30,49 +30,49 @@ import com.woorea.openstack.keystone.model.authentication.UsernamePassword; public class TestAll { - /** - * @param args - */ - public static void main(String[] args) { - Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); - Access access = keystone.tokens() - .authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) - .withTenantName("admin") - .execute(); - - Ceilometer ceilometer = new Ceilometer(ExamplesConfiguration.CEILOMETER_ENDPOINT); - ceilometer.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); + /** + * @param args + */ + public static void main(String[] args) { + Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); + Access access = keystone.tokens() + .authenticate(new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) + .withTenantName("admin") + .execute(); + + Ceilometer ceilometer = new Ceilometer(ExamplesConfiguration.CEILOMETER_ENDPOINT); + ceilometer.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); - /* - List<Resource> resources = ceilometer.execute(new ResourceList().eq("resource_id", "23b55841eedd41e99d5f3f32149ca086")); - - - for(Resource r : resources) { - Resource resource = ceilometer.execute(new ResourceShow().id(r.getResource())); - } - */ - - /* - //List<Meter> meters = ceilometer.meters().list().execute(); //execute(new MeterList().eq("project_id", "948eeb593acd4223ad572c49e1ef5709")); - - - for(Meter m : meters) { - System.out.println(m); - -// List<Sample> samples = ceilometer.execute(new MeterShow().name(m.getName())); -// for(Sample s : samples) { -// System.out.println("\t" + s); -// } - - List<Statistics> stats = ceilometer.meters().statistics().execute(); // (new MeterStatistics().name(m.getName())); - for(Statistics s : stats) { - System.out.println("\t\t" + s); - } - - - } - */ - - } + /* + List<Resource> resources = ceilometer.execute(new ResourceList().eq("resource_id", "23b55841eedd41e99d5f3f32149ca086")); + + + for(Resource r : resources) { + Resource resource = ceilometer.execute(new ResourceShow().id(r.getResource())); + } + */ + + /* + //List<Meter> meters = ceilometer.meters().list().execute(); //execute(new MeterList().eq("project_id", "948eeb593acd4223ad572c49e1ef5709")); + + + for(Meter m : meters) { + System.out.println(m); + +// List<Sample> samples = ceilometer.execute(new MeterShow().name(m.getName())); +// for(Sample s : samples) { +// System.out.println("\t" + s); +// } + + List<Statistics> stats = ceilometer.meters().statistics().execute(); // (new MeterStatistics().name(m.getName())); + for(Statistics s : stats) { + System.out.println("\t\t" + s); + } + + + } + */ + + } } diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumListNetworks.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumListNetworks.java index a700e1c..3fdaa9d 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumListNetworks.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumListNetworks.java @@ -31,33 +31,33 @@ import com.woorea.openstack.quantum.model.Networks; public class QuantumListNetworks { - /** - * @param args - */ - public static void main(String[] args) { - Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); - // access with unscoped token - Access access = keystone.tokens().authenticate( - new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) - .execute(); - // use the token in the following requests - keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); - - Tenants tenants = keystone.tenants().list().execute(); - // try to exchange token using the first tenant - if (tenants.getList().size() > 0) { - // access with tenant - access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute(); - - Quantum quantum = new Quantum(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "network", null, "public")); - quantum.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); - - Networks networks = quantum.networks().list().execute(); - for (Network network : networks) { - System.out.println(network); - } - } else { - System.out.println("No tenants found!"); - } - } + /** + * @param args + */ + public static void main(String[] args) { + Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); + // access with unscoped token + Access access = keystone.tokens().authenticate( + new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) + .execute(); + // use the token in the following requests + keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); + + Tenants tenants = keystone.tenants().list().execute(); + // try to exchange token using the first tenant + if (tenants.getList().size() > 0) { + // access with tenant + access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute(); + + Quantum quantum = new Quantum(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "network", null, "public")); + quantum.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); + + Networks networks = quantum.networks().list().execute(); + for (Network network : networks) { + System.out.println(network); + } + } else { + System.out.println("No tenants found!"); + } + } } diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumNetworkCreate.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumNetworkCreate.java index 1dab981..39f9eea 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumNetworkCreate.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumNetworkCreate.java @@ -47,78 +47,78 @@ import com.woorea.openstack.quantum.model.Subnets; public class QuantumNetworkCreate { - /** - * @param args - */ - public static void main(String[] args) { - Keystone keystone = new Keystone( - ExamplesConfiguration.KEYSTONE_AUTH_URL); - // access with unscoped token - Access access = keystone - .tokens() - .authenticate( - new UsernamePassword( - ExamplesConfiguration.KEYSTONE_USERNAME, - ExamplesConfiguration.KEYSTONE_PASSWORD)) - .execute(); - // use the token in the following requests - keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access - .getToken().getId())); - keystone.token(access.getToken().getId()); - Tenants tenants = keystone.tenants().list().execute(); - // try to exchange token using the first tenant + /** + * @param args + */ + public static void main(String[] args) { + Keystone keystone = new Keystone( + ExamplesConfiguration.KEYSTONE_AUTH_URL); + // access with unscoped token + Access access = keystone + .tokens() + .authenticate( + new UsernamePassword( + ExamplesConfiguration.KEYSTONE_USERNAME, + ExamplesConfiguration.KEYSTONE_PASSWORD)) + .execute(); + // use the token in the following requests + keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access + .getToken().getId())); + keystone.token(access.getToken().getId()); + Tenants tenants = keystone.tenants().list().execute(); + // try to exchange token using the first tenant - if (tenants.getList().size() > 0) { - // access with tenant - Network network = new Network(); - access = keystone - .tokens() - .authenticate( - new TokenAuthentication(access.getToken().getId())) - .withTenantId("tenantId").execute(); - Quantum quantum = new Quantum(KeystoneUtils.findEndpointURL( - access.getServiceCatalog(), "network", null, "public")); - quantum.setTokenProvider(new OpenStackSimpleTokenProvider(access - .getToken().getId())); - NetworkForCreate netcreate = new NetworkForCreate(); - netcreate.setTenantId("tenantId"); - netcreate.setName("net2"); - netcreate.setAdminStateUp(true); + if (tenants.getList().size() > 0) { + // access with tenant + Network network = new Network(); + access = keystone + .tokens() + .authenticate( + new TokenAuthentication(access.getToken().getId())) + .withTenantId("tenantId").execute(); + Quantum quantum = new Quantum(KeystoneUtils.findEndpointURL( + access.getServiceCatalog(), "network", null, "public")); + quantum.setTokenProvider(new OpenStackSimpleTokenProvider(access + .getToken().getId())); + NetworkForCreate netcreate = new NetworkForCreate(); + netcreate.setTenantId("tenantId"); + netcreate.setName("net2"); + netcreate.setAdminStateUp(true); - network = quantum.networks().create(netcreate).execute(); + network = quantum.networks().create(netcreate).execute(); - // Creating Subnet - try { - Subnet sub = new Subnet(); - SubnetForCreate subnet = new SubnetForCreate(); - subnet.setCidr(""); - subnet.setName(""); - subnet.setNetworkId(network.getId()); - subnet.setIpVersion(4); - sub = quantum.subnets().create(subnet).execute(); - RouterForCreate routerForCreate = new RouterForCreate(); - routerForCreate.setName("routerName"); - routerForCreate.setTenantId("tenantId"); - Router router = quantum.routers().create(routerForCreate) - .execute(); - RouterForAddInterface routerForAdd = new RouterForAddInterface(); - routerForAdd.setSubnetId(sub.getId()); - routerForAdd.setRouterId(router.getId()); - quantum.routers().addInterface(routerForAdd).execute(); + // Creating Subnet + try { + Subnet sub = new Subnet(); + SubnetForCreate subnet = new SubnetForCreate(); + subnet.setCidr(""); + subnet.setName(""); + subnet.setNetworkId(network.getId()); + subnet.setIpVersion(4); + sub = quantum.subnets().create(subnet).execute(); + RouterForCreate routerForCreate = new RouterForCreate(); + routerForCreate.setName("routerName"); + routerForCreate.setTenantId("tenantId"); + Router router = quantum.routers().create(routerForCreate) + .execute(); + RouterForAddInterface routerForAdd = new RouterForAddInterface(); + routerForAdd.setSubnetId(sub.getId()); + routerForAdd.setRouterId(router.getId()); + quantum.routers().addInterface(routerForAdd).execute(); - // System.out.println(sub); - } catch (Exception e) { - System.out.println(e.getMessage()); - } + // System.out.println(sub); + } catch (Exception e) { + System.out.println(e.getMessage()); + } - Networks networks = quantum.networks().list().execute(); + Networks networks = quantum.networks().list().execute(); - for (Network network1 : networks) { - System.out.println(network1); - } - } else { - System.out.println("No tenants found!"); - } + for (Network network1 : networks) { + System.out.println(network1); + } + } else { + System.out.println("No tenants found!"); + } - } + } } diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumQueryNetworks.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumQueryNetworks.java index 447af4e..e442c73 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumQueryNetworks.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumQueryNetworks.java @@ -30,46 +30,46 @@ import com.woorea.openstack.quantum.model.Network; public class QuantumQueryNetworks { - /** - * @param args - */ - public static void main(String[] args) { - Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); - // access with unscoped token - Access access = keystone.tokens().authenticate( - new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) - .execute(); - // use the token in the following requests - keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); + /** + * @param args + */ + public static void main(String[] args) { + Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); + // access with unscoped token + Access access = keystone.tokens().authenticate( + new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) + .execute(); + // use the token in the following requests + keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); - Tenants tenants = keystone.tenants().list().execute(); - // try to exchange token using the first tenant - if (tenants.getList().size() > 0) { - // access with tenant - access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute(); + Tenants tenants = keystone.tenants().list().execute(); + // try to exchange token using the first tenant + if (tenants.getList().size() > 0) { + // access with tenant + access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute(); - Quantum quantumClient = new Quantum(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "network", null, "public")); - quantumClient.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); + Quantum quantumClient = new Quantum(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "network", null, "public")); + quantumClient.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); - Network networkQuery = new Network(); - networkQuery.setName("benn.cs"); - networkQuery.setAdminStateUp(true); - /* - Networks networks = quantumClient.execute(NetworkQuery.queryNetworks(networkQuery)); + Network networkQuery = new Network(); + networkQuery.setName("benn.cs"); + networkQuery.setAdminStateUp(true); + /* + Networks networks = quantumClient.execute(NetworkQuery.queryNetworks(networkQuery)); - for (Network network : networks) { - System.out.println(network); - } + for (Network network : networks) { + System.out.println(network); + } - Subnet subnetQuery = new Subnet(); - subnetQuery.setIpversion(Subnet.IpVersion.IPV4); - Subnets Subnets = quantumClient.execute(NetworkQuery.querySubnets(subnetQuery)); - for (Subnet subnet : Subnets) { - System.out.println(subnet); - } - */ - } else { - System.out.println("No tenants found!"); - } - } + Subnet subnetQuery = new Subnet(); + subnetQuery.setIpversion(Subnet.IpVersion.IPV4); + Subnets Subnets = quantumClient.execute(NetworkQuery.querySubnets(subnetQuery)); + for (Subnet subnet : Subnets) { + System.out.println(subnet); + } + */ + } else { + System.out.println("No tenants found!"); + } + } } diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/objectstore/SwiftExample.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/objectstore/SwiftExample.java index bf741b1..36d0e08 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/objectstore/SwiftExample.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/objectstore/SwiftExample.java @@ -38,69 +38,69 @@ import com.woorea.openstack.swift.model.ObjectDownload; import com.woorea.openstack.swift.model.ObjectForUpload; public class SwiftExample { - - private static final File TEST_FILE = new File("pom.xml"); - - /** - * @param args - */ - public static void main(String[] args) throws Exception { - Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); - //access with unscoped token - Access access = keystone.tokens().authenticate( - new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) - .execute(); - - //use the token in the following requests - keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); - - Tenants tenants = keystone.tenants().list().execute(); - - //try to exchange token using the first tenant - if(tenants.getList().size() > 0) { - - access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute(); - - Swift swift = new Swift(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "object-store", null, "public")); - swift.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); - - //swiftClient.execute(new DeleteContainer("navidad2")); - - swift.containers().create("navidad2").execute(); - - System.out.println(swift.containers().list()); - - ObjectForUpload upload = new ObjectForUpload(); - upload.setContainer("navidad2"); - upload.setName("example2"); - upload.setInputStream(new FileInputStream(TEST_FILE)); - swift.containers().container("navidad2").upload(upload).execute(); - -// System.out.println(swiftClient.execute(new ListObjects("navidad2", new HashMap<String, String>() {{ -// put("path", ""); -// }})).get(0).getContentType()); - - - ObjectDownload download = swift.containers().container("navidad").download("example2").execute(); - write(download.getInputStream(), "example2"); - } + + private static final File TEST_FILE = new File("pom.xml"); + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); + //access with unscoped token + Access access = keystone.tokens().authenticate( + new UsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)) + .execute(); + + //use the token in the following requests + keystone.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); + + Tenants tenants = keystone.tenants().list().execute(); + + //try to exchange token using the first tenant + if(tenants.getList().size() > 0) { + + access = keystone.tokens().authenticate(new TokenAuthentication(access.getToken().getId())).withTenantId(tenants.getList().get(0).getId()).execute(); + + Swift swift = new Swift(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "object-store", null, "public")); + swift.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken().getId())); + + //swiftClient.execute(new DeleteContainer("navidad2")); + + swift.containers().create("navidad2").execute(); + + System.out.println(swift.containers().list()); + + ObjectForUpload upload = new ObjectForUpload(); + upload.setContainer("navidad2"); + upload.setName("example2"); + upload.setInputStream(new FileInputStream(TEST_FILE)); + swift.containers().container("navidad2").upload(upload).execute(); + +// System.out.println(swiftClient.execute(new ListObjects("navidad2", new HashMap<String, String>() {{ +// put("path", ""); +// }})).get(0).getContentType()); + + + ObjectDownload download = swift.containers().container("navidad").download("example2").execute(); + write(download.getInputStream(), "example2"); + } - } - - private static void write(InputStream is, String path) { - try { - OutputStream stream = new BufferedOutputStream(new FileOutputStream(path)); - int bufferSize = 1024; - byte[] buffer = new byte[bufferSize]; - int len = 0; - while ((len = is.read(buffer)) != -1) { - stream.write(buffer, 0, len); - } - stream.close(); - } catch(IOException e) { - throw new RuntimeException(e.getMessage(), e); - } - - } + } + + private static void write(InputStream is, String path) { + try { + OutputStream stream = new BufferedOutputStream(new FileOutputStream(path)); + int bufferSize = 1024; + byte[] buffer = new byte[bufferSize]; + int len = 0; + while ((len = is.read(buffer)) != -1) { + stream.write(buffer, 0, len); + } + stream.close(); + } catch(IOException e) { + throw new RuntimeException(e.getMessage(), e); + } + + } } diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/simple/OpenStackSimpleClient.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/simple/OpenStackSimpleClient.java index cf998fb..a2f9eb5 100644 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/simple/OpenStackSimpleClient.java +++ b/openstack-examples/src/main/java/com/woorea/openstack/examples/simple/OpenStackSimpleClient.java @@ -19,13 +19,13 @@ package com.woorea.openstack.examples.simple; public class OpenStackSimpleClient { - /** - * @param args - */ - public static void main(String[] args) { -// OpenStackClient client = new OpenStackClient(ExamplesConfiguration.KEYSTONE_AUTH_URL); -// Access access = client.request("/tokens").execute("POST", Entity.json("{\"auth\":{\"passwordCredentials\":{\"username\":\"\",\"password\":\"\"}}}"), Access.class); -// System.out.println(access); - } + /** + * @param args + */ + public static void main(String[] args) { +// OpenStackClient client = new OpenStackClient(ExamplesConfiguration.KEYSTONE_AUTH_URL); +// Access access = client.request("/tokens").execute("POST", Entity.json("{\"auth\":{\"passwordCredentials\":{\"username\":\"\",\"password\":\"\"}}}"), Access.class); +// System.out.println(access); + } } |