def get_tenants(self,
                    ids=None,
                    properties=None,
                    hierarchy=None,
                    include_self=None,
                    skip_invalid_ids=None,
                    status=None):
        """Does a GET request to /public/tenants.

        Returns the list of tenants.

        Args:
            ids (list of string, optional): TODO: type description here.
                Example:
            properties (list of PropertyEnum, optional): 'ViewBox' indicates
                view box data for tenant. 'Vlan' indicates vlan data for
                tenant. 'ProtectionPolicy' indicates protection policy for
                tenant. 'ProtectionJob' indicates protection job for tenant.
                'Entity' indicates entity data for tenant. 'Views' indicates
                view data for tenant. 'ActiveDirectory' indicates active
                directory for tenant. 'LdapProvider' indicates ldap provider
                for tenant. 'SwiftConfig' indicates Swift configuration for
                tenant.
            hierarchy (bool, optional): TODO: type description here. Example:
                            include_self (bool, optional): TODO: type description here.
                Example:
            skip_invalid_ids (bool, optional): TODO: type description here.
                Example:
            status (list of StatusGetTenantsEnum, optional): Filter by tenant
                status.

        Returns:
            list of Tenant: Response from the API. Get 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('get_tenants called.')

            # Prepare query URL
            self.logger.info('Preparing query URL for get_tenants.')
            _url_path = '/public/tenants'
            _query_builder = self.config.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {
                'ids': ids,
                'properties': properties,
                'hierarchy': hierarchy,
                'includeSelf': include_self,
                'skipInvalidIds': skip_invalid_ids,
                'status': status
            }
            _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_tenants.')
            _headers = {'accept': 'application/json'}

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for get_tenants.')
            _request = self.http_client.get(_query_url, headers=_headers)
            AuthManager.apply(_request, self.config)
            _context = self.execute_request(_request, name='get_tenants')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for get_tenants.')
            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
Example #2
0
    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
Example #3
0
    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
Example #4
0
    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
Example #5
0
    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 get_time_series_schema(self, entity_type, entity_id, entity_name):
        """Does a GET request to /public/statistics/timeSeriesSchema.

        Gets the Apollo schema information for an entity to list a series of
        data
        points.

        Args:
            entity_type (EntityTypeEnum): Specifies the type of the entity.
                The following entity types are available: cluster, viewbox.
                EntityType represents the various values for the entity type.
                'Cluster' indicates entity type of Cluster. 'StorageDomain'
                indicates entity type of Storage Domain.
            entity_id (long|int): Specifies the id of the entity.
            entity_name (string): Specifies the name of the entity.

        Returns:
            TimeSeriesSchemaResponse: 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_time_series_schema called.')

            # Validate required parameters
            self.logger.info(
                'Validating required parameters for get_time_series_schema.')
            self.validate_parameters(entity_type=entity_type,
                                     entity_id=entity_id,
                                     entity_name=entity_name)

            # Prepare query URL
            self.logger.info('Preparing query URL for get_time_series_schema.')
            _url_path = '/public/statistics/timeSeriesSchema'
            _query_builder = self.config.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {
                'entityType': entity_type,
                'entityId': entity_id,
                'entityName': entity_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_time_series_schema.')
            _headers = {'accept': 'application/json'}

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for get_time_series_schema.')
            _request = self.http_client.get(_query_url, headers=_headers)
            AuthManager.apply(_request, self.config)
            _context = self.execute_request(_request,
                                            name='get_time_series_schema')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for get_time_series_schema.')
            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,
                TimeSeriesSchemaResponse.from_dictionary)

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
    def get_tasks(self,
                  task_paths=None,
                  include_finished_tasks=None,
                  start_time_seconds=None,
                  end_time_seconds=None,
                  max_tasks=None,
                  exclude_sub_tasks=None,
                  attributes=None):
        """Does a GET request to /public/tasks/status.

        Gets the progress and status of tasks.

        Args:
            task_paths (list of string, optional): Specifies a list of tasks
                path by which to filter the results. Otherwise all of the
                tasks will be returned.
            include_finished_tasks (bool, optional): Specifies whether or not
                to include finished tasks. By default, Pulse will only include
                unfinished tasks.
            start_time_seconds (long|int, optional): Specifies a start time by
                which to filter tasks. Including a value here will result in
                tasks only being included if they started after the time
                specified.
            end_time_seconds (long|int, optional): Specifies an end time by
                which to filter tasks. Including a value here will result in
                tasks only being included if the ended before this time.
            max_tasks (int, optional): Specifies the maximum number of tasks
                to display. Defaults to 100.
            exclude_sub_tasks (bool, optional): Specifies whether or not to
                include subtasks. By default all subtasks of any task matching
                a query will be returned.
            attributes (list of string, optional): If specified, tasks
                matching the current query are further filtered by these
                KeyValuePairs. This gives client an ability to search by
                custom attributes that they specified during the task
                creation. Only the Tasks having 'all' of the specified
                key=value pairs will be returned. Attributes passed in should
                be separated by commas and each must follow the pattern
                "name:type:value". Valid types are "kInt64", "kDouble",
                "kString", and "kBytes".

        Returns:
            list of Task: 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_tasks called.')

            # Prepare query URL
            self.logger.info('Preparing query URL for get_tasks.')
            _url_path = '/public/tasks/status'
            _query_builder = self.config.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {
                'taskPaths': task_paths,
                'includeFinishedTasks': include_finished_tasks,
                'startTimeSeconds': start_time_seconds,
                'endTimeSeconds': end_time_seconds,
                'maxTasks': max_tasks,
                'excludeSubTasks': exclude_sub_tasks,
                'attributes': attributes
            }
            _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_tasks.')
            _headers = {'accept': 'application/json'}

            # Prepare and execute request
            self.logger.info('Preparing and executing request for get_tasks.')
            _request = self.http_client.get(_query_url, headers=_headers)
            AuthManager.apply(_request, self.config)
            _context = self.execute_request(_request, name='get_tasks')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for get_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,
                                              Task.from_dictionary)

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #8
0
    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
Example #9
0
    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
Example #10
0
    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
Example #11
0
    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_vlan_by_id(self, id):
        """Does a GET request to /public/vlans/{id}.

        Returns the VLAN corresponding to the specified VLAN ID or a
        specified
        vlan interface group name.
        Example: /public/vlans/intf_group1.20

        Args:
            id (int): Specifies the id of the VLAN.

        Returns:
            Vlan: 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_vlan_by_id called.')

            # Validate required parameters
            self.logger.info(
                'Validating required parameters for get_vlan_by_id.')
            self.validate_parameters(id=id)

            # Prepare query URL
            self.logger.info('Preparing query URL for get_vlan_by_id.')
            _url_path = '/public/vlans/{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_vlan_by_id.')
            _headers = {'accept': 'application/json'}

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for get_vlan_by_id.')
            _request = self.http_client.get(_query_url, headers=_headers)
            AuthManager.apply(_request)
            _context = self.execute_request(_request, name='get_vlan_by_id')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for get_vlan_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 RequestErrorErrorException('Error', _context)
            self.validate_response(_context)

            # Return appropriate type
            return APIHelper.json_deserialize(_context.response.raw_body,
                                              Vlan.from_dictionary)

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
    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
