def print_storage(self): """ Simply query for storage accessible by this group and print it. Backend supplies storage from the parent group(s) too. """ storage_response = storage.get_drivers(self.base_url, self.group_id, self.token) storage_dict = common.convert_response(storage_response) # response contains a field called 'drivers' drivers = storage_dict['drivers'] for d in drivers: # Each driver has a mount, describing how the storage resource is mounted in Athera sessions mount = d['mounts'][0] self.indented_print("{} storage mounted at {} with ID: {}".format(d['name'], mount['mountLocation'], d['id']), 1)
def __init__(self, logger, base_url, group_id, token, depth=1): self.logger = logger self.base_url = base_url self.group_id = group_id self.token = token self.depth = depth # Do an initial API call to look up information about this group using the group_id. group_response = groups.get_group(self.base_url, self.group_id, self.token) if group_response.status_code != 200: raise RuntimeError("Failed getting group {}".format(self.group_id)) self.group = common.convert_response(group_response) self.indented_print("[{}] {} with ID: {} {}".format(self.group['type'], self.group['name'], self.group['id'], self.depth))
def search_families(self, target): self.logger.info("Searching families for {}".format(target)) apps_response = apps.get_app_families(self.base_url, self.group_id, self.token) apps_dict = common.convert_response(apps_response) if not apps_dict or 'families' not in apps_dict: return None # response contains one field: # 'families' apps_list = apps_dict['families'] # Filter the whole list with the supplied search term, case-insensitive return list(filter(lambda x:target.lower() in x['name'].lower(), apps_list))
def validate_app(logger, base_url, group_id, token, app_id): """ Perform a lookup of the supplied app_id. Return None if not found """ app_response = apps.get_app(base_url, group_id, token, app_id) if not app_response: return None app_dict = common.convert_response(app_response) if not app_dict: return None logger.info("App: {}".format(app_dict)) return app_dict
def check_dropbox_connected(logger, base_url, group_id, token): """ Get all the user and group storage available for the supplied context (dictated by group_id). Iterate through the storage paths looking for a 'Dropbox' type. """ storage_response = storage.get_drivers(base_url, group_id, token) storage_dict = common.convert_response(storage_response) # response contains a field called 'drivers' drivers = storage_dict['drivers'] dropbox = None for d in drivers: logger.info("Driver: {:50} {}".format(d['name'], d['id'])) if d['type'] == "Dropbox": dropbox = d return dropbox
def get_children(self): """ For the current group, fetch the children. We could return the whole objects, but we're just returning the IDs. """ children_response = groups.get_group_children(self.base_url, self.group_id, self.token) if children_response.status_code != 200: self.logger.error("Failed getting children for group {}".format(self.group_id)) return None children = common.convert_response(children_response) if 'groups' not in children: self.logger.error("Missing groups data") return None # json data in contained within the 'groups' object, so extract that children = children['groups'] if len(children) == 0: # No children. Its a leaf return [] # Return just the ids. This is rather inefficient. How could you improve this? return [x['id'] for x in children]
def launch(logger, base_url, group_id, token): """ Run a compute job in the supplied group_id context. Compute jobs need 'arguments' to go into the 'payload'. The payload is POSTED to the API to describe the job required. """ # The JWT token contains a user id in its metadata. Lets extract it token_helper = common.TokenHelper(token) user_id = token_helper.get_user_id() logger.info("User ID {}".format(user_id)) # Use the provided helper functions to create the app specific arguments. # These are template parameters which will be swapped for things like start frame, end frame, on multi-part jobs. args = compute_arguments.get_nuke_arguments(NUKE_SCRIPT_WRITE_NODE) # Make a random job name name = "example_" + str(time.time()) region = common.select_region(logger, "Select a Region to run the compute job in") # Next, use the payload helper to build the job request body payload = compute.make_job_request( user_id, group_id, NUKE_COMPUTE_APP_ID, "/data/dropbox/{}".format(NUKE_SCRIPT_PATH_WITHIN_DROPBOX), name, 1, 100, 1, region, args) # Now its time to actually launch it compute_response = compute.create_job(base_url, group_id, token, payload) if compute_response.status_code == 200: compute_dict = common.convert_response(compute_response) logger.error("Create job succeeded: {}".format(compute_dict['id'])) return compute_dict['id'] else: logger.error("Create job failed [{}] {}".format( compute_response.status_code, compute_response.text)) return None