From a711e5fa150e40083acca86e60b020cf6cb49bb2 Mon Sep 17 00:00:00 2001 From: Rob Date: Tue, 26 Jul 2011 11:46:02 -0700 Subject: [PATCH] Added --state option to nimbus-admin Created documentation for nimbus-admin and nimbus-nodes in reference.html --- docs/src/admin/reference.html | 203 ++++++++++++++++++ .../admin/RemoteAdminToolsManagement.java | 1 + .../workspace/remoting/admin/client/Opts.java | 7 +- .../admin/client/RemoteAdminToolsMain.java | 17 ++ .../remoting/admin/client/adminHelp.txt | 1 + .../defaults/DefaultRemoteAdminToolsMgmt.java | 19 ++ 6 files changed, 247 insertions(+), 1 deletion(-) diff --git a/docs/src/admin/reference.html b/docs/src/admin/reference.html index 621c008c..6a393c34 100644 --- a/docs/src/admin/reference.html +++ b/docs/src/admin/reference.html @@ -196,6 +196,26 @@

Nimbus 2.8 Admin Reference

+
  • +

    + Nimbus Administration Tools +

    + +
  • + @@ -2470,10 +2490,193 @@

    Image Cache Configuration _NAMELINK(imagecache-config)

    cachedir is the path to the image cache and cache_size is the maximum size of the cache. When these values are enabled the cache will be in effect. +

    + +

    Nimbus Administration _NAMELINK(nimbusadministration)

    +

    +The nimbus administration tools, nimbus-admin and nimbus-nodes, can be +used for a number of useful things by an administrator of a nimbus +service. The nimbus-nodes tool is used for administrating all the VMM +nodes running on the service. With this tool you are able to list, +add, update and remove nodes on the service. +The nimbus-admin tool allows you to administrate all the running +virtual machines running on the service. With this tool you can +list the running VMs in a variety of contexts, as well as manually +shutdown currently running VMs. +

    +

    +Both tools also have a host of reporting output options which will +be covered later in the following sections. +

    + + +

    Nimbus Admin _NAMELINK(nimbus-admin)

    +

    +To start using the nimbus-admin tool first go to your nimbus home +directory. $NIMBUS_HOME/bin where you will find the script +nimbus-admin. Run ./nimbus-admin --help to see the help file which +lists all available commands. +

    +

    +List:
    +The --list command will display a list of virtual machines with the +following information:
    +id: the VM id number
    +node: the physical VMM node the VM is running on
    +group_id: the group id number this VM is associated with
    +group_name: the group name this VM is associated with
    +creator: The users DN name who started this VM
    +state: Current state of the VM (Running, propagated, etc)
    +start time: Time when the VM was created
    +end time: Time when the VM gets destroyed
    +memory: Amount of memory being used by this VM
    +cpu count: Number of cpu cores being used by this VM
    +uri: Image and repo information of this VM
    +

    +

    +The following commands can be used with list
    +--list (-l) List the VMs known to the IaaS service
    + --user (-u) -Option to list VMs by user display name
    + --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 (-hn) -Option to list VMs running under particular host
    +
    +So an example command would look like:
    +./nimbus-admin --list --host localhost +
    +

    +

    +Shutdown:
    +The --shutdown command destroys all the virtual machines specified. +When shutting down a VM, a soft shutdown is called first, which puts +the VM in "propagated" mode. Once the VM is propagated, it is then +fully destroyed. VMs can be shutdown in the following ways:
    +--all (-a) -Option to shutdown all running VMs on service
    +--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 + maximum of 30 seconds +

    +Example: ./nimbus-admin --shutdown --all

    +The --shutdown command also allows you to shutdown a list of VMs at once +by using a comma-separated list.
    +Example: ./nimbus-admin --shutdown --id 3,4,5,6,10,13
    +

    +

    +Nodes:
    +The --nodes command shows a list of all the VMM nodes running on the +service with a list of VM ids each one is running. +Example: ./nimbus-admin --nodes

    +node1: 3,4,5
    +node2: 1,2,6

    +

    + + +

    Nimbus Nodes _NAMELINK(nimbus-nodes)

    +

    +To start using the nimbus-nodes tool first go to your nimbus home +directory. $NIMBUS_HOME/bin where you will find the script +nimbus-nodes. Run ./nimbus-nodes --help to see the help file which +lists all available commands. +

    +

    +List:
    +The --list command of nimbus-nodes lists all the VMM nodes running +on the service. You can also input a comma separated list of VMMs +to list if you want to specify which VMMs you want to see. The +list function outputs the following information about each node: +

    +hostname:the VMM node name
    +pool:Resource pool name for this node
    +memory:total memory available for this node
    +memory available:current memory available on the node
    +networks:list of networks associated with this node. +Value of * means all available networks
    +in_use:whether or not this node is being used
    +active:whether or not this node is currently running
    +
    +

    +

    +Add:
    +The --add (-a) HOSTS command adds the specified VMM nodes to the +pool. Node paramets can be specified as additional arguments and +if no parameter is specified a default will be read from the +config file. +

    +

    +Update:
    +The --update (-u) HOSTS command updates the configuration values +of VMM nodes. At least one node parameter must be specified as +an additional argument. +

    +

    +VMM Node Parameters
    +The following node parameters can be used as additional arguments +for the --add and --update commands. +

    +--active (-A) Allow VMM nodes to take on new virtual machines. +Default for new nodes.
    +--inactive (-i) Prevent VMM nodes from accepting new VMs. +This will not terminate any already running VMs.
    +--memory (-m) Maximum memory available on node for VMs
    +--networks (-n) List of networks associated with a node. +A value of * means all available networks
    +--pool (-p) Resource pool name for this VMM node
    +

    +

    +Remove
    +The --remove (-d) command removes VMM nodes from the nimbus resource +pool. In use nodes cannot be removed. +

    +

    +Network Pool Allocation
    +The --allocation (-N) command provides network pool allocation +information. Outputs the following information for each pool +entry: hostname, ip, mac address, broadcast, subnet mask, gateway, +in_use, explicit mac.

    +This command also has three optional commands.
    +--pool allows you to enter a pool name and only displays +entries from that pool
    +--free displays only entries that are not in_use
    +--used displays only entries that are in_use
    +

    + +

    General Options _NAMELINK(gen-opts)

    +

    +These options are for general usage of nimbus-nodes and nimbus-admin +

    +--help (-h) Prints help file
    +--conf (-c) Use to specify an alternate configuration file.
    +--debug Enables debug output for troubleshooting +

    + + +

    Reporting Output Options _NAMELINK(output-opts)

    +

    +nimbus-nodes and nimbus-admin also have various reporting outputs +that can be used. These options work with any of the commands listed +above. +

    +--report (-r) FIELDS: Only report specified fields. Argument +is a comma-separated list
    +--batch (-b): Report results with one record perline, using +an optional delimiter.
    +--delimiter (-D): Delimiter between fields in batch mode. +Default is a single space.
    +--json (-j): Report results in JSON format.
    +--output (-o) FILE:Write results to FILE instead of stdout.

    +

    diff --git a/service-api/java/source/src/org/nimbustools/api/services/admin/RemoteAdminToolsManagement.java b/service-api/java/source/src/org/nimbustools/api/services/admin/RemoteAdminToolsManagement.java index 0cfd317f..8ec7086e 100644 --- a/service-api/java/source/src/org/nimbustools/api/services/admin/RemoteAdminToolsManagement.java +++ b/service-api/java/source/src/org/nimbustools/api/services/admin/RemoteAdminToolsManagement.java @@ -41,6 +41,7 @@ public interface RemoteAdminToolsManagement extends Remote { public String getAllVMsByHost(String hostname) throws RemoteException; public String getAllVMsByGroupId(String groupId) throws RemoteException; public String getAllVMsByGroupName(String groupName) throws RemoteException; + public String getVMsByState(String state) throws RemoteException; public Hashtable showVMsForAllHosts() throws RemoteException; public String shutdown(int type, String typeID, String seconds) throws RemoteException; } diff --git a/service/service/java/source/src/org/globus/workspace/remoting/admin/client/Opts.java b/service/service/java/source/src/org/globus/workspace/remoting/admin/client/Opts.java index 5ae76379..d4f7537e 100644 --- a/service/service/java/source/src/org/globus/workspace/remoting/admin/client/Opts.java +++ b/service/service/java/source/src/org/globus/workspace/remoting/admin/client/Opts.java @@ -207,13 +207,18 @@ public Options getOptions() { public final Option NODE_LIST_OPT = OptionBuilder.withLongOpt(NODE_LIST_LONG).create(NODE_LIST); + public static final String STATE = "S"; + public static final String STATE_LONG = "state"; + public final Option STATE_OPT = + OptionBuilder.withLongOpt(STATE_LONG).hasArg().create(STATE); + 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, POOL_AVAILABILITY_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_OPT, DN_OPT, GROUP_ID_OPT, - GROUP_NAME_OPT, FREE_OPT, USED_OPT, NODE_LIST_OPT + GROUP_NAME_OPT, FREE_OPT, USED_OPT, NODE_LIST_OPT, STATE_OPT }; } diff --git a/service/service/java/source/src/org/globus/workspace/remoting/admin/client/RemoteAdminToolsMain.java b/service/service/java/source/src/org/globus/workspace/remoting/admin/client/RemoteAdminToolsMain.java index b60f4397..e433b915 100644 --- a/service/service/java/source/src/org/globus/workspace/remoting/admin/client/RemoteAdminToolsMain.java +++ b/service/service/java/source/src/org/globus/workspace/remoting/admin/client/RemoteAdminToolsMain.java @@ -63,6 +63,7 @@ public class RemoteAdminToolsMain extends RMIConfig { private String groupName; private String hostname; private String seconds; + private String state; private List vmIDs; private List userList; private List DNList; @@ -222,6 +223,14 @@ private void loadArgs(String[] args) throws ParameterProblem { this.hostname = hostname; numOpts++; } + if(line.hasOption(Opts.STATE)) { + final String state = line.getOptionValue(Opts.STATE); + if(state == null || state.trim().length() == 0) { + throw new ParameterProblem("State value is empty"); + } + this.state = state; + numOpts++; + } } else if(this.action == ToolAction.ShutdownVMs) { if(line.hasOption(Opts.ALL_VMS)) { @@ -394,6 +403,14 @@ else if(this.hostname != null) { } vms = gson.fromJson(vmsJson, VMTranslation[].class); } + else if(this.state != null) { + final String vmsJson = this.remoteAdminToolsManagement.getVMsByState(state); + if(vmsJson == null) { + System.err.println("No vms with state " + state + " found"); + return; + } + vms = gson.fromJson(vmsJson, VMTranslation[].class); + } else { final String vmsJson = this.remoteAdminToolsManagement.getAllRunningVMs(); vms = gson.fromJson(vmsJson, VMTranslation[].class); diff --git a/service/service/java/source/src/org/globus/workspace/remoting/admin/client/adminHelp.txt b/service/service/java/source/src/org/globus/workspace/remoting/admin/client/adminHelp.txt index f8c730c0..9ed13cb3 100644 --- a/service/service/java/source/src/org/globus/workspace/remoting/admin/client/adminHelp.txt +++ b/service/service/java/source/src/org/globus/workspace/remoting/admin/client/adminHelp.txt @@ -21,6 +21,7 @@ Actions --gid (-g) -Option to list VMs by group id --gname (-gn) -Option to list VMs by group name --host (-hn) -Option to list VMs running under particular host + --state (-S) -Option to list VMs by their current state --nodes Lists all nodes on the service with a list of all VM ids running on each particular node diff --git a/service/service/java/source/src/org/globus/workspace/remoting/admin/defaults/DefaultRemoteAdminToolsMgmt.java b/service/service/java/source/src/org/globus/workspace/remoting/admin/defaults/DefaultRemoteAdminToolsMgmt.java index 814f5e9a..c7772109 100644 --- a/service/service/java/source/src/org/globus/workspace/remoting/admin/defaults/DefaultRemoteAdminToolsMgmt.java +++ b/service/service/java/source/src/org/globus/workspace/remoting/admin/defaults/DefaultRemoteAdminToolsMgmt.java @@ -160,6 +160,25 @@ public String getVMsByUser(String user) throws RemoteException { } } + public String getVMsByState(String state) throws RemoteException { + try { + VM[] vms = manager.getGlobalAll(); + final List vmts = new ArrayList(); + for(VM vm : vms) { + if(vm.getState().getState().equalsIgnoreCase(state)) + vmts.add(translateVM(vm)); + } + + if(vmts.size() == 0) + return null; + + return gson.toJson(vmts); + } + catch(ManageException e) { + throw new RemoteException(e.getMessage()); + } + } + public Hashtable showVMsForAllHosts() throws RemoteException { try { List hostnames = new ArrayList();