Commit aaff0953 authored by Timothy Stack's avatar Timothy Stack

Minor improvement to the node.available() method so you can get the
number of free nodes of a particular type (e.g. pc850).

  * xmlrpc/GNUmakefile.in: Add node_avail symlink.

  * xmlrpc/emulabserver.in: Add some optional parameters to
    node.available() so you can specify the class/type of nodes as
    well as project credentials.

  * xmlrpc/script_wrapper.py.in: Add node_avail class that calls
    node.available() with the given parameters.
parent 643384a2
......@@ -31,7 +31,7 @@ USERLIBS = sshxmlrpc.py emulabclient.py
SYMLINKS = node_admin node_reboot os_load create_image node_list \
delay_config link_config savelogs portstats eventsys_control \
readycount nscheck startexp batchexp startexp swapexp endexp \
modexp expinfo
modexp expinfo node_avail
#
# Force dependencies on the scripts so that they will be rerun through
......
......@@ -153,6 +153,25 @@ def CheckRequiredArgs(argdict, arglist):
pass
return None
#
# Check user permission to access a project.
#
def CheckProjPermission(uid, pid):
if not re.match("^[-\w]*$", pid):
return EmulabResponse(RESPONSE_BADARGS,
output="Illegal characters in project ID!")
res = DBQueryFatal("SELECT trust FROM group_membership "
"WHERE uid=%s and pid=%s and gid=%s",
(uid, pid, pid))
if len(res) == 0:
return EmulabResponse(RESPONSE_FORBIDDEN,
output=("You do not have permission to " +
"access project: " + pid))
return None
#
# Check user permission to access an experiment.
#
......@@ -2515,16 +2534,43 @@ class node:
except NoLoginsError, e:
return EmulabResponse(RESPONSE_REFUSED, output=str(e))
if not argdict.has_key("class"):
argdict["class"] = "pc"
pass
if not re.match("^[-\w]*$", str(argdict["class"])):
return EmulabResponse(RESPONSE_BADARGS,
output="Improperly formed node class")
type_test = ""
if argdict.has_key("type"):
if not re.match("^[-\w]*$", str(argdict["type"])):
return EmulabResponse(RESPONSE_BADARGS,
output="Improperly formed node type")
type_test = " and nt.type='%s'" % (str(argdict["type"]),)
pass
pid_clause = ""
if argdict.has_key("proj"):
permerror = CheckProjPermission(self.uid, argdict["proj"])
if permerror:
return permerror
pid_clause = " or p.pid='%s'" % (str(argdict["proj"]),)
pass
res = DBQueryFatal("SELECT count(a.node_id) FROM nodes AS a "
"left join reserved as b on a.node_id=b.node_id "
"left join node_types as nt on a.type=nt.type "
"left join nodetypeXpid_permissions as p "
" on a.type=p.type "
"WHERE b.node_id is null and a.role='testnode' "
" and nt.class = 'pc' and p.pid is null and "
" and nt.class=%s and "
" (p.pid is null" + pid_clause + ") and "
" (a.eventstate='ISUP' or "
" a.eventstate='PXEWAIT') and"
" (p.pid is null)")
" a.eventstate='PXEWAIT')" + type_test,
(argdict["class"],))
if len(res) == 0:
result = 0
......@@ -2537,7 +2583,6 @@ class node:
value=result,
output=str(result))
#
# Get the console parameters.
#
......
......@@ -79,6 +79,8 @@ API = {
"node_list" : { "func" : "node_list",
"help" : "Print physical mapping of nodes " +
"in an experiment" },
"node_avail" : { "func" : "node_avail",
"help" : "Print free node counts" },
"delay_config" : { "func" : "delay_config",
"help" : "Change the link shaping characteristics " +
"for a link or lan" },
......@@ -582,6 +584,61 @@ class node_list:
pass
#
# node_avail
#
class node_avail:
def __init__(self, argv=None):
self.argv = argv;
return
def apply(self):
params = {}
try:
opts, req_args = getopt.getopt(self.argv, "hp:t:c:", [
"help", "project=", "node-type=", "node-class=" ])
for opt, val in opts:
if opt in ("-h", "--help"):
self.usage();
return 0
elif opt in ("-p", "--project"):
params["proj"] = val
pass
elif opt in ("-c", "--node-class"):
params["class"] = val
pass
elif opt in ("-t", "--node-type"):
params["type"] = val
pass
pass
pass
except getopt.error, e:
print e.args[0]
self.usage();
return -1;
rval,response = do_method("node", "available", params)
return rval
def usage(self):
print "node_avail [-p project] [-c class] [-t type]"
print "Print the number of available nodes."
print "where:"
print " -p project - Specify project credentials for node types"
print " that are restricted"
print " -c class - The node class (Default: pc)"
print " -t type - The node type"
print
print "example:"
print " $ node_avail -t pc850"
wrapperoptions()
return
pass
#
# delay_config
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment