Repository: jclouds-examples Updated Branches: refs/heads/master 7963763ad -> 5f644baa6
Minor changes to compute-basics after code review Follow-up to c223b771 Project: http://git-wip-us.apache.org/repos/asf/jclouds-examples/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-examples/commit/5f644baa Tree: http://git-wip-us.apache.org/repos/asf/jclouds-examples/tree/5f644baa Diff: http://git-wip-us.apache.org/repos/asf/jclouds-examples/diff/5f644baa Branch: refs/heads/master Commit: 5f644baa6b3462633a5aabd52d68ee75ac02f947 Parents: 7963763 Author: Suriya priya Veluchamy <[email protected]> Authored: Wed Apr 2 20:49:18 2014 -0700 Committer: Andrew Phillips <[email protected]> Committed: Sun Apr 6 19:52:00 2014 -0400 ---------------------------------------------------------------------- compute-basics/README.md | 6 ++--- .../examples/compute/basics/MainApp.java | 28 +++++++++++--------- 2 files changed, 19 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/5f644baa/compute-basics/README.md ---------------------------------------------------------------------- diff --git a/compute-basics/README.md b/compute-basics/README.md index abf8866..78902ce 100755 --- a/compute-basics/README.md +++ b/compute-basics/README.md @@ -40,11 +40,11 @@ To destroy all nodes of the group *mygroup*: java -jar target/compute-basics-jar-with-dependencies.jar provider identity credential mygroup destroy -To list the nodes: *groupname* parameter is not used +To list all nodes (the *groupname* parameter is not used): java -jar target/compute-basics-jar-with-dependencies.jar provider identity credential mygroup listnodes -To list the images: *groupname* parameter is not used +To list all images (the *groupname* parameter is not used): java -jar target/compute-basics-jar-with-dependencies.jar provider identity credential mygroup listimages @@ -89,7 +89,7 @@ To list the images: *groupname* parameter is not used -jar target/compute-basics-jar-with-dependencies.jar \ openstack-nova-ec2 tenantId:accesskey secretkey mygroup add -### Google Cloud Engine provider +### Google Compute Engine provider java -jar target/compute-basics-jar-with-dependencies.jar \ google-compute-engine \ http://git-wip-us.apache.org/repos/asf/jclouds-examples/blob/5f644baa/compute-basics/src/main/java/org/jclouds/examples/compute/basics/MainApp.java ---------------------------------------------------------------------- diff --git a/compute-basics/src/main/java/org/jclouds/examples/compute/basics/MainApp.java b/compute-basics/src/main/java/org/jclouds/examples/compute/basics/MainApp.java index 3d2744b..1481567 100644 --- a/compute-basics/src/main/java/org/jclouds/examples/compute/basics/MainApp.java +++ b/compute-basics/src/main/java/org/jclouds/examples/compute/basics/MainApp.java @@ -110,12 +110,15 @@ public class MainApp { String credential = args[2]; String groupName = args[3]; Action action = Action.valueOf(args[4].toUpperCase()); + boolean providerIsGCE = provider.equalsIgnoreCase("google-compute-engine"); + if (action == Action.EXEC && args.length < PARAMETERS + 1) throw new IllegalArgumentException("please quote the command to exec as the last parameter"); String command = (action == Action.EXEC) ? args[5] : "echo hello"; - if (provider.equalsIgnoreCase("google-compute-engine")) - credential = getPrivateKeyFromFile(credential); // load the pem file as string + // For GCE, the credential parameter is the path to the private key file + if (providerIsGCE) + credential = getPrivateKeyFromFile(credential); if (action == Action.RUN && args.length < PARAMETERS + 1) throw new IllegalArgumentException("please pass the local file to run as the last parameter"); @@ -145,7 +148,7 @@ public class MainApp { // that tested to work with java, which tends to be Ubuntu or CentOS TemplateBuilder templateBuilder = compute.templateBuilder(); - if(provider.equalsIgnoreCase("google-compute-engine")) + if (providerIsGCE) templateBuilder.osFamily(OsFamily.CENTOS); // If you want to up the ram and leave everything default, you can @@ -215,17 +218,17 @@ public class MainApp { System.out.printf("<< destroyed nodes %s%n", destroyed); break; case LISTIMAGES: - Set<? extends Image> imageList = compute.listImages(); - System.out.printf(">> No of images %d\n", imageList.size()); - for (Image img : imageList) { + Set<? extends Image> images = compute.listImages(); + System.out.printf(">> No of images %d%n", images.size()); + for (Image img : images) { System.out.println(">>>> " + img); } break; case LISTNODES: - Set<? extends ComputeMetadata> nodeList = compute.listNodes(); - System.out.printf(">> No of nodes/instances %d\n", nodeList.size()); - for (ComputeMetadata nodeentry : nodeList) { - System.out.println(">>>> " + nodeentry); + Set<? extends ComputeMetadata> nodes = compute.listNodes(); + System.out.printf(">> No of nodes/instances %d%n", nodes.size()); + for (ComputeMetadata nodeData : nodes) { + System.out.println(">>>> " + nodeData); } break; } @@ -248,10 +251,11 @@ public class MainApp { try { return Strings2.toStringAndClose(new FileInputStream(filename)); } catch (java.io.IOException e) { - System.err.println("Exception : " + e); + System.err.println("Exception reading private key from '%s': " + filename); e.printStackTrace(); + System.exit(1); + return null; } - return null; } static int error = 0;
