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 (TenantCreateRequest, optional): Request to add or create a
                new tenant.

        Returns:
            TenantDetails: 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 ErrorErrorException('Error', _context)
            self.validate_response(_context)

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #2
0
    def update_protection_policy(self, body, id):
        """Does a PUT request to /public/protectionPolicies/{id}.

        Returns the updated Protection Policy.

        Args:
            body (ProtectionPolicyRequest): Request to update a Protection
                Policy.
            id (string): Specifies a unique id of the Protection Policy to
                return.

        Returns:
            ProtectionPolicy: 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_policy called.')

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

            # Prepare query URL
            self.logger.info(
                'Preparing query URL for update_protection_policy.')
            _url_path = '/public/protectionPolicies/{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_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_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_protection_policy')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info(
                'Validating response for update_protection_policy.')
            if _context.response.status_code == 0:
                raise ErrorErrorException('Error', _context)
            self.validate_response(_context)

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

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

        Returns the updated external Client Subnets of the cluster.

        Args:
            body (ExternalClientSubnets, optional): TODO: type description
                here. Example:

        Returns:
            ExternalClientSubnets: 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_external_client_subnets called.')

            # Prepare query URL
            self.logger.info(
                'Preparing query URL for update_external_client_subnets.')
            _url_path = '/public/externalClientSubnets'
            _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_external_client_subnets.')
            _headers = {
                'accept': 'application/json',
                'content-type': 'application/json; charset=utf-8'
            }

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for update_external_client_subnets.'
            )
            _request = self.http_client.put(
                _query_url,
                headers=_headers,
                parameters=APIHelper.json_serialize(body))
            AuthManager.apply(_request)
            _context = self.execute_request(
                _request, name='update_external_client_subnets')

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #4
0
    def get_vlans(self, all_under_hierarchy=None, tenant_ids=None):
        """Does a GET request to /public/vlans.

        Returns the VLANs for the Cohesity Cluster.

        Args:
            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.
            tenant_ids (list of string, optional): TenantIds contains ids of
                the tenants for which objects are to be returned.

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

            # Prepare query URL
            self.logger.info('Preparing query URL for get_vlans.')
            _url_path = '/public/vlans'
            _query_builder = Configuration.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {
                'allUnderHierarchy': all_under_hierarchy,
                'tenantIds': tenant_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_vlans.')
            _headers = {'accept': 'application/json'}

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

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for get_vlans.')
            if _context.response.status_code == 0:
                raise ErrorErrorException('Error', _context)
            self.validate_response(_context)

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #5
0
    def create_install_app(self, app_uid, version):
        """Does a POST request to /public/apps/{appUid}/versions/{version}.

        Only purchased apps can be installed using this api.

        Args:
            app_uid (long|int): Specifies the app Id.
            version (long|int): Specifies the app version.

        Returns:
            AppInformation: 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_install_app called.')

            # Validate required parameters
            self.logger.info(
                'Validating required parameters for create_install_app.')
            self.validate_parameters(app_uid=app_uid, version=version)

            # Prepare query URL
            self.logger.info('Preparing query URL for create_install_app.')
            _url_path = '/public/apps/{appUid}/versions/{version}'
            _url_path = APIHelper.append_url_with_template_parameters(
                _url_path, {
                    'appUid': app_uid,
                    'version': version
                })
            _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_install_app.')
            _headers = {'accept': 'application/json'}

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

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for create_install_app.')
            if _context.response.status_code == 0:
                raise ErrorErrorException('Error', _context)
            self.validate_response(_context)

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #6
0
    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 (UpdateStateParametersOfProtectionJobs, optional): TODO: type
                description here. Example: 

        Returns:
            SpecifiesTheResponseOfUpdationOfStateOfMultipleProtectionJobs:
                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 ErrorErrorException('Error', _context)
            self.validate_response(_context)

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #7
0
    def create_close_smb_file_open(self, body):
        """Does a POST request to /public/smbFileOpens.

        Returns nothing upon success.

        Args:
            body (CloseSMBFileOpenParameters): Request to close an active SMB
                file open.

        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_close_smb_file_open called.')

            # Validate required parameters
            self.logger.info(
                'Validating required parameters for create_close_smb_file_open.'
            )
            self.validate_parameters(body=body)

            # Prepare query URL
            self.logger.info(
                'Preparing query URL for create_close_smb_file_open.')
            _url_path = '/public/smbFileOpens'
            _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_close_smb_file_open.')
            _headers = {'content-type': 'application/json; charset=utf-8'}

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for create_close_smb_file_open.'
            )
            _request = self.http_client.post(
                _query_url,
                headers=_headers,
                parameters=APIHelper.json_serialize(body))
            AuthManager.apply(_request)
            _context = self.execute_request(_request,
                                            name='create_close_smb_file_open')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info(
                'Validating response for create_close_smb_file_open.')
            if _context.response.status_code == 0:
                raise ErrorErrorException('Error', _context)
            self.validate_response(_context)

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #8
0
    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 = Configuration.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)
            _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
