Skip to content
Permalink
Browse files
Minor changes to compute-basics after code review
Follow-up to c223b77
  • Loading branch information
suriyapriya authored and demobox committed Apr 6, 2014
1 parent 7963763 commit 5f644baa6b3462633a5aabd52d68ee75ac02f947
Showing 2 changed files with 19 additions and 15 deletions.
@@ -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 \
@@ -110,12 +110,15 @@ public static void main(String[] args) {
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 static void main(String[] args) {
// 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 static void main(String[] args) {
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 @@ private static String getPrivateKeyFromFile(String filename) {
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;

0 comments on commit 5f644ba

Please sign in to comment.