def info(): """Version and build information for the service. Returns ------- RestObj """ return get(_SERVICE_ROOT + '/apiMeta')
def getWorkflowVar(self, name, getSchema=False): headers = {'Accept-Language': 'en_us'} schema = get("/workflow/processes/" + str(self.wfProcessId) + "/variables/" + str(name), headers=headers, raw=True) if schema.get('value', None) is not None: self.log("Successfully got " + str(name) + " = " + str(schema['value']) + ".") else: self.log("Error getting variable " + str(name) + ".") self.log(schema) if getSchema: return schema return schema.get('value', None)
def get_model_contents(model): """The additional files and data associated with the model. Parameters ---------- model : str or dict The name or id of the model, or a dictionary representation of the model. Returns ------- list The code designated as the model's score code """ link = get_model_link(model, 'contents', refresh=True) if link is not None: return get(link.get('href'), headers={'Accept': link.get('itemType', '*/*')})
def get_module(module): if isinstance(module, dict) and all([k in module for k in ('id', 'name')]): return module try: # MAS module IDs appear to just be the lower case name. # Try to find by ID first return get(SERVICE_ROOT + '/modules/{}'.format(str(module).lower())) except HTTPError as e: if e.code == 404: pass else: raise e # Wasn't able to find by id, try searching by name results = list_modules(filter='eq(name, "{}")'.format(module)) # Not sure why, but as of 19w04 the filter doesn't seem to work. for result in results: if result['name'] == str(module): return result
def get_score_code(model): """The score code for a model registered in the model repository. Parameters ---------- model : str or dict The name or id of the model, or a dictionary representation of the model. Returns ------- str The code designated as the model's score code """ link = get_model_link(model, 'scoreCode', refresh=True) if link is not None: scorecode_uri = link.get('href') return get( scorecode_uri, headers={'Accept': 'text/vnd.sas.models.score.code.ds2package'})
def publish_model(model, destination, name=None, code=None, notes=None): from .model_repository import get_model, get_model_link code_types = { 'ds2package': 'ds2', 'datastep': 'datastep', '': '' } model = get_model(model) model_uri = get_model_link(model, 'self') # Get score code from registry if no code specified if code is None: code_link = get_model_link(model, 'scoreCode', True) if code_link: code = get(code_link['href']) request = dict( name=name or model.get('name'), notes=notes, destinationName=destination, ) modelContents = { 'modelName': model.get('name'), 'modelId': model.get('id'), 'sourceUri': model_uri.get('href'), 'publishLevel': 'model', # ?? What are the options? 'codeType': code_types[model.get('scoreCodeType', '').lower()], 'codeUri': '', # ?? Not needed if code is specified? 'code': code } request['modelContents'] = [modelContents] return post(ROOT_PATH + '/models', json=request, headers={'Content-Type': 'application/vnd.sas.models.publishing.request+json'})
def list_module_steps(module): module = get_module(module) return get(SERVICE_ROOT + '/modules/{}/steps'.format(module.id))
def get_module_step(module, step): module = get_module(module) r = get(SERVICE_ROOT + '/modules/{}/steps/{}'.format(module.id, step)) return r
def list_modules(filter=None): params = 'filter={}'.format(filter) if filter is not None else {} return get(SERVICE_ROOT + '/modules', params=params)
def list_destinations(): return get(ROOT_PATH + '/destinations').get('items', [])
def list_models(): return get(ROOT_PATH + '/models').get('items', [])