Example #9
0
    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 = Configuration.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)
            _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
Example #10
0
    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 = Configuration.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)
            _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 #11
0
    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 = Configuration.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)
            _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
Example #12
0
    def get_all_job_runs(self,
                         start_time,
                         end_time,
                         job_types=None,
                         page=None,
                         page_size=None):
        """Does a GET request to /public/monitoring/jobs.

        Specifying parameters can alter the results that are returned.

        Args:
            start_time (long|int): Specifies the start time of the time range
                of interest.
            end_time (long|int): Specifies the end time of the time range of
                interest.
            job_types (list of string, optional): Specifies the job types for
                which runs are needed.
            page (int, optional): Specifies the page number in case of
                pagination of response.
            page_size (int, optional): Specifies the size of the page in case
                of pagination of response.

        Returns:
            void: Response from the API. Specifies the common result structure
                of the response of all runs info (
protection, replication,
                archival etc.).

        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_all_job_runs called.')

            # Validate required parameters
            self.logger.info(
                'Validating required parameters for get_all_job_runs.')
            self.validate_parameters(start_time=start_time, end_time=end_time)

            # Prepare query URL
            self.logger.info('Preparing query URL for get_all_job_runs.')
            _url_path = '/public/monitoring/jobs'
            _query_builder = Configuration.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {
                'startTime': start_time,
                'endTime': end_time,
                'jobTypes': job_types,
                'page': page,
                'pageSize': page_size
            }
            _query_builder = APIHelper.append_url_with_query_parameters(
                _query_builder, _query_parameters,
                Configuration.array_serialization)
            _query_url = APIHelper.clean_url(_query_builder)

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

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for get_all_job_runs.')
            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_tenants(self,
                    ids=None,
                    properties=None,
                    hierarchy=None,
                    include_self=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 PropertiesEnum, 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.
            hierarchy (bool, optional): TODO: type description here. Example:
                            include_self (bool, optional): TODO: type description here.
                Example:
            status (list of Status7Enum, optional): Filter by tenant status.

        Returns:
            list of TenantDetails: 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 = Configuration.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {
                'ids': ids,
                'properties': properties,
                'hierarchy': hierarchy,
                'includeSelf': include_self,
                '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)
            _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 ErrorErrorException('Error', _context)
            self.validate_response(_context)

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
    def update_tenant_entity(self, body=None):
        """Does a PUT request to /public/tenants/entity.

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

        Args:
            body (TenantEntityUpdateDetails, optional): Request to associate
                entity for tenant.

        Returns:
            TenantEntityUpdate: Response from the API. Tenant Entity Update
                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_entity called.')

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

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for update_tenant_entity.')
            if _context.response.status_code == 0:
                raise ErrorErrorException('Error', _context)
            self.validate_response(_context)

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #15
0
    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 (ChangeProtectionJobStateParameters, 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 ErrorErrorException('Error', _context)
            self.validate_response(_context)

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #16
0
    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 = Configuration.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)
            _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
Example #17
0
    def create_protection_job(self, body):
        """Does a POST request to /public/protectionJobs.

        Returns the created Protection Job.

        Args:
            body (ProtectionJobRequest): Request to create a 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('create_protection_job called.')

            # Validate required parameters
            self.logger.info(
                'Validating required parameters for create_protection_job.')
            self.validate_parameters(body=body)

            # Prepare query URL
            self.logger.info('Preparing query URL for create_protection_job.')
            _url_path = '/public/protectionJobs'
            _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_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 create_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_protection_job')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for create_protection_job.')
            if _context.response.status_code == 0:
                raise ErrorErrorException('Error', _context)
            self.validate_response(_context)

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #18
0
    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 futher 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 = Configuration.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)
            _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 #19
0
    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 (ProtectionRunParameters): 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 ErrorErrorException('Error', _context)
            self.validate_response(_context)

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #20
0
    def update_protection_runs(self, body):
        """Does a PUT request to /public/protectionRuns.

        Update the expiration date (retention period) for the specified
        Protection
        Job Runs and their snapshots.
        After an expiration time is reached, the Job Run and its snapshots are
        deleted.
        If an expiration time of 0 is specified, a Job Run and its snapshots
        are immediately deleted.

        Args:
            body (UpdateProtectionJobRunsParam): Request to update the
                expiration time of Protection Job Runs.

        Returns:
            void: Response from the API. No Content

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        try:
            self.logger.info('update_protection_runs called.')

            # Validate required parameters
            self.logger.info(
                'Validating required parameters for update_protection_runs.')
            self.validate_parameters(body=body)

            # Prepare query URL
            self.logger.info('Preparing query URL for update_protection_runs.')
            _url_path = '/public/protectionRuns'
            _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_runs.')
            _headers = {'content-type': 'application/json; charset=utf-8'}

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for update_protection_runs.')
            _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_runs')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for update_protection_runs.')
            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 #21
