├── rackspace ├── images │ ├── Eclipse1.png │ ├── Eclipse2.png │ └── Eclipse3.png └── src │ ├── etc │ └── header.txt │ └── main │ ├── java │ └── org │ │ └── jclouds │ │ └── examples │ │ └── rackspace │ │ ├── cdn │ │ ├── Constants.java │ │ ├── PurgeServiceAssets.java │ │ ├── UpdateService.java │ │ └── DeleteService.java │ │ ├── cloudnetworks │ │ ├── Constants.java │ │ └── CreateNetwork.java │ │ ├── cloudloadbalancers │ │ ├── Constants.java │ │ ├── ListLoadBalancers.java │ │ └── DeleteLoadBalancers.java │ │ ├── clouddatabases │ │ ├── Constants.java │ │ ├── CreateUser.java │ │ ├── DeleteUser.java │ │ ├── GrantRootAccess.java │ │ ├── DeleteDatabase.java │ │ ├── CreateInstance.java │ │ ├── CreateDatabase.java │ │ └── DeleteInstance.java │ │ ├── cloudservers │ │ ├── Constants.java │ │ └── DeleteServer.java │ │ ├── cloudfiles │ │ ├── Constants.java │ │ ├── GetContainer.java │ │ ├── ListContainers.java │ │ ├── CreateContainer.java │ │ ├── ListObjects.java │ │ ├── GetObject.java │ │ └── DeleteObjectsAndContainer.java │ │ ├── autoscale │ │ ├── Constants.java │ │ ├── Utils.java │ │ ├── CreateWebhook.java │ │ └── UpdatePolicy.java │ │ ├── cloudblockstorage │ │ ├── Constants.java │ │ ├── ListVolumes.java │ │ ├── ListSnapshots.java │ │ ├── ListVolumeTypes.java │ │ ├── DeleteVolume.java │ │ └── DeleteSnapshot.java │ │ ├── carina │ │ ├── ListContainer.java │ │ ├── CreateComputeContainer.java │ │ ├── Utils.java │ │ └── CreateContainer.java │ │ ├── cloudqueues │ │ └── Constants.java │ │ ├── clouddns │ │ ├── Constants.java │ │ ├── DeleteDomains.java │ │ ├── ListDomains.java │ │ └── DeleteRecords.java │ │ └── Logging.java │ └── resources │ └── logback.xml ├── .gitignore ├── glacier ├── README.md ├── src │ └── main │ │ └── assembly │ │ └── jar-with-dependencies.xml └── pom.xml ├── blobstore-uploader ├── README.md ├── dependency-reduced-pom.xml ├── src │ └── main │ │ └── java │ │ └── org │ │ └── jclouds │ │ └── examples │ │ └── blobstore │ │ └── BlobUploaderMain.java └── pom.xml ├── blobstore-largeblob ├── README.md └── src │ └── main │ └── assembly │ └── jar-with-dependencies.xml ├── chef-basics ├── src │ └── main │ │ ├── resources │ │ └── logback.xml │ │ └── assembly │ │ └── jar-with-dependencies.xml └── README.md ├── compute-basics ├── src │ └── main │ │ ├── resources │ │ └── logback.xml │ │ └── assembly │ │ └── jar-with-dependencies.xml └── README.md ├── google-lb ├── src │ └── main │ │ ├── resources │ │ └── logback.xml │ │ └── assembly │ │ └── jar-with-dependencies.xml └── README.md ├── blobstore-basics ├── README.md ├── src │ └── main │ │ └── assembly │ │ └── jar-with-dependencies.xml └── pom.xml ├── dimensiondata ├── README.md ├── src │ └── main │ │ └── resources │ │ └── logback.xml └── pom.xml ├── openstack ├── README.md ├── src │ └── main │ │ └── resources │ │ └── logback.xml └── pom.xml └── README.md /rackspace/images/Eclipse1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/jclouds-examples/HEAD/rackspace/images/Eclipse1.png -------------------------------------------------------------------------------- /rackspace/images/Eclipse2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/jclouds-examples/HEAD/rackspace/images/Eclipse2.png -------------------------------------------------------------------------------- /rackspace/images/Eclipse3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/jclouds-examples/HEAD/rackspace/images/Eclipse3.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # use glob syntax. 2 | syntax: glob 3 | target/ 4 | test-output/ 5 | .settings/ 6 | .classpath 7 | .project 8 | .idea/ 9 | atlassian-ide-plugin.xml 10 | *.iml 11 | *.ipr 12 | *.iws 13 | *.class 14 | lib/ 15 | bin/ 16 | lein 17 | project.clj 18 | .lein-deps-sum 19 | .DS_STORE 20 | -------------------------------------------------------------------------------- /glacier/README.md: -------------------------------------------------------------------------------- 1 | # Glacier 2 | 3 | This is a simple example using the Glacier provider and BlobStore. 4 | 5 | ## Run 6 | 7 | Invoke the jar, passing the identity and the credential. 8 | 9 | Example: 10 | 11 | java -jar target/glacier-jar-with-dependencies.jar accesskey secretkey 12 | 13 | ## License 14 | 15 | Copyright (C) 2009-2014 The Apache Software Foundation 16 | 17 | Licensed under the Apache License, Version 2.0 18 | -------------------------------------------------------------------------------- /blobstore-uploader/README.md: -------------------------------------------------------------------------------- 1 | # blobstore-uploader 2 | 3 | This is a simple example command line client that attempts to upload many small to medium sized files to a provider supported by jclouds. 4 | 5 | ## Build 6 | 7 | ``` 8 | mvn clean install 9 | ``` 10 | 11 | ## Run 12 | 13 | This is an example command line: 14 | ``` 15 | java -jar .\target\blob-uploader-1.0-SNAPSHOT.jar --username bob --password 701addc5-14ff-474b-9ffc-23e8e91b46a4 --provider "rackspace-cloudfiles-us" --region DFW --directory "P:\somedirectory" 16 | ``` 17 | 18 | You can also specify the number of upload threads with --threads 19 | 20 | ## License 21 | 22 | Copyright (C) 2009-2014 The Apache Software Foundation 23 | 24 | Licensed under the Apache License, Version 2.0 25 | -------------------------------------------------------------------------------- /rackspace/src/etc/header.txt: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ -------------------------------------------------------------------------------- /blobstore-largeblob/README.md: -------------------------------------------------------------------------------- 1 | # blobstore-largeblob 2 | 3 | This is a simple example command line client that creates a container in a [BlobStore](http://jclouds.apache.org/start/blobstore/) provider and uploads a large file. 4 | 5 | ## Build 6 | 7 | Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the example. 8 | 9 | ## Run 10 | 11 | Invoke the jar, passing the name of the cloud provider you with to access (aws-s3 is currently tested), identity (ex. accesskey, username), credential (ex. secretkey, password), the filename you want to upload, then the name of the container you'd like to create, then the object name and eventually the optional parameters plainhttp or securehttp and a number representing the number of threads. 12 | 13 | Ex. for Amazon S3 14 | 15 | java -jar target/blobstore-largeblob-jar-with-dependencies.jar aws-s3 accesskey secretkey inputfile myfavoritecontainer keyname plainhttp 5 16 | 17 | "plainhttp" "5" are the two optional parameters. Default values are securehttp and 4 threads. 18 | 19 | The inputfile size has to be at least 32Mbytes size to be used multipart upload. Below this size it will fall back to simple upload. 20 | 21 | ## License 22 | 23 | Copyright (C) 2009-2014 The Apache Software Foundation 24 | 25 | Licensed under the Apache License, Version 2.0 26 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cdn/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.jclouds.examples.rackspace.cdn; 19 | 20 | /** 21 | * Constants used by the Rackspace Examples. 22 | */ 23 | public class Constants { 24 | // The provider configures jclouds To use the Rackspace Cloud (US) 25 | // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cdn-uk" 26 | public static final String PROVIDER = System.getProperty("provider.cs", "rackspace-cdn-us"); 27 | } 28 | -------------------------------------------------------------------------------- /blobstore-uploader/dependency-reduced-pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | blobstore-uploader 5 | blob-uploader 6 | 2.1.0 7 | 8 | 9 | 10 | maven-shade-plugin 11 | 12 | 13 | package 14 | 15 | shade 16 | 17 | 18 | blobstore-uploader 19 | 20 | 21 | 22 | org.jclouds.examples.blobstore.BlobUploaderMain 23 | 1 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 2.1.0 35 | 36 | 37 | -------------------------------------------------------------------------------- /chef-basics/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | %msg%n 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 36 | 37 | -------------------------------------------------------------------------------- /compute-basics/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | %msg%n 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 36 | 37 | -------------------------------------------------------------------------------- /google-lb/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | - %msg%n 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 36 | 37 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudnetworks/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.jclouds.examples.rackspace.cloudnetworks; 19 | 20 | /** 21 | * Constants used by the Rackspace Examples. 22 | */ 23 | public class Constants { 24 | // The provider configures jclouds to use the Rackspace Cloud (US). 25 | // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudnetworks-uk". 26 | public static final String PROVIDER = System.getProperty("provider.cloudnetworks", "rackspace-cloudnetworks-us"); 27 | public static final String REGION = System.getProperty("region", "DFW"); 28 | public static final String NAME = "jclouds-example"; 29 | } 30 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudloadbalancers/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudloadbalancers; 20 | 21 | 22 | /** 23 | * Constants used by the Rackspace Examples. 24 | */ 25 | public interface Constants { 26 | // The provider configures jclouds To use the Rackspace Cloud (US) 27 | // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudloadbalancers-uk" 28 | public static final String PROVIDER = System.getProperty("provider.clb", "rackspace-cloudloadbalancers-us"); 29 | public static final String REGION = System.getProperty("region", "IAD"); 30 | 31 | public static final String NAME = "jclouds-example"; 32 | } 33 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/clouddatabases/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.clouddatabases; 20 | 21 | /** 22 | * Constants used by the Rackspace Examples. 23 | */ 24 | public interface Constants { 25 | // The provider configures jclouds To use the Rackspace Cloud (US) 26 | // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-clouddatabases-uk" 27 | public static final String PROVIDER = System.getProperty("provider.cdb", "rackspace-clouddatabases-us"); 28 | public static final String REGION = System.getProperty("region", "IAD"); 29 | 30 | public static final String NAME = "jclouds-example"; 31 | public static final String PASSWORD = "0192j41dm311iaadjaoqpvplw"; 32 | } 33 | -------------------------------------------------------------------------------- /google-lb/README.md: -------------------------------------------------------------------------------- 1 | # google-lb 2 | 3 | This is a simple example command line client that demonstrates [Network Load Balancing](https://cloud.google.com/compute/docs/load-balancing/network/). It also demonstrates how to use JSON credentials to authenticate allocating resources on a Google project. 4 | 5 | ## Build 6 | 7 | Ensure you have **maven 3.02** or higher installed, then execute `mvn install` to build the example. 8 | 9 | ## Run 10 | 11 | Invoke the jar, passing in the path to a JSON key file and the **action** you wish to run. 12 | 13 | Supported actions are: 14 | 15 | - create 16 | - request 17 | - destroy 18 | - delete_startup_script 19 | 20 | 21 | To create the network loadbalancer, run: 22 | 23 | java -jar target/google-lb-jar-with-dependencies.jar ~/path/to/key.json create 24 | 25 | To demostrate the network loadbalancer is working, run the following command with your forwarding rule IP address: 26 | 27 | while true; do curl -m1 $IP; done 28 | 29 | Note: It may take some time for the setup to finish propigating. 30 | 31 | If you dont know your forwarding rule IP address, run: 32 | 33 | java -jar target/google-lb-jar-with-dependencies.jar ~/path/to/key.json request 34 | 35 | To destroy the allocated resources run: 36 | 37 | java -jar target/google-lb-jar-with-dependencies.jar ~/path/to/key.json destroy 38 | 39 | ## Getting a JSON key 40 | 41 | To get a JSON key file you must first set up a project and create a service account. Direction can be found [here](https://developers.google.com/console/help/new/#serviceaccounts). 42 | 43 | ## License 44 | 45 | Copyright (C) 2009-2014 The Apache Software Foundation 46 | 47 | Licensed under the Apache License, Version 2.0 48 | -------------------------------------------------------------------------------- /blobstore-basics/README.md: -------------------------------------------------------------------------------- 1 | # blobstore-basics 2 | 3 | This is a simple example command line client that creates a container in a [BlobStore](http://jclouds.apache.org/start/blobstore/) provider and lists the size of all the other containers. 4 | 5 | ## Build 6 | 7 | Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the example. 8 | 9 | ## Run 10 | 11 | Invoke the jar, passing the name of the cloud provider you with to access (ex. aws-s3, googlestorage), identity (ex. accesskey, username), credential (ex. secretkey, password), then the name of the container you'd like to create. 12 | 13 | For Amazon S3 14 | 15 | java -jar target/blobstore-basics-jar-with-dependencies.jar aws-s3 accesskey secretkey myfavoritecontainer 16 | 17 | For Rackspace CloudFiles 18 | 19 | java -jar target/blobstore-basics-jar-with-dependencies.jar cloudfiles-us username apikey myfavoritecontainer 20 | 21 | For IBM SoftLayer ObjectStore in `ams01` 22 | 23 | java -Djclouds.keystone.credential-type=tempAuthCredentials -Djclouds.endpoint=https://ams01.objectstorage.softlayer.net/auth/v1.0/ -jar target/blobstore-basics-jar-with-dependencies.jar openstack-swift username apikey myfavoritecontainer https://ams01.objectstorage.softlayer.net/auth/v1.0/ 24 | 25 | For Google Cloud Storage 26 | 27 | java -jar target/blobstore-basics-jar-with-dependencies.jar \ 28 | google-cloud-storage \ 29 | your-project-service-account-email@developer.gserviceaccount.com \ 30 | /path/to/json-key.json \ 31 | myfavoritecontainer 32 | 33 | 34 | ## License 35 | 36 | Copyright (C) 2009-2014 The Apache Software Foundation 37 | 38 | Licensed under the Apache License, Version 2.0 39 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudservers/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudservers; 20 | 21 | import static java.util.concurrent.TimeUnit.SECONDS; 22 | 23 | /** 24 | * Constants used by the Rackspace Examples. 25 | */ 26 | public interface Constants { 27 | // The provider configures jclouds To use the Rackspace Cloud (US) 28 | // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudservers-uk" 29 | public static final String PROVIDER = System.getProperty("provider.cs", "rackspace-cloudservers-us"); 30 | public static final String REGION = System.getProperty("region", "IAD"); 31 | 32 | public static final String NAME = "jclouds-example"; 33 | public static final String POLL_PERIOD_TWENTY_SECONDS = String.valueOf(SECONDS.toMillis(20)); 34 | } 35 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudfiles; 20 | 21 | /** 22 | * Constants used by the Rackspace Examples. 23 | */ 24 | public interface Constants { 25 | // The provider configures jclouds To use the Rackspace Cloud (US) 26 | // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudfiles-uk" 27 | public static final String PROVIDER = System.getProperty("provider.cf", "rackspace-cloudfiles-us"); 28 | public static final String REGION = System.getProperty("region", "IAD"); 29 | 30 | public static final String CONTAINER_PUBLISH = "jclouds-example-publish"; 31 | public static final String CONTAINER = "jclouds-example"; 32 | public static final String FILENAME = "createObjectFromFile"; 33 | public static final String SUFFIX = ".html"; 34 | } 35 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/autoscale/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.autoscale; 20 | 21 | /** 22 | * Constants used by the Rackspace Examples. 23 | */ 24 | public interface Constants { 25 | // The provider configures jclouds to use the Rackspace Cloud (US). 26 | // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-autoscale-uk". 27 | // Note that autoscale is not yet supported for the UK. 28 | public static final String PROVIDER = System.getProperty("provider.autoscale", "rackspace-autoscale-us"); 29 | public static final String REGION = System.getProperty("region", "DFW"); 30 | 31 | public static final String NAME = "jclouds-example"; 32 | public static final String SERVICE_NET = "11111111-1111-1111-1111-111111111111"; 33 | public static final String PUBLIC_NET = "00000000-0000-0000-0000-000000000000"; 34 | } 35 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudblockstorage; 20 | 21 | import static java.util.concurrent.TimeUnit.SECONDS; 22 | 23 | /** 24 | * Constants used by the Rackspace Examples. 25 | */ 26 | public interface Constants { 27 | // The provider configures jclouds To use the Rackspace Cloud (US) 28 | // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudblockstorage-uk" 29 | public static final String PROVIDER = System.getProperty("provider.cbs", "rackspace-cloudblockstorage-us"); 30 | public static final String REGION = System.getProperty("region", "IAD"); 31 | 32 | public static final String NAME = "jclouds-example"; 33 | public static final String POLL_PERIOD_TWENTY_SECONDS = String.valueOf(SECONDS.toMillis(20)); 34 | public static final String ROOT = "root"; 35 | public static final String PASSWORD = "sbmFPqaw5d43"; 36 | public static final String DEVICE = "/dev/xvdd"; 37 | } 38 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/carina/ListContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.carina; 20 | 21 | import static org.jclouds.examples.rackspace.carina.Utils.getDockerApiFromCarinaDirectory; 22 | 23 | import java.io.IOException; 24 | 25 | import org.jclouds.docker.DockerApi; 26 | import org.jclouds.docker.domain.ContainerSummary; 27 | 28 | /** 29 | * This example lists Carina containers 30 | * 31 | * To use, create/login at getcarina.com; then create a cluster and download the "get access" zip file. 32 | * Then extract the zip archive to a directory and pass the directory path as a parameter to main. 33 | */ 34 | public class ListContainer { 35 | 36 | public static void main(String[] args) throws IOException { 37 | 38 | DockerApi dockerApi = getDockerApiFromCarinaDirectory(args[0]); 39 | 40 | for( ContainerSummary c : dockerApi.getContainerApi().listContainers()) { 41 | System.out.println(c); 42 | } 43 | 44 | dockerApi.close(); 45 | } 46 | 47 | 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /chef-basics/src/main/assembly/jar-with-dependencies.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 24 | jar-with-dependencies 25 | 26 | jar 27 | 28 | false 29 | 30 | 31 | metaInf-services 32 | 33 | 34 | 35 | 36 | / 37 | true 38 | true 39 | runtime 40 | 41 | 42 | -------------------------------------------------------------------------------- /google-lb/src/main/assembly/jar-with-dependencies.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 24 | jar-with-dependencies 25 | 26 | jar 27 | 28 | false 29 | 30 | 31 | metaInf-services 32 | 33 | 34 | 35 | 36 | / 37 | true 38 | true 39 | runtime 40 | 41 | 42 | -------------------------------------------------------------------------------- /blobstore-basics/src/main/assembly/jar-with-dependencies.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 24 | jar-with-dependencies 25 | 26 | jar 27 | 28 | false 29 | 30 | 31 | metaInf-services 32 | 33 | 34 | 35 | 36 | / 37 | true 38 | true 39 | runtime 40 | 41 | 42 | -------------------------------------------------------------------------------- /compute-basics/src/main/assembly/jar-with-dependencies.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 24 | jar-with-dependencies 25 | 26 | jar 27 | 28 | false 29 | 30 | 31 | metaInf-services 32 | 33 | 34 | 35 | 36 | / 37 | true 38 | true 39 | runtime 40 | 41 | 42 | -------------------------------------------------------------------------------- /glacier/src/main/assembly/jar-with-dependencies.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 24 | jar-with-dependencies 25 | 26 | jar 27 | 28 | false 29 | 30 | 31 | metaInf-services 32 | 33 | 34 | 35 | 36 | / 37 | true 38 | true 39 | runtime 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /blobstore-largeblob/src/main/assembly/jar-with-dependencies.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 24 | jar-with-dependencies 25 | 26 | jar 27 | 28 | false 29 | 30 | 31 | metaInf-services 32 | 33 | 34 | 35 | 36 | / 37 | true 38 | true 39 | runtime 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudqueues/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudqueues; 20 | 21 | import java.util.UUID; 22 | 23 | /** 24 | * Constants used by the Rackspace Examples. 25 | */ 26 | public interface Constants { 27 | // The provider configures jclouds To use the Rackspace Cloud (US) 28 | // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudqueues-uk" 29 | final String PROVIDER = System.getProperty("provider.cbs", "rackspace-cloudqueues-us"); 30 | final String REGION = System.getProperty("region", "IAD"); 31 | 32 | final UUID PRODUCER_ID = UUID.fromString("3381af92-2b9e-11e3-b191-71861300734a"); 33 | final UUID CONSUMER_ID = UUID.fromString("3381af92-2b9e-11e3-b191-71861300734b"); 34 | final UUID PUBLISHER_ID = UUID.fromString("3381af92-2b9e-11e3-b191-71861300734c"); 35 | final UUID SUBSCRIBER_ID = UUID.fromString("3381af92-2b9e-11e3-b191-71861300734d"); 36 | final String NAME = "jclouds-example"; 37 | 38 | final int NUM_THREADS = 3; 39 | 40 | final String PRODUCER_NAME = "producer.name"; 41 | final String PUBLISHER_NAME = "publisher.name"; 42 | final String MESSAGE_TEXT = "message.text"; 43 | final String MESSAGE_NUM = "message.num"; 44 | } 45 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/autoscale/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.autoscale; 20 | 21 | import static org.jclouds.examples.rackspace.autoscale.Constants.NAME; 22 | 23 | import org.jclouds.rackspace.autoscale.v1.domain.Group; 24 | import org.jclouds.rackspace.autoscale.v1.domain.GroupState; 25 | import org.jclouds.rackspace.autoscale.v1.domain.ScalingPolicy; 26 | import org.jclouds.rackspace.autoscale.v1.features.GroupApi; 27 | import org.jclouds.rackspace.autoscale.v1.features.PolicyApi; 28 | 29 | /** 30 | * Helper methods for autoscale examples 31 | */ 32 | public class Utils { 33 | public static String getGroupId(GroupApi groupApi) { 34 | for ( GroupState state : groupApi.listGroupStates() ) { 35 | Group g = groupApi.get(state.getId()); 36 | for ( ScalingPolicy policy : g.getScalingPolicies() ) { 37 | if (policy.getName().equals(NAME)) return g.getId(); 38 | } 39 | } 40 | 41 | throw new IllegalArgumentException("Group not found"); 42 | } 43 | 44 | public static String getPolicyId(PolicyApi policyApi) { 45 | for ( ScalingPolicy policy : policyApi.list() ) { 46 | if (policy.getName().equals(NAME)) return policy.getId(); 47 | } 48 | 49 | throw new IllegalArgumentException("Policy not found"); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /dimensiondata/README.md: -------------------------------------------------------------------------------- 1 | # Dimension Data Examples 2 | Example code that uses jclouds to perform common tasks on an Dimension Data CloudControl. The class names are self-explanatory and the code is well commented for you to follow along. 3 | 4 | - [Requirements](#requirements) 5 | - [Environment](#environment) 6 | - [The Examples](#examples) 7 | - [Support and Feedback](#support-and-feedback) 8 | 9 | ## Requirements 10 | 11 | 1. Username and password for Dimension Data CloudControl - See the [Getting Started guide](http://jclouds.apache.org/guides/dimensiondata/). 12 | 1. Java Development Kit (JDK) version 6 or later - [Download](http://www.oracle.com/technetwork/java/javase/downloads/index.html). 13 | 1. Apache Maven - [Maven in 5 Minutes](http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html). 14 | 1. Git - [Download](http://git-scm.com/downloads). 15 | 16 | ## Environment 17 | To setup an environment to compile and run the examples use these commands: 18 | 19 | ``` 20 | git clone https://github.com/jclouds/jclouds-examples.git 21 | cd jclouds-examples/dimensiondata/ 22 | ``` 23 | 24 | To package the examples jar file and dependencies run: 25 | 26 | ``` 27 | mvn package 28 | ``` 29 | 30 | ## Examples 31 | 32 | To run individual examples from the command line use these commands: 33 | 34 | Every example class has a main method that takes the following arguments in the listed order: 35 | 36 | 1. API Endpoint 37 | 1. Username 38 | 1. Password 39 | 40 | If there are other arguments required they will follow. The command line format looks like this: 41 | ``` 42 | java -cp target\dimensiondata-cloudcontrol-examples--jar-with-dependencies.jar apiEndpoint username password 43 | ``` 44 | 45 | Try out an example. 46 | 47 | ``` 48 | java -cp target\dimensiondata-cloudcontrol-examples--jar-with-dependencies.jar org.jclouds.examples.dimensiondata.cloudcontrol.DeployNetworkDomainVlanAndServer apiEndpoint username password 49 | ``` 50 | 51 | Watch the terminal for output! 52 | 53 | ## Support and Feedback 54 | 55 | Your feedback is appreciated! If you have specific issues with Dimension Data CloudControl support in jclouds, we'd prefer that you file an issue via [JIRA](https://issues.apache.org/jira/browse/JCLOUDS). 56 | 57 | If you have questions or need help, please join our [community](http://jclouds.apache.org/community/) and subscribe to the jclouds user mailing list. 58 | -------------------------------------------------------------------------------- /openstack/README.md: -------------------------------------------------------------------------------- 1 | # OpenStack Examples 2 | Example code that uses jclouds to perform common tasks on an OpenStack Cloud. The class names are self-explanatory and the code is well commented for you to follow along. 3 | 4 | - [Requirements](#requirements) 5 | - [Environment](#environment) 6 | - [The Examples](#examples) 7 | - [Support and Feedback](#support-and-feedback) 8 | 9 | ## Requirements 10 | 11 | 1. Username and password for an OpenStack Cloud - See the [Getting Started guide](http://jclouds.apache.org/guides/openstack/). 12 | 1. Java Development Kit (JDK) version 6 or later - [Download](http://www.oracle.com/technetwork/java/javase/downloads/index.html). 13 | 1. Apache Maven - [Maven in 5 Minutes](http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html). 14 | 1. Git - [Download](http://git-scm.com/downloads). 15 | 16 | ## Environment 17 | To setup an environment to compile and run the examples use these commands: 18 | 19 | ``` 20 | git clone https://github.com/jclouds/jclouds-examples.git 21 | cd jclouds-examples/openstack/ 22 | ``` 23 | 24 | To download all dependencies, run: 25 | 26 | ``` 27 | mvn dependency:copy-dependencies "-DoutputDirectory=./lib" 28 | ``` 29 | 30 | If you also want to download the source jars, run: 31 | 32 | ``` 33 | mvn dependency:copy-dependencies "-DoutputDirectory=./lib" "-Dclassifier=sources" 34 | ``` 35 | 36 | ## Examples 37 | 38 | To run individual examples from the command line use these commands: 39 | 40 | Note: If you're on Windows, the only change you need to make is to use a ';' instead of a ':' in the paths. 41 | 42 | ``` 43 | javac -classpath "lib/*:src/main/java/:src/main/resources/" src/main/java/org/jclouds/examples/openstack/identity/*.java 44 | ``` 45 | 46 | Every example class has a main method that takes the following arguments in the listed order 47 | 48 | 1. Identity (Keystone) endpoint (e.g. an IP address or URL) 49 | 1. Tenant name 50 | 1. User name 51 | 1. Password 52 | 53 | Try out an example. 54 | 55 | ``` 56 | java -classpath "lib/*:src/main/java/:src/main/resources/" org.jclouds.examples.openstack.identity.CreateTenantAndUser identityEndpoint myTenantname myUsername myPassword 57 | ``` 58 | Watch the terminal for output! 59 | 60 | ## Support and Feedback 61 | 62 | Your feedback is appreciated! If you have specific issues with OpenStack support in jclouds, we'd prefer that you file an issue via [JIRA](https://issues.apache.org/jira/browse/JCLOUDS). 63 | 64 | If you have questions or need help, please join our [community](http://jclouds.apache.org/community/) and subscribe to the jclouds user mailing list. 65 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/clouddns/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.clouddns; 20 | 21 | import com.google.common.base.Function; 22 | import com.google.common.base.Predicate; 23 | import org.jclouds.rackspace.clouddns.v1.domain.Domain; 24 | 25 | import java.util.regex.Matcher; 26 | import java.util.regex.Pattern; 27 | 28 | 29 | /** 30 | * Constants used by the Rackspace Examples. 31 | */ 32 | public interface Constants { 33 | // The provider configures jclouds To use the Rackspace Cloud (US) 34 | // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-clouddns-uk" 35 | public static final String PROVIDER = System.getProperty("provider.cdns", "rackspace-clouddns-us"); 36 | 37 | public static final String NAME = System.getProperty("user.name") + "-jclouds-example.com"; 38 | public static final String ALT_NAME = "alt-" + NAME; 39 | public static final String CLOUD_SERVERS = "cloudServersOpenStack"; 40 | 41 | // subdomains contain two or more '.' 42 | public static final Pattern SUBDOMAIN_PATTERN = Pattern.compile(".*\\..*\\."); 43 | 44 | /** 45 | * Determine if a domain is a top level domain (i.e. not a subdomain). 46 | */ 47 | public static final Predicate IS_DOMAIN = new Predicate() { 48 | public boolean apply(Domain domain) { 49 | Matcher matcher = SUBDOMAIN_PATTERN.matcher(domain.getName()); 50 | return !matcher.find(); 51 | } 52 | }; 53 | 54 | /** 55 | * Take a Domain and return its id. 56 | */ 57 | public static final Function GET_DOMAIN_ID = new Function() { 58 | public Integer apply(Domain domain) { 59 | return domain.getId(); 60 | } 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jclouds-examples 2 | 3 | This repository contains various examples of using 4 | [jclouds](https://github.com/jclouds/jclouds). 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
projectdescription
BlobStore Basics (Java)Example code to create a container, blob, and list your blobs using the portable BlobStore API
Large Blob support (Java)Example code to create a container and use a parallel strategy to upload a large blob, the portable BlobStore API
Blob Uploader (Java)Example code to upload many small to medium sized files to a provider supported by jclouds.
Chef Basics (Java)Example code to add nodes to a group and execute Chef cookbooks on them using Chef Solo or a standard or Hosted Chef Server.
Compute Basics (Java)Example code to add nodes to a group and execute commands on them using the portable ComputeService API
AWS Glacier (Java)Example code that uses jclouds to manage using the Glacier provider and BlobStore..
Google LoadBalancer (Java)Example code that uses jclouds to manage Google [Network Load Balancing](https://cloud.google.com/compute/docs/load-balancing/network/).
OpenStack (Java)Example code that uses jclouds to perform common tasks on the OpenStack.
Rackspace (Java)Example code that uses jclouds to perform common tasks on the Rackspace Cloud.
47 | 48 | ![jclouds logo](http://jclouds.apache.org/img/fullsizelogo.jpg) 49 | 50 | ## License 51 | 52 | Copyright (C) 2009-2014 The Apache Software Foundation 53 | 54 | Licensed under the Apache License, Version 2.0 55 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/carina/CreateComputeContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.carina; 20 | 21 | import static org.jclouds.compute.predicates.NodePredicates.runningInGroup; 22 | 23 | import java.io.IOException; 24 | import java.util.Set; 25 | 26 | import org.jclouds.compute.ComputeServiceContext; 27 | import org.jclouds.compute.RunNodesException; 28 | import org.jclouds.compute.domain.NodeMetadata; 29 | import org.jclouds.compute.domain.Template; 30 | import org.jclouds.docker.compute.options.DockerTemplateOptions; 31 | 32 | /** 33 | * This example creates a container in Carina using the jclouds compute abstraction 34 | */ 35 | 36 | public class CreateComputeContainer { 37 | 38 | public static void main(String[] args) throws IOException, RunNodesException { 39 | // Get a context with docker that offers the portable ComputeService api 40 | ComputeServiceContext client = Utils.getComputeApiFromCarinaDirectory(args[0]); 41 | 42 | // Carina does not allow privileged mode containers 43 | DockerTemplateOptions dto = new DockerTemplateOptions(); 44 | dto.privileged(false); 45 | 46 | // Use a known sshd image for demonstration purposes: sickp/apline-sshd 47 | Template template = client.getComputeService() 48 | .templateBuilder() 49 | .options(dto) 50 | .imageNameMatches("sickp/alpine-sshd") 51 | .build(); 52 | 53 | // Run a couple nodes accessible via group container 54 | Set nodes = client.getComputeService().createNodesInGroup("jcloudscontainertest", 2, template); 55 | 56 | // Show the nodes 57 | for(NodeMetadata node : nodes) { 58 | System.out.println("Node: " + node.getName()); 59 | } 60 | 61 | // Cleanup 62 | client.getComputeService().destroyNodesMatching(runningInGroup("jcloudscontainertest")); 63 | 64 | // Release resources 65 | client.close(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/GetContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudfiles; 20 | 21 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.CONTAINER; 22 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.PROVIDER; 23 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.REGION; 24 | 25 | import java.io.Closeable; 26 | import java.io.IOException; 27 | 28 | import org.jclouds.ContextBuilder; 29 | import org.jclouds.openstack.swift.v1.domain.Container; 30 | import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi; 31 | 32 | import com.google.common.io.Closeables; 33 | 34 | /** 35 | * Create a Cloud Files container with some metadata associated with it. 36 | */ 37 | public class GetContainer implements Closeable { 38 | private final CloudFilesApi cloudFiles; 39 | 40 | /** 41 | * To get a username and API key see http://jclouds.apache.org/guides/rackspace/ 42 | * 43 | * The first argument (args[0]) must be your username 44 | * The second argument (args[1]) must be your API key 45 | */ 46 | public static void main(String[] args) throws IOException { 47 | GetContainer getContainer = new GetContainer(args[0], args[1]); 48 | 49 | try { 50 | getContainer.getContainer(); 51 | } 52 | catch (Exception e) { 53 | e.printStackTrace(); 54 | } 55 | finally { 56 | getContainer.close(); 57 | } 58 | } 59 | 60 | public GetContainer(String username, String apiKey) { 61 | cloudFiles = ContextBuilder.newBuilder(PROVIDER) 62 | .credentials(username, apiKey) 63 | .buildApi(CloudFilesApi.class); 64 | } 65 | 66 | private void getContainer() { 67 | System.out.format("Get Container%n"); 68 | 69 | Container container = cloudFiles.getContainerApi(REGION).get(CONTAINER); 70 | System.out.format(" %s%n", container); 71 | } 72 | 73 | /** 74 | * Always close your service when you're done with it. 75 | */ 76 | public void close() throws IOException { 77 | Closeables.close(cloudFiles, true); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/ListContainers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudfiles; 20 | 21 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.PROVIDER; 22 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.REGION; 23 | 24 | import java.io.Closeable; 25 | import java.io.IOException; 26 | import java.util.List; 27 | 28 | import org.jclouds.ContextBuilder; 29 | import org.jclouds.openstack.swift.v1.domain.Container; 30 | import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi; 31 | 32 | import com.google.common.io.Closeables; 33 | 34 | /** 35 | * List the Cloud Files containers associated with your account. 36 | * 37 | */ 38 | public class ListContainers implements Closeable { 39 | private final CloudFilesApi cloudFiles; 40 | 41 | /** 42 | * To get a username and API key see http://jclouds.apache.org/guides/rackspace/ 43 | * 44 | * The first argument (args[0]) must be your username 45 | * The second argument (args[1]) must be your API key 46 | */ 47 | public static void main(String[] args) throws IOException { 48 | ListContainers listContainers = new ListContainers(args[0], args[1]); 49 | 50 | try { 51 | listContainers.listContainers(); 52 | } 53 | catch (Exception e) { 54 | e.printStackTrace(); 55 | } 56 | finally { 57 | listContainers.close(); 58 | } 59 | } 60 | 61 | public ListContainers(String username, String apiKey) { 62 | cloudFiles = ContextBuilder.newBuilder(PROVIDER) 63 | .credentials(username, apiKey) 64 | .buildApi(CloudFilesApi.class); 65 | } 66 | 67 | private void listContainers() { 68 | System.out.format("List Containers%n"); 69 | 70 | List containers = cloudFiles.getContainerApi(REGION).list().toList(); 71 | for (Container container: containers) { 72 | System.out.format(" %s%n", container); 73 | } 74 | } 75 | 76 | /** 77 | * Always close your service when you're done with it. 78 | */ 79 | public void close() throws IOException { 80 | Closeables.close(cloudFiles, true); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /dimensiondata/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | - %m%n 25 | 26 | 27 | 28 | 29 | target/test-data/jclouds.log 30 | 31 | 32 | %d %-5p [%c] [%thread] %m%n 33 | 34 | 35 | 36 | 37 | target/test-data/jclouds-wire.log 38 | 39 | 40 | %d %-5p [%c] [%thread] %m%n 41 | 42 | 43 | 44 | 45 | target/test-data/jclouds-compute.log 46 | 47 | 48 | %d %-5p [%c] [%thread] %m%n 49 | 50 | 51 | 52 | 53 | target/test-data/jclouds-ssh.log 54 | 55 | 56 | %d %-5p [%c] [%thread] %m%n 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /openstack/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | - %m%n 25 | 26 | 27 | 28 | 29 | target/test-data/jclouds.log 30 | 31 | 32 | %d %-5p [%c] [%thread] %m%n 33 | 34 | 35 | 36 | 37 | target/test-data/jclouds-wire.log 38 | 39 | 40 | %d %-5p [%c] [%thread] %m%n 41 | 42 | 43 | 44 | 45 | target/test-data/jclouds-compute.log 46 | 47 | 48 | %d %-5p [%c] [%thread] %m%n 49 | 50 | 51 | 52 | 53 | target/test-data/jclouds-ssh.log 54 | 55 | 56 | %d %-5p [%c] [%thread] %m%n 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /rackspace/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 24 | - %m%n 25 | 26 | 27 | 28 | 29 | target/test-data/jclouds.log 30 | 31 | 32 | %d %-5p [%c] [%thread] %m%n 33 | 34 | 35 | 36 | 37 | target/test-data/jclouds-wire.log 38 | 39 | 40 | %d %-5p [%c] [%thread] %m%n 41 | 42 | 43 | 44 | 45 | target/test-data/jclouds-compute.log 46 | 47 | 48 | %d %-5p [%c] [%thread] %m%n 49 | 50 | 51 | 52 | 53 | target/test-data/jclouds-ssh.log 54 | 55 | 56 | %d %-5p [%c] [%thread] %m%n 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/ListVolumes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudblockstorage; 20 | 21 | import com.google.common.io.Closeables; 22 | import org.jclouds.ContextBuilder; 23 | import org.jclouds.openstack.cinder.v1.CinderApi; 24 | import org.jclouds.openstack.cinder.v1.domain.Volume; 25 | 26 | import java.io.Closeable; 27 | import java.io.IOException; 28 | import java.util.Set; 29 | 30 | import static org.jclouds.examples.rackspace.cloudblockstorage.Constants.PROVIDER; 31 | 32 | /** 33 | * This example lists all volumes. 34 | */ 35 | public class ListVolumes implements Closeable { 36 | private final CinderApi cinderApi; 37 | private final Set regions; 38 | 39 | /** 40 | * To get a username and API key see 41 | * http://jclouds.apache.org/guides/rackspace/ 42 | * 43 | * The first argument (args[0]) must be your username 44 | * The second argument (args[1]) must be your API key 45 | */ 46 | public static void main(String[] args) throws IOException { 47 | ListVolumes listVolumes = new ListVolumes(args[0], args[1]); 48 | 49 | try { 50 | listVolumes.listVolumes(); 51 | } 52 | catch (Exception e) { 53 | e.printStackTrace(); 54 | } 55 | finally { 56 | listVolumes.close(); 57 | } 58 | } 59 | 60 | public ListVolumes(String username, String apiKey) { 61 | cinderApi = ContextBuilder.newBuilder(PROVIDER) 62 | .credentials(username, apiKey) 63 | .buildApi(CinderApi.class); 64 | regions = cinderApi.getConfiguredRegions(); 65 | } 66 | 67 | private void listVolumes() { 68 | System.out.format("List Volumes%n"); 69 | 70 | for (String region: regions) { 71 | System.out.format(" %s%n", region); 72 | 73 | for (Volume volume: cinderApi.getVolumeApi(region).listInDetail()) { 74 | System.out.format(" %s%n", volume); 75 | } 76 | } 77 | } 78 | 79 | /** 80 | * Always close your service when you're done with it. 81 | * 82 | * Note that closing quietly like this is not necessary in Java 7. 83 | * You would use try-with-resources in the main method instead. 84 | */ 85 | public void close() throws IOException { 86 | Closeables.close(cinderApi, true); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/ListSnapshots.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudblockstorage; 20 | 21 | import com.google.common.io.Closeables; 22 | import org.jclouds.ContextBuilder; 23 | import org.jclouds.openstack.cinder.v1.CinderApi; 24 | import org.jclouds.openstack.cinder.v1.domain.Snapshot; 25 | 26 | import java.io.Closeable; 27 | import java.io.IOException; 28 | import java.util.Set; 29 | 30 | import static org.jclouds.examples.rackspace.cloudblockstorage.Constants.PROVIDER; 31 | 32 | /** 33 | * This example lists all of your snapshots. 34 | */ 35 | public class ListSnapshots implements Closeable { 36 | private final CinderApi cinderApi; 37 | private final Set regions; 38 | 39 | /** 40 | * To get a username and API key see 41 | * http://jclouds.apache.org/guides/rackspace/ 42 | * 43 | * The first argument (args[0]) must be your username 44 | * The second argument (args[1]) must be your API key 45 | */ 46 | public static void main(String[] args) throws IOException { 47 | ListSnapshots listSnapshots = new ListSnapshots(args[0], args[1]); 48 | 49 | try { 50 | listSnapshots.listSnapshots(); 51 | } 52 | catch (Exception e) { 53 | e.printStackTrace(); 54 | } 55 | finally { 56 | listSnapshots.close(); 57 | } 58 | } 59 | 60 | public ListSnapshots(String username, String apiKey) { 61 | cinderApi = ContextBuilder.newBuilder(PROVIDER) 62 | .credentials(username, apiKey) 63 | .buildApi(CinderApi.class); 64 | regions = cinderApi.getConfiguredRegions(); 65 | } 66 | 67 | private void listSnapshots() { 68 | System.out.format("List Snapshots%n"); 69 | 70 | for (String region: regions) { 71 | System.out.format(" %s%n", region); 72 | 73 | for (Snapshot snapshot: cinderApi.getSnapshotApi(region).listInDetail()) { 74 | System.out.format(" %s%n", snapshot); 75 | } 76 | } 77 | } 78 | 79 | /** 80 | * Always close your service when you're done with it. 81 | * 82 | * Note that closing quietly like this is not necessary in Java 7. 83 | * You would use try-with-resources in the main method instead. 84 | */ 85 | public void close() throws IOException { 86 | Closeables.close(cinderApi, true); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/CreateContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudfiles; 20 | 21 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.CONTAINER; 22 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.PROVIDER; 23 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.REGION; 24 | 25 | import java.io.Closeable; 26 | import java.io.IOException; 27 | 28 | import org.jclouds.ContextBuilder; 29 | import org.jclouds.openstack.swift.v1.options.CreateContainerOptions; 30 | import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi; 31 | 32 | import com.google.common.collect.ImmutableMap; 33 | import com.google.common.io.Closeables; 34 | 35 | /** 36 | * Create a Cloud Files container with some metadata associated with it. 37 | * 38 | */ 39 | public class CreateContainer implements Closeable { 40 | private final CloudFilesApi cloudFiles; 41 | 42 | /** 43 | * To get a username and API key see http://jclouds.apache.org/guides/rackspace/ 44 | * 45 | * The first argument (args[0]) must be your username 46 | * The second argument (args[1]) must be your API key 47 | */ 48 | public static void main(String[] args) throws IOException { 49 | CreateContainer createContainer = new CreateContainer(args[0], args[1]); 50 | 51 | try { 52 | createContainer.createContainer(); 53 | } 54 | catch (Exception e) { 55 | e.printStackTrace(); 56 | } 57 | finally { 58 | createContainer.close(); 59 | } 60 | } 61 | 62 | public CreateContainer(String username, String apiKey) { 63 | cloudFiles = ContextBuilder.newBuilder(PROVIDER) 64 | .credentials(username, apiKey) 65 | .buildApi(CloudFilesApi.class); 66 | } 67 | 68 | private void createContainer() { 69 | System.out.format("Create Container%n"); 70 | 71 | CreateContainerOptions options = CreateContainerOptions.Builder 72 | .metadata(ImmutableMap.of("key1", "value1", "key2", "value2")); 73 | 74 | cloudFiles.getContainerApi(REGION).create(CONTAINER, options); 75 | 76 | System.out.format(" %s%n", CONTAINER); 77 | } 78 | 79 | /** 80 | * Always close your service when you're done with it. 81 | */ 82 | public void close() throws IOException { 83 | Closeables.close(cloudFiles, true); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/ListVolumeTypes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudblockstorage; 20 | 21 | import com.google.common.io.Closeables; 22 | import org.jclouds.ContextBuilder; 23 | import org.jclouds.openstack.cinder.v1.CinderApi; 24 | import org.jclouds.openstack.cinder.v1.domain.VolumeType; 25 | 26 | import java.io.Closeable; 27 | import java.io.IOException; 28 | import java.util.Set; 29 | 30 | import static org.jclouds.examples.rackspace.cloudblockstorage.Constants.PROVIDER; 31 | 32 | /** 33 | * This example lists all volume types. 34 | */ 35 | public class ListVolumeTypes implements Closeable { 36 | private final CinderApi cinderApi; 37 | private final Set regions; 38 | 39 | /** 40 | * To get a username and API key see 41 | * http://jclouds.apache.org/guides/rackspace/ 42 | * 43 | * The first argument (args[0]) must be your username 44 | * The second argument (args[1]) must be your API key 45 | */ 46 | public static void main(String[] args) throws IOException { 47 | ListVolumeTypes listVolumeTypes = new ListVolumeTypes(args[0], args[1]); 48 | 49 | try { 50 | listVolumeTypes.listVolumeTypes(); 51 | } 52 | catch (Exception e) { 53 | e.printStackTrace(); 54 | } 55 | finally { 56 | listVolumeTypes.close(); 57 | } 58 | } 59 | 60 | public ListVolumeTypes(String username, String apiKey) { 61 | cinderApi = ContextBuilder.newBuilder(PROVIDER) 62 | .credentials(username, apiKey) 63 | .buildApi(CinderApi.class); 64 | regions = cinderApi.getConfiguredRegions(); 65 | } 66 | 67 | private void listVolumeTypes() { 68 | System.out.format("List Volumes Types%n"); 69 | 70 | for (String region: regions) { 71 | System.out.format(" %s%n", region); 72 | 73 | for (VolumeType volumeType: cinderApi.getVolumeTypeApi(region).list()) { 74 | System.out.format(" %s%n", volumeType); 75 | } 76 | } 77 | } 78 | 79 | /** 80 | * Always close your service when you're done with it. 81 | * 82 | * Note that closing quietly like this is not necessary in Java 7. 83 | * You would use try-with-resources in the main method instead. 84 | */ 85 | public void close() throws IOException { 86 | Closeables.close(cinderApi, true); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudnetworks/CreateNetwork.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.jclouds.examples.rackspace.cloudnetworks; 18 | 19 | import static org.jclouds.examples.rackspace.cloudnetworks.Constants.REGION; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | 24 | import org.jclouds.ContextBuilder; 25 | import org.jclouds.openstack.neutron.v2.NeutronApi; 26 | import org.jclouds.openstack.neutron.v2.domain.Network; 27 | import org.jclouds.openstack.neutron.v2.features.NetworkApi; 28 | 29 | import com.google.common.io.Closeables; 30 | 31 | /** 32 | * Demonstrates how to create a Poppy service on Rackspace (Rackspace CDN). 33 | * Cleans up the service on fail. 34 | */ 35 | public class CreateNetwork implements Closeable { 36 | private final NeutronApi neutronApi; 37 | 38 | /** 39 | * To get a username and API key see 40 | * http://jclouds.apache.org/guides/rackspace/ 41 | * 42 | * The first argument (args[0]) must be your username 43 | * The second argument (args[1]) must be your API key 44 | */ 45 | public static void main(String[] args) throws IOException { 46 | CreateNetwork createNetwork = new CreateNetwork(args[0], args[1]); 47 | 48 | try { 49 | createNetwork.createNetwork(); 50 | } 51 | catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | finally { 55 | createNetwork.close(); 56 | } 57 | } 58 | 59 | public CreateNetwork(String username, String apiKey) { 60 | neutronApi = ContextBuilder.newBuilder("rackspace-cloudnetworks-us") 61 | .credentials(username, apiKey) 62 | .buildApi(NeutronApi.class); 63 | } 64 | 65 | private void createNetwork() { 66 | NetworkApi networkApi = neutronApi.getNetworkApi(REGION); 67 | Network net = null; 68 | try { 69 | net = networkApi.create(Network.createBuilder("jclouds-test").build()); 70 | } finally { 71 | // Cleanup 72 | if (net != null) { 73 | networkApi.delete(net.getId()); 74 | } 75 | } 76 | } 77 | 78 | /** 79 | * Always close your service when you're done with it. 80 | * 81 | * Note that closing quietly like this is not necessary in Java 7. 82 | * You would use try-with-resources in the main method instead. 83 | */ 84 | public void close() throws IOException { 85 | Closeables.close(neutronApi, true); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /glacier/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 22 | 4.0.0 23 | org.apache.jclouds.examples 24 | glacier-examples 25 | 2.1.0 26 | glacier-examples 27 | 28 | 29 | 2.1.0 30 | 31 | 32 | 33 | 34 | org.apache.jclouds.labs 35 | glacier 36 | ${jclouds.version} 37 | 38 | 39 | 40 | 41 | ${project.artifactId} 42 | 43 | 44 | maven-compiler-plugin 45 | 3.1 46 | 47 | ${project.build.sourceEncoding} 48 | 1.6 49 | 1.6 50 | 51 | 52 | 53 | org.apache.maven.plugins 54 | maven-jar-plugin 55 | 2.4 56 | 57 | 58 | 59 | org.jclouds.examples.glacier.MainApp 60 | 61 | 62 | 63 | 64 | 65 | maven-assembly-plugin 66 | 2.2.1 67 | 68 | 69 | src/main/assembly/jar-with-dependencies.xml 70 | 71 | 72 | 73 | org.jclouds.examples.glacier.MainApp 74 | 75 | 76 | 77 | 78 | 79 | make-assembly 80 | package 81 | 82 | single 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /chef-basics/README.md: -------------------------------------------------------------------------------- 1 | # chef-basics 2 | 3 | This is a simple example command line client that creates a node in a [ComputeService](http://jclouds.apache.org/start/compute/) provider and installs an Apache web server on everything in its group using Chef. 4 | 5 | ## Build 6 | 7 | Ensure you have maven 3.02 or higher installed, then execute 'mvn install' to build the example. Note you also need an ssh key setup in your home directory. 8 | 9 | If you don't already have ~/.ssh/id_rsa present, generate a key with the command 'ssh-keygen -t rsa' and leave the passphrase blank. 10 | 11 | Also make sure you have the private keys for the client and validator if you are using a Chef Server. 12 | 13 | ## Run 14 | 15 | Invoke the jar, passing the name of the cloud provider you with to access (ex. aws-ec2, gogrid), identity (ex. accesskey, username), credential (ex. secretkey, password), then the name of the group you'd like to add the node to. The 5th parameter must be add, chef or destroy, noting that destroy will destroy all nodes in the group. If the 5th parameter is chef or solo, you must provide the list of recipes to install, separated by commas. 16 | 17 | Also, if the 5th parameter is 'chef', you must provide the connection details to the chef server. See the examples below: 18 | 19 | java -jar target/chef-basics-jar-with-dependencies.jar provider identity credential mygroup add 20 | 21 | java -Dchef.endpoint=http://chefendpoint -Dchef.client=clientname -Dchef.validator=validatorname -jar target/chef-basics-jar-with-dependencies.jar provider identity credential mygroup chef apache2 22 | 23 | java -jar target/chef-basics-jar-with-dependencies.jar provider identity credential mygroup solo apache2 24 | 25 | java -jar target/chef-basics-jar-with-dependencies.jar provider identity credential mygroup destroy 26 | 27 | Ex. for Amazon EC2 28 | 29 | java -jar target/chef-basics-jar-with-dependencies.jar aws-ec2 accesskey secretkey mygroup add 30 | 31 | Ex. for HP Cloud 32 | 33 | java -jar target/chef-basics-jar-with-dependencies.jar hpcloud-compute tenantId:accesskey secretkey mygroup add 34 | 35 | Ex. for TryStack.org 36 | 37 | java -jar target/chef-basics-jar-with-dependencies.jar trystack-nova tenantId:user password mygroup add 38 | 39 | Ex. for Abiquo 40 | 41 | java -Dabiquo.endpoint=http://abiquohost/api -jar target/chef-basics-jar-with-dependencies.jar abiquo user password mygroup add 42 | 43 | Ex. for your own OpenStack Nova 44 | 45 | java -Dopenstack-nova.image-id=RegionOne/15 -Dopenstack-nova.login-user=ubuntu -Djclouds.trust-all-certs=true -Djclouds.keystone.credential-type=passwordCredentials -Dopenstack-nova.endpoint=https://keystone:35357 -jar target/chef-basics-jar-with-dependencies.jar openstack-nova tenantId:user password mygroup add 46 | 47 | Ex. for Virtualbox 48 | java -jar target/chef-basics-jar-with-dependencies.jar virtualbox vboxwebsrv-username vboxwebsrv-password mygroup add 49 | 50 | Ex. for your own OpenStack Nova emulating EC2 51 | 52 | java -Dopenstack-nova-ec2.image-id=nova/ami-00000009 -Dopenstack-nova-ec2.login-user=ubuntu -Djclouds.trust-all-certs=true -Dopenstack-nova-ec2.endpoint=https://novahost/services/Cloud -jar target/chef-basics-jar-with-dependencies.jar openstack-nova-ec2 tenantId:accesskey secretkey mygroup add 53 | 54 | ## License 55 | 56 | Copyright (C) 2009-2014 The Apache Software Foundation 57 | 58 | Licensed under the Apache License, Version 2.0 59 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudloadbalancers/ListLoadBalancers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudloadbalancers; 20 | 21 | import com.google.common.io.Closeables; 22 | import org.jclouds.ContextBuilder; 23 | import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi; 24 | import org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer; 25 | import org.jclouds.rackspace.cloudloadbalancers.v1.features.LoadBalancerApi; 26 | 27 | import java.io.Closeable; 28 | import java.io.IOException; 29 | 30 | import static org.jclouds.examples.rackspace.cloudloadbalancers.Constants.PROVIDER; 31 | 32 | /** 33 | * This example lists all Load Balancers. 34 | * 35 | */ 36 | public class ListLoadBalancers implements Closeable { 37 | private final CloudLoadBalancersApi clbApi; 38 | 39 | /** 40 | * To get a username and API key see http://jclouds.apache.org/guides/rackspace/ 41 | * 42 | * The first argument (args[0]) must be your username 43 | * The second argument (args[1]) must be your API key 44 | */ 45 | public static void main(String[] args) throws IOException { 46 | ListLoadBalancers listLoadBalancers = new ListLoadBalancers(args[0], args[1]); 47 | 48 | try { 49 | listLoadBalancers.listLoadBalancers(); 50 | } 51 | catch (Exception e) { 52 | e.printStackTrace(); 53 | } 54 | finally { 55 | listLoadBalancers.close(); 56 | } 57 | } 58 | 59 | public ListLoadBalancers(String username, String apiKey) { 60 | clbApi = ContextBuilder.newBuilder(PROVIDER) 61 | .credentials(username, apiKey) 62 | .buildApi(CloudLoadBalancersApi.class); 63 | } 64 | 65 | private void listLoadBalancers() { 66 | System.out.format("List Load Balancers%n"); 67 | 68 | for (String region: clbApi.getConfiguredRegions()) { 69 | System.out.format(" %s%n", region); 70 | 71 | LoadBalancerApi lbApi = clbApi.getLoadBalancerApi(region); 72 | 73 | for (LoadBalancer loadBalancer: lbApi.list().concat()) { 74 | System.out.format(" %s%n", loadBalancer); 75 | } 76 | } 77 | } 78 | 79 | /** 80 | * Always close your service when you're done with it. 81 | * 82 | * Note that closing quietly like this is not necessary in Java 7. 83 | * You would use try-with-resources in the main method instead. 84 | */ 85 | public void close() throws IOException { 86 | Closeables.close(clbApi, true); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/clouddns/DeleteDomains.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.clouddns; 20 | 21 | import com.google.common.collect.Iterables; 22 | import com.google.common.io.Closeables; 23 | import org.jclouds.ContextBuilder; 24 | import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; 25 | import org.jclouds.rackspace.clouddns.v1.domain.Domain; 26 | 27 | import java.io.Closeable; 28 | import java.io.IOException; 29 | import java.util.Set; 30 | import java.util.concurrent.TimeoutException; 31 | 32 | import static org.jclouds.examples.rackspace.clouddns.Constants.*; 33 | import static org.jclouds.rackspace.clouddns.v1.predicates.JobPredicates.awaitComplete; 34 | 35 | /** 36 | * This example deletes all domains. 37 | * 38 | */ 39 | public class DeleteDomains implements Closeable { 40 | private final CloudDNSApi dnsApi; 41 | 42 | /** 43 | * To get a username and API key see http://jclouds.apache.org/guides/rackspace/ 44 | * 45 | * The first argument (args[0]) must be your username 46 | * The second argument (args[1]) must be your API key 47 | */ 48 | public static void main(String[] args) throws IOException { 49 | DeleteDomains deleteDomains = new DeleteDomains(args[0], args[1]); 50 | 51 | try { 52 | deleteDomains.deleteAllDomains(); 53 | } 54 | catch (Exception e) { 55 | e.printStackTrace(); 56 | } 57 | finally { 58 | deleteDomains.close(); 59 | } 60 | } 61 | 62 | public DeleteDomains(String username, String apiKey) { 63 | dnsApi = ContextBuilder.newBuilder(PROVIDER) 64 | .credentials(username, apiKey) 65 | .buildApi(CloudDNSApi.class); 66 | } 67 | 68 | private void deleteAllDomains() throws TimeoutException { 69 | System.out.format("Delete Domains%n"); 70 | 71 | Set allDomains = dnsApi.getDomainApi().list().concat().toSet(); 72 | Iterable topLevelDomains = Iterables.filter(allDomains, IS_DOMAIN); 73 | Iterable topLevelDomainIds = Iterables.transform(topLevelDomains, GET_DOMAIN_ID); 74 | 75 | awaitComplete(dnsApi, dnsApi.getDomainApi().delete(topLevelDomainIds, true)); 76 | 77 | System.out.format(" Deleted %s top level domains and all subdomains%n", Iterables.size(topLevelDomainIds)); 78 | } 79 | 80 | /** 81 | * Always close your service when you're done with it. 82 | * 83 | * Note that closing quietly like this is not necessary in Java 7. 84 | * You would use try-with-resources in the main method instead. 85 | */ 86 | public void close() throws IOException { 87 | Closeables.close(dnsApi, true); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cdn/PurgeServiceAssets.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.jclouds.examples.rackspace.cdn; 19 | 20 | import static org.jclouds.examples.rackspace.cdn.Constants.PROVIDER; 21 | 22 | import java.io.Closeable; 23 | import java.io.IOException; 24 | 25 | import org.jclouds.ContextBuilder; 26 | import org.jclouds.openstack.poppy.v1.PoppyApi; 27 | import org.jclouds.openstack.poppy.v1.domain.Service; 28 | import org.jclouds.openstack.poppy.v1.features.ServiceApi; 29 | 30 | import com.google.common.io.Closeables; 31 | 32 | /** 33 | * Purges cached service assets. 34 | * This removes CDN-cached files from the cache. 35 | * The system will reload these assets into the cache the next time they are requested. 36 | */ 37 | public class PurgeServiceAssets implements Closeable { 38 | private final PoppyApi cdnApi; 39 | private final ServiceApi serviceApi; 40 | 41 | /** 42 | * To get a username and API key see 43 | * http://jclouds.apache.org/guides/rackspace/ 44 | * 45 | * The first argument (args[0]) must be your username 46 | * The second argument (args[1]) must be your API key 47 | */ 48 | public static void main(String[] args) throws IOException { 49 | PurgeServiceAssets purgeServiceAssets = new PurgeServiceAssets(args[0], args[1]); 50 | 51 | try { 52 | purgeServiceAssets.updateService(); 53 | } 54 | catch (Exception e) { 55 | e.printStackTrace(); 56 | } 57 | finally { 58 | purgeServiceAssets.close(); 59 | } 60 | } 61 | 62 | public PurgeServiceAssets(String username, String apiKey) { 63 | cdnApi = ContextBuilder.newBuilder(PROVIDER) 64 | .credentials(username, apiKey) 65 | .buildApi(PoppyApi.class); 66 | 67 | serviceApi = cdnApi.getServiceApi(); 68 | } 69 | 70 | private void updateService() { 71 | try { 72 | Service serviceList = serviceApi.list().concat().toSet().iterator().next(); 73 | System.out.println("Purging assets for " + serviceList.getId()); 74 | /** Only available in SNAPSHOT builds. Not available in 1.9.0 75 | serviceApi.deleteAsset(serviceList.getId(), "image/1.jpg")); 76 | serviceApi.deleteAssets(serviceList.getId())); 77 | */ 78 | } finally { 79 | // Do nothing on fail. 80 | } 81 | } 82 | 83 | /** 84 | * Always close your service when you're done with it. 85 | * 86 | * Note that closing quietly like this is not necessary in Java 7. 87 | * You would use try-with-resources in the main method instead. 88 | */ 89 | public void close() throws IOException { 90 | Closeables.close(cdnApi, true); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/carina/Utils.java: -------------------------------------------------------------------------------- 1 | package org.jclouds.examples.rackspace.carina;/* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | import java.io.File; 19 | import java.io.IOException; 20 | import java.nio.charset.Charset; 21 | import java.util.Properties; 22 | 23 | import org.jclouds.ContextBuilder; 24 | import org.jclouds.compute.ComputeServiceContext; 25 | import org.jclouds.docker.DockerApi; 26 | import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; 27 | import org.jclouds.sshj.config.SshjSshClientModule; 28 | 29 | import com.google.common.collect.ImmutableSet; 30 | import com.google.common.io.Files; 31 | import com.google.inject.Module; 32 | 33 | public class Utils { 34 | public static DockerApi getDockerApiFromCarinaDirectory(String path) throws IOException { 35 | // docker.ps1 contains the endpoint 36 | String endpoint = "https://" + 37 | Files.readFirstLine(new File(joinPath(path, "docker.ps1")), 38 | Charset.forName("UTF-8")).split("=")[1].replace("\"", "").substring(6); 39 | 40 | // enable logging 41 | Iterable modules = ImmutableSet. of(new SLF4JLoggingModule()); 42 | Properties overrides = new Properties(); 43 | 44 | // disable certificate checking for Carina 45 | overrides.setProperty("jclouds.trust-all-certs", "true"); 46 | 47 | return ContextBuilder.newBuilder("docker") 48 | // Use the unencrypted credentials 49 | .credentials(joinPath(path, "cert.pem"), joinPath(path, "key.pem")) 50 | .overrides(overrides) 51 | .endpoint(endpoint) 52 | .modules(modules) 53 | .buildApi(DockerApi.class); 54 | } 55 | 56 | public static ComputeServiceContext getComputeApiFromCarinaDirectory(String path) throws IOException { 57 | // docker.ps1 contains the endpoint 58 | String endpoint = "https://" + 59 | Files.readFirstLine(new File(joinPath(path, "docker.ps1")), 60 | Charset.forName("UTF-8")).split("=")[1].replace("\"", "").substring(6); 61 | 62 | // enable logging and sshj 63 | Iterable modules = ImmutableSet. of(new SLF4JLoggingModule(), new SshjSshClientModule()); 64 | Properties overrides = new Properties(); 65 | 66 | // disable certificate checking for Carina 67 | overrides.setProperty("jclouds.trust-all-certs", "true"); 68 | 69 | return ContextBuilder.newBuilder("docker") 70 | .credentials(joinPath(path, "cert.pem"), joinPath(path, "key.pem")) 71 | .modules(modules) 72 | .overrides(overrides) 73 | .endpoint(endpoint) 74 | .buildView(ComputeServiceContext.class); 75 | } 76 | 77 | // Concatenate two different paths 78 | public static String joinPath(String path1, String path2) { 79 | return new File(path1, path2).toString(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/carina/CreateContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.carina; 20 | 21 | import static org.jclouds.examples.rackspace.carina.Utils.getDockerApiFromCarinaDirectory; 22 | 23 | import java.io.IOException; 24 | import java.util.List; 25 | import java.util.Map; 26 | import java.util.Map.Entry; 27 | import java.util.UUID; 28 | 29 | import org.jclouds.docker.DockerApi; 30 | import org.jclouds.docker.domain.Config; 31 | import org.jclouds.docker.domain.Container; 32 | import org.jclouds.docker.domain.HostConfig; 33 | 34 | import com.google.common.collect.ImmutableList; 35 | 36 | /** 37 | * This example creates a Carina container 38 | * 39 | * To use, create/login at getcarina.com; then create a cluster and download the "get access" zip file. 40 | * Then extract the zip archive to a directory and pass the directory path as a parameter to main. 41 | */ 42 | public class CreateContainer { 43 | 44 | public static void main(String[] args) throws IOException { 45 | 46 | DockerApi dockerApi = getDockerApiFromCarinaDirectory(args[0]); 47 | 48 | /** 49 | * Specifying .publishAllPorts(true) in the HostConfig when *creating* the container is the simplest and 50 | * arguably best way to publish the ports this container will be using. Using .portBindings to specify particular 51 | * ports is somewhat more involved. 52 | * 53 | * However, because of https://github.com/docker/docker/issues/4635, TCP and UDP will be exposed on different 54 | * ports. 55 | */ 56 | Container container = dockerApi.getContainerApi().createContainer("mumble", 57 | Config.builder() 58 | .image("extra/mumble") 59 | .hostConfig( 60 | HostConfig.builder() 61 | .publishAllPorts(true) 62 | .build()) 63 | .env( 64 | ImmutableList.of( 65 | "MAX_USERS=50", 66 | "SERVER_TEXT=Welcome to My Mumble Server", 67 | "SUPW=" + UUID.randomUUID() 68 | )) 69 | .build()); 70 | 71 | String id = container.id(); 72 | 73 | dockerApi.getContainerApi().startContainer(id); 74 | 75 | for(Entry>> portList : dockerApi.getContainerApi().inspectContainer(id).networkSettings().ports().entrySet()) { 76 | for(Map port: portList.getValue()) { 77 | System.out.println("Port: " + portList.getKey() + " -> " + port.get("HostIp") + ":" + port.get("HostPort")); 78 | } 79 | } 80 | 81 | // Cleanup 82 | dockerApi.getContainerApi().stopContainer(id); 83 | dockerApi.getContainerApi().removeContainer(id); 84 | 85 | dockerApi.close(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cdn/UpdateService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.jclouds.examples.rackspace.cdn; 19 | 20 | import static org.jclouds.examples.rackspace.cdn.Constants.PROVIDER; 21 | 22 | import java.io.Closeable; 23 | import java.io.IOException; 24 | 25 | import org.jclouds.ContextBuilder; 26 | import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; 27 | import org.jclouds.openstack.poppy.v1.PoppyApi; 28 | import org.jclouds.openstack.poppy.v1.domain.Service; 29 | import org.jclouds.openstack.poppy.v1.features.ServiceApi; 30 | 31 | import com.google.common.collect.ImmutableSet; 32 | import com.google.common.io.Closeables; 33 | import com.google.inject.Module; 34 | 35 | /** 36 | * Updates a Poppy service. (Rackspace CDN). 37 | * This operation internally diffs a target Service with a currently exsiting source service 38 | * and automatically sends the json-patch diff to Poppy, which applies it. 39 | */ 40 | public class UpdateService implements Closeable { 41 | private final PoppyApi cdnApi; 42 | private final ServiceApi serviceApi; 43 | 44 | /** 45 | * To get a username and API key see 46 | * http://jclouds.apache.org/guides/rackspace/ 47 | * 48 | * The first argument (args[0]) must be your username 49 | * The second argument (args[1]) must be your API key 50 | */ 51 | public static void main(String[] args) throws IOException { 52 | UpdateService updateService = new UpdateService(args[0], args[1]); 53 | 54 | try { 55 | updateService.updateService(); 56 | } 57 | catch (Exception e) { 58 | e.printStackTrace(); 59 | } 60 | finally { 61 | updateService.close(); 62 | } 63 | } 64 | 65 | public UpdateService(String username, String apiKey) { 66 | cdnApi = ContextBuilder.newBuilder(PROVIDER) 67 | .credentials(username, apiKey) 68 | .buildApi(PoppyApi.class); 69 | 70 | serviceApi = cdnApi.getServiceApi(); 71 | } 72 | 73 | private void updateService() { 74 | try { 75 | Service serviceList = serviceApi.list().concat().toSet().iterator().next(); 76 | 77 | System.out.println("Update service " + serviceList.getId()); 78 | System.out.println("Status: " + serviceList.getStatus()); 79 | 80 | org.jclouds.openstack.poppy.v1.domain.UpdateService updated = serviceList.toUpdatableService().name("updated_name").build(); 81 | serviceApi.update(serviceList.getId(), serviceList, updated); 82 | } finally { 83 | // Do nothing on fail. 84 | } 85 | } 86 | 87 | /** 88 | * Always close your service when you're done with it. 89 | * 90 | * Note that closing quietly like this is not necessary in Java 7. 91 | * You would use try-with-resources in the main method instead. 92 | */ 93 | public void close() throws IOException { 94 | Closeables.close(cdnApi, true); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cdn/DeleteService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.jclouds.examples.rackspace.cdn; 19 | 20 | import static org.jclouds.examples.rackspace.cdn.Constants.PROVIDER; 21 | 22 | import java.io.Closeable; 23 | import java.io.IOException; 24 | 25 | import org.jclouds.ContextBuilder; 26 | import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; 27 | import org.jclouds.openstack.poppy.v1.PoppyApi; 28 | import org.jclouds.openstack.poppy.v1.domain.Service; 29 | import org.jclouds.openstack.poppy.v1.features.ServiceApi; 30 | 31 | import com.google.common.collect.ImmutableSet; 32 | import com.google.common.io.Closeables; 33 | import com.google.inject.Module; 34 | 35 | /** 36 | * Updates a Poppy service. (Rackspace CDN). 37 | * This operation internally diffs a target Service with a currently exsiting source service 38 | * and automatically sends the json-patch diff to Poppy, which applies it. 39 | */ 40 | public class DeleteService implements Closeable { 41 | private final PoppyApi cdnApi; 42 | private final ServiceApi serviceApi; 43 | 44 | /** 45 | * To get a username and API key see 46 | * http://jclouds.apache.org/guides/rackspace/ 47 | * 48 | * The first argument (args[0]) must be your username 49 | * The second argument (args[1]) must be your API key 50 | */ 51 | public static void main(String[] args) throws IOException { 52 | DeleteService deleteService = new DeleteService(args[0], args[1]); 53 | 54 | try { 55 | deleteService.deleteService(); 56 | } 57 | catch (Exception e) { 58 | e.printStackTrace(); 59 | } 60 | finally { 61 | deleteService.close(); 62 | } 63 | } 64 | 65 | public DeleteService(String username, String apiKey) { 66 | Iterable modules = ImmutableSet. of(new SLF4JLoggingModule()); 67 | cdnApi = ContextBuilder.newBuilder(PROVIDER) 68 | .credentials(username, apiKey) 69 | .modules(modules) 70 | .buildApi(PoppyApi.class); 71 | 72 | serviceApi = cdnApi.getServiceApi(); 73 | } 74 | 75 | private void deleteService() { 76 | 77 | String serviceId = null; 78 | try { 79 | // Delete all services 80 | 81 | for (Service service : serviceApi.list().concat().toList()) { 82 | System.out.println("Delete service " + service.getId()); 83 | serviceApi.delete(service.getId()); 84 | } 85 | 86 | } finally { 87 | // Do nothing on fail 88 | } 89 | } 90 | 91 | /** 92 | * Always close your service when you're done with it. 93 | * 94 | * Note that closing quietly like this is not necessary in Java 7. 95 | * You would use try-with-resources in the main method instead. 96 | */ 97 | public void close() throws IOException { 98 | Closeables.close(cdnApi, true); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/clouddatabases/CreateUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.clouddatabases; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | import java.util.concurrent.TimeoutException; 24 | 25 | import org.jclouds.ContextBuilder; 26 | import org.jclouds.openstack.trove.v1.TroveApi; 27 | import org.jclouds.openstack.trove.v1.domain.Instance; 28 | import org.jclouds.openstack.trove.v1.features.InstanceApi; 29 | import org.jclouds.openstack.trove.v1.features.UserApi; 30 | 31 | import com.google.common.io.Closeables; 32 | 33 | import static org.jclouds.examples.rackspace.clouddatabases.Constants.*; 34 | 35 | /** 36 | * This example will create a User on the database created in the CreateDatabase example. 37 | */ 38 | public class CreateUser implements Closeable { 39 | private final TroveApi troveApi; 40 | private final InstanceApi instanceApi; 41 | private final UserApi userApi; 42 | 43 | /** 44 | * To get a username and API key see 45 | * http://jclouds.apache.org/guides/rackspace/ 46 | * 47 | * The first argument (args[0]) must be your username. 48 | * The second argument (args[1]) must be your API key. 49 | */ 50 | public static void main(String[] args) throws IOException { 51 | CreateUser createUser = new CreateUser(args[0], args[1]); 52 | 53 | try { 54 | createUser.createUser(); 55 | } 56 | catch (Exception e) { 57 | e.printStackTrace(); 58 | } 59 | finally { 60 | createUser.close(); 61 | } 62 | } 63 | 64 | public CreateUser(String username, String apiKey) { 65 | troveApi = ContextBuilder.newBuilder(PROVIDER) 66 | .credentials(username, apiKey) 67 | .buildApi(TroveApi.class); 68 | 69 | instanceApi = troveApi.getInstanceApi(REGION); 70 | userApi = troveApi.getUserApi(REGION, getInstance().getId()); 71 | } 72 | 73 | /** 74 | * @return Instance The Instance created in the CreateInstance example. 75 | */ 76 | private Instance getInstance() { 77 | for (Instance instance: instanceApi.list()) { 78 | if (instance.getName().startsWith(NAME)) { 79 | return instance; 80 | } 81 | } 82 | 83 | throw new RuntimeException(NAME + " not found. Run the CreateInstance example first."); 84 | } 85 | 86 | private void createUser() throws TimeoutException { 87 | System.out.format("Create User%n"); 88 | userApi.create(NAME, PASSWORD, NAME); 89 | } 90 | 91 | /** 92 | * Always close your service when you're done with it. 93 | * 94 | * Note that closing quietly like this is not necessary in Java 7. 95 | * You would use try-with-resources in the main method instead. 96 | */ 97 | public void close() throws IOException { 98 | Closeables.close(troveApi, true); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/autoscale/CreateWebhook.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.autoscale; 20 | 21 | import static org.jclouds.examples.rackspace.autoscale.Constants.NAME; 22 | import static org.jclouds.examples.rackspace.autoscale.Constants.PROVIDER; 23 | import static org.jclouds.examples.rackspace.autoscale.Constants.REGION; 24 | 25 | import java.io.Closeable; 26 | import java.io.IOException; 27 | 28 | import org.jclouds.ContextBuilder; 29 | import org.jclouds.rackspace.autoscale.v1.AutoscaleApi; 30 | import org.jclouds.rackspace.autoscale.v1.domain.Webhook; 31 | import org.jclouds.rackspace.autoscale.v1.features.GroupApi; 32 | import org.jclouds.rackspace.autoscale.v1.features.PolicyApi; 33 | import org.jclouds.rackspace.autoscale.v1.features.WebhookApi; 34 | 35 | import com.google.common.collect.FluentIterable; 36 | import com.google.common.collect.ImmutableMap; 37 | import com.google.common.io.Closeables; 38 | 39 | /** 40 | * This example creates a webhook for the Scaling Policy. 41 | */ 42 | public class CreateWebhook implements Closeable { 43 | private final AutoscaleApi autoscaleApi; 44 | private final WebhookApi webhookApi; 45 | 46 | /** 47 | * To get a username and API key see 48 | * http://jclouds.apache.org/guides/rackspace/ 49 | * 50 | * The first argument (args[0]) must be your username 51 | * The second argument (args[1]) must be your API key 52 | */ 53 | public static void main(String[] args) throws IOException { 54 | CreateWebhook createWebhook = new CreateWebhook(args[0], args[1]); 55 | 56 | try { 57 | createWebhook.createWebhook(); 58 | } 59 | catch (Exception e) { 60 | e.printStackTrace(); 61 | } 62 | finally { 63 | createWebhook.close(); 64 | } 65 | } 66 | 67 | public CreateWebhook(String username, String apiKey) { 68 | autoscaleApi = ContextBuilder.newBuilder(PROVIDER) 69 | .credentials(username, apiKey) 70 | .buildApi(AutoscaleApi.class); 71 | 72 | GroupApi groupApi = autoscaleApi.getGroupApi(REGION); 73 | String groupId = Utils.getGroupId(groupApi); 74 | PolicyApi policyApi = autoscaleApi.getPolicyApi(REGION, groupId); 75 | String policyId = Utils.getPolicyId(policyApi); 76 | webhookApi = autoscaleApi.getWebhookApi(REGION, groupId, policyId); 77 | } 78 | 79 | private void createWebhook() { 80 | System.out.format("Create Webhook%n"); 81 | 82 | FluentIterable result = webhookApi.create(NAME, ImmutableMap.of()); 83 | 84 | System.out.format(" %s%n", result.first().get()); 85 | } 86 | 87 | /** 88 | * Always close your service when you're done with it. 89 | * 90 | * Note that closing quietly like this is not necessary in Java 7. 91 | * You would use try-with-resources in the main method instead. 92 | */ 93 | public void close() throws IOException { 94 | Closeables.close(autoscaleApi, true); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /blobstore-uploader/src/main/java/org/jclouds/examples/blobstore/BlobUploaderMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.jclouds.examples.blobstore; 19 | 20 | import java.io.File; 21 | import java.io.IOException; 22 | import java.util.Collection; 23 | import java.util.concurrent.ExecutorService; 24 | import java.util.concurrent.Executors; 25 | import java.util.concurrent.TimeUnit; 26 | import java.util.concurrent.atomic.AtomicLong; 27 | 28 | import org.apache.commons.io.FileUtils; 29 | import org.apache.commons.io.filefilter.CanReadFileFilter; 30 | import org.apache.commons.io.filefilter.TrueFileFilter; 31 | 32 | import joptsimple.OptionException; 33 | import joptsimple.OptionParser; 34 | import joptsimple.OptionSet; 35 | 36 | public class BlobUploaderMain { 37 | private static int numThreads = 3; 38 | public static long totalBytes = 0; 39 | public static AtomicLong bytesUploaded = new AtomicLong(0); 40 | 41 | public static void main(String[] args) throws IOException { 42 | 43 | OptionParser parser = new OptionParser(); 44 | parser.accepts("directory").withRequiredArg().required().ofType(String.class); 45 | parser.accepts("provider").withRequiredArg().required().ofType(String.class); 46 | parser.accepts("username").withRequiredArg().required().ofType(String.class); 47 | parser.accepts("password").withRequiredArg().required().ofType(String.class); 48 | parser.accepts("region").withRequiredArg().required().ofType(String.class); 49 | parser.accepts("threads").withRequiredArg().ofType(Integer.TYPE).describedAs("number of parallel threads"); 50 | OptionSet options = null; 51 | 52 | try { 53 | options = parser.parse(args); 54 | } catch (OptionException e) { 55 | System.out.println(e.getLocalizedMessage()); 56 | parser.printHelpOn(System.out); 57 | return; 58 | } 59 | 60 | if (options.has("threads")) { 61 | numThreads = Integer.valueOf((String)options.valueOf("numThreads")); 62 | } 63 | 64 | File rootDir = new File((String) options.valueOf("directory")); 65 | Collection files = FileUtils.listFiles(rootDir, CanReadFileFilter.CAN_READ, TrueFileFilter.TRUE); 66 | totalBytes = FileUtils.sizeOfDirectory(rootDir); 67 | 68 | System.out.println("Uploading " + rootDir.getName() + " " + totalBytes / FileUtils.ONE_MB + "MB"); 69 | 70 | ExecutorService executor = Executors.newFixedThreadPool(numThreads); 71 | 72 | for (File f : files) { 73 | BlobUploader b = 74 | new BlobUploader( 75 | (String) options.valueOf("username"), 76 | (String) options.valueOf("password"), 77 | (String) options.valueOf("provider"), 78 | (String) options.valueOf("region"), 79 | f); 80 | executor.execute(b); 81 | } 82 | executor.shutdown(); 83 | 84 | try { 85 | executor.awaitTermination(1, TimeUnit.DAYS); 86 | } catch (InterruptedException e) { 87 | e.printStackTrace(); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/clouddatabases/DeleteUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.clouddatabases; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | import java.util.concurrent.TimeoutException; 24 | 25 | import org.jclouds.ContextBuilder; 26 | import org.jclouds.openstack.trove.v1.TroveApi; 27 | import org.jclouds.openstack.trove.v1.domain.Instance; 28 | import org.jclouds.openstack.trove.v1.features.InstanceApi; 29 | import org.jclouds.openstack.trove.v1.features.UserApi; 30 | 31 | import com.google.common.io.Closeables; 32 | 33 | import static org.jclouds.examples.rackspace.clouddatabases.Constants.*; 34 | 35 | /** 36 | * This example will delete the User created in the CreateUser example. 37 | */ 38 | public class DeleteUser implements Closeable { 39 | private final TroveApi troveApi; 40 | private final InstanceApi instanceApi; 41 | private final UserApi userApi; 42 | 43 | /** 44 | * To get a username and API key see 45 | * http://jclouds.apache.org/guides/rackspace/ 46 | * 47 | * The first argument (args[0]) must be your username. 48 | * The second argument (args[1]) must be your API key. 49 | */ 50 | public static void main(String[] args) throws IOException { 51 | DeleteUser deleteUser = new DeleteUser(args[0], args[1]); 52 | 53 | try { 54 | deleteUser.deleteUser(); 55 | } 56 | catch (Exception e) { 57 | e.printStackTrace(); 58 | } 59 | finally { 60 | deleteUser.close(); 61 | } 62 | } 63 | 64 | public DeleteUser(String username, String apiKey) { 65 | troveApi = ContextBuilder.newBuilder(PROVIDER) 66 | .credentials(username, apiKey) 67 | .buildApi(TroveApi.class); 68 | 69 | instanceApi = troveApi.getInstanceApi(REGION); 70 | userApi = troveApi.getUserApi(REGION, getInstance().getId()); 71 | } 72 | 73 | /** 74 | * @return Instance The Instance created in the CreateInstance example. 75 | */ 76 | private Instance getInstance() { 77 | for (Instance instance : instanceApi.list()) { 78 | if (instance.getName().startsWith(NAME)) { 79 | return instance; 80 | } 81 | } 82 | 83 | throw new RuntimeException(NAME + " not found. Run the CreateInstance example first."); 84 | } 85 | 86 | private void deleteUser() throws TimeoutException { 87 | System.out.format("Delete User%n"); 88 | 89 | boolean result = userApi.delete(NAME); 90 | 91 | System.out.format(" %s%n", result); 92 | } 93 | 94 | /** 95 | * Always close your service when you're done with it. 96 | * 97 | * Note that closing quietly like this is not necessary in Java 7. 98 | * You would use try-with-resources in the main method instead. 99 | */ 100 | public void close() throws IOException { 101 | Closeables.close(troveApi, true); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/clouddatabases/GrantRootAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.clouddatabases; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | import java.util.concurrent.TimeoutException; 24 | 25 | import org.jclouds.ContextBuilder; 26 | import org.jclouds.openstack.trove.v1.TroveApi; 27 | import org.jclouds.openstack.trove.v1.domain.Instance; 28 | import org.jclouds.openstack.trove.v1.features.InstanceApi; 29 | 30 | import com.google.common.io.Closeables; 31 | 32 | import static org.jclouds.examples.rackspace.clouddatabases.Constants.*; 33 | 34 | /** 35 | * This example grants root permissions to the instance created in the CreateInstance example. 36 | */ 37 | public class GrantRootAccess implements Closeable { 38 | private final TroveApi troveApi; 39 | private final InstanceApi instanceApi; 40 | 41 | /** 42 | * To get a username and API key see 43 | * http://jclouds.apache.org/guides/rackspace/ 44 | * 45 | * The first argument (args[0]) must be your username. 46 | * The second argument (args[1]) must be your API key. 47 | */ 48 | public static void main(String[] args) throws IOException { 49 | GrantRootAccess grantRootAccess = new GrantRootAccess(args[0], args[1]); 50 | 51 | try { 52 | grantRootAccess.grantRootAccess(); 53 | } 54 | catch (Exception e) { 55 | e.printStackTrace(); 56 | } 57 | finally { 58 | grantRootAccess.close(); 59 | } 60 | } 61 | 62 | public GrantRootAccess(String username, String apiKey) { 63 | troveApi = ContextBuilder.newBuilder(PROVIDER) 64 | .credentials(username, apiKey) 65 | .buildApi(TroveApi.class); 66 | 67 | instanceApi = troveApi.getInstanceApi(REGION); 68 | } 69 | 70 | /** 71 | * @return Instance The Instance created in the CreateInstance example. 72 | */ 73 | private Instance getInstance() { 74 | for (Instance instance: instanceApi.list()) { 75 | if (instance.getName().startsWith(NAME)) { 76 | return instance; 77 | } 78 | } 79 | 80 | throw new RuntimeException(NAME + " not found. Run the CreateInstance example first."); 81 | } 82 | 83 | private void grantRootAccess() throws TimeoutException { 84 | System.out.format("Grant root access%n"); 85 | 86 | String password = instanceApi.enableRoot(getInstance().getId()); // enable root on the instance 87 | 88 | System.out.format(" Password: %s%n", password); // remove this in your code, never echo credentials 89 | } 90 | 91 | /** 92 | * Always close your service when you're done with it. 93 | * 94 | * Note that closing quietly like this is not necessary in Java 7. 95 | * You would use try-with-resources in the main method instead. 96 | */ 97 | public void close() throws IOException { 98 | Closeables.close(troveApi, true); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/ListObjects.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudfiles; 20 | 21 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.CONTAINER; 22 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.PROVIDER; 23 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.REGION; 24 | 25 | import java.io.Closeable; 26 | import java.io.IOException; 27 | 28 | import org.jclouds.ContextBuilder; 29 | import org.jclouds.openstack.swift.v1.domain.ObjectList; 30 | import org.jclouds.openstack.swift.v1.domain.SwiftObject; 31 | import org.jclouds.openstack.swift.v1.features.ObjectApi; 32 | import org.jclouds.openstack.swift.v1.options.ListContainerOptions; 33 | import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi; 34 | 35 | import com.google.common.io.Closeables; 36 | 37 | /** 38 | * List objects in the Cloud Files container from the CreateContainer example. 39 | * 40 | */ 41 | public class ListObjects implements Closeable { 42 | private final CloudFilesApi cloudFiles; 43 | 44 | /** 45 | * To get a username and API key see http://jclouds.apache.org/guides/rackspace/ 46 | * 47 | * The first argument (args[0]) must be your username 48 | * The second argument (args[1]) must be your API key 49 | */ 50 | public static void main(String[] args) throws IOException { 51 | ListObjects listContainers = new ListObjects(args[0], args[1]); 52 | 53 | try { 54 | listContainers.listObjects(); 55 | listContainers.listObjectsWithFiltering(); 56 | } 57 | catch (Exception e) { 58 | e.printStackTrace(); 59 | } 60 | finally { 61 | listContainers.close(); 62 | } 63 | } 64 | 65 | public ListObjects(String username, String apiKey) { 66 | cloudFiles = ContextBuilder.newBuilder(PROVIDER) 67 | .credentials(username, apiKey) 68 | .buildApi(CloudFilesApi.class); 69 | } 70 | 71 | private void listObjects() { 72 | System.out.format("List Objects%n"); 73 | 74 | ObjectApi objectApi = cloudFiles.getObjectApi(REGION, CONTAINER); 75 | ObjectList objects = objectApi.list(); 76 | 77 | for (SwiftObject object: objects) { 78 | System.out.format(" %s%n", object); 79 | } 80 | } 81 | 82 | private void listObjectsWithFiltering() { 83 | System.out.format("List Objects With Filtering%n"); 84 | 85 | ObjectApi objectApi = cloudFiles.getObjectApi(REGION, CONTAINER); 86 | 87 | ListContainerOptions filter = ListContainerOptions.Builder.prefix("createObjectFromString"); 88 | ObjectList objects = objectApi.list(filter); 89 | 90 | for (SwiftObject object: objects) { 91 | System.out.format(" %s%n", object); 92 | } 93 | } 94 | 95 | /** 96 | * Always close your service when you're done with it. 97 | */ 98 | public void close() throws IOException { 99 | Closeables.close(cloudFiles, true); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/clouddatabases/DeleteDatabase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.clouddatabases; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | import java.util.concurrent.TimeoutException; 24 | 25 | import org.jclouds.ContextBuilder; 26 | import org.jclouds.openstack.trove.v1.TroveApi; 27 | import org.jclouds.openstack.trove.v1.domain.Instance; 28 | import org.jclouds.openstack.trove.v1.features.DatabaseApi; 29 | import org.jclouds.openstack.trove.v1.features.InstanceApi; 30 | 31 | import com.google.common.io.Closeables; 32 | 33 | import static org.jclouds.examples.rackspace.clouddatabases.Constants.*; 34 | 35 | /** 36 | * This example will delete the database created in the CreateDatabase example. 37 | */ 38 | public class DeleteDatabase implements Closeable { 39 | private final TroveApi troveApi; 40 | private final InstanceApi instanceApi; 41 | private final DatabaseApi databaseApi; 42 | 43 | /** 44 | * To get a username and API key see 45 | * http://jclouds.apache.org/guides/rackspace/ 46 | * 47 | * The first argument (args[0]) must be your username. 48 | * The second argument (args[1]) must be your API key. 49 | */ 50 | public static void main(String[] args) throws IOException { 51 | DeleteDatabase deleteDatabase = new DeleteDatabase(args[0], args[1]); 52 | 53 | try { 54 | deleteDatabase.deleteDatabase(); 55 | } 56 | catch (Exception e) { 57 | e.printStackTrace(); 58 | } 59 | finally { 60 | deleteDatabase.close(); 61 | } 62 | } 63 | 64 | public DeleteDatabase(String username, String apiKey) { 65 | troveApi = ContextBuilder.newBuilder(PROVIDER) 66 | .credentials(username, apiKey) 67 | .buildApi(TroveApi.class); 68 | 69 | instanceApi = troveApi.getInstanceApi(REGION); 70 | databaseApi = troveApi.getDatabaseApi(REGION, getInstance().getId()); 71 | } 72 | 73 | /** 74 | * @return Instance The Instance created in the CreateInstance example. 75 | */ 76 | private Instance getInstance() { 77 | for (Instance instance : instanceApi.list()) { 78 | if (instance.getName().startsWith(NAME)) { 79 | return instance; 80 | } 81 | } 82 | 83 | throw new RuntimeException(NAME + " not found. Run the CreateInstance example first."); 84 | } 85 | 86 | private void deleteDatabase() throws TimeoutException { 87 | System.out.format("Delete Database%n"); 88 | 89 | boolean result = databaseApi.delete(NAME); 90 | 91 | System.out.format(" %s%n", result); 92 | } 93 | 94 | /** 95 | * Always close your service when you're done with it. 96 | * 97 | * Note that closing quietly like this is not necessary in Java 7. 98 | * You would use try-with-resources in the main method instead. 99 | */ 100 | public void close() throws IOException { 101 | Closeables.close(troveApi, true); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /blobstore-uploader/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 4.0.0 24 | 25 | blobstore-uploader 26 | blob-uploader 27 | 2.1.0 28 | 29 | 30 | 2.1.0 31 | 32 | 33 | 34 | 35 | org.apache.jclouds.driver 36 | jclouds-slf4j 37 | ${jclouds.version} 38 | 39 | 40 | ch.qos.logback 41 | logback-classic 42 | 1.2.13 43 | 44 | 45 | org.apache.jclouds 46 | jclouds-allblobstore 47 | ${jclouds.version} 48 | 49 | 50 | net.sf.jopt-simple 51 | jopt-simple 52 | 4.8 53 | 54 | 55 | commons-io 56 | commons-io 57 | 2.14.0 58 | 59 | 60 | commons-codec 61 | commons-codec 62 | 1.9 63 | 64 | 65 | 66 | 67 | 68 | org.apache.maven.plugins 69 | maven-shade-plugin 70 | 71 | 72 | package 73 | 74 | shade 75 | 76 | 77 | blobstore-uploader 78 | 79 | 80 | 81 | org.jclouds.examples.blobstore.BlobUploaderMain 82 | 1 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/clouddatabases/CreateInstance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.clouddatabases; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | import java.util.concurrent.TimeoutException; 24 | 25 | import org.jclouds.ContextBuilder; 26 | import org.jclouds.openstack.trove.v1.TroveApi; 27 | import org.jclouds.openstack.trove.v1.domain.Flavor; 28 | import org.jclouds.openstack.trove.v1.domain.Instance; 29 | import org.jclouds.openstack.trove.v1.features.FlavorApi; 30 | import org.jclouds.openstack.trove.v1.utils.TroveUtils; 31 | 32 | import com.google.common.collect.Iterables; 33 | import com.google.common.io.Closeables; 34 | 35 | import static org.jclouds.examples.rackspace.clouddatabases.Constants.*; 36 | 37 | /** 38 | * This example creates a Cloud Databases instance. 39 | * This instance will be used to run a database later on in the Create Database example. 40 | */ 41 | public class CreateInstance implements Closeable { 42 | private final TroveApi troveApi; 43 | private final FlavorApi flavorApi; 44 | 45 | /** 46 | * To get a username and API key see 47 | * http://jclouds.apache.org/guides/rackspace/ 48 | * 49 | * The first argument (args[0]) must be your username. 50 | * The second argument (args[1]) must be your API key. 51 | */ 52 | public static void main(String[] args) throws IOException { 53 | CreateInstance createInstance = new CreateInstance(args[0], args[1]); 54 | 55 | try { 56 | Flavor flavor = createInstance.getFlavor(); 57 | createInstance.createInstance(flavor); 58 | } 59 | catch (Exception e) { 60 | e.printStackTrace(); 61 | } 62 | finally { 63 | createInstance.close(); 64 | } 65 | } 66 | 67 | public CreateInstance(String username, String apiKey) { 68 | troveApi = ContextBuilder.newBuilder(PROVIDER) 69 | .credentials(username, apiKey) 70 | .buildApi(TroveApi.class); 71 | 72 | flavorApi = troveApi.getFlavorApi(REGION); 73 | } 74 | 75 | /** 76 | * @return Flavor The first Flavor available. 77 | */ 78 | private Flavor getFlavor() { 79 | return Iterables.getFirst(flavorApi.list(), null); 80 | } 81 | 82 | private void createInstance(Flavor flavor) throws TimeoutException { 83 | System.out.format("Create Instance for Flavor: %s%n", flavor.getId()); 84 | 85 | TroveUtils utils = new TroveUtils(troveApi); 86 | // This call will take a while - it ensures a working instance is created. 87 | Instance instance = utils.getWorkingInstance(REGION, NAME, "" + flavor.getId(), 1); 88 | 89 | System.out.format(" %s%n", instance); 90 | } 91 | 92 | /** 93 | * Always close your service when you're done with it. 94 | * 95 | * Note that closing quietly like this is not necessary in Java 7. 96 | * You would use try-with-resources in the main method instead. 97 | */ 98 | public void close() throws IOException { 99 | Closeables.close(troveApi, true); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/clouddatabases/CreateDatabase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.clouddatabases; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | import java.util.concurrent.TimeoutException; 24 | 25 | import org.jclouds.ContextBuilder; 26 | import org.jclouds.openstack.trove.v1.TroveApi; 27 | import org.jclouds.openstack.trove.v1.domain.Instance; 28 | import org.jclouds.openstack.trove.v1.features.DatabaseApi; 29 | import org.jclouds.openstack.trove.v1.features.InstanceApi; 30 | 31 | import com.google.common.io.Closeables; 32 | 33 | import static org.jclouds.examples.rackspace.clouddatabases.Constants.*; 34 | 35 | /** 36 | * This example creates a MySQL database on a Cloud Databases instance. 37 | * The instance is created in the CreateInstance example. 38 | * Think of the instance as a type of server. Multiple databases can run on the same instance. 39 | */ 40 | public class CreateDatabase implements Closeable { 41 | private final TroveApi troveApi; 42 | private final InstanceApi instanceApi; 43 | private final DatabaseApi databaseApi; 44 | 45 | /** 46 | * To get a username and API key see 47 | * http://jclouds.apache.org/guides/rackspace/ 48 | * 49 | * The first argument (args[0]) must be your username 50 | * The second argument (args[1]) must be your API key 51 | */ 52 | public static void main(String[] args) throws IOException { 53 | CreateDatabase createDatabase = new CreateDatabase(args[0], args[1]); 54 | 55 | try { 56 | createDatabase.createDatabase(); 57 | } 58 | catch (Exception e) { 59 | e.printStackTrace(); 60 | } 61 | finally { 62 | createDatabase.close(); 63 | } 64 | } 65 | 66 | public CreateDatabase(String username, String apiKey) { 67 | troveApi = ContextBuilder.newBuilder(PROVIDER) 68 | .credentials(username, apiKey) 69 | .buildApi(TroveApi.class); 70 | 71 | instanceApi = troveApi.getInstanceApi(REGION); 72 | databaseApi = troveApi.getDatabaseApi(REGION, getInstance().getId()); 73 | } 74 | 75 | /** 76 | * @return Instance The Instance created in the CreateInstance example. 77 | */ 78 | private Instance getInstance() { 79 | for (Instance instance: instanceApi.list()) { 80 | if (instance.getName().startsWith(NAME)) { 81 | return instance; 82 | } 83 | } 84 | 85 | throw new RuntimeException(NAME + " not found. Run the CreateInstance example first."); 86 | } 87 | 88 | private void createDatabase() throws TimeoutException { 89 | System.out.format("Create Database%n"); 90 | databaseApi.create(NAME); 91 | } 92 | 93 | /** 94 | * Always close your service when you're done with it. 95 | * 96 | * Note that closing quietly like this is not necessary in Java 7. 97 | * You would use try-with-resources in the main method instead. 98 | */ 99 | public void close() throws IOException { 100 | Closeables.close(troveApi, true); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/clouddns/ListDomains.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.clouddns; 20 | 21 | import com.google.common.io.Closeables; 22 | import org.jclouds.ContextBuilder; 23 | import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; 24 | import org.jclouds.rackspace.clouddns.v1.domain.Domain; 25 | import org.jclouds.rackspace.clouddns.v1.domain.Subdomain; 26 | 27 | import java.io.Closeable; 28 | import java.io.IOException; 29 | 30 | import static org.jclouds.examples.rackspace.clouddns.Constants.*; 31 | 32 | /** 33 | * This example lists domains. 34 | * 35 | */ 36 | public class ListDomains implements Closeable { 37 | private final CloudDNSApi dnsApi; 38 | 39 | /** 40 | * To get a username and API key see http://jclouds.apache.org/guides/rackspace/ 41 | * 42 | * The first argument (args[0]) must be your username 43 | * The second argument (args[1]) must be your API key 44 | */ 45 | public static void main(String[] args) throws IOException { 46 | ListDomains listDomains = new ListDomains(args[0], args[1]); 47 | 48 | try { 49 | int domainId = listDomains.listDomains(); 50 | listDomains.listWithFilterByNamesMatching(); 51 | listDomains.listSubdomains(domainId); 52 | } 53 | catch (Exception e) { 54 | e.printStackTrace(); 55 | } 56 | finally { 57 | listDomains.close(); 58 | } 59 | } 60 | 61 | public ListDomains(String username, String apiKey) { 62 | dnsApi = ContextBuilder.newBuilder(PROVIDER) 63 | .credentials(username, apiKey) 64 | .buildApi(CloudDNSApi.class); 65 | } 66 | 67 | private int listDomains() { 68 | System.out.format("List Domains%n"); 69 | 70 | Iterable domains = dnsApi.getDomainApi().list().concat(); 71 | int domainId = 0; 72 | 73 | for (Domain domain: domains) { 74 | System.out.format(" %s%n", domain); 75 | 76 | if (domain.getName().equals(NAME)) { 77 | domainId = domain.getId(); 78 | } 79 | } 80 | 81 | return domainId; 82 | } 83 | 84 | private void listWithFilterByNamesMatching() { 85 | System.out.format("List With Filter By Names Matching%n"); 86 | 87 | Iterable domains = dnsApi.getDomainApi().listWithFilterByNamesMatching(ALT_NAME).concat(); 88 | 89 | for (Domain domain: domains) { 90 | System.out.format(" %s%n", domain); 91 | } 92 | } 93 | 94 | private void listSubdomains(int domainId) { 95 | System.out.format("List Subdomains%n"); 96 | 97 | Iterable subdomains = dnsApi.getDomainApi().listSubdomains(domainId).concat(); 98 | 99 | for (Subdomain subdomain: subdomains) { 100 | System.out.format(" %s%n", subdomain); 101 | } 102 | } 103 | 104 | /** 105 | * Always close your service when you're done with it. 106 | * 107 | * Note that closing quietly like this is not necessary in Java 7. 108 | * You would use try-with-resources in the main method instead. 109 | */ 110 | public void close() throws IOException { 111 | Closeables.close(dnsApi, true); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/autoscale/UpdatePolicy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.autoscale; 20 | 21 | import static org.jclouds.examples.rackspace.autoscale.Constants.NAME; 22 | import static org.jclouds.examples.rackspace.autoscale.Constants.PROVIDER; 23 | import static org.jclouds.examples.rackspace.autoscale.Constants.REGION; 24 | 25 | import java.io.Closeable; 26 | import java.io.IOException; 27 | 28 | import org.jclouds.ContextBuilder; 29 | import org.jclouds.rackspace.autoscale.v1.AutoscaleApi; 30 | import org.jclouds.rackspace.autoscale.v1.domain.CreateScalingPolicy; 31 | import org.jclouds.rackspace.autoscale.v1.domain.CreateScalingPolicy.ScalingPolicyTargetType; 32 | import org.jclouds.rackspace.autoscale.v1.domain.CreateScalingPolicy.ScalingPolicyType; 33 | import org.jclouds.rackspace.autoscale.v1.features.GroupApi; 34 | import org.jclouds.rackspace.autoscale.v1.features.PolicyApi; 35 | 36 | import com.google.common.io.Closeables; 37 | 38 | /** 39 | * This example updates a Scaling Policy in a Scaling Group. 40 | */ 41 | public class UpdatePolicy implements Closeable { 42 | private final AutoscaleApi autoscaleApi; 43 | private final PolicyApi policyApi; 44 | 45 | /** 46 | * To get a username and API key see 47 | * http://jclouds.apache.org/guides/rackspace/ 48 | * 49 | * The first argument (args[0]) must be your username 50 | * The second argument (args[1]) must be your API key 51 | */ 52 | public static void main(String[] args) throws IOException { 53 | UpdatePolicy updatePolicy = new UpdatePolicy(args[0], args[1]); 54 | 55 | try { 56 | updatePolicy.updatePolicy(); 57 | } 58 | catch (Exception e) { 59 | e.printStackTrace(); 60 | } 61 | finally { 62 | updatePolicy.close(); 63 | } 64 | } 65 | 66 | public UpdatePolicy(String username, String apiKey) { 67 | autoscaleApi = ContextBuilder.newBuilder(PROVIDER) 68 | .credentials(username, apiKey) 69 | .buildApi(AutoscaleApi.class); 70 | 71 | GroupApi groupApi = autoscaleApi.getGroupApi(REGION); 72 | String groupId = Utils.getGroupId(groupApi); 73 | policyApi = autoscaleApi.getPolicyApi(REGION, groupId); 74 | } 75 | 76 | private void updatePolicy() { 77 | System.out.format("Update autoscale policy%n"); 78 | 79 | String policyId = policyApi.list().first().get().getId(); 80 | 81 | CreateScalingPolicy scalingPolicy = CreateScalingPolicy.builder() 82 | .cooldown(3) 83 | .type(ScalingPolicyType.WEBHOOK) 84 | .name(NAME) 85 | .targetType(ScalingPolicyTargetType.INCREMENTAL) 86 | .target("1") 87 | .build(); 88 | 89 | boolean result = policyApi.update(policyId, scalingPolicy); 90 | 91 | System.out.format(" %s%n", result); 92 | } 93 | 94 | /** 95 | * Always close your service when you're done with it. 96 | * 97 | * Note that closing quietly like this is not necessary in Java 7. 98 | * You would use try-with-resources in the main method instead. 99 | */ 100 | public void close() throws IOException { 101 | Closeables.close(autoscaleApi, true); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /blobstore-basics/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 22 | 4.0.0 23 | org.apache.jclouds.examples 24 | blobstore-basics 25 | 2.1.0 26 | blobstore-basics 27 | jclouds blobstore example that creates a container, then displays the size of each container 28 | 29 | 30 | 2.1.0 31 | 32 | 33 | 34 | 35 | org.apache.jclouds 36 | jclouds-blobstore 37 | ${jclouds.version} 38 | 39 | 40 | org.apache.jclouds 41 | jclouds-allblobstore 42 | ${jclouds.version} 43 | 44 | 47 | 54 | 55 | 56 | ${project.artifactId} 57 | 58 | 59 | maven-compiler-plugin 60 | 3.1 61 | 62 | ${project.build.sourceEncoding} 63 | 1.6 64 | 1.6 65 | 66 | 67 | 68 | org.apache.maven.plugins 69 | maven-jar-plugin 70 | 2.4 71 | 72 | 73 | 74 | org.jclouds.examples.blobstore.basics.MainApp 75 | 76 | 77 | 78 | 79 | 80 | maven-assembly-plugin 81 | 2.2.1 82 | 83 | 84 | src/main/assembly/jar-with-dependencies.xml 85 | 86 | 87 | 88 | org.jclouds.examples.blobstore.basics.MainApp 89 | 90 | 91 | 92 | 93 | 94 | make-assembly 95 | package 96 | 97 | single 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudservers/DeleteServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudservers; 20 | 21 | import com.google.common.io.Closeables; 22 | import org.jclouds.ContextBuilder; 23 | import org.jclouds.compute.ComputeService; 24 | import org.jclouds.compute.ComputeServiceContext; 25 | import org.jclouds.compute.domain.NodeMetadata; 26 | 27 | import java.io.Closeable; 28 | import java.io.IOException; 29 | import java.util.Properties; 30 | import java.util.Set; 31 | 32 | import static org.jclouds.compute.config.ComputeServiceProperties.POLL_INITIAL_PERIOD; 33 | import static org.jclouds.compute.config.ComputeServiceProperties.POLL_MAX_PERIOD; 34 | import static org.jclouds.compute.predicates.NodePredicates.inGroup; 35 | import static org.jclouds.examples.rackspace.cloudservers.Constants.*; 36 | 37 | /** 38 | * This example destroys the server created in the CreateServer example. 39 | * 40 | */ 41 | public class DeleteServer implements Closeable { 42 | private ComputeService computeService; 43 | 44 | /** 45 | * To get a username and API key see http://jclouds.apache.org/guides/rackspace/ 46 | * 47 | * The first argument (args[0]) must be your username 48 | * The second argument (args[1]) must be your API key 49 | */ 50 | public static void main(String[] args) throws IOException { 51 | DeleteServer deleteServer = new DeleteServer(args[0], args[1]); 52 | 53 | try { 54 | deleteServer.deleteServer(); 55 | } 56 | catch (Exception e) { 57 | e.printStackTrace(); 58 | } 59 | finally { 60 | deleteServer.close(); 61 | } 62 | } 63 | 64 | public DeleteServer(String username, String apiKey) { 65 | // These properties control how often jclouds polls for a status udpate 66 | Properties overrides = new Properties(); 67 | overrides.setProperty(POLL_INITIAL_PERIOD, POLL_PERIOD_TWENTY_SECONDS); 68 | overrides.setProperty(POLL_MAX_PERIOD, POLL_PERIOD_TWENTY_SECONDS); 69 | 70 | ComputeServiceContext context = ContextBuilder.newBuilder(PROVIDER) 71 | .credentials(username, apiKey) 72 | .overrides(overrides) 73 | .buildView(ComputeServiceContext.class); 74 | computeService = context.getComputeService(); 75 | } 76 | 77 | /** 78 | * This will delete all servers in group {@link Constants#NAME} 79 | */ 80 | private void deleteServer() { 81 | System.out.format("Delete Server%n"); 82 | 83 | // This method will continue to poll for the server status and won't return until this server is DELETED 84 | // If you want to know what's happening during the polling, enable logging. See 85 | // /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java 86 | Set servers = computeService.destroyNodesMatching(inGroup(NAME)); 87 | 88 | for (NodeMetadata nodeMetadata: servers) { 89 | System.out.format(" %s%n", nodeMetadata); 90 | } 91 | } 92 | 93 | /** 94 | * Always close your service when you're done with it. 95 | */ 96 | public void close() throws IOException { 97 | Closeables.close(computeService.getContext(), true); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/clouddns/DeleteRecords.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.clouddns; 20 | 21 | import com.google.common.collect.Iterables; 22 | import com.google.common.io.Closeables; 23 | import org.jclouds.ContextBuilder; 24 | import org.jclouds.rackspace.clouddns.v1.CloudDNSApi; 25 | import org.jclouds.rackspace.clouddns.v1.domain.Domain; 26 | import org.jclouds.rackspace.clouddns.v1.domain.RecordDetail; 27 | 28 | import java.io.Closeable; 29 | import java.io.IOException; 30 | import java.util.Set; 31 | import java.util.concurrent.TimeoutException; 32 | 33 | import static org.jclouds.examples.rackspace.clouddns.Constants.ALT_NAME; 34 | import static org.jclouds.examples.rackspace.clouddns.Constants.PROVIDER; 35 | import static org.jclouds.rackspace.clouddns.v1.functions.RecordFunctions.GET_RECORD_ID; 36 | import static org.jclouds.rackspace.clouddns.v1.predicates.JobPredicates.awaitComplete; 37 | 38 | /** 39 | * This example deletes the records on a domain. 40 | * 41 | */ 42 | public class DeleteRecords implements Closeable { 43 | private final CloudDNSApi dnsApi; 44 | 45 | /** 46 | * To get a username and API key see http://jclouds.apache.org/guides/rackspace/ 47 | * 48 | * The first argument (args[0]) must be your username 49 | * The second argument (args[1]) must be your API key 50 | */ 51 | public static void main(String[] args) throws IOException { 52 | DeleteRecords deleteRecords = new DeleteRecords(args[0], args[1]); 53 | 54 | try { 55 | Domain domain = deleteRecords.getDomain(); 56 | deleteRecords.deleteRecords(domain); 57 | } 58 | catch (Exception e) { 59 | e.printStackTrace(); 60 | } 61 | finally { 62 | deleteRecords.close(); 63 | } 64 | } 65 | 66 | public DeleteRecords(String username, String apiKey) { 67 | dnsApi = ContextBuilder.newBuilder(PROVIDER) 68 | .credentials(username, apiKey) 69 | .buildApi(CloudDNSApi.class); 70 | } 71 | 72 | private Domain getDomain() { 73 | for (Domain domain: dnsApi.getDomainApi().list().concat()) { 74 | if (domain.getName().startsWith(ALT_NAME)) { 75 | return domain; 76 | } 77 | } 78 | 79 | throw new RuntimeException(ALT_NAME + " not found. Run CreateDomains example first."); 80 | } 81 | 82 | private void deleteRecords(Domain domain) throws TimeoutException { 83 | System.out.format("Delete Records%n"); 84 | 85 | Set recordDetails = dnsApi.getRecordApi(domain.getId()).listByType("TXT").concat().toSet(); 86 | Iterable recordIds = Iterables.transform(recordDetails, GET_RECORD_ID); 87 | 88 | awaitComplete(dnsApi, dnsApi.getRecordApi(domain.getId()).delete(recordIds)); 89 | 90 | System.out.format(" Deleted %s records", Iterables.size(recordDetails)); 91 | } 92 | 93 | /** 94 | * Always close your service when you're done with it. 95 | * 96 | * Note that closing quietly like this is not necessary in Java 7. 97 | * You would use try-with-resources in the main method instead. 98 | */ 99 | public void close() throws IOException { 100 | Closeables.close(dnsApi, true); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /openstack/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 22 | 4.0.0 23 | org.apache.jclouds.examples 24 | openstack-examples 25 | 2.1.0 26 | openstack-examples 27 | 28 | 29 | 2.1.0 30 | 31 | 32 | 33 | 34 | 35 | org.apache.jclouds.driver 36 | jclouds-slf4j 37 | ${jclouds.version} 38 | 39 | 40 | org.apache.jclouds.driver 41 | jclouds-sshj 42 | ${jclouds.version} 43 | 44 | 45 | 46 | org.apache.jclouds.api 47 | openstack-keystone 48 | ${jclouds.version} 49 | 50 | 51 | org.apache.jclouds.api 52 | openstack-nova 53 | ${jclouds.version} 54 | 55 | 56 | org.apache.jclouds.api 57 | openstack-cinder 58 | ${jclouds.version} 59 | 60 | 61 | org.apache.jclouds.api 62 | openstack-trove 63 | ${jclouds.version} 64 | 65 | 66 | org.apache.jclouds.labs 67 | openstack-glance 68 | ${jclouds.version} 69 | 70 | 71 | org.apache.jclouds.labs 72 | openstack-marconi 73 | ${jclouds.version} 74 | 75 | 76 | org.apache.jclouds.api 77 | openstack-neutron 78 | ${jclouds.version} 79 | 80 | 81 | 82 | ch.qos.logback 83 | logback-classic 84 | 1.2.13 85 | 86 | 87 | mysql 88 | mysql-connector-java 89 | 8.0.28 90 | 91 | 92 | 93 | 94 | 95 | 96 | maven-compiler-plugin 97 | 3.1 98 | 99 | ${project.build.sourceEncoding} 100 | 1.6 101 | 1.6 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudloadbalancers/DeleteLoadBalancers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudloadbalancers; 20 | 21 | import com.google.common.io.Closeables; 22 | import org.jclouds.ContextBuilder; 23 | import org.jclouds.rackspace.cloudloadbalancers.v1.CloudLoadBalancersApi; 24 | import org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer; 25 | import org.jclouds.rackspace.cloudloadbalancers.v1.features.LoadBalancerApi; 26 | import org.jclouds.rackspace.cloudloadbalancers.v1.predicates.LoadBalancerPredicates; 27 | 28 | import java.io.Closeable; 29 | import java.io.IOException; 30 | import java.util.concurrent.TimeoutException; 31 | 32 | import static org.jclouds.examples.rackspace.cloudloadbalancers.Constants.*; 33 | 34 | /** 35 | * This example deletes Load Balancers. 36 | * 37 | */ 38 | public class DeleteLoadBalancers implements Closeable { 39 | private final CloudLoadBalancersApi clbApi; 40 | private final LoadBalancerApi lbApi; 41 | 42 | /** 43 | * To get a username and API key see http://jclouds.apache.org/guides/rackspace/ 44 | * 45 | * The first argument (args[0]) must be your username 46 | * The second argument (args[1]) must be your API key 47 | */ 48 | public static void main(String[] args) throws IOException { 49 | DeleteLoadBalancers listLoadBalancers = new DeleteLoadBalancers(args[0], args[1]); 50 | 51 | try { 52 | listLoadBalancers.deleteLoadBalancers(); 53 | } 54 | catch (Exception e) { 55 | e.printStackTrace(); 56 | } 57 | finally { 58 | listLoadBalancers.close(); 59 | } 60 | } 61 | 62 | public DeleteLoadBalancers(String username, String apiKey) { 63 | clbApi = ContextBuilder.newBuilder(PROVIDER) 64 | .credentials(username, apiKey) 65 | .buildApi(CloudLoadBalancersApi.class); 66 | lbApi = clbApi.getLoadBalancerApi(REGION); 67 | } 68 | 69 | /** 70 | * This method will delete all Load Balancers starting with Constants.NAME. 71 | */ 72 | private void deleteLoadBalancers() throws TimeoutException { 73 | System.out.format("Delete Load Balancers%n"); 74 | 75 | for (LoadBalancer loadBalancer: lbApi.list().concat()) { 76 | if (loadBalancer.getName().startsWith(NAME)) { 77 | lbApi.delete(loadBalancer.getId()); 78 | 79 | // Wait for the Load Balancer to be Deleted before moving on 80 | // If you want to know what's happening during the polling, enable logging. See 81 | // /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java 82 | if (!LoadBalancerPredicates.awaitDeleted(lbApi).apply(loadBalancer)) { 83 | throw new TimeoutException("Timeout on loadBalancer: " + loadBalancer); 84 | } 85 | 86 | System.out.format(" %s%n", loadBalancer); 87 | } 88 | } 89 | } 90 | 91 | /** 92 | * Always close your service when you're done with it. 93 | * 94 | * Note that closing quietly like this is not necessary in Java 7. 95 | * You would use try-with-resources in the main method instead. 96 | */ 97 | public void close() throws IOException { 98 | Closeables.close(clbApi, true); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /dimensiondata/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 4.0.0 24 | 25 | 26 | org.apache.jclouds.examples 27 | jclouds-examples 28 | 2.1.0 29 | 30 | 31 | dimensiondata-cloudcontrol-examples 32 | dimensiondata-cloudcontrol-examples 33 | 2.2.0-SNAPSHOT 34 | 35 | 36 | 2.2.0-SNAPSHOT 37 | 38 | 39 | 40 | 41 | org.apache.jclouds.labs 42 | dimensiondata-cloudcontrol 43 | ${jclouds.version} 44 | 45 | 46 | org.apache.jclouds 47 | jclouds-compute 48 | ${jclouds.version} 49 | 50 | 51 | org.apache.jclouds.driver 52 | jclouds-slf4j 53 | ${jclouds.version} 54 | 55 | 56 | 57 | ch.qos.logback 58 | logback-classic 59 | 1.2.13 60 | 61 | 62 | org.apache.jclouds.driver 63 | jclouds-slf4j 64 | ${jclouds.version} 65 | compile 66 | 67 | 68 | 69 | 70 | 71 | 72 | maven-compiler-plugin 73 | 3.1 74 | 75 | ${project.build.sourceEncoding} 76 | 1.7 77 | 1.7 78 | 79 | 80 | 81 | maven-assembly-plugin 82 | 2.2.1 83 | 84 | 85 | jar-with-dependencies 86 | 87 | 88 | 89 | 90 | make-assembly 91 | package 92 | 93 | single 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/DeleteVolume.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudblockstorage; 20 | 21 | import com.google.common.io.Closeables; 22 | import org.jclouds.ContextBuilder; 23 | import org.jclouds.openstack.cinder.v1.CinderApi; 24 | import org.jclouds.openstack.cinder.v1.domain.Volume; 25 | import org.jclouds.openstack.cinder.v1.features.VolumeApi; 26 | import org.jclouds.openstack.cinder.v1.predicates.VolumePredicates; 27 | 28 | import java.io.Closeable; 29 | import java.io.IOException; 30 | import java.util.concurrent.TimeoutException; 31 | 32 | import static org.jclouds.examples.rackspace.cloudblockstorage.Constants.*; 33 | 34 | /** 35 | * This example deletes a volume. 36 | */ 37 | public class DeleteVolume implements Closeable { 38 | private final CinderApi cinderApi; 39 | private final VolumeApi volumeApi; 40 | 41 | /** 42 | * To get a username and API key see 43 | * http://jclouds.apache.org/guides/rackspace/ 44 | * 45 | * The first argument (args[0]) must be your username 46 | * The second argument (args[1]) must be your API key 47 | */ 48 | public static void main(String[] args) throws IOException { 49 | DeleteVolume deleteVolume = new DeleteVolume(args[0], args[1]); 50 | 51 | try { 52 | Volume volume = deleteVolume.getVolume(); 53 | deleteVolume.deleteVolume(volume); 54 | } 55 | catch (Exception e) { 56 | e.printStackTrace(); 57 | } 58 | finally { 59 | deleteVolume.close(); 60 | } 61 | } 62 | 63 | public DeleteVolume(String username, String apiKey) { 64 | cinderApi = ContextBuilder.newBuilder(PROVIDER) 65 | .credentials(username, apiKey) 66 | .buildApi(CinderApi.class); 67 | volumeApi = cinderApi.getVolumeApi(REGION); 68 | } 69 | 70 | /** 71 | * @return Volume The Volume created in the CreateVolumeAndAttach example 72 | */ 73 | private Volume getVolume() { 74 | for (Volume volume: volumeApi.list()) { 75 | if (volume.getName().startsWith(NAME)) { 76 | return volume; 77 | } 78 | } 79 | 80 | throw new RuntimeException(NAME + " not found. Run the CreateVolumeAndAttach example first."); 81 | } 82 | 83 | private void deleteVolume(Volume volume) throws TimeoutException { 84 | System.out.format("Delete Volume%n"); 85 | 86 | boolean result = volumeApi.delete(volume.getId()); 87 | 88 | // Wait for the volume to be deleted before moving on 89 | // If you want to know what's happening during the polling, enable 90 | // logging. See /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java 91 | if (!VolumePredicates.awaitDeleted(volumeApi).apply(volume)) { 92 | throw new TimeoutException("Timeout on volume: " + volume); 93 | } 94 | 95 | System.out.format(" %s%n", result); 96 | } 97 | 98 | /** 99 | * Always close your service when you're done with it. 100 | * 101 | * Note that closing quietly like this is not necessary in Java 7. 102 | * You would use try-with-resources in the main method instead. 103 | */ 104 | public void close() throws IOException { 105 | Closeables.close(cinderApi, true); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/GetObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudfiles; 20 | 21 | import com.google.common.io.ByteStreams; 22 | import com.google.common.io.Closeables; 23 | import org.jclouds.ContextBuilder; 24 | import org.jclouds.openstack.swift.v1.domain.SwiftObject; 25 | import org.jclouds.openstack.swift.v1.features.ObjectApi; 26 | import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi; 27 | 28 | import java.io.BufferedOutputStream; 29 | import java.io.Closeable; 30 | import java.io.File; 31 | import java.io.FileOutputStream; 32 | import java.io.IOException; 33 | import java.io.InputStream; 34 | 35 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.CONTAINER; 36 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.PROVIDER; 37 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.REGION; 38 | 39 | /** 40 | * Gets an object from a container and displays the results. 41 | * 42 | * NOTE: Run the {@link UploadObjects} example prior to running this example. 43 | * 44 | */ 45 | public class GetObject implements Closeable { 46 | private final CloudFilesApi cloudFiles; 47 | 48 | /** 49 | * To get a username and API key see http://jclouds.apache.org/guides/rackspace/ 50 | * 51 | * The first argument (args[0]) must be your username 52 | * The second argument (args[1]) must be your API key 53 | */ 54 | public static void main(String[] args) throws IOException { 55 | GetObject getObject = new GetObject(args[0], args[1]); 56 | 57 | try { 58 | SwiftObject swiftObject = getObject.getObject(); 59 | getObject.writeObject(swiftObject); 60 | } 61 | catch (Exception e) { 62 | e.printStackTrace(); 63 | } 64 | finally { 65 | getObject.close(); 66 | } 67 | } 68 | 69 | public GetObject(String username, String apiKey) { 70 | cloudFiles = ContextBuilder.newBuilder(PROVIDER) 71 | .credentials(username, apiKey) 72 | .buildApi(CloudFilesApi.class); 73 | 74 | } 75 | 76 | private SwiftObject getObject() { 77 | System.out.format("Get Object%n"); 78 | 79 | ObjectApi objectApi = cloudFiles.getObjectApi(REGION, CONTAINER); 80 | SwiftObject swiftObject = objectApi.get("uploadObjectFromFile.txt"); 81 | 82 | System.out.format(" %s%n", swiftObject); 83 | 84 | return swiftObject; 85 | } 86 | 87 | private void writeObject(SwiftObject swiftObject) throws IOException { 88 | System.out.format("Write Object%n"); 89 | 90 | InputStream inputStream = swiftObject.getPayload().openStream(); 91 | File file = File.createTempFile("uploadObjectFromFile", ".txt"); 92 | BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file)); 93 | 94 | try { 95 | ByteStreams.copy(inputStream, outputStream); 96 | } 97 | finally { 98 | inputStream.close(); 99 | outputStream.close(); 100 | } 101 | 102 | System.out.format(" %s%n", file.getAbsolutePath()); 103 | } 104 | 105 | /** 106 | * Always close your service when you're done with it. 107 | */ 108 | public void close() throws IOException { 109 | Closeables.close(cloudFiles, true); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudfiles/DeleteObjectsAndContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudfiles; 20 | 21 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.CONTAINER; 22 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.PROVIDER; 23 | import static org.jclouds.examples.rackspace.cloudfiles.Constants.REGION; 24 | 25 | import java.io.Closeable; 26 | import java.io.IOException; 27 | import java.util.List; 28 | 29 | import org.jclouds.ContextBuilder; 30 | import org.jclouds.openstack.swift.v1.domain.Container; 31 | import org.jclouds.openstack.swift.v1.domain.ObjectList; 32 | import org.jclouds.openstack.swift.v1.domain.SwiftObject; 33 | import org.jclouds.openstack.swift.v1.features.ObjectApi; 34 | import org.jclouds.openstack.swift.v1.options.ListContainerOptions; 35 | import org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi; 36 | 37 | import com.google.common.io.Closeables; 38 | 39 | /** 40 | * Delete the objects from the CreateObjects example and delete the Cloud Files container from the 41 | * CreateContainer example. 42 | * 43 | */ 44 | public class DeleteObjectsAndContainer implements Closeable { 45 | private final CloudFilesApi cloudFiles; 46 | 47 | /** 48 | * To get a username and API key see http://jclouds.apache.org/guides/rackspace/ 49 | * 50 | * The first argument (args[0]) must be your username 51 | * The second argument (args[1]) must be your API key 52 | */ 53 | public static void main(String[] args) throws IOException { 54 | DeleteObjectsAndContainer deleteObjectsAndContainer = new DeleteObjectsAndContainer(args[0], args[1]); 55 | 56 | try { 57 | deleteObjectsAndContainer.deleteObjectsAndContainer(); 58 | } 59 | catch (Exception e) { 60 | e.printStackTrace(); 61 | } 62 | finally { 63 | deleteObjectsAndContainer.close(); 64 | } 65 | } 66 | 67 | public DeleteObjectsAndContainer(String username, String apiKey) { 68 | cloudFiles = ContextBuilder.newBuilder(PROVIDER) 69 | .credentials(username, apiKey) 70 | .buildApi(CloudFilesApi.class); 71 | } 72 | 73 | /** 74 | * This will delete all containers that start with {@link Constants#CONTAINER} and the objects within those containers. 75 | */ 76 | private void deleteObjectsAndContainer() { 77 | System.out.format("Delete Container%n"); 78 | 79 | List containers = cloudFiles.getContainerApi(REGION) 80 | .list(ListContainerOptions.Builder.prefix(CONTAINER)).toList(); 81 | 82 | for (Container container: containers) { 83 | System.out.format(" %s%n", container.getName()); 84 | 85 | ObjectApi objectApi = cloudFiles.getObjectApi(REGION, container.getName()); 86 | ObjectList objects = objectApi.list(); 87 | 88 | for (SwiftObject object: objects) { 89 | System.out.format(" %s%n", object.getName()); 90 | objectApi.delete(object.getName()); 91 | } 92 | 93 | cloudFiles.getContainerApi(REGION).deleteIfEmpty(container.getName()); 94 | } 95 | } 96 | 97 | /** 98 | * Always close your service when you're done with it. 99 | */ 100 | public void close() throws IOException { 101 | Closeables.close(cloudFiles, true); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /compute-basics/README.md: -------------------------------------------------------------------------------- 1 | # compute-basics 2 | 3 | This is a simple example command line client that creates a node in a [ComputeService](http://jclouds.apache.org/start/compute/) provider and executes `echo hello` on everything in its group. 4 | 5 | ## Build 6 | 7 | Ensure you have **maven 3.02** or higher installed, then execute `mvn install` to build the example. 8 | Note you also need an ssh key setup in your home directory. 9 | 10 | If you don't already have `~/.ssh/id_rsa` present, generate a key with the command `ssh-keygen -t rsa` and leave the passphrase blank. 11 | 12 | ## Run 13 | 14 | Invoke the jar, passing the name of the cloud provider you with to access (ex. aws-ec2, gogrid), identity (ex. accesskey, username), credential (ex. secretkey, password), then the name of the group you'd like to add the node to. 15 | 16 | The 4th parameter represents the **action** you want to run. Supported actions are: 17 | 18 | - add 19 | - exec 20 | - run 21 | - destroy 22 | - listnodes 23 | - listimages 24 | 25 | Noting that **destroy** will destroy all nodes in the group. If the 4th parameter is exec, you must quote a command to execute across the group of nodes. 26 | 27 | To add a node to the group *mygroup*: 28 | 29 | java -jar target/compute-basics-jar-with-dependencies.jar provider identity credential mygroup add 30 | 31 | To execute a command to all nodes of the group *mygroup*: 32 | 33 | java -jar target/compute-basics-jar-with-dependencies.jar provider identity credential mygroup exec "echo hello" 34 | 35 | To run a script file in all nodes of the group *mygroup* 36 | 37 | java -jar target/compute-basics-jar-with-dependencies.jar provider identity credential mygroup run /path/to/script-file 38 | 39 | To destroy all nodes of the group *mygroup*: 40 | 41 | java -jar target/compute-basics-jar-with-dependencies.jar provider identity credential mygroup destroy 42 | 43 | To list all nodes (the *groupname* parameter is not used): 44 | 45 | java -jar target/compute-basics-jar-with-dependencies.jar provider identity credential mygroup listnodes 46 | 47 | To list all images (the *groupname* parameter is not used): 48 | 49 | java -jar target/compute-basics-jar-with-dependencies.jar provider identity credential mygroup listimages 50 | 51 | 52 | ### Amazon EC2 53 | 54 | java -jar target/compute-basics-jar-with-dependencies.jar aws-ec2 \ 55 | accesskey secretkey mygroup add 56 | 57 | ### HP Cloud 58 | 59 | java -jar target/compute-basics-jar-with-dependencies.jar hpcloud-compute \ 60 | tenantId:accesskey secretkey mygroup add 61 | 62 | ### TryStack.org 63 | 64 | java -jar target/compute-basics-jar-with-dependencies.jar trystack-nova tenantId:user password mygroup add 65 | 66 | ### Your own OpenStack Nova 67 | 68 | java \ 69 | -Dopenstack-nova.image-id=RegionOne/15 \ 70 | -Dopenstack-nova.login-user=ubuntu \ 71 | -Djclouds.trust-all-certs=true \ 72 | -Djclouds.keystone.credential-type=passwordCredentials \ 73 | -Dopenstack-nova.endpoint=https://keystone:35357 \ 74 | -jar target/compute-basics-jar-with-dependencies.jar \ 75 | openstack-nova tenantId:user password mygroup add 76 | 77 | ### Your own OpenStack Nova emulating EC2 78 | 79 | java \ 80 | -Dopenstack-nova-ec2.image-id=nova/ami-00000009 \ 81 | -Dopenstack-nova-ec2.login-user=ubuntu \ 82 | -Djclouds.trust-all-certs=true \ 83 | -Dopenstack-nova-ec2.endpoint=https://novahost/services/Cloud \ 84 | -jar target/compute-basics-jar-with-dependencies.jar \ 85 | openstack-nova-ec2 tenantId:accesskey secretkey mygroup add 86 | 87 | ### Google Compute Engine provider 88 | 89 | java -jar target/compute-basics-jar-with-dependencies.jar \ 90 | google-compute-engine \ 91 | your-project-service-account-email@developer.gserviceaccount.com \ 92 | /path/to/json-key.json \ 93 | mygroup add 94 | 95 | For more information on service accounts and getting a JSON key see [here](https://developers.google.com/console/help/new/#serviceaccounts) 96 | 97 | ## License 98 | 99 | Copyright (C) 2009-2014 The Apache Software Foundation 100 | 101 | Licensed under the Apache License, Version 2.0 102 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/clouddatabases/DeleteInstance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.clouddatabases; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | import java.util.concurrent.TimeoutException; 24 | 25 | import org.jclouds.ContextBuilder; 26 | import org.jclouds.openstack.trove.v1.TroveApi; 27 | import org.jclouds.openstack.trove.v1.domain.Instance; 28 | import org.jclouds.openstack.trove.v1.features.InstanceApi; 29 | import org.jclouds.openstack.trove.v1.predicates.InstancePredicates; 30 | 31 | import com.google.common.io.Closeables; 32 | 33 | import static org.jclouds.examples.rackspace.clouddatabases.Constants.*; 34 | 35 | /** 36 | * This example will delete the instance created in the CreateInstance example. 37 | */ 38 | public class DeleteInstance implements Closeable { 39 | private final TroveApi troveApi; 40 | private final InstanceApi instanceApi; 41 | 42 | /** 43 | * To get a username and API key see 44 | * http://jclouds.apache.org/guides/rackspace/ 45 | * 46 | * The first argument (args[0]) must be your username. 47 | * The second argument (args[1]) must be your API key. 48 | */ 49 | public static void main(String[] args) throws IOException { 50 | DeleteInstance deleteInstance = new DeleteInstance(args[0], args[1]); 51 | 52 | try { 53 | deleteInstance.deleteInstance(deleteInstance.getInstance()); 54 | } 55 | catch (Exception e) { 56 | e.printStackTrace(); 57 | } 58 | finally { 59 | deleteInstance.close(); 60 | } 61 | } 62 | 63 | public DeleteInstance(String username, String apiKey) { 64 | troveApi = ContextBuilder.newBuilder(PROVIDER) 65 | .credentials(username, apiKey) 66 | .buildApi(TroveApi.class); 67 | 68 | instanceApi = troveApi.getInstanceApi(REGION); 69 | } 70 | 71 | /** 72 | * @return Instance The Instance created in the CreateInstance example. 73 | */ 74 | private Instance getInstance() { 75 | for (Instance instance : instanceApi.list()) { 76 | if (instance.getName().startsWith(NAME)) { 77 | return instance; 78 | } 79 | } 80 | 81 | throw new RuntimeException(NAME + " not found. Run the CreateInstance example first."); 82 | } 83 | 84 | private void deleteInstance(Instance instance) throws TimeoutException { 85 | System.out.format("Delete Instance%n"); 86 | 87 | boolean result = instanceApi.delete(instance.getId()); 88 | 89 | // Wait for the instance to be deleted before moving on 90 | // If you want to know what's happening during the polling, enable logging. See 91 | // /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java 92 | if (!InstancePredicates.awaitDeleted(instanceApi).apply(instance)) { 93 | throw new TimeoutException("Timeout on instance: " + instance); 94 | } 95 | 96 | System.out.format(" %s%n", result); 97 | } 98 | 99 | /** 100 | * Always close your service when you're done with it. 101 | * 102 | * Note that closing quietly like this is not necessary in Java 7. 103 | * You would use try-with-resources in the main method instead. 104 | */ 105 | public void close() throws IOException { 106 | Closeables.close(troveApi, true); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/cloudblockstorage/DeleteSnapshot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace.cloudblockstorage; 20 | 21 | import com.google.common.io.Closeables; 22 | import org.jclouds.ContextBuilder; 23 | import org.jclouds.openstack.cinder.v1.CinderApi; 24 | import org.jclouds.openstack.cinder.v1.domain.Snapshot; 25 | import org.jclouds.openstack.cinder.v1.features.SnapshotApi; 26 | import org.jclouds.openstack.cinder.v1.predicates.SnapshotPredicates; 27 | 28 | import java.io.Closeable; 29 | import java.io.IOException; 30 | import java.util.concurrent.TimeoutException; 31 | 32 | import static org.jclouds.examples.rackspace.cloudblockstorage.Constants.*; 33 | 34 | /** 35 | * This example deletes a snapshot. 36 | */ 37 | public class DeleteSnapshot implements Closeable { 38 | private final CinderApi cinderApi; 39 | private final SnapshotApi snapshotApi; 40 | 41 | /** 42 | * To get a username and API key see 43 | * http://jclouds.apache.org/guides/rackspace/ 44 | * 45 | * The first argument (args[0]) must be your username 46 | * The second argument (args[1]) must be your API key 47 | */ 48 | public static void main(String[] args) throws IOException { 49 | DeleteSnapshot deleteSnapshot = new DeleteSnapshot(args[0], args[1]); 50 | 51 | try { 52 | Snapshot snapshot = deleteSnapshot.getSnapshot(); 53 | deleteSnapshot.deleteSnapshot(snapshot); 54 | } 55 | catch (Exception e) { 56 | e.printStackTrace(); 57 | } 58 | finally { 59 | deleteSnapshot.close(); 60 | } 61 | } 62 | 63 | public DeleteSnapshot(String username, String apiKey) { 64 | cinderApi = ContextBuilder.newBuilder(PROVIDER) 65 | .credentials(username, apiKey) 66 | .buildApi(CinderApi.class); 67 | snapshotApi = cinderApi.getSnapshotApi(REGION); 68 | } 69 | 70 | /** 71 | * @return Snapshot The Snapshot created in the CreateSnapshot example 72 | */ 73 | private Snapshot getSnapshot() { 74 | for (Snapshot snapshot : snapshotApi.list()) { 75 | if (snapshot.getName().startsWith(NAME)) { 76 | return snapshot; 77 | } 78 | } 79 | 80 | throw new RuntimeException(NAME + " not found. Run the CreateSnapshot example first."); 81 | } 82 | 83 | private void deleteSnapshot(Snapshot snapshot) throws TimeoutException { 84 | System.out.format("Delete Snapshot%n"); 85 | 86 | boolean result = snapshotApi.delete(snapshot.getId()); 87 | 88 | // Wait for the snapshot to be deleted before moving on 89 | // If you want to know what's happening during the polling, enable logging. 90 | // See /jclouds-example/rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java 91 | if (!SnapshotPredicates.awaitDeleted(snapshotApi).apply(snapshot)) { 92 | throw new TimeoutException("Timeout on snapshot: " + snapshot); 93 | } 94 | 95 | System.out.format(" %s%n", result); 96 | } 97 | 98 | /** 99 | * Always close your service when you're done with it. 100 | * 101 | * Note that closing quietly like this is not necessary in Java 7. 102 | * You would use try-with-resources in the main method instead. 103 | */ 104 | public void close() throws IOException { 105 | Closeables.close(cinderApi, true); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /rackspace/src/main/java/org/jclouds/examples/rackspace/Logging.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.jclouds.examples.rackspace; 20 | 21 | import java.io.Closeable; 22 | import java.io.IOException; 23 | import java.util.Set; 24 | 25 | import org.jclouds.ContextBuilder; 26 | import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; 27 | import org.jclouds.openstack.nova.v2_0.NovaApi; 28 | 29 | import com.google.common.collect.ImmutableSet; 30 | import com.google.common.io.Closeables; 31 | import com.google.inject.Module; 32 | 33 | /** 34 | * This example shows you how to log what jclouds is doing. This is extremely useful for debugging, submitting bug 35 | * reports, getting help, and figuring exactly what the HTTP requests and resonses look like. 36 | * 37 | * In this example we use the Simple Logging Facade for Java (SLF4J). The implementation of SLF4J that we'll use is 38 | * Logback so you'll need to download the Logback JARs from http://logback.qos.ch/download.html and put them on your 39 | * classpath. 40 | * 41 | * The last key ingredient is the file /jclouds-examples/rackspace/src/main/resources/logback.xml which configures 42 | * the logging. As it is configured right now it will log wire input/output and headers to standard out (STDOUT). 43 | * This means that you will be able to see on your console everything that is sent in the request (marked by ">>") 44 | * and everything received in the response (marked by "<<"). 45 | */ 46 | public class Logging implements Closeable { 47 | private final NovaApi nova; 48 | 49 | /** 50 | * To get a username and API key see http://jclouds.apache.org/guides/rackspace/ 51 | * 52 | * The first argument (args[0]) must be your username 53 | * The second argument (args[1]) must be your API key 54 | */ 55 | public static void main(String[] args) throws IOException { 56 | Logging logging = new Logging(args[0], args[1]); 57 | 58 | try { 59 | logging.getConfiguredZones(); 60 | } 61 | catch (Exception e) { 62 | e.printStackTrace(); 63 | } 64 | finally { 65 | logging.close(); 66 | } 67 | } 68 | 69 | public Logging(String username, String apiKey) { 70 | // The provider configures jclouds To use the Rackspace Cloud (US) 71 | // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudservers-uk" 72 | String provider = System.getProperty("provider.cs", "rackspace-cloudservers-us"); 73 | 74 | // This module is responsible for enabling logging 75 | Iterable modules = ImmutableSet. of(new SLF4JLoggingModule()); 76 | 77 | nova = ContextBuilder.newBuilder(provider) 78 | .credentials(username, apiKey) 79 | .modules(modules) // don't forget to add the modules to your context! 80 | .buildApi(NovaApi.class); 81 | } 82 | 83 | private void getConfiguredZones() { 84 | // Calling getConfiguredRegions() talks to the cloud which gets logged 85 | Set regions = nova.getConfiguredRegions(); 86 | 87 | System.out.format("Zones%n"); 88 | 89 | for (String region : regions) { 90 | System.out.format(" %s%n", region); 91 | } 92 | } 93 | 94 | /** 95 | * Always close your service when you're done with it. 96 | */ 97 | public void close() throws IOException { 98 | Closeables.close(nova, true); 99 | } 100 | } 101 | --------------------------------------------------------------------------------