Example #14
0
    def get_cluster(self, fetch_stats=None, fetch_time_series_schema=None):
        """Does a GET request to /public/cluster.

        Returns information about this Cohesity Cluster.

        Args:
            fetch_stats (bool, optional): If 'true', also get statistics about
                the Cohesity Cluster.
            fetch_time_series_schema (bool, optional): Specifies whether to
                get time series schema info of the cluster.

        Returns:
            Cluster: Response from the API. Successful 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_cluster called.')

            # Prepare query URL
            self.logger.info('Preparing query URL for get_cluster.')
            _url_path = '/public/cluster'
            _query_builder = self.config.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {
                'fetchStats': fetch_stats,
                'fetchTimeSeriesSchema': fetch_time_series_schema
            }
            _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.')
            _headers = {'accept': 'application/json'}

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for get_cluster.')
            _request = self.http_client.get(_query_url, headers=_headers)
            AuthManager.apply(_request, self.config)
            _context = self.execute_request(_request, name='get_cluster')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for get_cluster.')
            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,
                                              Cluster.from_dictionary)

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
    def get_entity_schema_by_name(self, schema_name):
        """Does a GET request to /public/statistics/entitiesSchema/{schemaName}.

        An entity schema specifies the meta-data associated with entity such
        as the
        list of attributes and a time series of data.
        For example, for a Disk entity, the entity schema specifies the Node
        that is
        using this Disk, the type of the Disk, and Metrics about the Disk such
        as
        Space Usage, Read IOs and Write IOs. Metrics define data points (time
        series
        data) to track over a period of time for a specific interval.
        In the Cohesity Dashboard, similar functionality is provided in
        Advanced
        Diagnostics.

        Args:
            schema_name (string): Name of the Schema

        Returns:
            list of EntitySchemaProto: 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_entity_schema_by_name called.')

            # Validate required parameters
            self.logger.info(
                'Validating required parameters for get_entity_schema_by_name.'
            )
            self.validate_parameters(schema_name=schema_name)

            # Prepare query URL
            self.logger.info(
                'Preparing query URL for get_entity_schema_by_name.')
            _url_path = '/public/statistics/entitiesSchema/{schemaName}'
            _url_path = APIHelper.append_url_with_template_parameters(
                _url_path, {'schemaName': schema_name})
            _query_builder = self.config.get_base_uri()
            _query_builder += _url_path
            _query_url = APIHelper.clean_url(_query_builder)

            # Prepare headers
            self.logger.info(
                'Preparing headers for get_entity_schema_by_name.')
            _headers = {'accept': 'application/json'}

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for get_entity_schema_by_name.'
            )
            _request = self.http_client.get(_query_url, headers=_headers)
            AuthManager.apply(_request, self.config)
            _context = self.execute_request(_request,
                                            name='get_entity_schema_by_name')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info(
                'Validating response for get_entity_schema_by_name.')
            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, EntitySchemaProto.from_dictionary)

        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 get_entities(self,
                     schema_name,
                     include_aggr_metric_sources=None,
                     metric_names=None,
                     max_entities=None):
        """Does a GET request to /public/statistics/entities.

        An entity is an object found on the Cohesity Cluster, such as a disk
        or a
        Node.
        In the Cohesity Dashboard, similar functionality is provided in
        Advanced
        Diagnostics.

        Args:
            schema_name (string): Specifies the entity schema to search for
                entities.
            include_aggr_metric_sources (bool, optional): Specifies whether to
                include the sources of aggregate metrics of an entity.
            metric_names (list of string, optional): Specifies the list of
                metric names to return such as 'kRandomIos' which corresponds
                to 'Random IOs' in Advanced Diagnostics of the Cohesity
                Dashboard.
            max_entities (int, optional): Specifies the maximum entities
                returned in the result. By default this field is 500.

        Returns:
            list of EntityProto: 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_entities called.')

            # Validate required parameters
            self.logger.info(
                'Validating required parameters for get_entities.')
            self.validate_parameters(schema_name=schema_name)

            # Prepare query URL
            self.logger.info('Preparing query URL for get_entities.')
            _url_path = '/public/statistics/entities'
            _query_builder = self.config.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {
                'schemaName': schema_name,
                'includeAggrMetricSources': include_aggr_metric_sources,
                'metricNames': metric_names,
                'maxEntities': max_entities
            }
            _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_entities.')
            _headers = {'accept': 'application/json'}

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for get_entities.')
            _request = self.http_client.get(_query_url, headers=_headers)
            AuthManager.apply(_request, self.config)
            _context = self.execute_request(_request, name='get_entities')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for get_entities.')
            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,
                                              EntityProto.from_dictionary)

        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 get_time_series_stats(self,
                              schema_name,
                              metric_name,
                              start_time_msecs,
                              entity_id=None,
                              entity_id_list=None,
                              end_time_msecs=None,
                              rollup_function=None,
                              rollup_interval_secs=None):
        """Does a GET request to /public/statistics/timeSeriesStats.

        A Metric specifies a data point (such as CPU usage and IOPS) to track
        over a
        period of time.
        For example for a disk in the Cluster, you can report on the 'Disk
        Health'
        (kDiskAwaitTimeMsecs) Metric of the 'Disk Health Metrics'
        (kSentryDiskStats)
        Schema for the last week.
        You must specify the 'k' names as input and not the descriptive
        names.
        You must also specify the id of the entity that you are reporting on
        such as
        a Cluster, disk drive, job, etc.
        Get the entityId by running the GET /public/statistics/entities
        operation.
        In the Cohesity Dashboard, similar functionality is provided in
        Advanced
        Diagnostics.

        Args:
            schema_name (string): Specifies the name of entity schema such as
                'kIceboxJobVaultStats'.
            metric_name (string): Specifies the name of the metric such as the
                'kDiskAwaitTimeMsecs' which is displayed as 'Disk Health' in
                Advanced Diagnostics of the Cohesity Dashboard.
            start_time_msecs (long|int): Specifies the start time for the
                series of metric data. Specify the start time as a Unix epoch
                Timestamp (in milliseconds).
            entity_id (string, optional): Specifies the id of the entity
                represented as a string. Get the entityId by running the GET
                public/statistics/entities operation.
            entity_id_list (list of string, optional): Specifies an entity id
                list represented as a string. The stats result will be the sum
                over all these entities. If both EntityIdList and EntityId are
                specified, EntityId will be ignored.
            end_time_msecs (long|int, optional): Specifies the end time for
                the series of metric data. Specify the end time as a Unix
                epoch Timestamp (in milliseconds). If not specified, the data
                points up to the current time are returned.
            rollup_function (string, optional): Specifies the rollup function
                to apply to the data points for the time interval specified by
                rollupInternalSecs. The following rollup functions are
                available: sum, average, count, max, min, median,
                percentile95, latest, and rate. For more information about the
                functions, see the Advanced Diagnostics in the Cohesity online
                help. If not specified, raw data is returned.
            rollup_interval_secs (int, optional): Specifies the time interval
                granularity (in seconds) for the specified rollup function.
                Only specify a value if Rollup function is also specified.

        Returns:
            MetricDataBlock: 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_time_series_stats called.')

            # Validate required parameters
            self.logger.info(
                'Validating required parameters for get_time_series_stats.')
            self.validate_parameters(schema_name=schema_name,
                                     metric_name=metric_name,
                                     start_time_msecs=start_time_msecs)

            # Prepare query URL
            self.logger.info('Preparing query URL for get_time_series_stats.')
            _url_path = '/public/statistics/timeSeriesStats'
            _query_builder = self.config.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {
                'schemaName': schema_name,
                'metricName': metric_name,
                'startTimeMsecs': start_time_msecs,
                'entityId': entity_id,
                'entityIdList': entity_id_list,
                'endTimeMsecs': end_time_msecs,
                'rollupFunction': rollup_function,
                'rollupIntervalSecs': rollup_interval_secs
            }
            _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_time_series_stats.')
            _headers = {'accept': 'application/json'}

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for get_time_series_stats.')
            _request = self.http_client.get(_query_url, headers=_headers)
            AuthManager.apply(_request, self.config)
            _context = self.execute_request(_request,
                                            name='get_time_series_stats')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for get_time_series_stats.')
            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,
                                              MetricDataBlock.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
