def get_view_boxes(self, fetch_stats=None, tenant_ids=None, all_under_hierarchy=None, ids=None, names=None, cluster_partition_ids=None): """Does a GET request to /public/viewBoxes. If no parameters are specified, all Domains (View Boxes) currently on the Cohesity Cluster are returned. Specifying parameters filters the results that are returned. Args: fetch_stats (bool, optional): Specifies whether to include usage and performance statistics. tenant_ids (list of string, optional): TenantIds contains ids of the tenants for which objects are to be returned. all_under_hierarchy (bool, optional): AllUnderHierarchy specifies if objects of all the tenants under the hierarchy of the logged in user's organization should be returned. ids (list of long|int, optional): Filter by a list of Storage Domain (View Box) ids. If empty, View Boxes are not filtered by id. names (list of string, optional): Filter by a list of Storage Domain (View Box) Names. If empty, Storage Domains (View Boxes) are not filtered by Name. cluster_partition_ids (list of long|int, optional): Filter by a list of Cluster Partition Ids. Returns: list of DomainViewBox: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_view_boxes called.') # Prepare query URL self.logger.info('Preparing query URL for get_view_boxes.') _url_path = '/public/viewBoxes' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'fetchStats': fetch_stats, 'tenantIds': tenant_ids, 'allUnderHierarchy': all_under_hierarchy, 'ids': ids, 'names': names, 'clusterPartitionIds': cluster_partition_ids } _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_view_boxes.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_view_boxes.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='get_view_boxes') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_view_boxes.') if _context.response.status_code == 0: raise ErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, DomainViewBox.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def list_remote_vault_restore_tasks(self): """Does a GET request to /public/remoteVaults/restoreTasks. A remote Vault restore task can restore archived data from a Vault (External Target) to this local Cluster. This is part of the CloudRetrieve functionality for finding and restoring archived data from remote Vaults to an alternative (non-original) Cluster. Returns: list of RemoteVaultRestoreTaskStatus: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('list_remote_vault_restore_tasks called.') # Prepare query URL self.logger.info( 'Preparing query URL for list_remote_vault_restore_tasks.') _url_path = '/public/remoteVaults/restoreTasks' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for list_remote_vault_restore_tasks.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for list_remote_vault_restore_tasks.' ) _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request( _request, name='list_remote_vault_restore_tasks') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for list_remote_vault_restore_tasks.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, RemoteVaultRestoreTaskStatus.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def update_tenant_protection_job(self, body=None): """Does a PUT request to /public/tenants/protectionJob. Returns success if the update for protection job is successful for specified tenant. Args: body (TenantProtectionJobUpdateParameters, optional): Request to update existing protection jobs. Returns: TenantProtectionJobUpdate: Response from the API. Tenant Protection Job Mapping Response. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('update_tenant_protection_job called.') # Prepare query URL self.logger.info( 'Preparing query URL for update_tenant_protection_job.') _url_path = '/public/tenants/protectionJob' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for update_tenant_protection_job.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for update_tenant_protection_job.' ) _request = self.http_client.put( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request( _request, name='update_tenant_protection_job') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for update_tenant_protection_job.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, TenantProtectionJobUpdate.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_remote_vault_search_job_results(self, search_job_id, cluster_id, cluster_incarnation_id, page_count=None, cluster_name=None, cookie=None): """Does a GET request to /public/remoteVaults/searchJobResults. Specify a unique id of the search Job using a combination of the searchJobId, clusterId, and clusterIncarnationId parameters, which are all required. The results can be optionally filtered by the remote Cluster name. This is part of the CloudRetrieve functionality for finding and restoring archived data from a remote Vault. Args: search_job_id (long|int): Specifies the id of the remote Vault search Job assigned by the Cohesity Cluster. Used in combination with the clusterId and clusterIncarnationId to uniquely identify the search Job. cluster_id (long|int): Specifies the Cohesity Cluster id where the search Job was created. Used in combination with the searchJobId and clusterIncarnationId to uniquely identify the search Job. cluster_incarnation_id (long|int): Specifies the incarnation id of the Cohesity Cluster where the search Job was created. Used in combination with the searchJobId and clusterId to uniquely identify the search Job. page_count (int, optional): Specifies the number of Protection Jobs to return in the response to support pagination. cluster_name (string, optional): Optionally filter the result by the remote Cohesity Cluster name. cookie (string, optional): Specifies the opaque string cookie returned by the previous response, to get next set of results. Used in combination with pageCount to support pagination. Returns: RemoteVaultSearchJobResults: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_remote_vault_search_job_results called.') # Validate required parameters self.logger.info( 'Validating required parameters for get_remote_vault_search_job_results.' ) self.validate_parameters( search_job_id=search_job_id, cluster_id=cluster_id, cluster_incarnation_id=cluster_incarnation_id) # Prepare query URL self.logger.info( 'Preparing query URL for get_remote_vault_search_job_results.') _url_path = '/public/remoteVaults/searchJobResults' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'searchJobId': search_job_id, 'clusterId': cluster_id, 'clusterIncarnationId': cluster_incarnation_id, 'pageCount': page_count, 'clusterName': cluster_name, 'cookie': cookie } _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for get_remote_vault_search_job_results.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_remote_vault_search_job_results.' ) _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request( _request, name='get_remote_vault_search_job_results') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for get_remote_vault_search_job_results.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, RemoteVaultSearchJobResults.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def create_remote_vault_search_job(self, body): """Does a POST request to /public/remoteVaults/searchJobs. A search Job finds Protection Jobs that archived data to a Vault (External Target) which also match the specified search criteria. The results can be optionally filtered by specifying a Cluster match string, a Protection Job match string, a start time and an end time. This is part of the CloudRetrieve functionality for finding and restoring archived data from remote Vaults to an alternative (non-original) Cluster. NOTE: A Vault is equivalent to an External Target in the Cohesity Dashboard. A search Job is equivalent to a search task in the Cohesity Dashboard. Args: body (CreateRemoteVaultSearchJobParameters): Request to create a search of a remote Vault. Returns: CreatedRemoteVaultSearchJobUid: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('create_remote_vault_search_job called.') # Validate required parameters self.logger.info( 'Validating required parameters for create_remote_vault_search_job.' ) self.validate_parameters(body=body) # Prepare query URL self.logger.info( 'Preparing query URL for create_remote_vault_search_job.') _url_path = '/public/remoteVaults/searchJobs' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for create_remote_vault_search_job.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for create_remote_vault_search_job.' ) _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request( _request, name='create_remote_vault_search_job') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for create_remote_vault_search_job.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, CreatedRemoteVaultSearchJobUid.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def create_launch_app_instance(self, body): """Does a POST request to /public/appInstances. Only installed apps can be launched. Args: body (LaunchAppInstance): Request to launch app. Returns: AppInstanceIdParameterSpecifiesAppInstanceIdInPathParameter: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('create_launch_app_instance called.') # Validate required parameters self.logger.info( 'Validating required parameters for create_launch_app_instance.' ) self.validate_parameters(body=body) # Prepare query URL self.logger.info( 'Preparing query URL for create_launch_app_instance.') _url_path = '/public/appInstances' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for create_launch_app_instance.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for create_launch_app_instance.' ) _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='create_launch_app_instance') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for create_launch_app_instance.') if _context.response.status_code == 0: raise ErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, AppInstanceIdParameterSpecifiesAppInstanceIdInPathParameter. from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def create_remote_vault_restore_task(self, body): """Does a POST request to /public/remoteVaults/restoreTasks. Returns the id of the remote Vault restore Task that was created. After a Vault is searched by a search Job, this operation can be called to create a task that restores the indexes and/or the Snapshots of a Protection Job, which were archived on a remote Vault (External Target). This is part of the CloudRetrieve functionality for finding and restoring archived data from remote Vaults to an alternative (non-original) Cluster. Args: body (CreateRemoteVaultRestoreTaskParameters): Request to create a remote Vault restore task. Returns: UniversalId: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('create_remote_vault_restore_task called.') # Validate required parameters self.logger.info( 'Validating required parameters for create_remote_vault_restore_task.' ) self.validate_parameters(body=body) # Prepare query URL self.logger.info( 'Preparing query URL for create_remote_vault_restore_task.') _url_path = '/public/remoteVaults/restoreTasks' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for create_remote_vault_restore_task.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for create_remote_vault_restore_task.' ) _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request( _request, name='create_remote_vault_restore_task') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for create_remote_vault_restore_task.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, UniversalId.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_ldap_provider(self, tenant_ids=None, all_under_hierarchy=None, ids=None): """Does a GET request to /public/ldapProvider. Lists the LDAP providers. Args: tenant_ids (list of string, optional): TenantIds contains ids of the tenants for which objects are to be returned. all_under_hierarchy (bool, optional): AllUnderHierarchy specifies if objects of all the tenants under the hierarchy of the logged in user's organization should be returned. ids (list of long|int, optional): Specifies the ids of the LDAP providers to fetch. Returns: list of LdapProviderResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_ldap_provider called.') # Prepare query URL self.logger.info('Preparing query URL for get_ldap_provider.') _url_path = '/public/ldapProvider' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'tenantIds': tenant_ids, 'allUnderHierarchy': all_under_hierarchy, 'ids': ids } _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_ldap_provider.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_ldap_provider.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='get_ldap_provider') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_ldap_provider.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, LdapProviderResponse.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_cluster_partitions(self, ids=None, names=None): """Does a GET request to /public/clusterPartitions. If no parameters are specified, all Cluster Partitions currently on the Cohesity Cluster are returned. Specifying parameters filters the results that are returned. Args: ids (list of long|int, optional): Array of Cluster Partition Ids. Filter by a list of Cluster Partition ids. If empty, the Cluster Partitions are not filtered by id. names (list of string, optional): Array of Cluster Partition Names. Filter by a list of Cluster Partition Names. If empty, the Cluster Partitions are not filtered by names. Returns: list of ClusterPartition: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_cluster_partitions called.') # Prepare query URL self.logger.info('Preparing query URL for get_cluster_partitions.') _url_path = '/public/clusterPartitions' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'ids': ids, 'names': names } _query_builder = APIHelper.append_url_with_query_parameters(_query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_cluster_partitions.') _headers = { 'accept': 'application/json' } # Prepare and execute request self.logger.info('Preparing and executing request for get_cluster_partitions.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name = 'get_cluster_partitions') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_cluster_partitions.') if _context.response.status_code == 0: raise ErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, ClusterPartition.from_dictionary) except Exception as e: self.logger.error(e, exc_info = True)
def create_kms_config(self, body=None): """Does a POST request to /public/kmsConfig. Returns the created KMS config. Args: body (KmsConfiguration, optional): TODO: type description here. Example: Returns: KmsConfigurationResponse: Response from the API. Response after KMS has been created. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('create_kms_config called.') # Prepare query URL self.logger.info('Preparing query URL for create_kms_config.') _url_path = '/public/kmsConfig' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for create_kms_config.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for create_kms_config.') _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='create_kms_config') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for create_kms_config.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, KmsConfigurationResponse.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def update_ldap_provider(self, body): """Does a PUT request to /public/ldapProvider. Returns the updated LDAP provider. Args: body (UpdateLdapProviderParam): Request to update a LDAP provider. Returns: LdapProviderResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('update_ldap_provider called.') # Validate required parameters self.logger.info( 'Validating required parameters for update_ldap_provider.') self.validate_parameters(body=body) # Prepare query URL self.logger.info('Preparing query URL for update_ldap_provider.') _url_path = '/public/ldapProvider' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for update_ldap_provider.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for update_ldap_provider.') _request = self.http_client.put( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='update_ldap_provider') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for update_ldap_provider.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, LdapProviderResponse.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_roles(self, tenant_ids=None, all_under_hierarchy=None, name=None): """Does a GET request to /public/roles. If the 'name' parameter is not specified, all roles defined on the Cohesity Cluster are returned. In addition, information about each role is returned such as the name, description, assigned privileges, etc. If an exact role name (such as COHESITY_VIEWER) is specified in the 'name' parameter, only information about that single role is returned. Args: tenant_ids (list of string, optional): TenantIds contains ids of the tenants for which objects are to be returned. all_under_hierarchy (bool, optional): AllUnderHierarchy specifies if objects of all the tenants under the hierarchy of the logged in user's organization should be returned. name (string, optional): Specifies the name of the role. Returns: list of RoleInformation: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_roles called.') # Prepare query URL self.logger.info('Preparing query URL for get_roles.') _url_path = '/public/roles' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'tenantIds': tenant_ids, 'allUnderHierarchy': all_under_hierarchy, 'name': name } _query_builder = APIHelper.append_url_with_query_parameters(_query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_roles.') _headers = { 'accept': 'application/json' } # Prepare and execute request self.logger.info('Preparing and executing request for get_roles.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name = 'get_roles') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_roles.') if _context.response.status_code == 0: raise ErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, RoleInformation.from_dictionary) except Exception as e: self.logger.error(e, exc_info = True) raise
def update_role(self, name, body=None): """Does a PUT request to /public/roles/{name}. For example, you could update the privileges assigned to a Role. Returns the updated role. Args: name (string): Specifies the name of the role to update. body (RoleUpdate, optional): Request to update a custom role. Returns: RoleInformation: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('update_role called.') # Validate required parameters self.logger.info('Validating required parameters for update_role.') self.validate_parameters(name=name) # Prepare query URL self.logger.info('Preparing query URL for update_role.') _url_path = '/public/roles/{name}' _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 'name': name }) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for update_role.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info('Preparing and executing request for update_role.') _request = self.http_client.put(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name = 'update_role') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for update_role.') if _context.response.status_code == 0: raise ErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, RoleInformation.from_dictionary) except Exception as e: self.logger.error(e, exc_info = True) raise
def update_upgrade_node(self, body): """Does a PUT request to /public/nodes/software. Sends a request to upgrade the software version of a Node. By default, the Node that the request is sent to is the only one upgraded, but the user can specify if they want to attempt to upgrade all free nodes on the network. Before using this, you need to upload a new package to the Node you want to upgrade by using the /public/packages endpoint. Args: body (UpgradeNodeParameters): TODO: type description here. Example: Returns: UpgradeNodeResult: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('update_upgrade_node called.') # Validate required parameters self.logger.info('Validating required parameters for update_upgrade_node.') self.validate_parameters(body=body) # Prepare query URL self.logger.info('Preparing query URL for update_upgrade_node.') _url_path = '/public/nodes/software' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for update_upgrade_node.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info('Preparing and executing request for update_upgrade_node.') _request = self.http_client.put(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name = 'update_upgrade_node') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for update_upgrade_node.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, UpgradeNodeResult.from_dictionary) except Exception as e: self.logger.error(e, exc_info = True) raise
def get_protection_jobs(self, tenant_ids=None, all_under_hierarchy=None, ids=None, names=None, policy_ids=None, environments=None, is_active=None, is_deleted=None, only_return_basic_summary=None, include_last_run_and_stats=None, include_rpo_snapshots=None, only_return_data_migration_jobs=None): """Does a GET request to /public/protectionJobs. If no parameters are specified, all Protection Jobs currently on the Cohesity Cluster are returned. Specifying parameters filters the results that are returned. Args: tenant_ids (list of string, optional): TenantIds contains ids of the tenants for which objects are to be returned. all_under_hierarchy (bool, optional): AllUnderHierarchy specifies if objects of all the tenants under the hierarchy of the logged in user's organization should be returned. ids (list of long|int, optional): Filter by a list of Protection Job ids. names (list of string, optional): Filter by a list of Protection Job names. policy_ids (list of string, optional): Filter by Policy ids that are associated with Protection Jobs. Only Jobs associated with the specified Policy ids, are returned. environments (list of EnvironmentGetProtectionJobsEnum, optional): Filter by environment types such as 'kVMware', 'kView', etc. Only Jobs protecting the specified environment types are returned. NOTE: 'kPuppeteer' refers to Cohesity's Remote Adapter. is_active (bool, optional): Filter by Inactive or Active Jobs. If not set, all Inactive and Active Jobs are returned. If true, only Active Jobs are returned. If false, only Inactive Jobs are returned. When you create a Protection Job on a Primary Cluster with a replication schedule, the Cluster creates an Inactive copy of the Job on the Remote Cluster. In addition, when an Active and running Job is deactivated, the Job becomes Inactive. is_deleted (bool, optional): If true, return only Protection Jobs that have been deleted but still have Snapshots associated with them. If false, return all Protection Jobs except those Jobs that have been deleted and still have Snapshots associated with them. A Job that is deleted with all its Snapshots is not returned for either of these cases. only_return_basic_summary (bool, optional): if true then only job descriptions and the most recent run of the job will be returned. include_last_run_and_stats (bool, optional): If true, return the last Protection Run of the Job and the summary stats. include_rpo_snapshots (bool, optional): If true, then the Protected Objects protected by RPO policies will also be returned. only_return_data_migration_jobs (bool, optional): OnlyReturnDataMigrationJobs specifies if only data migration jobs should be returned. If not set, no data migration job will be returned. Returns: list of ProtectionJob: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_protection_jobs called.') # Prepare query URL self.logger.info('Preparing query URL for get_protection_jobs.') _url_path = '/public/protectionJobs' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'tenantIds': tenant_ids, 'allUnderHierarchy': all_under_hierarchy, 'ids': ids, 'names': names, 'policyIds': policy_ids, 'environments': environments, 'isActive': is_active, 'isDeleted': is_deleted, 'onlyReturnBasicSummary': only_return_basic_summary, 'includeLastRunAndStats': include_last_run_and_stats, 'includeRpoSnapshots': include_rpo_snapshots, 'onlyReturnDataMigrationJobs': only_return_data_migration_jobs } _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_protection_jobs.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_protection_jobs.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='get_protection_jobs') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_protection_jobs.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, ProtectionJob.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_cluster_partition_by_id(self, id): """Does a GET request to /public/clusterPartitions/{id}. Returns the Cluster Partition corresponding to the specified Cluster Partition Id. Args: id (long|int): Specifies a unique id of the Cluster Partition to return. Returns: ClusterPartition: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_cluster_partition_by_id called.') # Validate required parameters self.logger.info('Validating required parameters for get_cluster_partition_by_id.') self.validate_parameters(id=id) # Prepare query URL self.logger.info('Preparing query URL for get_cluster_partition_by_id.') _url_path = '/public/clusterPartitions/{id}' _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 'id': id }) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_cluster_partition_by_id.') _headers = { 'accept': 'application/json' } # Prepare and execute request self.logger.info('Preparing and executing request for get_cluster_partition_by_id.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name = 'get_cluster_partition_by_id') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_cluster_partition_by_id.') if _context.response.status_code == 404: raise APIException('Not Found', _context) elif (_context.response.status_code < 200) or (_context.response.status_code > 208): raise ErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, ClusterPartition.from_dictionary) except Exception as e: self.logger.error(e, exc_info = True)
def get_smb_file_opens(self, file_path=None, view_name=None, page_count=None, cookie=None): """Does a GET request to /public/smbFileOpens. If no parameters are specified, all active SMB file opens currently on the Cohesity Cluster are returned. Specifying parameters filters the results that are returned. Args: file_path (string, optional): Specifies the filepath in the view relative to the root filesystem. If this field is specified, viewName field must also be specified. view_name (string, optional): Specifies the name of the View in which to search. If a view name is not specified, all the views in the Cluster is searched. This field is mandatory if filePath field is specified. page_count (int, optional): Specifies the maximum number of active opens to return in the response. This field cannot be set above 1000. If this is not set, maximum of 1000 entries are returned. cookie (string, optional): Specifies the opaque string returned in the previous response. If this is set, next set of active opens just after the previous response are returned. If this is not set, first set of active opens are returned. Returns: SmbActiveFileOpensResponse: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_smb_file_opens called.') # Prepare query URL self.logger.info('Preparing query URL for get_smb_file_opens.') _url_path = '/public/smbFileOpens' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'filePath': file_path, 'viewName': view_name, 'pageCount': page_count, 'cookie': cookie } _query_builder = APIHelper.append_url_with_query_parameters(_query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_smb_file_opens.') _headers = { 'accept': 'application/json' } # Prepare and execute request self.logger.info('Preparing and executing request for get_smb_file_opens.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name = 'get_smb_file_opens') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_smb_file_opens.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, SmbActiveFileOpensResponse.from_dictionary) except Exception as e: self.logger.error(e, exc_info = True) raise
def create_clone_refresh_task(self, body): """Does a POST request to /public/restore/applicationsClone/refresh. Returns the created Clone Refresh Task which refreshes the clone with specified data. Args: body (CloneRefreshRequest): Request to create a Clone Refresh Task. Returns: RestoreTaskWrapper: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('create_clone_refresh_task called.') # Validate required parameters self.logger.info( 'Validating required parameters for create_clone_refresh_task.' ) self.validate_parameters(body=body) # Prepare query URL self.logger.info( 'Preparing query URL for create_clone_refresh_task.') _url_path = '/public/restore/applicationsClone/refresh' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for create_clone_refresh_task.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for create_clone_refresh_task.' ) _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='create_clone_refresh_task') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for create_clone_refresh_task.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, RestoreTaskWrapper.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def update_app_instance_state(self, app_instance_id, body): """Does a PUT request to /public/appInstances/{appInstanceId}/states. Changes the state of the app instances. Args: app_instance_id (long|int): Specifies the app instance Id. body (UpdateAppInstanceStateParameters): Request to update app instance state. Returns: void: Response from the API. No Content Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('update_app_instance_state called.') # Validate required parameters self.logger.info( 'Validating required parameters for update_app_instance_state.' ) self.validate_parameters(app_instance_id=app_instance_id, body=body) # Prepare query URL self.logger.info( 'Preparing query URL for update_app_instance_state.') _url_path = '/public/appInstances/{appInstanceId}/states' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'appInstanceId': app_instance_id}) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for update_app_instance_state.') _headers = {'content-type': 'application/json; charset=utf-8'} # Prepare and execute request self.logger.info( 'Preparing and executing request for update_app_instance_state.' ) _request = self.http_client.put( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='update_app_instance_state') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for update_app_instance_state.') if _context.response.status_code == 0: raise ErrorErrorException('Error', _context) self.validate_response(_context) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_privileges(self, name=None): """Does a GET request to /public/privileges. If the 'name' parameter is not specified, all privileges defined on the Cohesity Cluster are returned. In addition, information about each privilege is returned such as the associated category, description, name, etc. If an exact privilege name (such as PRINCIPAL_VIEW) is specified in the 'name' parameter, only information about that single privilege is returned. Args: name (string, optional): Specifies the name of the privilege. Returns: list of PrivilegeInfo: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_privileges called.') # Prepare query URL self.logger.info('Preparing query URL for get_privileges.') _url_path = '/public/privileges' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = {'name': name} _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_privileges.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_privileges.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='get_privileges') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_privileges.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, PrivilegeInfo.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def upload_vault_encryption_keys(self, id, body=None): """Does a PUT request to /public/remoteVaults/encryptionKeys/{id}. This request contains multiple files stored as multipart mime data. Each file has a key used to encrypt data between a remote Cluster and the remote Vault. Content of the file should be same as the file downloaded from the remote Cluster. Args: id (long|int): Specifies a unique id of the Vault. body (list of VaultEncryptionKey, optional): Request to upload encryption keys of a remote Vault. Returns: void: Response from the API. No Content Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('upload_vault_encryption_keys called.') # Validate required parameters self.logger.info( 'Validating required parameters for upload_vault_encryption_keys.' ) self.validate_parameters(id=id) # Prepare query URL self.logger.info( 'Preparing query URL for upload_vault_encryption_keys.') _url_path = '/public/remoteVaults/encryptionKeys/{id}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'id': id}) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for upload_vault_encryption_keys.') _headers = {'content-type': 'application/json; charset=utf-8'} # Prepare and execute request self.logger.info( 'Preparing and executing request for upload_vault_encryption_keys.' ) _request = self.http_client.put( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request( _request, name='upload_vault_encryption_keys') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for upload_vault_encryption_keys.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) except Exception as e: self.logger.error(e, exc_info=True) raise
def change_protection_job_state(self, id, body=None): """Does a POST request to /public/protectionJobState/{id}. If the Protection Job is currently running (not paused) and true is passed in, this operation stops any new Runs of this Protection Job from stating and executing. However, any existing Runs that were already executing will continue to run. If this Projection Job is paused and false is passed in, this operation restores the Job to a running state and new Runs are started as defined by the schedule in the Policy associated with the Job. Returns success if the paused state is changed. Args: id (long|int): Specifies a unique id of the Protection Job. body (ChangeProtectionJobStateParam, optional): TODO: type description here. Example: Returns: void: Response from the API. No Content Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('change_protection_job_state called.') # Validate required parameters self.logger.info( 'Validating required parameters for change_protection_job_state.' ) self.validate_parameters(id=id) # Prepare query URL self.logger.info( 'Preparing query URL for change_protection_job_state.') _url_path = '/public/protectionJobState/{id}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'id': id}) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for change_protection_job_state.') _headers = {'content-type': 'application/json; charset=utf-8'} # Prepare and execute request self.logger.info( 'Preparing and executing request for change_protection_job_state.' ) _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='change_protection_job_state') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for change_protection_job_state.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) except Exception as e: self.logger.error(e, exc_info=True) raise
def delete_stop_remote_vault_search_job(self, body): """Does a DELETE request to /public/remoteVaults/searchJobs. This is part of the CloudRetrieve functionality for finding and restoring archived data from remote Vaults to an alternative (non-original) Cluster. Args: body (StopRemoteVaultSearchJobParameters): Request to stop a Remote Vault Search Job. Returns: void: Response from the API. No Content Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('delete_stop_remote_vault_search_job called.') # Validate required parameters self.logger.info( 'Validating required parameters for delete_stop_remote_vault_search_job.' ) self.validate_parameters(body=body) # Prepare query URL self.logger.info( 'Preparing query URL for delete_stop_remote_vault_search_job.') _url_path = '/public/remoteVaults/searchJobs' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for delete_stop_remote_vault_search_job.') _headers = {'content-type': 'application/json; charset=utf-8'} # Prepare and execute request self.logger.info( 'Preparing and executing request for delete_stop_remote_vault_search_job.' ) _request = self.http_client.delete( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request( _request, name='delete_stop_remote_vault_search_job') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for delete_stop_remote_vault_search_job.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) except Exception as e: self.logger.error(e, exc_info=True) raise
def create_run_protection_job(self, id, body): """Does a POST request to /public/protectionJobs/run/{id}. Immediately excute a single Job Run and ignore the schedule defined in the Policy. A Protection Policy associated with the Job may define up to three backup run types: 1) Regular (CBT utilized), 2) Full (CBT not utilized) and 3) Log. The passed in run type defines what type of backup is done by the Job Run. The schedule defined in the Policy for the backup run type is ignored but other settings such as the snapshot retention and retry settings are used. Returns success if the Job Run starts. Args: id (long|int): Specifies a unique id of the Protection Job. body (RunProtectionJobParam): Specifies the type of backup. If not specified, the 'kRegular' backup is run. Returns: void: Response from the API. No Content Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('create_run_protection_job called.') # Validate required parameters self.logger.info( 'Validating required parameters for create_run_protection_job.' ) self.validate_parameters(id=id, body=body) # Prepare query URL self.logger.info( 'Preparing query URL for create_run_protection_job.') _url_path = '/public/protectionJobs/run/{id}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'id': id}) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for create_run_protection_job.') _headers = {'content-type': 'application/json; charset=utf-8'} # Prepare and execute request self.logger.info( 'Preparing and executing request for create_run_protection_job.' ) _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='create_run_protection_job') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for create_run_protection_job.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) except Exception as e: self.logger.error(e, exc_info=True) raise
def list_remote_vault_search_job_by_id(self, id): """Does a GET request to /public/remoteVaults/searchJobs/{id}. Specify an id for a completed or running search Job. A search Job finds data that has been archived to a Vault (External Target). The returned results do not include Job Run (Snapshot) information. It is part of the CloudRetrieve functionality for finding and restoring archived data from remote Vaults to an alternative (non-original) Cluster. Args: id (long|int): Specifies the id of the remote Vault search Job to return. Returns: RemoteVaultSearchJobInformation: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('list_remote_vault_search_job_by_id called.') # Validate required parameters self.logger.info( 'Validating required parameters for list_remote_vault_search_job_by_id.' ) self.validate_parameters(id=id) # Prepare query URL self.logger.info( 'Preparing query URL for list_remote_vault_search_job_by_id.') _url_path = '/public/remoteVaults/searchJobs/{id}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'id': id}) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for list_remote_vault_search_job_by_id.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for list_remote_vault_search_job_by_id.' ) _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request( _request, name='list_remote_vault_search_job_by_id') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for list_remote_vault_search_job_by_id.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, RemoteVaultSearchJobInformation.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def update_protection_jobs_state(self, body=None): """Does a POST request to /public/protectionJobs/states. Note that the pause or resume actions will take effect from next Protection Run. Also, user can specify only one type of action on all the Protection Jobs. Deactivate and activate actions are independent of pause and resume state. Deactivate and activate actions are useful in case of failover situations. Returns success if the state of all the Protection Jobs state is changed successfully. Args: body (UpdateProtectionJobsStateParams, optional): TODO: type description here. Example: Returns: UpdateProtectionJobsState: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('update_protection_jobs_state called.') # Prepare query URL self.logger.info( 'Preparing query URL for update_protection_jobs_state.') _url_path = '/public/protectionJobs/states' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for update_protection_jobs_state.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for update_protection_jobs_state.' ) _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request( _request, name='update_protection_jobs_state') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for update_protection_jobs_state.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize( _context.response.raw_body, UpdateProtectionJobsState.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def create_tenant(self, body=None): """Does a POST request to /public/tenants. A tenant is required to support MultiTenant architecture for service provider (SP) to facilitate data and view segregations in the Cohesity Dashboard. Returns the created/added tenant. Args: body (TenantCreateParameters, optional): Request to add or create a new tenant. Returns: Tenant: Response from the API. Create Tenants response Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('create_tenant called.') # Prepare query URL self.logger.info('Preparing query URL for create_tenant.') _url_path = '/public/tenants' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for create_tenant.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for create_tenant.') _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='create_tenant') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for create_tenant.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, Tenant.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def update_protection_job(self, body, id): """Does a PUT request to /public/protectionJobs/{id}. Returns the updated Protection Job. Args: body (ProtectionJobRequestBody): Request to update a protection job. id (long|int): Specifies a unique id of the Protection Job. Returns: ProtectionJob: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('update_protection_job called.') # Validate required parameters self.logger.info( 'Validating required parameters for update_protection_job.') self.validate_parameters(body=body, id=id) # Prepare query URL self.logger.info('Preparing query URL for update_protection_job.') _url_path = '/public/protectionJobs/{id}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'id': id}) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for update_protection_job.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for update_protection_job.') _request = self.http_client.put( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='update_protection_job') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for update_protection_job.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, ProtectionJob.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_download_tenants_proxy(self, id=None): """Does a GET request to /public/tenants/proxy/image. Returns the tenant proxy to be downloaded. Args: id (string, optional): Specifies the id of the tenant. Returns: list of int: Response from the API. Tenants Proxy Download Response. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_download_tenants_proxy called.') # Prepare query URL self.logger.info( 'Preparing query URL for get_download_tenants_proxy.') _url_path = '/public/tenants/proxy/image' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = {'id': id} _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for get_download_tenants_proxy.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_download_tenants_proxy.' ) _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='get_download_tenants_proxy') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for get_download_tenants_proxy.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_groups(self, name=None, domain=None, filter_by_owned_domains=None, tenant_ids=None, all_under_hierarchy=None): """Does a GET request to /public/groups. If no parameters are specified, all groups currently on the Cohesity Cluster are returned. Specifying parameters filters the results that are returned. Args: name (string, optional): Optionally specify a group name to filter by. All groups containing name will be returned. domain (string, optional): If no domain is specified, all groups on the Cohesity Cluster are searched. If a domain is specified, only groups on the Cohesity Cluster associated with that domain are searched. filter_by_owned_domains (bool, optional): If FilterByOwnedDomains is set to true, then the groups are filtered to show only the ones that are in the domains owned by the current tenant or user. tenant_ids (list of string, optional): TenantIds contains ids of the tenants for which objects are to be returned. all_under_hierarchy (bool, optional): AllUnderHierarchy specifies if objects of all the tenants under the hierarchy of the logged in user's organization should be returned. Returns: list of Group: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_groups called.') # Prepare query URL self.logger.info('Preparing query URL for get_groups.') _url_path = '/public/groups' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'name': name, 'domain': domain, 'filterByOwnedDomains': filter_by_owned_domains, 'tenantIds': tenant_ids, 'allUnderHierarchy': all_under_hierarchy } _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_groups.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info('Preparing and executing request for get_groups.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='get_groups') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_groups.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, Group.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise