def execute(self, path, uri, params): if (path is not None): command = singletonURIHelperInstance.getUri( self.COMPONENT_TYPE, "catalog") requestUrl = command.format(path) else: command = singletonURIHelperInstance.getUri( self.COMPONENT_TYPE, "get-service") requestUrl = command.format(uri) paramsDict = common.toDict(params) #If the label object is null, then it shows an error if (not (paramsDict.has_key("label"))): paramsDict["label"] = "" query = None if (params is not None): for key, value in paramsDict.iteritems(): if (query is None): query = "?" + key + "=" + value else: query = query + "&" + key + "=" + value if (query is not None): requestUrl = requestUrl + query # The requestUrl has '' as a string instead of an empty string. requestUrl = requestUrl.replace("''", "") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "POST", requestUrl, None, None) o = common.json_decode(s) return o
def execute(self, path, uri, params): if (path is not None): command = singletonURIHelperInstance.getUri( self.COMPONENT_TYPE, "catalog") requestUrl = command.format(path) else: command = singletonURIHelperInstance.getUri( self.COMPONENT_TYPE, "get-service") requestUrl = command.format(uri) paramsDict = common.toDict(params) #If the label object is null, then it shows an error if(not(paramsDict.has_key("label"))): paramsDict["label"]="" query = None if (params is not None): for key, value in paramsDict.iteritems(): if (query is None): query = "?" + key + "=" + value else: query = query + "&" + key + "=" + value if (query is not None): requestUrl = requestUrl + query # The requestUrl has '' as a string instead of an empty string. requestUrl=requestUrl.replace("''","") (s, h) = common.service_json_request( self.__ipAddr, self.__port, "POST", requestUrl, None, None) o = common.json_decode(s) return o
def get_catalog(self, uriPath, xml=False): if (uriPath is None): uriPath = "" elif (uriPath.startswith("/") is False): uriPath = "/" + uriPath command = singletonURIHelperInstance.getUri( self.COMPONENT_TYPE, "catalog") port = self.__port if(len(uriPath) == 0): port = common.getenv('VIPR_UI_PORT') (s, h) = common.service_json_request(self.__ipAddr, port, "GET", command.format(uriPath), None) o = common.json_decode(s) inactive = common.get_node_value(o, 'inactive') if (inactive): return None if (xml): (s, h) = common.service_json_request(self.__ipAddr, port, "GET", command.format(uriPath), None, None, xml) return s else: return o
def update(self, uri, name, type, hourOfDay, length, lengthType, dayOfWeek, dayOfMonth, lastDayOfMonth=False): request = dict() if name is not None: request["label"] = name if type is not None: request["executionWindowType"] = type if hourOfDay is not None: request["hourOfDayInUTC"] = hourOfDay if length is not None: request["executionWindowLength"] = length if lengthType is not None: request["executionWindowLengthType"] = lengthType if dayOfWeek is not None: request["dayOfWeek"] = dayOfWeek if dayOfMonth is not None: request["dayOfMonth"] = dayOfMonth if lastDayOfMonth is not None: request["lastDayOfMonth"] = lastDayOfMonth body = json.dumps(request) command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "show") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "PUT", command.format(uri), body) o = common.json_decode(s) return o
def rollback_task_by_uri(self, taskid): command = singletonURIHelperInstance.getUri( self.COMPONENT_TYPE, "rollback") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "POST", command.format(taskid), None)
def reject(self, uri): command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "reject") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "POST", command.format(uri), None, None) return s
def __get_quota_uri(self, resource_type, resource_uri): return ( singletonURIHelperInstance.getUri( resource_type, "quota").format( resource_uri) )
def get_catalog(self, uriPath, xml=False): if (uriPath is None): uriPath = "" elif (uriPath.startswith("/") is False): uriPath = "/" + uriPath command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "catalog") port = self.__port if (len(uriPath) == 0): port = common.getenv('VIPR_UI_PORT') (s, h) = common.service_json_request(self.__ipAddr, port, "GET", command.format(uriPath), None) o = common.json_decode(s) inactive = common.get_node_value(o, 'inactive') if (inactive): return None if (xml): (s, h) = common.service_json_request(self.__ipAddr, port, "GET", command.format(uriPath), None, None, xml) return s else: return o
def delete(self, uri): command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "show") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "DELETE", command.format(uri), None) return s
def reject(self, uri): command = singletonURIHelperInstance.getUri( self.COMPONENT_TYPE, "reject") (s, h) = common.service_json_request( self.__ipAddr, self.__port, "POST", command.format(uri), None, None) return s
def list(self): command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "list") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET", command, None) o = common.json_decode(s) return o
def get_descriptor(self, uri): command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "get-descriptor") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET", command.format(uri), None, None) o = common.json_decode(s) return o
def get_descriptor(self, uri): command = singletonURIHelperInstance.getUri( self.COMPONENT_TYPE, "get-descriptor") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET", command.format(uri), None, None) o = common.json_decode(s) return o
def get_tasks_by_taskid(componentType, task_id, ipAddr, port): task_uri_constant = singletonURIHelperInstance.getUri( componentType, "task_by_id") (s, h) = service_json_request(ipAddr, port, "GET", task_uri_constant.format(task_id), None) if (not s): return None o = json_decode(s) return o
def get_tasks_by_taskid(componentType, task_id, ipAddr, port): task_uri_constant = singletonURIHelperInstance.getUri( componentType, "task_by_id") (s, h) = service_json_request( ipAddr, port, "GET", task_uri_constant.format(task_id), None) if (not s): return None o = json_decode(s) return o
def get_tasks_by_resourceuri(componentType, resource_uri, ipAddr, port): task_list_uri_constant = singletonURIHelperInstance.getUri( componentType, "tasks_list") (s, h) = service_json_request( ipAddr, port, "GET", task_list_uri_constant.format(resource_uri), None) if (not s): return [] o = json_decode(s) res = o["task"] return res
def show_execution_by_uri(self, uri, xml): command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "show-execution") if xml is True: (s, h) = common.service_json_request( self.__ipAddr, self.__port, "GET", command.format(uri), None, None, xml ) return s else: (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET", command.format(uri), None, None) o = common.json_decode(s) return o
def get_tasks_by_resourceuri(componentType, resource_uri, ipAddr, port): task_list_uri_constant = singletonURIHelperInstance.getUri( componentType, "tasks_list") (s, h) = service_json_request(ipAddr, port, "GET", task_list_uri_constant.format(resource_uri), None) if (not s): return [] o = json_decode(s) res = o["task"] return res
def create( self, name, tenantname, type, hourOfDay, length, lengthType, dayOfWeek, dayOfMonth, minuteOfHour, lastDayOfMonth=False, ): new_request = { "tenant": tenantname, "hour_of_day_in_utc": hourOfDay, "minute_of_hour_in_utc": minuteOfHour, "execution_window_length": length, "execution_window_length_type": lengthType, "execution_window_type": type, "day_of_week": dayOfWeek, "day_of_month": dayOfMonth, "last_day_of_month": lastDayOfMonth, "name": name, } if minuteOfHour is not None: new_request["minute_of_hour_in_utc"] = minuteOfHour if tenantname is not None: from tenant import Tenant tenant_obj = Tenant(self.__ipAddr, self.__port) try: tenant_uri = tenant_obj.tenant_query(None) except SOSError as e: raise e new_request["tenant"] = tenant_uri body = json.dumps(new_request) command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "create") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "POST", command, body) o = common.json_decode(s) return o
def create(self, name, tenantname, type, hourOfDay, length, lengthType, dayOfWeek, dayOfMonth, minuteOfHour, lastDayOfMonth=False): new_request = { "tenant": tenantname, "hour_of_day_in_utc": hourOfDay, "minute_of_hour_in_utc": minuteOfHour, "execution_window_length": length, "execution_window_length_type": lengthType, "execution_window_type": type, "day_of_week": dayOfWeek, "day_of_month": dayOfMonth, "last_day_of_month": lastDayOfMonth, "name": name } if (minuteOfHour is not None): new_request["minute_of_hour_in_utc"] = minuteOfHour if (tenantname is not None): from tenant import Tenant tenant_obj = Tenant(self.__ipAddr, self.__port) try: tenant_uri = tenant_obj.tenant_query(None) except SOSError as e: raise e new_request["tenant"] = tenant_uri body = json.dumps(new_request) command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "create") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "POST", command, body) o = common.json_decode(s) return o
def show_execution_by_uri(self, uri, xml): command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "show-execution") if (xml is True): (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET", command.format(uri), None, None, xml) return s else: (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET", command.format(uri), None, None) o = common.json_decode(s) return o
def update(self, uri, name, type, hourOfDay, length, lengthType, dayOfWeek, dayOfMonth, lastDayOfMonth=False): request = dict() if (name is not None): request["label"] = name if (type is not None): request["executionWindowType"] = type if (hourOfDay is not None): request["hourOfDayInUTC"] = hourOfDay if (length is not None): request["executionWindowLength"] = length if (lengthType is not None): request["executionWindowLengthType"] = lengthType if (dayOfWeek is not None): request["dayOfWeek"] = dayOfWeek if (dayOfMonth is not None): request["dayOfMonth"] = dayOfMonth if (lastDayOfMonth is not None): request["lastDayOfMonth"] = lastDayOfMonth body = json.dumps(request) command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "show") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "PUT", command.format(uri), body) o = common.json_decode(s) return o
def get_service(self, uri, xml=False): command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "get-service") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET", command.format(uri), None, None) o = common.json_decode(s) inactive = common.get_node_value(o, 'inactive') if (inactive): return None if (xml): (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET", command.format(uri), None, None, xml) return s else: return o
def get_service(self, uri, xml=False): command = singletonURIHelperInstance.getUri( self.COMPONENT_TYPE, "get-service") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET", command.format(uri), None, None) o = common.json_decode(s) inactive = common.get_node_value(o, 'inactive') if (inactive): return None if (xml): (s, h) = common.service_json_request( self.__ipAddr, self.__port, "GET", command.format(uri), None, None, xml) return s else: return o
def list_tasks(ipAddr, port, componentType, project_name, resource_name=None, task_id=None): resourceSearchUri = singletonURIHelperInstance.getUri( componentType, "search_by_project") uris = search_by_project(project_name, resourceSearchUri, ipAddr, port) if (resource_name): for uri in uris: resource = show_resource(ipAddr, port, componentType, uri, True) if (resource['name'] == resource_name): if (not task_id): return get_tasks_by_resourceuri(componentType, resource["id"], ipAddr, port) else: res = get_task_by_resourceuri_and_taskId( componentType, resource["id"], task_id, ipAddr, port) if (res): return res raise SOSError(SOSError.NOT_FOUND_ERR, "Resource with name: " + resource_name + " not found") elif (task_id): for uri in uris: res = get_tasks_by_taskid(componentType, task_id, ipAddr, port) if (res): return res raise SOSError(SOSError.NOT_FOUND_ERR, "Task Id: " + task_id + "not found") else: # resourec_name is not given, get all tasks all_tasks = [] for uri in uris: res = get_tasks_by_resourceuri(componentType, uri, ipAddr, port) if (res and len(res) > 0): all_tasks += res return all_tasks
def list(self, type, params): command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "list") requestUrl = command.format(type) paramsDict = common.toDict(params) query = None if (params is not None): for key, value in paramsDict.iteritems(): if (query is None): query = "?" + key + "=" + value else: query = query + "&" + key + "=" + value if (query is not None): requestUrl = requestUrl + query (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET", requestUrl, None, None) o = common.json_decode(s) return o
def list(self, type, params): command = singletonURIHelperInstance.getUri( self.COMPONENT_TYPE, "list") requestUrl = command.format(type) paramsDict = common.toDict(params) query = None if (params is not None): for key, value in paramsDict.iteritems(): if (query is None): query = "?" + key + "=" + value else: query = query + "&" + key + "=" + value if (query is not None): requestUrl = requestUrl + query (s, h) = common.service_json_request(self.__ipAddr, self.__port, "GET", requestUrl, None, None) o = common.json_decode(s) return o
def list_unmanaged_tasks(ipAddr, port, componentType, project_name, resource_name=None, task_id=None): resourceSearchUri = singletonURIHelperInstance.getUri( componentType, "search_by_project") uris = search_by_project(project_name, resourceSearchUri, ipAddr, port) if(resource_name): for uri in uris: resource = show_resource(ipAddr, port, componentType, uri, True) if(resource['name'] == resource_name): if(not task_id): return get_unmanaged_tasks_by_resourceuri( componentType, resource["id"], ipAddr, port) else: res = get_unmanaged_task_by_resourceuri_and_taskId( componentType, resource["id"], task_id, ipAddr, port) if(res): return res raise SOSError(SOSError.NOT_FOUND_ERR, "Resource with name: " + resource_name + " not found") elif(task_id): for uri in uris: res = get_tasks_by_taskid(componentType, task_id, ipAddr, port) if(res): return res raise SOSError(SOSError.NOT_FOUND_ERR, "Task Id: " + task_id + "not found") else: # resourec_name is not given, get all tasks all_tasks = [] for uri in uris: res = get_tasks_by_resourceuri(componentType, uri, ipAddr, port) if(res and len(res) > 0): all_tasks += res return all_tasks
def show_resource(ipAddr, port, componentType, uri, show_inactive=False, xml=False): showUriConstant = singletonURIHelperInstance.getUri(componentType, "show") if (xml): (s, h) = service_json_request(ipAddr, port, "GET", showUriConstant.format(uri), None, None, xml) return s (s, h) = service_json_request(ipAddr, port, "GET", showUriConstant.format(uri), None) o = json_decode(s) if (show_inactive): return o inactive = get_node_value(o, 'inactive') if (inactive): return None return o
def show_resource(ipAddr, port, componentType, uri, show_inactive=False, xml=False): showUriConstant = singletonURIHelperInstance.getUri( componentType, "show") if(xml): (s, h) = service_json_request(ipAddr, port, "GET", showUriConstant.format(uri), None, None, xml) return s (s, h) = service_json_request(ipAddr, port, "GET", showUriConstant.format(uri), None) o = json_decode(s) if(show_inactive): return o inactive = get_node_value(o, 'inactive') if(inactive): return None return o
def __get_quota_uri(self, resource_type, resource_uri): return (singletonURIHelperInstance.getUri( resource_type, "quota").format(resource_uri))
def rollback_task_by_uri(self, taskid): command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE, "rollback") (s, h) = common.service_json_request(self.__ipAddr, self.__port, "POST", command.format(taskid), None)