Example #21
0
    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 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
Example #23
0
    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 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
Example #25
0
    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 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
Example #27
0
    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 get_entities_schema(self, schema_names=None, metric_names=None):
        """Does a GET request to /public/statistics/entitiesSchema.

        An entity schema specifies the meta-data associated with entity such
        as
        the list of attributes and a time series of data.
        For example, for a Disk entity, the entity schema specifies the Node
        that is
        using this Disk, the type of the Disk, and Metrics about the Disk such
        as Space
        Usage, Read IOs and Write IOs. Metrics define data points (time series
        data)
        to track over a period of time for a specific interval.
        If no parameters are specified, all entity schemas found on the
        Cohesity
        Cluster are returned.
        Specifying parameters filters the results that are returned.
        In the Cohesity Dashboard, similar functionality is provided in
        Advanced
        Diagnostics.

        Args:
            schema_names (list of string, optional): Specifies the list of
                schema names to filter by such as 'kIceboxJobVaultStats' which
                corresponds to 'External Target Job Stats' in Advanced
                Diagnostics of the Cohesity Dashboard.
            metric_names (list of string, optional): Specifies the list of
                metric names to filter by such as 'kRandomIos' which
                corresponds to 'Random IOs' in Advanced Diagnostics of the
                Cohesity Dashboard.

        Returns:
            list of EntitySchemaProto: 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_entities_schema called.')

            # Prepare query URL
            self.logger.info('Preparing query URL for get_entities_schema.')
            _url_path = '/public/statistics/entitiesSchema'
            _query_builder = self.config.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {
                'schemaNames': schema_names,
                'metricNames': metric_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_entities_schema.')
            _headers = {'accept': 'application/json'}

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for get_entities_schema.')
            _request = self.http_client.get(_query_url, headers=_headers)
            AuthManager.apply(_request, self.config)
            _context = self.execute_request(_request,
                                            name='get_entities_schema')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for get_entities_schema.')
            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, EntitySchemaProto.from_dictionary)

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #29
0
    def update_tenant_protection_policy(self, body=None):
        """Does a PUT request to /public/tenants/policy.

        Returns success if the update for protection policy permission data
        is
        successful for specified tenant.

        Args:
            body (TenantProtectionPolicyUpdateParameters, optional): Request
                to update existing protection policies.

        Returns:
            TenantProtectionPolicyUpdate: Response from the API. Tenant
                Protection Policy 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_policy called.')

            # Prepare query URL
            self.logger.info(
                'Preparing query URL for update_tenant_protection_policy.')
            _url_path = '/public/tenants/policy'
            _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_policy.')
            _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_policy.'
            )
            _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_policy')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info(
                'Validating response for update_tenant_protection_policy.')
            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,
                TenantProtectionPolicyUpdate.from_dictionary)

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
    def get_tenants_proxy_config(self, id=None, validate_only=None):
        """Does a GET request to /public/tenants/proxy/config.

        Returns the config for tenants proxy.

        Args:
            id (string, optional): Specifies the id of the tenant.
            validate_only (bool, optional): Specifies whether to only validate
                the config request.

        Returns:
            list of int: Response from the API. Get Tenants Proxy Config
                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_tenants_proxy_config called.')

            # Prepare query URL
            self.logger.info(
                'Preparing query URL for get_tenants_proxy_config.')
            _url_path = '/public/tenants/proxy/config'
            _query_builder = self.config.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {'id': id, 'validateOnly': validate_only}
            _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_tenants_proxy_config.')
            _headers = {'accept': 'application/json'}

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for get_tenants_proxy_config.'
            )
            _request = self.http_client.get(_query_url, headers=_headers)
            AuthManager.apply(_request, self.config)
            _context = self.execute_request(_request,
                                            name='get_tenants_proxy_config')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info(
                'Validating response for get_tenants_proxy_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)

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise