Permalink
Browse files

Added ability to shut down VMs by user_name, DN, group id and group name

Also rearranged code in DefaultRemoteAdminToolsMgmt
  • Loading branch information...
1 parent 6c23dfb commit 327d36de471f5f2ff7a12ebbd447467b870c2e2b @rrusnak1 rrusnak1 committed with oldpatricka Jul 12, 2011
@@ -28,12 +28,16 @@
public static final int SHUTDOWN_ALL = 0;
public static final int SHUTDOWN_ID = 1;
public static final int SHUTDOWN_HOST = 2;
+ public static final int SHUTDOWN_UNAME = 3;
+ public static final int SHUTDOWN_DN = 4;
+ public static final int SHUTDOWN_GID = 5;
+ public static final int SHUTDOWN_GNAME = 6;
public String getAllRunningVMs() throws RemoteException;
public String getVMsByDN(String userDN) throws RemoteException;
public String getVMsByUser(String user) throws RemoteException;
public String getAllVMsByHost(String hostname) throws RemoteException;
- public String[] getAllVMsByGroupId(String groupId) throws RemoteException;
- public String[] getAllVMsByGroupName(String groupName) throws RemoteException;
+ public String getAllVMsByGroupId(String groupId) throws RemoteException;
+ public String getAllVMsByGroupName(String groupName) throws RemoteException;
public String shutdown(int type, String typeID, String seconds) throws RemoteException;
}
@@ -30,12 +30,14 @@
private String endTime;
private String memory;
private String cpuCount;
+ private String uri;
//Used by Gson
public VMTranslation() {}
public VMTranslation(String id, String node, String callerIdentity, String groupId, String groupName,
- String state, String startTime, String endTime, String memory, String cpuCount) {
+ String state, String startTime, String endTime, String memory, String cpuCount,
+ String uri) {
this.id = id;
this.node = node;
this.callerIdentity = callerIdentity;
@@ -46,6 +48,7 @@ public VMTranslation(String id, String node, String callerIdentity, String group
this.endTime = endTime;
this.memory = memory;
this.cpuCount = cpuCount;
+ this.uri = uri;
}
public String getId() {
@@ -78,4 +81,7 @@ public String getMemory() {
public String getCpuCount() {
return cpuCount;
}
+ public String getUri() {
+ return uri;
+ }
}
@@ -182,22 +182,17 @@ public Options getOptions() {
public final Option SECONDS_OPT =
OptionBuilder.withLongOpt(SECONDS_LONG).hasOptionalArg().create(SECONDS);
- public static final String HOST_LIST = "hl";
- public static final String HOST_LIST_LONG = "host";
- public final Option HOST_LIST_OPT =
- OptionBuilder.withLongOpt(HOST_LIST_LONG).hasOptionalArg().create(HOST_LIST);
-
- public static final String HOST_SHUTDOWN = "hs";
- public static final String HOST_SHUTDOWN_LONG = "hostname";
- public final Option HOST_SHUTDOWN_OPT =
- OptionBuilder.withLongOpt(HOST_SHUTDOWN_LONG).hasOptionalArg().create(HOST_SHUTDOWN);
+ public static final String HOST = "hn";
+ public static final String HOST_LONG = "host";
+ public final Option HOST_OPT =
+ OptionBuilder.withLongOpt(HOST_LONG).hasOptionalArg().create(HOST);
public final Option[] ALL_ENABLED_OPTIONS = {
HELP_OPT, DEBUG_OPT, CONFIG_OPT, BATCH_OPT, DELIMITER_OPT,
REPORT_OPT, JSON_OPT, OUTPUT_OPT, ADD_NODES_OPT, LIST_NODES_OPT,
REMOVE_NODES_OPT, UPDATE_NODES_OPT, NETWORKS_OPT, MEMORY_OPT, POOL_OPT,
ACTIVE_OPT, INACTIVE_OPT, LIST_VMS_OPT, SHUTDOWN_VMS_OPT, USER_OPT, ID_OPT,
- SECONDS_OPT, ALL_VMS_OPT, HOST_LIST_OPT, HOST_SHUTDOWN_OPT, DN_OPT, GROUP_ID_OPT,
+ SECONDS_OPT, ALL_VMS_OPT, HOST_OPT, DN_OPT, GROUP_ID_OPT,
GROUP_NAME_OPT
};
@@ -45,10 +45,11 @@
private static final String FIELD_END = "end time";
private static final String FIELD_MEMORY = "memory";
private static final String FIELD_CPU_COUNT = "cpu count";
+ private static final String FIELD_URI = "uri";
final static String[] ADMIN_FIELDS = new String[] {
FIELD_ID, FIELD_NODE, FIELD_GROUP_ID, FIELD_GROUP_NAME, FIELD_CREATOR, FIELD_STATE, FIELD_START,
- FIELD_END, FIELD_MEMORY, FIELD_CPU_COUNT};
+ FIELD_END, FIELD_MEMORY, FIELD_CPU_COUNT, FIELD_URI};
private ToolAction action;
private RemoteAdminToolsManagement remoteAdminToolsManagement;
@@ -200,8 +201,8 @@ private void loadArgs(String[] args) throws ParameterProblem {
this.groupName = gname;
numOpts++;
}
- if(line.hasOption(Opts.HOST_LIST)) {
- final String hostname = line.getOptionValue(Opts.HOST_LIST);
+ if(line.hasOption(Opts.HOST)) {
+ final String hostname = line.getOptionValue(Opts.HOST);
if(hostname == null || hostname.trim().length() == 0) {
throw new ParameterProblem("Host value is empty");
}
@@ -222,8 +223,40 @@ else if(this.action == ToolAction.ShutdownVMs) {
this.vmID = id;
numOpts++;
}
- if(line.hasOption(Opts.HOST_SHUTDOWN)) {
- final String hostname = line.getOptionValue(Opts.HOST_SHUTDOWN);
+ if(line.hasOption(Opts.USER)) {
+ final String user = line.getOptionValue(Opts.USER);
+ if(user == null || user.trim().length() == 0) {
+ throw new ParameterProblem("User value is empty");
+ }
+ this.user = user;
+ numOpts++;
+ }
+ if(line.hasOption(Opts.DN)) {
+ final String dn = line.getOptionValue(Opts.DN);
+ if(dn == null || dn.trim().length() == 0) {
+ throw new ParameterProblem("DN value is empty");
+ }
+ this.userDN = dn;
+ numOpts++;
+ }
+ if(line.hasOption(Opts.GROUP_ID)) {
+ final String gid = line.getOptionValue(Opts.GROUP_ID);
+ if(gid == null || gid.trim().length() == 0) {
+ throw new ParameterProblem("Group id value is empty");
+ }
+ this.groupId = gid;
+ numOpts++;
+ }
+ if(line.hasOption(Opts.GROUP_NAME)) {
+ final String gname = line.getOptionValue(Opts.GROUP_NAME);
+ if(gname == null || gname.trim().length() == 0) {
+ throw new ParameterProblem("Group name value is empty");
+ }
+ this.groupName = gname;
+ numOpts++;
+ }
+ if(line.hasOption(Opts.HOST)) {
+ final String hostname = line.getOptionValue(Opts.HOST);
if(hostname == null || hostname.trim().length() == 0) {
throw new ParameterProblem("Hostname value is empty");
}
@@ -325,32 +358,20 @@ else if(this.userDN != null) {
vms = gson.fromJson(vmsJson, VMTranslation[].class);
}
else if(this.groupId != null) {
- final String[] vmsJson = this.remoteAdminToolsManagement.getAllVMsByGroupId(groupId);
+ final String vmsJson = this.remoteAdminToolsManagement.getAllVMsByGroupId(groupId);
if(vmsJson == null) {
System.err.println("No vms with group id " + groupId + " found");
return;
}
- for(int i = 0; i < vmsJson.length; i++) {
- if(vmsJson[i] != null) {
- vms = gson.fromJson(vmsJson[i], VMTranslation[].class);
- reporter.report(vmsToMaps(vms), this.outStream);
- }
- }
- return;
+ vms = gson.fromJson(vmsJson, VMTranslation[].class);
}
else if(this.groupName != null) {
- final String[] vmsJson = this.remoteAdminToolsManagement.getAllVMsByGroupName(groupName);
+ final String vmsJson = this.remoteAdminToolsManagement.getAllVMsByGroupName(groupName);
if(vmsJson == null) {
System.err.println("No vms with group name " + groupName + " found");
return;
}
- for(int i = 0; i < vmsJson.length; i++) {
- if(vmsJson[i] != null) {
- vms = gson.fromJson(vmsJson[i], VMTranslation[].class);
- reporter.report(vmsToMaps(vms), this.outStream);
- }
- }
- return;
+ vms = gson.fromJson(vmsJson, VMTranslation[].class);
}
else if(this.hostname != null) {
final String vmsJson = this.remoteAdminToolsManagement.getAllVMsByHost(hostname);
@@ -394,12 +415,28 @@ else if(vmID != null) {
result = this.remoteAdminToolsManagement.shutdown(
RemoteAdminToolsManagement.SHUTDOWN_ID, vmID, seconds);
}
+ else if(user != null) {
+ result = this.remoteAdminToolsManagement.shutdown(
+ RemoteAdminToolsManagement.SHUTDOWN_UNAME, user, seconds);
+ }
+ else if(userDN != null) {
+ result = this.remoteAdminToolsManagement.shutdown(
+ RemoteAdminToolsManagement.SHUTDOWN_DN, userDN, seconds);
+ }
+ else if(groupId != null) {
+ result = this.remoteAdminToolsManagement.shutdown(
+ RemoteAdminToolsManagement.SHUTDOWN_GID, groupId, seconds);
+ }
+ else if(groupName != null) {
+ result = this.remoteAdminToolsManagement.shutdown(
+ RemoteAdminToolsManagement.SHUTDOWN_GNAME, groupName, seconds);
+ }
else if(hostname != null) {
result = this.remoteAdminToolsManagement.shutdown(
RemoteAdminToolsManagement.SHUTDOWN_HOST, hostname, seconds);
}
else {
- result = "Shutdown requires either --all, --id or --hostname option";
+ result = "Shutdown requires either --all, --id, --user or --hostname option";
}
if(result != null)
System.err.println(result);
@@ -418,7 +455,7 @@ else if(hostname != null) {
}
private static Map<String, String> vmToMap(VMTranslation vmt) {
- final HashMap<String, String> map = new HashMap(8);
+ final HashMap<String, String> map = new HashMap(11);
map.put(FIELD_ID, vmt.getId());
map.put(FIELD_NODE, vmt.getNode());
map.put(FIELD_GROUP_ID, vmt.getGroupId());
@@ -429,6 +466,7 @@ else if(hostname != null) {
map.put(FIELD_END, vmt.getEndTime());
map.put(FIELD_MEMORY, vmt.getMemory());
map.put(FIELD_CPU_COUNT, vmt.getCpuCount());
+ map.put(FIELD_URI, vmt.getUri());
return map;
}
@@ -20,14 +20,18 @@ Actions
--dn (-d) -Option to list VMs by user DN name
--gid (-g) -Option to list VMs by group id
--gname (-gn) -Option to list VMs by group name
- --host (-hl) -Option to list VMs running under particular host
+ --host (-hn) -Option to list VMs running under particular host
--shutdown (-s) Shutdown VMs known to the IaaS service. Can
shutdown by all, id or hostname
--all (-a) -Option to shutdown all running VMs on service
- --id (-i) -Option to shutdown VM by VM ID
- --hostname (-hs) -Option to shutdown all VMs with specified host
+ --id (-i) -Option to shutdown VM by VM id
+ --user (-u) -Option to shutdown VM by user display name
+ --dn (-d) -Option to shutdown VM by user DN name
+ --gid (-g) -Option to shutdown VM by group id
+ --gname (-gn) -Option to shutdown VM by group name
+ --host (-hn) -Option to shutdown all VMs with specified host
--seconds (-s) -Amount of time to wait for VMs to shutdown to
propagation mode before being trashed. If
seconds option not specified, default is a
Oops, something went wrong.

0 comments on commit 327d36d

Please sign in to comment.