Skip to content

Commit

Permalink
Updates to Python interface to REST:
Browse files Browse the repository at this point in the history
 - Spelling / grammar issues resolved in documenation
 - Refactored 'execute_job' -> 'submit_job'
  • Loading branch information
jrschmidt2 committed Jun 15, 2022
1 parent 0228239 commit ef1cfea
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions webmo/webmo_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, base_url, username, password=""):
Args:
base_url(str): The base URL (ending in rest.cgi) of the WeBMO rest endpoint
username(str): The WebMO usrname
username(str): The WebMO username
password(str, optional): The WebMO password; if omitted, this is supplied interactively
Returns:
Expand All @@ -38,14 +38,16 @@ def __init__(self, base_url, username, password=""):
self._auth=r.json() #save an authorization token need to authenticate future REST requests

def __del__(self):
"""Destuctor for WebMOREST
"""Destructor for WebMOREST
This destructor automatically deletes the session token using the REST interface
"""

#End the REST ssessions
r = requests.delete(self._base_url + '/sessions', params=self._auth)
r.raise_for_status() #raise an exception if there is a problem with the request
#do not raise an exception for a failed request in this case due to issues
#with object managment in Jupyter (i.e. on code re-run, a new token is made
#prior to deletion!)

#
# Users resource
Expand All @@ -68,7 +70,7 @@ def get_users(self):
def get_user_info(self, username):
"""Returns information about the specified user
This call returns a JSON formatted string summarize information about the requested user. For non-
This call returns a JSON formatted string summarizing information about the requested user. For non-
administrative users, only requests for the authenticated user will be accepted.
Arguments:
Expand Down Expand Up @@ -102,7 +104,7 @@ def get_groups(self):
def get_group_info(self, groupname):
"""Returns information about the specified group
This call returns a JSON formatted string summarize information about the requested group. For non-
This call returns a JSON formatted string summarizing information about the requested group. For non-
administrative users, only requests for the authenticated group will be accepted.
Arguments:
Expand All @@ -126,8 +128,8 @@ def get_folders(self, target_user=""):
This call returns a list of available folders. Administrative users must specify the target user,
otherwise the folders owned by the current user are returned.
Arguemnts:
target_user(str, optional): The target username whose folders are retreived. Otherwise, uses the authenticated user.
Arguments:
target_user(str, optional): The target username whose folders are retrieved. Otherwise, uses the authenticated user.
Returns:
A list of folders
Expand All @@ -146,14 +148,14 @@ def get_folders(self, target_user=""):
def get_jobs(self, engine="", status="", folder_id="", job_name="", target_user=""):
"""Fetches a list of jobs satisfying the specified filter criteria
This call returns a list of available jobs owned by the current user or (for adminstrative users)
This call returns a list of available jobs owned by the current user or (for administrative users)
the specified target user AND the specified filter criteria.
Arguemnts:
Arguements:
engine(str, optional): Filter by specified computational engine
status(str, optional): Filter by job status
folder_id(str, optional): Filter by folder ID (not name!)
target_user(str, optional): The target username whose jobs are retreived. Otherwise, uses the authenticated user.
target_user(str, optional): The target username whose jobs are retrieved. Otherwise, uses the authenticated user.
Returns:
A list of jobs meeting the specified criteria
Expand Down Expand Up @@ -208,7 +210,7 @@ def get_job_geometry(self, job_number):
job_number(int): The job about whom to return information
Returns:
A string containing XYZ formatted optmized geometry
A string containing XYZ formatted optimized geometry
"""

r = requests.get(self._base_url + "/jobs/%d/geometry" % job_number, params=self._auth)
Expand Down Expand Up @@ -281,10 +283,10 @@ def import_job(self, job_name, filename, engine):
r.raise_for_status()
return r.json()["jobNumber"]

def execute_job(self, job_name, input_file_contents, engine):
def submit_job(self, job_name, input_file_contents, engine, queue=None):
"""Submits and executes a new WebMO job
This call submits and executes a new job to a computational enginge, generating a new WebMO job.
This call submits and executes a new job to a computational engine, generating a new WebMO job.
Arguments:
job_name(str): The name of the new WebMO job
Expand All @@ -296,7 +298,7 @@ def execute_job(self, job_name, input_file_contents, engine):
"""

params = self._auth.copy()
params.update({'jobName' : job_name, 'engine' : engine, 'inputFile': input_file_contents})
params.update({'jobName' : job_name, 'engine' : engine, 'inputFile': input_file_contents, 'queue': queue})
r = requests.post(self._base_url + '/jobs', data=params)
r.raise_for_status()
return r.json()["jobNumber"]
Expand Down

0 comments on commit ef1cfea

Please sign in to comment.