def search_protection_runs(self, uuid): """Does a GET request to /public/search/protectionRuns. Returns the information of latest snapshot of a particular object across all snapshot target locations. Args: uuid (string): Specifies the unique id of the Protection Source. Returns: ProtectionRunResponse: 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('search_protection_runs called.') # Validate required parameters self.logger.info( 'Validating required parameters for search_protection_runs.') self.validate_parameters(uuid=uuid) # Prepare query URL self.logger.info('Preparing query URL for search_protection_runs.') _url_path = '/public/search/protectionRuns' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = {'uuid': uuid} _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 search_protection_runs.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for search_protection_runs.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='search_protection_runs') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for search_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, ProtectionRunResponse.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_consumer_stats(self, consumer_type=None, max_count=None, cookie=None, consumer_id_list=None, consumer_entity_id_list=None, fetch_view_box_name=None, fetch_tenant_name=None, fetch_protection_policy=None, fetch_protection_environment=None, view_boxes_id_list=None, organizations_id_list=None, tenant_ids=None, include_service_provider=None): """Does a GET request to /public/stats/consumers. Gets the statistics of consumers. Args: consumer_type (ConsumerTypeGetConsumerStatsEnum, optional): Specifies the consumer type. Type of the consumer can be one of the following three, 'kViews', indicates the stats info of Views used per organization (tenant) per view box (storage domain). 'kProtectionRuns', indicates the stats info of Protection Runs used per organization (tenant) per view box (storage domain). 'kReplicationRuns', indicates the stats info of Replication In used per organization (tenant) per view box (storage domain). max_count (long|int, optional): Specifies a limit on the number of stats groups returned. cookie (string, optional): Specifies the opaque string returned in the previous response. If this is set, next set of active opens just after the previous response are returned. If this is not set, first set of active opens are returned. consumer_id_list (list of long|int, optional): Specifies a list of consumer ids. consumer_entity_id_list (list of string, optional): Specifies a list of consumer entity ids. If this field is specified, each entity id must corresponds to the id in 'ConsumerIdList' in the same index, and the length of 'ConsumerEntityIdList' and 'ConsumerIdList' must be the same. fetch_view_box_name (bool, optional): Specifies whether to fetch view box (storage domain) name for each consumer. fetch_tenant_name (bool, optional): Specifies whether to fetch tenant (organization) name for each consumer. fetch_protection_policy (bool, optional): Specifies whether to fetch protection policy for each consumer. This field is applicable only if 'consumerType' is 'kProtectionRuns' or 'kReplicationRuns'. fetch_protection_environment(bool, optional): Specifies whether to fetch protection environment for each consumer. This field is applicable only if 'consumerType' is 'kProtectionRuns' or 'kReplicationRuns'. view_boxes_id_list (list of long|int, optional): Specifies a list of view boxes (storage domain) id. organizations_id_list (list of string, optional): Specifies a list of organizations (tenant) id. tenant_ids (list of string, optional): Specifies a list of organizations (tenant) id. This field is added to allow tenantIds json tag. This list will be concatenated with TenantsIdList to form full list of tenantsIdList. include_service_provider(bool, optional): Specifies whether to fetch the consumption of external service providers. These information will be listed as a unique organization (tenant) in response. By default it is false. Returns: GetConsumerStatsResult: 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_consumer_stats called.') # Prepare query URL self.logger.info('Preparing query URL for get_consumer_stats.') _url_path = '/public/stats/consumers' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_parameters = { 'consumerType': consumer_type, 'maxCount': max_count, 'cookie': cookie, 'consumerIdList': consumer_id_list, 'consumerEntityIdList': consumer_entity_id_list, 'fetchViewBoxName': fetch_view_box_name, 'fetchTenantName': fetch_tenant_name, 'fetchProtectionPolicy': fetch_protection_policy, 'fetchProtectionEnvironment': fetch_protection_environment, 'viewBoxesIdList': view_boxes_id_list, 'organizationsIdList': organizations_id_list, 'tenantIds': tenant_ids, 'includeServiceProvider': include_service_provider } _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_consumer_stats.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_consumer_stats.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request, self.config) _context = self.execute_request(_request, name='get_consumer_stats') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_consumer_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, GetConsumerStatsResult.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_active_alerts_stats(self, start_time_usecs, end_time_usecs): """Does a GET request to /public/stats/alerts. Compute the statistics on the active Alerts generated on the cluster based on the provided time interval. Args: start_time_usecs (long|int): Specifies the start time Unix time epoch in microseconds from which the active alerts stats are computed. end_time_usecs (long|int): Specifies the end time Unix time epoch in microseconds to which the active alerts stats are computed. Returns: ActiveAlertsStats: 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_active_alerts_stats called.') # Validate required parameters self.logger.info( 'Validating required parameters for get_active_alerts_stats.') self.validate_parameters(start_time_usecs=start_time_usecs, end_time_usecs=end_time_usecs) # Prepare query URL self.logger.info( 'Preparing query URL for get_active_alerts_stats.') _url_path = '/public/stats/alerts' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_parameters = { 'startTimeUsecs': start_time_usecs, 'endTimeUsecs': end_time_usecs } _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_active_alerts_stats.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_active_alerts_stats.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request, self.config) _context = self.execute_request(_request, name='get_active_alerts_stats') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for get_active_alerts_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, ActiveAlertsStats.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_view_boxes(self, fetch_stats=None, tenant_ids=None, all_under_hierarchy=None, ids=None, names=None, cluster_partition_ids=None): """Does a GET request to /public/viewBoxes. If no parameters are specified, all Domains (View Boxes) currently on the Cohesity Cluster are returned. Specifying parameters filters the results that are returned. Args: fetch_stats (bool, optional): Specifies whether to include usage and performance statistics. tenant_ids (list of string, optional): TenantIds contains ids of the tenants for which objects are to be returned. all_under_hierarchy (bool, optional): AllUnderHierarchy specifies if objects of all the tenants under the hierarchy of the logged in user's organization should be returned. ids (list of long|int, optional): Filter by a list of Storage Domain (View Box) ids. If empty, View Boxes are not filtered by id. names (list of string, optional): Filter by a list of Storage Domain (View Box) Names. If empty, Storage Domains (View Boxes) are not filtered by Name. cluster_partition_ids (list of long|int, optional): Filter by a list of Cluster Partition Ids. Returns: list of DomainViewBox: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_view_boxes called.') # Prepare query URL self.logger.info('Preparing query URL for get_view_boxes.') _url_path = '/public/viewBoxes' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'fetchStats': fetch_stats, 'tenantIds': tenant_ids, 'allUnderHierarchy': all_under_hierarchy, 'ids': ids, 'names': names, 'clusterPartitionIds': cluster_partition_ids } _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_view_boxes.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_view_boxes.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='get_view_boxes') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_view_boxes.') if _context.response.status_code == 0: raise ErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, DomainViewBox.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def update_view_box(self, id, body): """Does a PUT request to /public/viewBoxes/{id}. Returns the updated Domain (View Box). Args: id (long|int): Id of the Storage Domain (View Box) body (StorageDomainViewBoxRequest): Request to update a Storage Domain (View Box) configuration. Returns: DomainViewBox: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('update_view_box called.') # Validate required parameters self.logger.info( 'Validating required parameters for update_view_box.') self.validate_parameters(id=id, body=body) # Prepare query URL self.logger.info('Preparing query URL for update_view_box.') _url_path = '/public/viewBoxes/{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_view_box.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for update_view_box.') _request = self.http_client.put( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='update_view_box') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for update_view_box.') if _context.response.status_code == 0: raise ErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, DomainViewBox.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def search_active_directory_principals(self, domain=None, object_class=None, search=None, sids=None, include_computers=None): """Does a GET request to /public/activeDirectory/principals. Optionally limit the search results by specifying security identifiers (SIDs), an object class (user or group) or a substring. You can specify SIDs or a substring but not both. Args: domain (string, optional): Specifies the domain name of the principals to search. If specified the principals in that domain are searched. Domain could be an Active Directory domain joined by the Cluster or any one of the trusted domains of the Active Directory domain or the LOCAL domain. If not specified, all the domains are searched. object_class (ObjectClassSearchActiveDirectoryPrincipalsEnum, optional): Optionally filter by a principal object class such as 'kGroup' or 'kUser'. If 'kGroup' is specified, only group principals are returned. If 'kUser' is specified, only user principals are returned. If not specified, both group and user principals are returned. 'kUser' specifies a user object class. 'kGroup' specifies a group object class. 'kComputer' specifies a computer object class. 'kWellKnownPrincipal' specifies a well known principal. search (string, optional): Optionally filter by matching a substring. Only principals in the with a name or sAMAccountName that matches part or all of the specified substring are returned. If specified, a 'sids' parameter should not be specified. sids (list of string, optional): Optionally filter by a list of security identifiers (SIDs) found in the specified domain. Only principals matching the specified SIDs are returned. If specified, a 'search' parameter should not be specified. include_computers (bool, optional): Specifies if Computer/GMSA accounts need to be included in this search. Returns: list of ActiveDirectoryPrincipal: 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('search_active_directory_principals called.') # Prepare query URL self.logger.info( 'Preparing query URL for search_active_directory_principals.') _url_path = '/public/activeDirectory/principals' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_parameters = { 'domain': domain, 'objectClass': object_class, 'search': search, 'sids': sids, 'includeComputers': include_computers } _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 search_active_directory_principals.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for search_active_directory_principals.' ) _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request, self.config) _context = self.execute_request( _request, name='search_active_directory_principals') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for search_active_directory_principals.') 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, ActiveDirectoryPrincipal.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_active_directory_entry(self, domains=None, tenant_ids=None, all_under_hierarchy=None): """Does a GET request to /public/activeDirectory. After a Cohesity Cluster has been joined to an Active Directory domain, the users and groups in the domain can be authenticated on the Cohesity Cluster using their Active Directory credentials. NOTE: The userName and password fields are not populated by this operation. Args: domains (list of string, optional): Specifies the domains to fetch active directory entries. tenant_ids (list of string, optional): TenantIds contains ids of the tenants for which objects are to be returned. all_under_hierarchy (bool, optional): AllUnderHierarchy specifies if objects of all the tenants under the hierarchy of the logged in user's organization should be returned. Returns: list of ActiveDirectoryEntry: 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_active_directory_entry called.') # Prepare query URL self.logger.info( 'Preparing query URL for get_active_directory_entry.') _url_path = '/public/activeDirectory' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_parameters = { 'domains': domains, 'tenantIds': tenant_ids, 'allUnderHierarchy': all_under_hierarchy } _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for get_active_directory_entry.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_active_directory_entry.' ) _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request, self.config) _context = self.execute_request(_request, name='get_active_directory_entry') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for get_active_directory_entry.') 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, ActiveDirectoryEntry.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def update_role(self, name, body=None): """Does a PUT request to /public/roles/{name}. For example, you could update the privileges assigned to a Role. Returns the updated role. Args: name (string): Specifies the name of the role to update. body (RoleUpdateParameters, optional): Request to update a custom role. Returns: Role: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('update_role called.') # Validate required parameters self.logger.info('Validating required parameters for update_role.') self.validate_parameters(name=name) # Prepare query URL self.logger.info('Preparing query URL for update_role.') _url_path = '/public/roles/{name}' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'name': name}) _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for update_role.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for update_role.') _request = self.http_client.put( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='update_role') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for update_role.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, Role.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_roles(self, tenant_ids=None, all_under_hierarchy=None, name=None): """Does a GET request to /public/roles. If the 'name' parameter is not specified, all roles defined on the Cohesity Cluster are returned. In addition, information about each role is returned such as the name, description, assigned privileges, etc. If an exact role name (such as COHESITY_VIEWER) is specified in the 'name' parameter, only information about that single role is returned. Args: tenant_ids (list of string, optional): TenantIds contains ids of the tenants for which objects are to be returned. all_under_hierarchy (bool, optional): AllUnderHierarchy specifies if objects of all the tenants under the hierarchy of the logged in user's organization should be returned. name (string, optional): Specifies the name of the role. Returns: list of Role: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_roles called.') # Prepare query URL self.logger.info('Preparing query URL for get_roles.') _url_path = '/public/roles' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'tenantIds': tenant_ids, 'allUnderHierarchy': all_under_hierarchy, 'name': name } _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_roles.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info('Preparing and executing request for get_roles.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='get_roles') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_roles.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, Role.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def update_tenant_vlan(self, body=None): """Does a PUT request to /public/tenants/vlan. Returns success if the update for vlan data is successful for specified tenant. Args: body (TenantVlanUpdateParameters, optional): Request to update existing tenant vlan. Returns: TenantVlanUpdate: Response from the API. Tenant Vlan 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_vlan called.') # Prepare query URL self.logger.info('Preparing query URL for update_tenant_vlan.') _url_path = '/public/tenants/vlan' _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_vlan.') _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_vlan.') _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_vlan') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for update_tenant_vlan.') 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, TenantVlanUpdate.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def create_role(self, body=None): """Does a POST request to /public/roles. Returns the new custom role that was created. A custom role is a user-defined role that is created using the REST API, the Cohesity Cluster or the CLI. Args: body (RoleCreateParameters, optional): Request to create a new custom Role. Returns: Role: 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_role called.') # Prepare query URL self.logger.info('Preparing query URL for create_role.') _url_path = '/public/roles' _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_role.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for create_role.') _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='create_role') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for create_role.') 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, Role.from_dictionary) 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 PropertyEnum, optional): 'ViewBox' indicates view box data for tenant. 'Vlan' indicates vlan data for tenant. 'ProtectionPolicy' indicates protection policy for tenant. 'ProtectionJob' indicates protection job for tenant. 'Entity' indicates entity data for tenant. 'Views' indicates view data for tenant. 'ActiveDirectory' indicates active directory for tenant. 'LdapProvider' indicates ldap provider for tenant. hierarchy (bool, optional): TODO: type description here. Example: include_self (bool, optional): TODO: type description here. Example: status (list of StatusGetTenantsEnum, optional): Filter by tenant status. Returns: list of Tenant: Response from the API. Get Tenants Response. Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_tenants called.') # Prepare query URL self.logger.info('Preparing query URL for get_tenants.') _url_path = '/public/tenants' _query_builder = 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 RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, Tenant.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def create_tenant(self, body=None): """Does a POST request to /public/tenants. A tenant is required to support MultiTenant architecture for service provider (SP) to facilitate data and view segregations in the Cohesity Dashboard. Returns the created/added tenant. Args: body (TenantCreateParameters, optional): Request to add or create a new tenant. Returns: Tenant: Response from the API. Create Tenants response Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('create_tenant called.') # Prepare query URL self.logger.info('Preparing query URL for create_tenant.') _url_path = '/public/tenants' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for create_tenant.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for create_tenant.') _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='create_tenant') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for create_tenant.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, Tenant.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def search_protection_sources(self, search_string=None, protection_status=None, environments=None, last_protection_job_run_status=None, physical_server_host_types=None, registered_source_uuids=None, start_index=None, page_count=None): """Does a GET request to /public/search/protectionSources. Returns list of all the objects along with the protection status information. Args: search_string (string, optional): Specifies the search string to query the name of the Protection Source or the name of the job protecting a Protection Source. protection_status (list of string, optional): Specifies the protection status of the object. If specified, the objects are filtered based on current protection status of that object on the cluster. Possible values that can be passed are "protected", "unprotected" or both. If not specified, all the objects are returned irrespective of protection status of the object. environments (list of EnvironmentSearchProtectionSourcesEnum, optional): Specifies the environment type by which Protection Sources will be filtered. Supported environment types such as 'kView', 'kSQL', 'kVMware', etc. NOTE: 'kPuppeteer' refers to Cohesity's Remote Adapter. 'kVMware' indicates the VMware Protection Source environment. 'kHyperV' indicates the HyperV Protection Source environment. 'kSQL' indicates the SQL Protection Source environment. 'kView' indicates the View Protection Source environment. 'kPuppeteer' indicates the Cohesity's Remote Adapter. 'kPhysical' indicates the physical Protection Source environment. 'kPure' indicates the Pure Storage Protection Source environment. 'kAzure' indicates the Microsoft's Azure Protection Source environment. 'kNetapp' indicates the Netapp Protection Source environment. 'kAgent' indicates the Agent Protection Source environment. 'kGenericNas' indicates the Genreric Network Attached Storage Protection Source environment. 'kAcropolis' indicates the Acropolis Protection Source environment. 'kPhsicalFiles' indicates the Physical Files Protection Source environment. 'kIsilon' indicates the Dell EMC's Isilon Protection Source environment. 'kGPFS' indicates IBM's GPFS Protection Source environment. 'kKVM' indicates the KVM Protection Source environment. 'kAWS' indicates the AWS Protection Source environment. 'kExchange' indicates the Exchange Protection Source environment. 'kHyperVVSS' indicates the HyperV VSS Protection Source environment. 'kOracle' indicates the Oracle Protection Source environment. 'kGCP' indicates the Google Cloud Platform Protection Source environment. 'kFlashBlade' indicates the Flash Blade Protection Source environment. 'kAWSNative' indicates the AWS Native Protection Source environment. 'kVCD' indicates the VMware's Virtual cloud Director Protection Source environment. 'kO365' indicates the Office 365 Protection Source environment. 'kO365Outlook' indicates Office 365 outlook Protection Source environment. 'kHyperFlex' indicates the Hyper Flex Protection Source environment. 'kGCPNative' indicates the GCP Native Protection Source environment. 'kAzureNative' indicates the Azure Native Protection Source environment. 'kKubernetes' indicates a Kubernetes Protection Source environment. last_protection_job_run_status (list of int, optional): Specifies the last Protection Job run status of the object. If specified, objects will be filtered based on last job run status. physical_server_host_types (list of PhysicalServerHostTypeEnum, optional): Specifies physical server host OS type. If specified, the physical server objects will be filtered based on OS type of the server. 'kLinux' indicates the Linux operating system. 'kWindows' indicates the Microsoft Windows operating system. 'kAix' indicates the IBM AIX operating system. 'kSolaris' indicates the Oracle Solaris operating system. 'kSapHana' indicates the Sap Hana database system developed by SAP SE. 'kOther' indicates the other types of operating system. registered_source_uuids (list of string, optional): Specifies the list of Registered Sources Uuids. Only items from the listed Registered Sources are returned. start_index (int, optional): Specifies an index number that can be used to return subsets of items in multiple requests. Break up the items to return into multiple requests by setting pageCount and using startIndex to return a subsets of items. For example, set startIndex to 0 to get the first set of items for the first request. Increment startIndex by pageCount to get the next set of items for a next request. page_count (int, optional): Specifies the number of items to return in the response for pagination purposes. Default the pageCount to MaxSearchResponseSize if this is unspecified. Returns: list of ProtectionSourceResponse: 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('search_protection_sources called.') # Prepare query URL self.logger.info( 'Preparing query URL for search_protection_sources.') _url_path = '/public/search/protectionSources' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'searchString': search_string, 'protectionStatus': protection_status, 'environments': environments, 'lastProtectionJobRunStatus': last_protection_job_run_status, 'physicalServerHostTypes': physical_server_host_types, 'registeredSourceUuids': registered_source_uuids, 'startIndex': start_index, '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 search_protection_sources.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for search_protection_sources.' ) _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='search_protection_sources') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for search_protection_sources.') 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, ProtectionSourceResponse.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def create_active_directory_entry(self, body): """Does a POST request to /public/activeDirectory. After a Cohesity Cluster has been joined to an Active Directory domain, the users and groups in the domain can be authenticated on the Cohesity Cluster using their Active Directory credentials. Args: body (CreateActiveDirectoryEntryParams): Request to join an Active Directory. Returns: ActiveDirectoryEntry: 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_active_directory_entry called.') # Validate required parameters self.logger.info( 'Validating required parameters for create_active_directory_entry.' ) self.validate_parameters(body=body) # Prepare query URL self.logger.info( 'Preparing query URL for create_active_directory_entry.') _url_path = '/public/activeDirectory' _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 create_active_directory_entry.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for create_active_directory_entry.' ) _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request, self.config) _context = self.execute_request( _request, name='create_active_directory_entry') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for create_active_directory_entry.') 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, ActiveDirectoryEntry.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def list_sources_for_principals(self, sids=None): """Does a GET request to /public/principals/protectionSources. From the passed in list principals (specified by SIDs), return the list of Protection Sources objects and View names that each principal has permission to access. Args: sids (list of string, optional): Specifies a list of security identifiers (SIDs) that specify user or group principals. Returns: list of SourcesForSid: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('list_sources_for_principals called.') # Prepare query URL self.logger.info( 'Preparing query URL for list_sources_for_principals.') _url_path = '/public/principals/protectionSources' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = {'sids': sids} _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 list_sources_for_principals.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for list_sources_for_principals.' ) _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='list_sources_for_principals') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for list_sources_for_principals.') 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, SourcesForSid.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_active_directory_domain_controllers(self, domain_name=None): """Does a GET request to /public/activeDirectory/domainControllers. List the domain controllers for a domain. Args: domain_name (string, optional): Specifies the domain name Returns: DomainControllers: 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_active_directory_domain_controllers called.') # Prepare query URL self.logger.info( 'Preparing query URL for get_active_directory_domain_controllers.' ) _url_path = '/public/activeDirectory/domainControllers' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_parameters = {'domainName': domain_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_active_directory_domain_controllers.' ) _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_active_directory_domain_controllers.' ) _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request, self.config) _context = self.execute_request( _request, name='get_active_directory_domain_controllers') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for get_active_directory_domain_controllers.' ) 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, DomainControllers.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def create_reset_s_3_secret_key(self, body=None): """Does a POST request to /public/users/s3SecretKey. Returns the new key that was generated. Args: body (ResetS3SecretAccessKey, optional): Request to reset the S3 secret access key for the specified Cohesity user. Returns: NewS3SecretAccessKey: Response from the API. New S3 Secret Access Key. 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_reset_s_3_secret_key called.') # Prepare query URL self.logger.info( 'Preparing query URL for create_reset_s_3_secret_key.') _url_path = '/public/users/s3SecretKey' _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_reset_s_3_secret_key.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for create_reset_s_3_secret_key.' ) _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='create_reset_s_3_secret_key') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for create_reset_s_3_secret_key.') 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, NewS3SecretAccessKey.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def add_active_directory_principals(self, body=None): """Does a POST request to /public/activeDirectory/principals. After a group or user has been added to a Cohesity Cluster, the referenced Active Directory principal can be used by the Cohesity Cluster. In addition, this operation maps Cohesity roles with a group or user and this mapping defines the privileges allowed on the Cohesity Cluster for the group or user. For example if an 'management' group is created on the Cohesity Cluster for the Active Directory 'management' principal group and is associated with the Cohesity 'View' role, all users in the referenced Active Directory 'management' principal group can log in to the Cohesity Dashboard but will only have view-only privileges. These users cannot create new Protection Jobs, Policies, Views, etc. NOTE: Local Cohesity users and groups cannot be created by this operation. Local Cohesity users or groups do not have an associated Active Directory principals and are created directly in the default LOCAL domain. Args: body (list of ActiveDirectoryPrincipalsAddParameters, optional): Request to add groups or users to the Cohesity Cluster. Returns: list of AddedActiveDirectoryPrincipal: 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('add_active_directory_principals called.') # Prepare query URL self.logger.info( 'Preparing query URL for add_active_directory_principals.') _url_path = '/public/activeDirectory/principals' _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 add_active_directory_principals.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for add_active_directory_principals.' ) _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request, self.config) _context = self.execute_request( _request, name='add_active_directory_principals') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for add_active_directory_principals.') 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, AddedActiveDirectoryPrincipal.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
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
def update_preferred_domain_controllers(self, body, name): """Does a PUT request to /public/activeDirectory/{name}/preferredDomainControllers. Updates the preferred domain controllers of an Active Directory Args: body (list of PreferredDomainController): Request to update preferred domain controllers of an Active Directory. name (string): Specifies the Active Directory Domain Name. Returns: ActiveDirectoryEntry: 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_preferred_domain_controllers called.') # Validate required parameters self.logger.info( 'Validating required parameters for update_preferred_domain_controllers.' ) self.validate_parameters(body=body, name=name) # Prepare query URL self.logger.info( 'Preparing query URL for update_preferred_domain_controllers.') _url_path = '/public/activeDirectory/{name}/preferredDomainControllers' _url_path = APIHelper.append_url_with_template_parameters( _url_path, {'name': name}) _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info( 'Preparing headers for update_preferred_domain_controllers.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for update_preferred_domain_controllers.' ) _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_preferred_domain_controllers') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for update_preferred_domain_controllers.') 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, ActiveDirectoryEntry.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def update_web_server_certificate(self, body=None): """Does a PUT request to /public/certificates/webServer. Returns the updated Web Server Certificate on the cluster. Args: body (SslCertificateConfig, optional): TODO: type description here. Example: Returns: SslCertificateConfig: 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_web_server_certificate called.') # Prepare query URL self.logger.info( 'Preparing query URL for update_web_server_certificate.') _url_path = '/public/certificates/webServer' _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_web_server_certificate.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for update_web_server_certificate.' ) _request = self.http_client.put( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request( _request, name='update_web_server_certificate') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for update_web_server_certificate.') 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, SslCertificateConfig.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_view_box_by_id(self, id): """Does a GET request to /public/viewBoxes/{id}. Returns the Domain (View Box) corresponding to the specified Domain (View Box) Id. Args: id (long|int): Id of the Storage Domain (View Box) Returns: DomainViewBox: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_view_box_by_id called.') # Validate required parameters self.logger.info( 'Validating required parameters for get_view_box_by_id.') self.validate_parameters(id=id) # Prepare query URL self.logger.info('Preparing query URL for get_view_box_by_id.') _url_path = '/public/viewBoxes/{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_view_box_by_id.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_view_box_by_id.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='get_view_box_by_id') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_view_box_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, DomainViewBox.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def create_generate_access_token(self, body): """Does a POST request to /public/accessTokens. Before making other REST API requests, your REST client must make a 'POST /public/accessToken' request with a valid Cohesity username and password. This POST request returns an access token and type in the response that is generated by the Cohesity Cluster. Subsequent requests to other Cohesity REST API operations must specify the returned access token and type by setting 'Authorization' in the http header in the following format: Authorization: token_type access_token The generated token is valid for 24 hours. If a request is made with an expired token, the 'Token expired' error message is returned. Add code to your REST client to check for this error and request another access token before reissuing the request. Args: body (CreateAccessTokenCredentialRequest): Request to generate access token. Returns: AccessToken: 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_generate_access_token called.') # Validate required parameters self.logger.info( 'Validating required parameters for create_generate_access_token.' ) self.validate_parameters(body=body) # Prepare query URL self.logger.info( 'Preparing query URL for create_generate_access_token.') _url_path = '/public/accessTokens' _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_generate_access_token.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for create_generate_access_token.' ) _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) _context = self.execute_request( _request, name='create_generate_access_token') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for create_generate_access_token.') 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, AccessToken.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_view_stats(self, metric=None, num_top_views=None): """Does a GET request to /public/stats/views. Compute the statistics on Views. Args: metric (MetricEnum, optional): Specifies the metric to which stats has to be sorted. num_top_views (long|int, optional): Specifies the number of views for which stats has to be computed. Specifying this field will return the Views sorted in the descending order on the metric specified. If specified, minimum value is 1. If not specified, all views will be returned. If metric is not specified, this parameter must also not be specified. Returns: ViewStatsSnapshot: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_view_stats called.') # Prepare query URL self.logger.info('Preparing query URL for get_view_stats.') _url_path = '/public/stats/views' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_parameters = { 'metric': metric, 'numTopViews': num_top_views } _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_view_stats.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_view_stats.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request, self.config) _context = self.execute_request(_request, name='get_view_stats') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_view_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, ViewStatsSnapshot.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def create_group(self, body=None): """Does a POST request to /public/groups. If an Active Directory domain is specified, a new group is added to the Cohesity Cluster for the specified Active Directory group principal. If the LOCAL domain is specified, a new group is created directly in the default LOCAL domain on the Cohesity Cluster. Returns the created or added group. Args: body (GroupParameters, optional): Request to add or create a Group. Returns: Group: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('create_group called.') # Prepare query URL self.logger.info('Preparing query URL for create_group.') _url_path = '/public/groups' _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_group.') _headers = { 'accept': 'application/json', 'content-type': 'application/json; charset=utf-8' } # Prepare and execute request self.logger.info( 'Preparing and executing request for create_group.') _request = self.http_client.post( _query_url, headers=_headers, parameters=APIHelper.json_serialize(body)) AuthManager.apply(_request) _context = self.execute_request(_request, name='create_group') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for create_group.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, Group.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_file_distribution_stats(self, entity_type): """Does a GET request to /public/stats/files. Compute the file distribution statistics on a given entity like cluster or storage domain. Args: entity_type (EntityTypeGetFileDistributionStatsEnum): Specifies the entity type on which file distribution stats are computed. Returns: list of FileDistributionStats: 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_file_distribution_stats called.') # Validate required parameters self.logger.info( 'Validating required parameters for get_file_distribution_stats.' ) self.validate_parameters(entity_type=entity_type) # Prepare query URL self.logger.info( 'Preparing query URL for get_file_distribution_stats.') _url_path = '/public/stats/files' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_parameters = {'entityType': entity_type} _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_file_distribution_stats.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_file_distribution_stats.' ) _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request, self.config) _context = self.execute_request(_request, name='get_file_distribution_stats') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for get_file_distribution_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, FileDistributionStats.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_groups(self, name=None, domain=None, filter_by_owned_domains=None, tenant_ids=None, all_under_hierarchy=None): """Does a GET request to /public/groups. If no parameters are specified, all groups currently on the Cohesity Cluster are returned. Specifying parameters filters the results that are returned. Args: name (string, optional): Optionally specify a group name to filter by. All groups containing name will be returned. domain (string, optional): If no domain is specified, all groups on the Cohesity Cluster are searched. If a domain is specified, only groups on the Cohesity Cluster associated with that domain are searched. filter_by_owned_domains (bool, optional): If FilterByOwnedDomains is set to true, then the groups are filtered to show only the ones that are in the domains owned by the current tenant or user. tenant_ids (list of string, optional): TenantIds contains ids of the tenants for which objects are to be returned. all_under_hierarchy (bool, optional): AllUnderHierarchy specifies if objects of all the tenants under the hierarchy of the logged in user's organization should be returned. Returns: list of Group: Response from the API. Success Raises: APIException: When an error occurs while fetching the data from the remote API. This exception includes the HTTP Response code, an error message, and the HTTP body that was received in the request. """ try: self.logger.info('get_groups called.') # Prepare query URL self.logger.info('Preparing query URL for get_groups.') _url_path = '/public/groups' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'name': name, 'domain': domain, 'filterByOwnedDomains': filter_by_owned_domains, 'tenantIds': tenant_ids, 'allUnderHierarchy': all_under_hierarchy } _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_groups.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info('Preparing and executing request for get_groups.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='get_groups') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_groups.') if _context.response.status_code == 0: raise RequestErrorErrorException('Error', _context) self.validate_response(_context) # Return appropriate type return APIHelper.json_deserialize(_context.response.raw_body, Group.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_protected_objects_summary(self, exclude_types=None): """Does a GET request to /public/stats/protectionSummary. Computes the protected objects summary on the cluster. Args: exclude_types (list of ExcludeTypeGetProtectedObjectsSummaryEnum, optional): Specifies the environment types to exclude. Returns: ProtectedObjectsSummary: 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_protected_objects_summary called.') # Prepare query URL self.logger.info( 'Preparing query URL for get_protected_objects_summary.') _url_path = '/public/stats/protectionSummary' _query_builder = self.config.get_base_uri() _query_builder += _url_path _query_parameters = {'excludeTypes': exclude_types} _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_protected_objects_summary.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info( 'Preparing and executing request for get_protected_objects_summary.' ) _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request, self.config) _context = self.execute_request( _request, name='get_protected_objects_summary') # Endpoint and global error handling using HTTP status codes. self.logger.info( 'Validating response for get_protected_objects_summary.') 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, ProtectedObjectsSummary.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise
def get_alerts(self, max_alerts, alert_id_list=None, alert_type_list=None, alert_category_list=None, property_key=None, property_value=None, start_date_usecs=None, end_date_usecs=None, alert_state_list=None, alert_severity_list=None, alert_type_bucket_list=None, resolution_id_list=None, tenant_ids=None, all_under_hierarchy=None): """Does a GET request to /public/alerts. Returns all Alert objects found on the Cohesity Cluster that match the filter criteria specified using parameters. The Cohesity Cluster creates an Alert when a potential problem is found or when a threshold has been exceeded on the Cohesity Cluster. If no filter parameters are specified, all Alert objects are returned. Each object provides details about the Alert such as the Status and Severity. Args: max_alerts (int): Specifies the number of returned Alerts to be returned. The newest Alerts are returned. alert_id_list (list of string, optional): Specifies list of Alert ids to filter alerts by. alert_type_list (list of int, optional): Specifies list of Alert Types to filter alerts by. alert_category_list (list of AlertCategoryListGetAlertsEnum, optional): Specifies list of Alert Categories. property_key (string, optional): Specifies name of the property to filter alerts by. property_value (string, optional): Specifies value of the property to filter alerts by. start_date_usecs (long|int, optional): Specifies start time Unix epoch time in microseconds to filter alerts by. end_date_usecs (long|int, optional): Specifies end time Unix epoch time in microseconds to filter alerts by. alert_state_list (list of AlertStateListEnum, optional): Specifies list of Alert States to filter alerts by. alert_severity_list (list of AlertSeverityListEnum, optional): Specifies list of Alert severity to filter alerts by. alert_type_bucket_list (list of AlertTypeBucketListEnum, optional): Specifies the list of Alert type bucket. Specifies the Alert type bucket. kSoftware - Alerts which are related to Cohesity services. kHardware - Alerts related to hardware on which Cohesity software is running. kService - Alerts related to other external services. kOther - Alerts not of one of above categories. resolution_id_list (list of long|int, optional): Specifies alert resolution ids to filter alerts by. tenant_ids (list of string, optional): TenantIds contains ids of the tenants for which objects are to be returned. all_under_hierarchy (bool, optional): AllUnderHierarchy specifies if objects of all the tenants under the hierarchy of the logged in user's organization should be returned. Returns: list of Alert: 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_alerts called.') # Validate required parameters self.logger.info('Validating required parameters for get_alerts.') self.validate_parameters(max_alerts=max_alerts) # Prepare query URL self.logger.info('Preparing query URL for get_alerts.') _url_path = '/public/alerts' _query_builder = Configuration.get_base_uri() _query_builder += _url_path _query_parameters = { 'maxAlerts': max_alerts, 'alertIdList': alert_id_list, 'alertTypeList': alert_type_list, 'alertCategoryList': alert_category_list, 'propertyKey': property_key, 'propertyValue': property_value, 'startDateUsecs': start_date_usecs, 'endDateUsecs': end_date_usecs, 'alertStateList': alert_state_list, 'alertSeverityList': alert_severity_list, 'alertTypeBucketList': alert_type_bucket_list, 'resolutionIdList': resolution_id_list, 'tenantIds': tenant_ids, 'allUnderHierarchy': all_under_hierarchy } _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, _query_parameters, Configuration.array_serialization) _query_url = APIHelper.clean_url(_query_builder) # Prepare headers self.logger.info('Preparing headers for get_alerts.') _headers = {'accept': 'application/json'} # Prepare and execute request self.logger.info('Preparing and executing request for get_alerts.') _request = self.http_client.get(_query_url, headers=_headers) AuthManager.apply(_request) _context = self.execute_request(_request, name='get_alerts') # Endpoint and global error handling using HTTP status codes. self.logger.info('Validating response for get_alerts.') 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, Alert.from_dictionary) except Exception as e: self.logger.error(e, exc_info=True) raise