def get_document(self, args): """Gets a Datastore document. Required Arguments: * `query` - A query in JSON format to select the correct Document. Optional Arguments: * `collection` - a document collection. 'Default' if omitted. Returns: A [Datastore Document Object](restapi/api-response-objects.html#DatastoreDocument){:target="_blank"}. """ # define the required parameters for this call required_params = ["query"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp collection = args["collection"] if "collection" in args else "" query = json.loads(args["query"]) doc = datastore.Document(query, collection) if doc.ID: if args.get("output_format") == "json": return R(response=doc.AsJSON()) elif args.get("output_format") == "text": return R(response=doc.AsText()) else: return R(response=doc.AsXML()) else: return R(err_code=R.Codes.GetError, err_detail="Unable to find Data Document using query %s." % args["query"])
def get_account(self, args): """Gets a Cloud Account. Required Arguments: * `name` - a Cloud Account name or ID. Returns: A [Cloud Account Object](restapi/api-response-objects.html#CloudAccount){:target="_blank"}. """ # this is a developer function if not api._DEVELOPER: return R(err_code=R.Codes.Forbidden, err_msg="Only Developers or Administrators can perform this function.") required_params = ["name"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp name = args.get("name") obj = cloud.CloudAccount() obj.FromName(name) if args.get("output_format") == "json": return R(response=obj.AsJSON()) elif args.get("output_format") == "text": return R(response=obj.AsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=obj.AsXML())
def delete_cloud_keypair(self, args): """Removes a Key Pair from a Cloud. Required Arguments: * `cloud` - Name or ID of the Cloud. * `name` - Name of the Key Pair to delete. Returns: A list of [Cloud KeyPair Objects](restapi/api-response-objects.html#CloudKeyPair){:target="_blank"}. """ # this is a developer function if not api._DEVELOPER: return R(err_code=R.Codes.Forbidden, err_msg="Only Developers or Administrators can perform this function.") required_params = ["cloud", "name"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp obj = cloud.Cloud() obj.FromName(args["cloud"]) obj.DeleteKeyPair(args.get("name")) catocommon.write_delete_log(api._USER_ID, catocommon.CatoObjectTypes.CloudKeyPair, obj.ID, obj.Name, "KeyPair [%s] removed from Cloud via API." % args.get("name")) # so what do we return when we add a keypair? How about a list of all the keypairs. if args.get("output_format") == "json": return R(response=obj.KeyPairsAsJSON()) elif args.get("output_format") == "text": return R(response=obj.KeyPairsAsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=obj.KeyPairsAsXML())
def get_task_plans(self, args): """Gets a list of the queued execution plans for a Task. Required Arguments: * `task` - Value can be either a Task ID or Name. Optional Arguments: * `version` - A specific version. ('Default' if omitted.) Returns: A list of [Execution Plan Objects](restapi/api-response-objects.html#ExecutionPlan){:target="_blank"}. """ # define the required parameters for this call required_params = ["task"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp ver = args["version"] if "version" in args else "" obj = task.Task() obj.FromNameVersion(args["task"], ver) if not api.is_object_allowed(obj.ID, catocommon.CatoObjectTypes.Task): return R(err_code=R.Codes.Forbidden, err_msg="You do not have access to the details of this Task.") if args.get("output_format") == "json": return R(response=obj.PlansAsJSON()) elif args.get("output_format") == "text": return R(response=obj.PlansAsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=obj.PlansAsXML())
def add_object_tag(self, args): """Adds a security Tag to an object. Required Arguments: * `tag` - The name of the Tag. * `object_id` - The ID of the object. * `object_type` - The numeric type of the object. Returns: Success message successful, error message on failure. Valid and currently implemented `object_type` values are: * `User` = 1 * `Asset` = 2 * `Task` = 3 * `Canvas Item` = 50 * `Deployment` = 70 * `Application Template` = 71 """ # this is a admin function if not api._ADMIN: return R(err_code=R.Codes.Forbidden, err_msg="Only Administrators can perform this function.") # define the required parameters for this call required_params = ["tag", "object_id", "object_type"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp tag.ObjectTags.Add(args["tag"], args["object_id"], args["object_type"]) catocommon.write_add_log(api._USER_ID, args["object_type"], args["object_id"], args["object_id"], "Tag [%s] added to object via API." % args["tag"]) return R(response="Tag successfully added to object.")
def delete_tag(self, args): """Deletes a security Tag. Required Arguments: * `name` - The name of the Tag. Returns: Success message if successful, error message on failure. """ # this is a admin function, kick out if not api._ADMIN: return R(err_code=R.Codes.Forbidden, err_msg="Only Administrators can perform this function.") # define the required parameters for this call required_params = ["name"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp obj = tag.Tag(args["name"], None) obj.DBDelete() catocommon.write_delete_log(api._USER_ID, catocommon.CatoObjectTypes.Tag, obj.Name, obj.Name, "Tag [%s] deleted via API." % obj.Name) return R(response="Delete operation successful.")
def delete_credential(self, args): """Removes a Shared Credential. Required Arguments: * `credential` - Name or ID of the Credential to delete. Returns: Success message if successful, error message on failure. """ # this is a developer function if not api._DEVELOPER: return R(err_code=R.Codes.Forbidden, err_msg="Only Developers or Administrators can perform this function.") required_params = ["credential"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp obj = asset.Credential() obj.FromName(args["credential"]) obj.DBDelete() catocommon.write_delete_log(api._USER_ID, catocommon.CatoObjectTypes.Credential, obj.ID, obj.Name, "Credential [%s] deleted via API." % obj.Name) return R(response="Delete operation successful.")
def delete_asset(self, args): """Deletes an Asset. Required Arguments: * asset - Either the Asset ID or Name. Returns: Nothing if successful, error messages on failure. """ # this is a admin function if not api._ADMIN: return R(err_code=R.Codes.Forbidden, err_msg="Only Administrators can perform this function.") required_params = ["asset"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp obj = asset.Asset() obj.FromName(args["asset"]) if not api.is_object_allowed(obj.ID, catocommon.CatoObjectTypes.Asset): return R(err_code=R.Codes.Forbidden, err_msg="You do not have access to the details of this Asset.") asset.Assets.Delete(["'%s'" % obj.ID]) catocommon.write_delete_log(api._USER_ID, catocommon.CatoObjectTypes.Asset, obj.ID, obj.Name, "Deleted via API.") return R(response="[%s] successfully deleted." % obj.Name)
def resubmit_task_instance(self, args): """Resubmits an Errored or Cancelled Task Instance. Resubmit is *only* valid on Errored or Cancelled Task Instances. Required Arguments: * `instance` - The Task Instance identifier. Returns: Returns: Nothing if successful, error messages on failure. """ # this is a developer function if not api._DEVELOPER: return R(err_code=R.Codes.Forbidden, err_msg="Only Developers or Administrators can perform this function.") required_params = ["instance"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp obj = task.TaskInstance(args["instance"]) if obj.Error: return R(err_code=R.Codes.GetError, err_detail=obj.Error) # if deployment_id and sequence_instance: # msg = "Task [%s] Instance [%s] resubmitted by [%s]." % (ti.task_name_label, ti.task_instance, username) # deployment.WriteDeploymentLog(msg, dep_id=deployment_id, seq_inst=sequence_instance) if not api.is_object_allowed(obj.task_id, catocommon.CatoObjectTypes.Task): return R(err_code=R.Codes.Forbidden, err_msg="You do not have access to details of this Task.") result, err = obj.Resubmit(api._USER_ID) if result: return R(response="Instance [%s] successfully resubmitted." % args["instance"]) else: return R(err_code=R.Codes.StartFailure, err_detail=err)
def get_cloud(self, args): """Gets a Cloud object. Required Arguments: * `name` - a Cloud name or ID. Returns: A [Cloud Object](restapi/api-response-objects.html#Cloud){:target="_blank"}. """ required_params = ["name"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp name = args.get("name") obj = cloud.Cloud() obj.FromName(name) if args.get("output_format") == "json": return R(response=obj.AsJSON()) elif args.get("output_format") == "text": return R(response=obj.AsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=obj.AsXML())
def remove_object_tag(self, args): """Removes a security Tag from an object. Required Arguments: * `tag` - The name of the Tag. * `object_id` - The ID of the object. * `object_type` - The numeric type of the object. Returns: Success message if successful, error message on failure. """ # this is a admin function if not api._ADMIN: return R(err_code=R.Codes.Forbidden, err_msg="Only Administrators can perform this function.") # define the required parameters for this call required_params = ["tag", "object_id", "object_type"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp tag.ObjectTags.Remove(args["tag"], args["object_id"]) catocommon.write_delete_log(api._USER_ID, args["object_type"], args["object_id"], args["object_id"], "Tag [%s] removed from object via API." % args["tag"]) return R(response="Tag successfully removed from object.")
def create_task_from_json(self, args): """Create a new Task from a JSON Task backup document. Required Arguments: * `json` - A properly formatted JSON representation of a Task. Returns: A [Task Object](restapi/api-response-objects.html#Task){:target="_blank"}. """ # define the required parameters for this call required_params = ["json"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp t = task.Task() t.FromJSON(args["json"], args.get("on_conflict")) result, msg = t.DBSave() if result: catocommon.write_add_log(api._USER_ID, catocommon.CatoObjectTypes.Task, t.ID, t.Name, "Task created.") if args.get("output_format") == "json": return R(response=t.AsJSON()) elif args.get("output_format") == "text": return R(response=t.AsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=t.AsXML()) else: return R(err_code=R.Codes.CreateError, err_detail=msg)
def delete_task(self, args): """Deletes all versions of a Task. Required Arguments: * `task` - Either the Task ID or Name. Optional Arguments: * `force_delete` - Delete the Task, even if there are historical rows and references. (Valid values: 1, yes, true) Returns: Nothing if successful, error messages on failure. """ # this is a admin function if not api._ADMIN: return R(err_code=R.Codes.Forbidden, err_msg="Only Administrators can perform this function.") required_params = ["task"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp force = catocommon.is_true(args.get("force_delete")) obj = task.Task() obj.FromNameVersion(name=args["task"], include_code=False) if not api.is_object_allowed(obj.ID, catocommon.CatoObjectTypes.Task): return R(err_code=R.Codes.Forbidden, err_msg="You do not have access to the details of this Task.") task.Tasks.Delete(["'%s'" % obj.ID], force) catocommon.write_delete_log(api._USER_ID, catocommon.CatoObjectTypes.Task, obj.ID, obj.Name, "Deleted via API.") return R(response="[%s] successfully deleted." % obj.Name)
def get_task(self, args): """Gets a Task object. Required Arguments: * `task` - Value can be either a Task ID or Name. Optional Arguments: * `version` - A specific version. ('Default' if omitted.) * `include_code` - Whether to include Codeblocks and Steps. (Only included if 'output_format' is 'json' or 'xml'. 'False' if omitted.) Returns: A [Task Object](restapi/api-response-objects.html#Task){:target="_blank"}. """ # define the required parameters for this call required_params = ["task"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp ver = args["version"] if "version" in args else "" ic = True if "include_code" in args else False obj = task.Task() obj.FromNameVersion(args["task"], ver) if not api.is_object_allowed(obj.ID, catocommon.CatoObjectTypes.Task): return R(err_code=R.Codes.Forbidden, err_msg="You do not have access to the details of this Task.") if args.get("output_format") == "json": return R(response=obj.AsJSON(include_code=ic)) elif args.get("output_format") == "text": return R(response=obj.AsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=obj.AsXML(include_code=ic))
def create_task(self, args): """Create a new Task. Required Arguments: * `name` - a name for the new Task. Optional Arguments: * `code` - a Task code. * `desc` - a Task description. Returns: A [Task Object](restapi/api-response-objects.html#Task){:target="_blank"}. """ # define the required parameters for this call required_params = ["name"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp code = args["code"] if "code" in args else "" desc = args["desc"] if "desc" in args else "" t = task.Task().DBCreateNew(args["name"], code, desc) catocommon.write_add_log(api._USER_ID, catocommon.CatoObjectTypes.Task, t.ID, t.Name, "Task created.") if args.get("output_format") == "json": return R(response=t.AsJSON()) elif args.get("output_format") == "text": return R(response=t.AsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=t.AsXML())
def stop_task(self, args): """Stops a running Task Instance. Required Arguments: * `instance` - The Task Instance identifier. Returns: Nothing if successful, error messages on failure. """ # this is a developer function if not api._DEVELOPER: return R(err_code=R.Codes.Forbidden, err_msg="Only Developers or Administrators can perform this function.") required_params = ["instance"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp ti = task.TaskInstance(args["instance"]) if not api.is_object_allowed(ti.task_id, catocommon.CatoObjectTypes.Task): return R(err_code=R.Codes.Forbidden, err_msg="You do not have access to the details of this Task.") ti.Stop() return R(response="Instance [%s] successfully stopped." % args["instance"])
def get_task_log(self, args): """Gets the run log for a Task Instance. Required Arguments: * `instance` - The Task Instance identifier. Returns: A [Task Log Object](restapi/api-response-objects.html#TaskLog){:target="_blank"}. """ required_params = ["instance"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp obj = task.TaskRunLog(args["instance"]) if not api.is_object_allowed(obj.task_id, catocommon.CatoObjectTypes.Task): return R(err_code=R.Codes.Forbidden, err_msg="You do not have access to the details of this Task.") if args.get("output_format") == "json": return R(response=obj.AsJSON()) elif args.get("output_format") == "text": return R(response=obj.AsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=obj.AsXML())
def create_tag(self, args): """Creates a new security Tag. Required Arguments: * `name` - The name of the new Tag. (AlphaNumeric ONLY. Cannot contain spaces, punctuation or special characters.) Optional Arguments: * `description` - Describe the Tag. Returns: The new [Tag Object](restapi/api-response-objects.html#Tag){:target="_blank"} if successful, error message on failure. """ # this is a admin function, kick out if not api._ADMIN: return R(err_code=R.Codes.Forbidden, err_msg="Only Administrators can perform this function.") # define the required parameters for this call required_params = ["name"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp obj = tag.Tag(args["name"], args.get("description")) obj.DBCreateNew() catocommon.write_add_log(api._USER_ID, catocommon.CatoObjectTypes.Tag, obj.Name, obj.Name, "Tag created by API.") if args.get("output_format") == "json": return R(response=obj.AsJSON()) elif args.get("output_format") == "text": return R(response=obj.AsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=obj.AsXML())
def set_document_value(self, args): """Sets the value of a key in a Datastore document. Required Arguments: * `query` - A query in JSON format to select the correct Document. * `lookupkey` - The section of the document to retrieve. Optional Arguments: * `collection` - a document collection. 'Default' if omitted. * `value` - The value to set this item. Item will be cleared if omitted. Returns: A success message, or error messages on failure. """ # define the required parameters for this call required_params = ["query", "lookupkey"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp collection = args["collection"] if "collection" in args else "" value = args["value"] if "value" in args else "" query = json.loads(args["query"]) doc = datastore.Document(query, collection) if doc.ID: # we have a document! let's dig in to it. result = doc.Set(args["lookupkey"], value) if result: return R(response="Value successfully set.") else: return R(err_code=R.Codes.CreateError, err_detail="Value was not set, see logfile for details.") else: return R(err_code=R.Codes.GetError, err_detail="Unable to find Document using query [%s]." % args["query"])
def create_credential(self, args): """Creates a new Shared Credential. > Only a 'Developer' can create Credentials. Required Arguments: * `name` - The full name of the user. * `username` - A login name for the user. * `password` - Password for the user. If password is not provided, a random password will be generated. Optional Arguments: * `description` - Description of the Credential. * `privileged` = Additional password required to put certain devices into 'privileged' mode. * `domain` - A domain for the Credential. Returns: A [Credential Object](restapi/api-response-objects.html#Credential){:target="_blank"}. """ # this is a admin function, kick out if not api._DEVELOPER: return R(err_code=R.Codes.Forbidden, err_msg="Only Developers or Administrators can perform this function.") # define the required parameters for this call required_params = ["name", "username", "password"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp # a little different than the others ... credential objects must be instantiated before calling DBCreateNew obj = asset.Credential() obj.FromArgs(args["name"], args.get("description"), args["username"], args["password"], 0, args.get("domain"), args.get("privileged"), None) result = obj.DBCreateNew() if not result: return R(err_code=R.Codes.CreateError, err_detail="Unable to create Credential.") catocommon.write_add_log(api._USER_ID, catocommon.CatoObjectTypes.Credential, obj.ID, obj.Name, "Credential created by API.") if args.get("output_format") == "json": return R(response=obj.AsJSON()) elif args.get("output_format") == "text": return R(response=obj.AsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=obj.AsXML())
def create_account(self, args): """ Creates a Cloud Account. Required Arguments: * `name` - a name for the new Account. * `provider` - one of the valid cloud providers. * `login` - the login id (access key) for this Account. * `password` - a password (secret key) for this Account. * `default_cloud` - the name of a default Cloud for this Account. Optional Arguments: * `account_number` - an Account number. Returns: The new [Cloud Account Object](restapi/api-response-objects.html#CloudAccount){:target="_blank"}. """ # this is a developer function if not api._DEVELOPER: return R(err_code=R.Codes.Forbidden, err_msg="Only Developers or Administrators can perform this function.") required_params = ["name", "provider", "login", "password", "default_cloud"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp name = args.get("name") provider = args.get("provider") login = args.get("login") pw = args.get("password") default_cloud = args.get("default_cloud") acct_number = args.get("account_number", "") obj = cloud.CloudAccount.DBCreateNew(provider, name, login, pw, acct_number, default_cloud) catocommon.write_add_log(api._USER_ID, catocommon.CatoObjectTypes.CloudAccount, obj.ID, obj.Name, "Account created via API.") if args.get("output_format") == "json": return R(response=obj.AsJSON()) elif args.get("output_format") == "text": return R(response=obj.AsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=obj.AsXML())
def get_document_value(self, args): """Gets the value of a key in a Datastore document. > Datastore queries always return a list of document matches, even if the result set happens to only return data from one document. Required Arguments: * `query` - A query in JSON format to select the correct Document. * `lookupkey` - The section of the Document to retrieve. Returns the entire document if omitted. Optional Arguments: * `collection` - a document collection. 'Default' if omitted. Returns: A text value. """ # define the required parameters for this call required_params = ["query", "lookupkey"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp collection = args["collection"] if "collection" in args else "" query = json.loads(args["query"]) doc = datastore.Document(query, collection) if doc.ID: # we have a document! let's dig in to it. result = doc.Lookup(args["lookupkey"]) if result: return R(response=catocommon.ObjectOutput.IterableAsJSON(result)) # # now, the section we obtained might be a document itself... # # so let's serialize it. # if args.get("output_format") == "json": # return R(response=doc.AsJSON()) # elif args.get("output_format") == "text": # return R(response=doc.AsText()) # else: # return R(response=doc.AsXML()) else: return R(response="Lookup found no match.") else: return R(err_code=R.Codes.GetError, err_detail="Unable to find Document for Object ID [%s]." % args["doc_id"])
def set_document_values(self, args): """Sets multiple values in a Datastore document. Required Arguments: * `query` - A query in JSON format to select the correct Document. * `updatedoc` - A document representing path:value pairs to be updated. Optional Arguments: * `collection` - a document collection. 'Default' if omitted. Multiple keys are updated in a looping manner. Unsuccessful updates will return an error, but will not stop subsequent updates from occuring. Returns: A success message, or error messages on failure. """ # define the required parameters for this call required_params = ["query", "updatedoc"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp collection = args["collection"] if "collection" in args else "" query = json.loads(args["query"]) updatedoc = json.loads(args["updatedoc"]) targetdoc = datastore.Document(query, collection) if targetdoc.ID: # loop each key in the updatedoc, and call doc.Set # collect all errors into a single response, key:error format failed = [] for path, value in updatedoc.iteritems(): result = targetdoc.Set(path, value) if not result: failed.append(path) if not failed: return R(response="All values successfully set.") else: return R(err_code=R.Codes.UpdateError, err_detail="Failed to update the following keys: %s" % (catocommon.ObjectOutput.AsJSON(failed))) else: return R(err_code=R.Codes.GetError, err_detail="Unable to find Document using query [%s]." % query)
def create_cloud(self, args): """Creates a Cloud. Required Arguments: * `name` - a name for the new Cloud. * `provider` - one of the valid cloud providers. * `apiurl` - URL of the Cloud API endpoint. * `apiprotocol` - Cloud API endpoint protocol. Optional Arguments: * `default_account` - the name of a default Account for this Cloud. Returns: The new [Cloud Object](restapi/api-response-objects.html#Cloud){:target="_blank"}. """ # this is a developer function if not api._DEVELOPER: return R(err_code=R.Codes.Forbidden, err_msg="Only Developers or Administrators can perform this function.") required_params = ["name", "provider", "apiurl", "apiprotocol"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp name = args.get("name") provider = args.get("provider") apiurl = args.get("apiurl") apiprotocol = args.get("apiprotocol") default_account = args.get("default_account") obj = cloud.Cloud.DBCreateNew(name, provider, apiurl, apiprotocol, "", default_account) catocommon.write_add_log(api._USER_ID, catocommon.CatoObjectTypes.Cloud, obj.ID, obj.Name, "Cloud created via API.") if args.get("output_format") == "json": return R(response=obj.AsJSON()) elif args.get("output_format") == "text": return R(response=obj.AsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=obj.AsXML())
def export_task(self, args): """Create a backup file for a single Task. > The behavior of this command is different depending on the output_format. * If 'json', it will return a JSON LIST of individual Task XML documents. * If 'xml' (default) OR 'text', it will return a single XML document of Tasks. Required Arguments: * `task` - Value can be either a Task ID, Code or Name. Optional Arguments: * `version`` - A specific version. ('Default' if omitted.) * `include_refs`` - If true, will analyze each task and include any referenced Tasks. Returns: A collection of Task backup objects. """ # define the required parameters for this call required_params = ["task"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp obj = task.Task() obj.FromNameVersion(args["task"], args.get("version")) if not api.is_object_allowed(obj.ID, catocommon.CatoObjectTypes.Task): return R(err_code=R.Codes.Forbidden, err_msg="You do not have access to the details of this Task.") tids = [obj.ID] docs = task.Tasks.Export(tids, args.get("include_refs"), args.get("output_format")) if args.get("output_format") == "json": return R(response="[%s]" % "".join(docs)) else: return R(response="<tasks>%s</tasks>" % "".join(docs))
def list_cloud_keypairs(self, args): """Lists all the Key Pairs defined on a Cloud. Required Arguments: * `cloud` - Name or ID of a Cloud. Returns: A list of [Cloud KeyPair Objects](restapi/api-response-objects.html#CloudKeyPair){:target="_blank"}. """ required_params = ["cloud"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp obj = cloud.Cloud() obj.FromName(args["cloud"]) if args.get("output_format") == "json": return R(response=obj.KeyPairsAsJSON()) elif args.get("output_format") == "text": return R(response=obj.KeyPairsAsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=obj.KeyPairsAsXML())
def get_asset(self, args): """Gets an Asset. Required Arguments: * `asset` - an Asset Name or ID. Returns: An [Asset Object](restapi/api-response-objects.html#Asset){:target="_blank"}. """ required_params = ["asset"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp obj = asset.Asset() obj.FromName(args.get("asset")) if args.get("output_format") == "json": return R(response=obj.AsJSON()) elif args.get("output_format") == "text": return R(response=obj.AsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=obj.AsXML())
def delete_plan(self, args): """Deletes a specific queued execution Plan. Required Arguments: * `plan_id` - The integer ID of the Plan to delete. Returns: Nothing if successful, error messages on failure. """ # this is a admin function if not api._ADMIN: return R(err_code=R.Codes.Forbidden, err_msg="Only Administrators can perform this function.") required_params = ["plan_id"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp task.Task.DeletePlan(args["plan_id"]) catocommon.write_delete_log(api._USER_ID, catocommon.CatoObjectTypes.Task, "", "", "Plan [%s] deleted via API." % (args["plan_id"])) return R(response="Plan [%s] successfully deleted." % args["plan_id"])
def get_task_instance_status(self, args): """Gets just the Status of a Task Instance. Required Arguments: * `instance` - The Task Instance identifier. Returns: The 'Status' from a [Task Instance Object](restapi/api-response-objects.html#TaskInstance){:target="_blank"}. """ required_params = ["instance"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp obj = task.TaskInstance(args["instance"]) if obj.Error: return R(err_code=R.Codes.GetError, err_detail=obj.Error) if args.get("output_format") == "json": return R(response={"task_status": obj.task_status}) elif args.get("output_format") == "xml": return R(response='<task_status>%s</task_status>' % obj.task_status) else: return R(response=obj.task_status)
def create_asset(self, args): """Creates an Asset. Required Arguments: * name - a name for the new Asset. Optional Arguments: * `status` - either 'Active' or 'Inactive'. ('Active' if omitted.) * `db_name` - a Database name. * `address` - the network address of the Asset. * `port` - a service port for the Address. * `conn_string` - some Assets make their connections via an explicit connection string. * `user` - a User ID to associate with this Asset. * `password` - a Password to associate with this Asset. * `shared_credential` - the name of a Shared Credential to use. **Regarding Credentials:** Credentials are optional on an Asset, however if provided there are rules. Explicit details can be associated with *only this Asset*, or a Shared Credential can be specified. The minimum required to create a LOCAL set of credentials on this Asset are: * `user` - a User ID for the Credential * `password` - a Password for the Credential To specify a Shared Credential, provide the `shared_credential` argument, which is the name of an existing Credential. Returns: An [Asset Object](restapi/api-response-objects.html#Asset){:target="_blank"}. """ # this is a developer function if not api._DEVELOPER: return R(err_code=R.Codes.Forbidden, err_msg="Only Developers or Administrators can perform this function.") required_params = ["name"] has_required, resp = api.check_required_params(required_params, args) if not has_required: return resp # build a dictionary suitable for creating an asset _a = { "Name": args.get("name"), "Status": args.get("status"), "DBName": args.get("db_name"), "Port": args.get("port"), "Address": args.get("address"), "ConnString": args.get("conn_string"), "Credential": { "SharedOrLocal": 0 if args.get("shared_credential") else 1, "Username": args.get("user"), "Password": args.get("password"), "Name": args.get("shared_credential") } } obj, err = asset.Asset.DBCreateNew(_a) if err: return R(err_code=R.Codes.CreateError, err_detail=err) catocommon.write_add_log(api._USER_ID, catocommon.CatoObjectTypes.Asset, obj.ID, obj.Name, "Asset created via API.") if args.get("output_format") == "json": return R(response=obj.AsJSON()) elif args.get("output_format") == "text": return R(response=obj.AsText(args.get("output_delimiter"), args.get("header"))) else: return R(response=obj.AsXML())