0
    def get_smb_file_opens(self,
                           cookie=None,
                           file_path=None,
                           view_name=None,
                           page_count=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:
            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.
            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.

        Returns:
            SMBActiveFileOpenResponse: 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 = {
                'cookie': cookie,
                'filePath': file_path,
                'viewName': view_name,
                'pageCount': page_count
            }
            _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 ErrorErrorException('Error', _context)
            self.validate_response(_context)

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #22
0
    def get_protection_runs(self,
                            job_id=None,
                            include_rpo_snapshots=None,
                            started_time_usecs=None,
                            start_time_usecs=None,
                            end_time_usecs=None,
                            num_runs=None,
                            exclude_tasks=None,
                            source_id=None,
                            run_types=None,
                            exclude_error_runs=None,
                            exclude_non_restoreable_runs=None):
        """Does a GET request to /public/protectionRuns.

        If no parameters are specified, Job Runs currently
        on the Cohesity Cluster are returned. Both running and completed Job
        Runs
        are reported.
        Specifying parameters filters the results that are returned.

        Args:
            job_id (long|int, optional): Filter by a Protection Job that is
                specified by id. If not specified, all Job Runs for all
                Protection Jobs are returned.
            include_rpo_snapshots (bool, optional): If true, then the
                snapshots for Protection Sources protected by Rpo policies
                will also be returned.
            started_time_usecs (long|int, optional): Return a specific Job Run
                by specifying a time and a jobId. Specify the time when the
                Job Run started as a Unix epoch Timestamp (in microseconds).
                If this field is specified, jobId must also be specified.
            start_time_usecs (long|int, optional): Filter by a start time.
                Only Job Runs that started after the specified time are
                returned. Specify the start time as a Unix epoch Timestamp (in
                microseconds).
            end_time_usecs (long|int, optional): Filter by a end time
                specified as a Unix epoch Timestamp (in microseconds). Only
                Job Runs that completed before the specified end time are
                returned.
            num_runs (long|int, optional): Specify the number of Job Runs to
                return. The newest Job Runs are returned.
            exclude_tasks (bool, optional): If true, the individual backup
                status for all the objects protected by the Job Run are not
                populated in the response. For example in a VMware
                environment, the status of backing up each VM associated with
                a Job is not returned.
            source_id (long|int, optional): Filter by source id. Only Job Runs
                protecting the specified source (such as a VM or View) are
                returned. The source id is assigned by the Cohesity Cluster.
            run_types (list of string, optional): Filter by run type such as
                'kFull', 'kRegular' or 'kLog'. If not specified, Job Runs of
                all types are returned.
            exclude_error_runs (bool, optional): Filter out Jobs Runs with
                errors by setting this field to 'true'. If not set or set to
                'false', Job Runs with errors are returned.
            exclude_non_restoreable_runs (bool, optional): Filter out jobs
                runs that cannot be restored by setting this field to 'true'.
                If not set or set to 'false', Runs without any successful
                object will be returned. The default value is false.

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

            # Prepare query URL
            self.logger.info('Preparing query URL for get_protection_runs.')
            _url_path = '/public/protectionRuns'
            _query_builder = Configuration.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {
                'jobId': job_id,
                'includeRpoSnapshots': include_rpo_snapshots,
                'startedTimeUsecs': started_time_usecs,
                'startTimeUsecs': start_time_usecs,
                'endTimeUsecs': end_time_usecs,
                'numRuns': num_runs,
                'excludeTasks': exclude_tasks,
                'sourceId': source_id,
                'runTypes': run_types,
                'excludeErrorRuns': exclude_error_runs,
                'excludeNonRestoreableRuns': exclude_non_restoreable_runs
            }
            _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_runs.')
            _headers = {'accept': 'application/json'}

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

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #23
0
    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
        InterfaceName.<VLAN ID>.
        Example 1: /public/vlans/10
        Example 2: /public/vlans/bond0.20
        Example 3: /public/vlans/bond1.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 ErrorErrorException('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
Example #24
0
    def create_cancel_protection_job_run(self, id, body=None):
        """Does a POST request to /public/protectionRuns/cancel/{id}.

        Cancel a Protection Job run.

        Args:
            id (long|int): Specifies a unique id of the Protection Job.
            body (CancelProtectionJobRunParam, 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('create_cancel_protection_job_run called.')

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

            # Prepare query URL
            self.logger.info(
                'Preparing query URL for create_cancel_protection_job_run.')
            _url_path = '/public/protectionRuns/cancel/{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_cancel_protection_job_run.')
            _headers = {'content-type': 'application/json; charset=utf-8'}

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for create_cancel_protection_job_run.'
            )
            _request = self.http_client.post(
                _query_url,
                headers=_headers,
                parameters=APIHelper.json_serialize(body))
            AuthManager.apply(_request)
            _context = self.execute_request(
                _request, name='create_cancel_protection_job_run')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info(
                'Validating response for create_cancel_protection_job_run.')
            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 #25
