diff options
Diffstat (limited to 'openstack-examples')
19 files changed, 0 insertions, 1354 deletions
diff --git a/openstack-examples/pom.xml b/openstack-examples/pom.xml deleted file mode 100644 index 4bf6b15..0000000 --- a/openstack-examples/pom.xml +++ /dev/null @@ -1,84 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onap.so</groupId> - <artifactId>openstack-java-sdk</artifactId> - <version>1.2.1-SNAPSHOT</version> - </parent> - <groupId>org.onap.so.libs.openstack-java-sdk</groupId> - <artifactId>openstack-examples</artifactId> - <name>OpenStack Examples</name> - <description>OpenStack Examples</description> - <dependencies> - <dependency> - <groupId>org.onap.so</groupId> - <artifactId>keystone-client</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onap.so</groupId> - <artifactId>nova-client</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onap.so</groupId> - <artifactId>heat-client</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onap.so</groupId> - <artifactId>swift-client</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onap.so</groupId> - <artifactId>quantum-client</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onap.so</groupId> - <artifactId>ceilometer-client</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onap.so</groupId> - <artifactId>glance-client</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - <profiles> - <profile> - <id>jersey</id> - <dependencies> - <dependency> - <groupId>org.onap.so</groupId> - <artifactId>jersey-connector</artifactId> - <version>3.1.0-SNAPSHOT</version> - </dependency> - </dependencies> - </profile> - <profile> - <id>jersey2</id> - <activation> - <activeByDefault>true</activeByDefault> - </activation> - <dependencies> - <dependency> - <groupId>org.onap.so</groupId> - <artifactId>jersey2-connector</artifactId> - <version>3.2.0-SNAPSHOT</version> - </dependency> - </dependencies> - </profile> - <profile> - <id>resteasy</id> - <dependencies> - <dependency> - <groupId>org.onap.so</groupId> - <artifactId>resteasy-connector</artifactId> - <version>3.2.0-SNAPSHOT</version> - </dependency> - </dependencies> - </profile> - </profiles> -</project> 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 deleted file mode 100644 index 2fa2f5f..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/ExamplesConfiguration.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples; - - -import com.woorea.openstack.base.client.OpenStackSimpleTokenProvider; -import com.woorea.openstack.keystone.Keystone; -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 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/NovaCreateServer.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaCreateServer.java deleted file mode 100644 index 937ab5c..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaCreateServer.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.compute; - - -import com.woorea.openstack.base.client.OpenStackSimpleTokenProvider; -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.Keystone; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.model.Tenants; -import com.woorea.openstack.nova.Nova; -import com.woorea.openstack.nova.model.Flavors; -import com.woorea.openstack.nova.model.Images; -import com.woorea.openstack.nova.model.KeyPairs; -import com.woorea.openstack.nova.model.Server; -import com.woorea.openstack.nova.model.ServerForCreate; - -public class NovaCreateServer { - - /** - * @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() - .withUsernamePassword(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() - .withToken(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 nova = new Nova(ExamplesConfiguration.NOVA_ENDPOINT.concat(tenants - .getList().get(0).getId())); - nova.setTokenProvider(new OpenStackSimpleTokenProvider(access.getToken() - .getId())); - // novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024); - // create a new keypair - // KeyPair keyPair = - // novaClient.execute(KeyPairsExtension.createKeyPair("mykeypair")); - // System.out.println(keyPair.getPrivateKey()); - - // create security group - // SecurityGroup securityGroup = - // novaClient.execute(SecurityGroupsExtension.createSecurityGroup("mysecuritygroup", - // "description")); - - // novaClient.execute(SecurityGroupsExtension.createSecurityGroupRule(securityGroup.getId(), - // "UDP", 9090, 9092, "0.0.0.0/0")); - // novaClient.execute(SecurityGroupsExtension.createSecurityGroupRule(securityGroup.getId(), - // "TCP", 8080, 8080, "0.0.0.0/0")); - - KeyPairs keysPairs = nova.keyPairs().list().execute(); - - Images images = nova.images().list(true).execute(); - - Flavors flavors = nova.flavors().list(true).execute(); - - ServerForCreate serverForCreate = new ServerForCreate(); - serverForCreate.setName("woorea"); - serverForCreate.setFlavorRef(flavors.getList().get(0).getId()); - serverForCreate.setImageRef(images.getList().get(1).getId()); - serverForCreate.setKeyName(keysPairs.getList().get(0).getName()); - serverForCreate.getSecurityGroups() - .add(new ServerForCreate.SecurityGroup("default")); - // serverForCreate.getSecurityGroups().add(new - // ServerForCreate.SecurityGroup(securityGroup.getName())); - - Server server = nova.servers().boot(serverForCreate).execute(); - System.out.println(server); - - } else { - System.out.println("No tenants found!"); - } - - } - -} 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 deleted file mode 100644 index 25b196c..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListFlavors.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.compute; - - -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.Keystone; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.model.Tenants; -import com.woorea.openstack.keystone.model.authentication.TokenAuthentication; -import com.woorea.openstack.keystone.model.authentication.UsernamePassword; -import com.woorea.openstack.nova.Nova; -import com.woorea.openstack.nova.model.Flavor; -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!"); - } - - } - -} 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 deleted file mode 100644 index 1f7a431..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListImages.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.compute; - - -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.Keystone; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.model.Tenants; -import com.woorea.openstack.keystone.model.authentication.TokenAuthentication; -import com.woorea.openstack.keystone.model.authentication.UsernamePassword; -import com.woorea.openstack.nova.Nova; -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!"); - } - - } - -} 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 deleted file mode 100644 index 0331a62..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaListServers.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.compute; - - -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.Keystone; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.model.authentication.UsernamePassword; -import com.woorea.openstack.nova.Nova; -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); - } - - } - -} 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 deleted file mode 100644 index dfc5f06..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/compute/NovaStopStartServer.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.compute; - -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.Keystone; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.model.authentication.UsernamePassword; -import com.woorea.openstack.nova.Nova; -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(); - } - } -} 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 deleted file mode 100644 index f0eef65..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/glance/GlanceListImages.java +++ /dev/null @@ -1,99 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.glance; - -import com.woorea.openstack.glance.model.ImageDownload; -import com.woorea.openstack.glance.model.ImageUpload; -import com.woorea.openstack.keystone.utils.KeystoneTokenProvider; - -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.glance.Glance; -import com.woorea.openstack.glance.model.Image; -import com.woorea.openstack.glance.model.Images; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.model.Access.Service; -import com.woorea.openstack.keystone.model.Access.Service.Endpoint; - -import java.io.ByteArrayInputStream; -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(); - } - } - -} diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/heat/HeatListStacks.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/heat/HeatListStacks.java deleted file mode 100644 index 66a886f..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/heat/HeatListStacks.java +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.heat; - -/* - * Modifications copyright (c) 2017 AT&T Intellectual Property - */ - -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.heat.Heat; -import com.woorea.openstack.heat.model.CreateStackParam; -import com.woorea.openstack.heat.model.Stack; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.utils.KeystoneTokenProvider; -import com.woorea.openstack.keystone.utils.KeystoneUtils; - -import java.util.Collections; - -public class HeatListStacks { - - private static String TEMPLATE = "{\n" + - " \"HeatTemplateFormatVersion\": \"2012-12-12\",\n" + - " \"Parameters\": {},\n" + - " \"Mappings\": {},\n" + - " \"Resources\": {\n" + - " \"my-test-server\": {\n" + - " \"Type\": \"OS::Nova::Server\",\n" + - " \"Properties\": {\n" + - " \"flavor\": \"m1.small\",\n" + - " \"image\": \"centos:latest\"\n" + - " }\n" + - " }\n" + - " }\n" + - "}"; - - /** - * @param args - */ - public static void main(String[] args) throws InterruptedException { - KeystoneTokenProvider keystone = new KeystoneTokenProvider( - ExamplesConfiguration.KEYSTONE_ENDPOINT, - ExamplesConfiguration.KEYSTONE_USERNAME, - ExamplesConfiguration.KEYSTONE_PASSWORD - ); - - Access access = keystone.getAccessByTenant(ExamplesConfiguration.TENANT_NAME); - - String endpointURL = KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "orchestration", null, "public"); - - - Heat heat = new Heat(endpointURL); - heat.setTokenProvider(keystone - .getProviderByTenant(ExamplesConfiguration.TENANT_NAME)); - - CreateStackParam param = new CreateStackParam(); - param.setStackName("helloWorld"); - param.setTimeoutMinutes(1); - param.setParameters(Collections.<String, Object>emptyMap()); - param.setTemplate(TEMPLATE); - - System.out.printf("Create: " + heat.getStacks().create(param).execute()); - Thread.sleep(3000); - - for (Stack s : heat.getStacks().list().execute()) { - System.out.println(s.getDescription()); - System.out.println(s.getId()); - System.out.println(s.getStackName()); - System.out.println(s.getStackStatus()); - System.out.println(s.getCreationTime()); - System.out.println(s.getUpdatedTime()); - System.out.println(s.getLinks()); - - System.out.println(heat.getStacks().byName(s.getStackName()).execute()); - - - } - } -} diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/hpcloud/Keystone3Authentication.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/hpcloud/Keystone3Authentication.java deleted file mode 100644 index cd12696..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/hpcloud/Keystone3Authentication.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.hpcloud; - - -import com.woorea.openstack.base.client.OpenStackResponse; -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.v3.model.Authentication; -import com.woorea.openstack.keystone.v3.model.Authentication.Identity; -import com.woorea.openstack.keystone.v3.Keystone; -import com.woorea.openstack.keystone.v3.model.Token; - -public class Keystone3Authentication { - - /** - * @param args - */ - public static void main(String[] args) { - Keystone keystone = new Keystone(ExamplesConfiguration.KEYSTONE_AUTH_URL); - - Authentication auth = new Authentication(); - auth.setIdentity(Identity.password(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD)); - - OpenStackResponse response = keystone.tokens().authenticate(auth).request(); - - String tokenId = response.header("X-Subject-Token"); - - Token token = response.getEntity(Token.class); - - System.out.println(tokenId); - - System.out.println(token); - - } - -} diff --git a/openstack-examples/src/main/java/com/woorea/openstack/examples/hpcloud/KeystoneAuthentication.java b/openstack-examples/src/main/java/com/woorea/openstack/examples/hpcloud/KeystoneAuthentication.java deleted file mode 100644 index f1c764f..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/hpcloud/KeystoneAuthentication.java +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.hpcloud; - - -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.Keystone; -import com.woorea.openstack.keystone.model.Access; - -public class KeystoneAuthentication { - - private static final String KEYSTONE_AUTH_URL = "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0"; - - /** - * @param args - */ - public static void main(String[] args) { - Keystone keystone = new Keystone(KEYSTONE_AUTH_URL); - - // access with unscoped token - Access access = keystone - .tokens() - .authenticate() - .withUsernamePassword(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD) - .execute(); - - System.out.println(access); - - } - -} 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 deleted file mode 100644 index 5ef94cb..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/keystone/KeystoneCreateTenant.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.keystone; - - -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.Keystone; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.model.Tenant; -import com.woorea.openstack.keystone.model.authentication.TokenAuthentication; -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(); - - 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()); - } -} 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 deleted file mode 100644 index e99d1ce..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/keystone/KeystoneCreateUser.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.keystone; - - -import com.woorea.openstack.base.client.OpenStackSimpleTokenProvider; -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.Keystone; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.model.User; -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(); - - 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(); - } -} 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 deleted file mode 100644 index bdb20c0..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/metering/v2/TestAll.java +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.metering.v2; - -import java.util.List; - - -import com.woorea.openstack.base.client.OpenStackSimpleTokenProvider; -import com.woorea.openstack.ceilometer.Ceilometer; -import com.woorea.openstack.ceilometer.v2.model.Meter; -import com.woorea.openstack.ceilometer.v2.model.Statistics; -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.Keystone; -import com.woorea.openstack.keystone.model.Access; -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())); - - /* - 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 deleted file mode 100644 index 3fdaa9d..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumListNetworks.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.network; - -import com.woorea.openstack.keystone.utils.KeystoneUtils; - -import com.woorea.openstack.base.client.OpenStackSimpleTokenProvider; -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.Keystone; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.model.Tenants; -import com.woorea.openstack.keystone.model.authentication.TokenAuthentication; -import com.woorea.openstack.keystone.model.authentication.UsernamePassword; -import com.woorea.openstack.quantum.Quantum; -import com.woorea.openstack.quantum.model.Network; -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!"); - } - } -} 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 deleted file mode 100644 index 39f9eea..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumNetworkCreate.java +++ /dev/null @@ -1,124 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.network; - -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; - -import com.woorea.openstack.keystone.utils.KeystoneUtils; - -import com.woorea.openstack.base.client.OpenStackSimpleTokenProvider; -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.Keystone; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.model.Tenant; -import com.woorea.openstack.keystone.model.Tenants; -import com.woorea.openstack.keystone.model.authentication.TokenAuthentication; -import com.woorea.openstack.keystone.model.authentication.UsernamePassword; -import com.woorea.openstack.quantum.Quantum; -import com.woorea.openstack.quantum.api.NetworksResource; -import com.woorea.openstack.quantum.api.NetworksResource.Create; -import com.woorea.openstack.quantum.model.Network; -import com.woorea.openstack.quantum.model.NetworkForCreate; -import com.woorea.openstack.quantum.model.Networks; -import com.woorea.openstack.quantum.model.Port; -import com.woorea.openstack.quantum.model.PortForCreate; -import com.woorea.openstack.quantum.model.Router; -import com.woorea.openstack.quantum.model.RouterForAddInterface; -import com.woorea.openstack.quantum.model.RouterForCreate; -import com.woorea.openstack.quantum.model.Subnet; -import com.woorea.openstack.quantum.model.SubnetForCreate; -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 - - 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(); - - // 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()); - } - - Networks networks = quantum.networks().list().execute(); - - 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 deleted file mode 100644 index e442c73..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/network/QuantumQueryNetworks.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.network; - -import com.woorea.openstack.keystone.utils.KeystoneUtils; - -import com.woorea.openstack.base.client.OpenStackSimpleTokenProvider; -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.Keystone; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.model.Tenants; -import com.woorea.openstack.keystone.model.authentication.TokenAuthentication; -import com.woorea.openstack.keystone.model.authentication.UsernamePassword; -import com.woorea.openstack.quantum.Quantum; -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())); - - 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())); - - 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); - } - - 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 deleted file mode 100644 index 36d0e08..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/objectstore/SwiftExample.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package com.woorea.openstack.examples.objectstore; - -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import com.woorea.openstack.keystone.utils.KeystoneUtils; - -import com.woorea.openstack.base.client.OpenStackSimpleTokenProvider; -import com.woorea.openstack.examples.ExamplesConfiguration; -import com.woorea.openstack.keystone.Keystone; -import com.woorea.openstack.keystone.model.Access; -import com.woorea.openstack.keystone.model.Tenants; -import com.woorea.openstack.keystone.model.authentication.TokenAuthentication; -import com.woorea.openstack.keystone.model.authentication.UsernamePassword; -import com.woorea.openstack.swift.Swift; -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 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 deleted file mode 100644 index a2f9eb5..0000000 --- a/openstack-examples/src/main/java/com/woorea/openstack/examples/simple/OpenStackSimpleClient.java +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -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); - } - -} |