0
    def get_protection_policies(self,
                                environments=None,
                                vault_ids=None,
                                tenant_ids=None,
                                all_under_hierarchy=None,
                                ids=None,
                                names=None):
        """Does a GET request to /public/protectionPolicies.

        If no parameters are specified, all Protection Policies currently on
        the
        Cohesity Cluster are returned.
        Specifying parameters filters the results that are returned.

        Args:
            environments (list of Environments1Enum, optional): Filter by
                Environment type such as 'kVMware', 'kView', etc. Only
                Policies protecting the specified environment type are
                returned. NOTE: 'kPuppeteer' refers to Cohesity's Remote
                Adapter.
            vault_ids (list of long|int, optional): Filter by a list of Vault
                ids. Policies archiving to any of the specified vaults will be
                returned.
            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 string, optional): Filter by a list of Protection
                Policy ids.
            names (list of string, optional): Filter by a list of Protection
                Policy names.

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

            # Prepare query URL
            self.logger.info(
                'Preparing query URL for get_protection_policies.')
            _url_path = '/public/protectionPolicies'
            _query_builder = Configuration.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {
                'environments': environments,
                'vaultIds': vault_ids,
                'tenantIds': tenant_ids,
                'allUnderHierarchy': all_under_hierarchy,
                'ids': ids,
                'names': names
            }
            _query_builder = APIHelper.append_url_with_query_parameters(
                _query_builder, _query_parameters,
                Configuration.array_serialization)
            _query_url = APIHelper.clean_url(_query_builder)

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

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

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info(
                'Validating response for get_protection_policies.')
            if _context.response.status_code == 0:
                raise ErrorErrorException('Error', _context)
            self.validate_response(_context)

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #26
0
    def get_protection_run_errors(self,
                                  job_id,
                                  start_time_usecs,
                                  task_id,
                                  limit_number_of_errors=None,
                                  pagination_cookie=None):
        """Does a GET request to /public/protectionRuns/errors.

        jobId, startTimeUsecs and taskId have to be provided to get the a list
        of
        errors for a job run task.

        Args:
            job_id (long|int): Specifies the id of the Protection Job whose
                runs are to be returned. This field is required.
            start_time_usecs (long|int): Specifies the time when the Job Run
                started as a Unix epoch Timestamp (in microseconds). This
                field is required
            task_id (long|int): Specifies the id of the Protection Run task
                for which errors are to be returned. This field is required to
                get the errors list.
            limit_number_of_errors (long|int, optional): Specifies the number
                of the results expected.
            pagination_cookie (string, optional): Specifies the cookie for
                next set of results.

        Returns:
            ProtectionRunErrors: 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_run_errors called.')

            # Validate required parameters
            self.logger.info(
                'Validating required parameters for get_protection_run_errors.'
            )
            self.validate_parameters(job_id=job_id,
                                     start_time_usecs=start_time_usecs,
                                     task_id=task_id)

            # Prepare query URL
            self.logger.info(
                'Preparing query URL for get_protection_run_errors.')
            _url_path = '/public/protectionRuns/errors'
            _query_builder = Configuration.get_base_uri()
            _query_builder += _url_path
            _query_parameters = {
                'jobId': job_id,
                'startTimeUsecs': start_time_usecs,
                'taskId': task_id,
                'limitNumberOfErrors': limit_number_of_errors,
                'paginationCookie': pagination_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_protection_run_errors.')
            _headers = {'accept': 'application/json'}

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

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #27
0
    def create_virtual_cluster(self, body):
        """Does a POST request to /public/clusters/virtualEdition.

        Sends a request to create a new Virtual Edition Cohesity Cluster and
        returns
        the IDs, name and software version of the new cluster.

        Args:
            body (CreateVirtualClusterParameters): TODO: type description
                here. Example:

        Returns:
            CreateClusterResult: 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_virtual_cluster called.')

            # Validate required parameters
            self.logger.info(
                'Validating required parameters for create_virtual_cluster.')
            self.validate_parameters(body=body)

            # Prepare query URL
            self.logger.info('Preparing query URL for create_virtual_cluster.')
            _url_path = '/public/clusters/virtualEdition'
            _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_virtual_cluster.')
            _headers = {
                'accept': 'application/json',
                'content-type': 'application/json; charset=utf-8'
            }

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for create_virtual_cluster.')
            _request = self.http_client.post(
                _query_url,
                headers=_headers,
                parameters=APIHelper.json_serialize(body))
            AuthManager.apply(_request)
            _context = self.execute_request(_request,
                                            name='create_virtual_cluster')

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
Example #28
0
    def get_protection_jobs(self,
                            include_last_run_and_stats=None,
                            policy_ids=None,
                            is_active=None,
                            is_deleted=None,
                            only_return_basic_summary=None,
                            environments=None,
                            tenant_ids=None,
                            all_under_hierarchy=None,
                            ids=None,
                            names=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:
            include_last_run_and_stats (bool, optional): If true, return the
                last Protection Run of the Job and the summary stats.
            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.
            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.
            environments (list of EnvironmentsEnum, 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.
            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.

        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 = {
                'includeLastRunAndStats': include_last_run_and_stats,
                'policyIds': policy_ids,
                'isActive': is_active,
                'isDeleted': is_deleted,
                'onlyReturnBasicSummary': only_return_basic_summary,
                'environments': environments,
                'tenantIds': tenant_ids,
                'allUnderHierarchy': all_under_hierarchy,
                'ids': ids,
                'names': names
            }
            _query_builder = APIHelper.append_url_with_query_parameters(
                _query_builder, _query_parameters,
                Configuration.array_serialization)
            _query_url = APIHelper.clean_url(_query_builder)

            # Prepare headers
            self.logger.info('Preparing headers for get_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 ErrorErrorException('Error', _context)
            self.validate_response(_context)

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

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
    def update_static_route(self,
                            ip,
                            body=None):
        """Does a PUT request to /public/staticRoutes/{ip}.

        Returns the created or updated Static Route on the Cohesity Cluster.

        Args:
            ip (string): Specifies the subnet IP of the route destination
                network.
            body (StaticRoute, optional): TODO: type description here.
                Example:

        Returns:
            StaticRoute: 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_static_route called.')

            # Validate required parameters
            self.logger.info('Validating required parameters for update_static_route.')
            self.validate_parameters(ip=ip)

            # Prepare query URL
            self.logger.info('Preparing query URL for update_static_route.')
            _url_path = '/public/staticRoutes/{ip}'
            _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
                'ip': ip
            })
            _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_static_route.')
            _headers = {
                'accept': 'application/json',
                'content-type': 'application/json; charset=utf-8'
            }

            # Prepare and execute request
            self.logger.info('Preparing and executing request for update_static_route.')
            _request = self.http_client.put(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
            AuthManager.apply(_request)
            _context = self.execute_request(_request, name = 'update_static_route')

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for update_static_route.')
            if _context.response.status_code == 0:
                raise ErrorErrorException('Error', _context)
            self.validate_response(_context)

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

        except Exception as e:
            self.logger.error(e, exc_info = True)
            raise
Example #30
0
    def update_app_instance_settings(self, app_instance_id, body):
        """Does a PUT request to /public/appInstanceSettings/{appInstanceId}.

        Changes the settings of the app instance.

        Args:
            app_instance_id (string): Specifies the app instance Id.
            body (UpdateAppInstanceSettingsParameters): Request to update app
                instance settings.

        Returns:
            void: Response from the API. No Content

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """
        try:
            self.logger.info('update_app_instance_settings called.')

            # Validate required parameters
            self.logger.info(
                'Validating required parameters for update_app_instance_settings.'
            )
            self.validate_parameters(app_instance_id=app_instance_id,
                                     body=body)

            # Prepare query URL
            self.logger.info(
                'Preparing query URL for update_app_instance_settings.')
            _url_path = '/public/appInstanceSettings/{appInstanceId}'
            _url_path = APIHelper.append_url_with_template_parameters(
                _url_path, {'appInstanceId': app_instance_id})
            _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 update_app_instance_settings.')
            _headers = {
                'accept': 'application/json',
                'content-type': 'application/json; charset=utf-8'
            }

            # Prepare and execute request
            self.logger.info(
                'Preparing and executing request for update_app_instance_settings.'
            )
            _request = self.http_client.put(
                _query_url,
                headers=_headers,
                parameters=APIHelper.json_serialize(body))
            AuthManager.apply(_request, self.config)
            _context = self.execute_request(
                _request, name='update_app_instance_settings')

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