def create_mount(self, mount_options):
        """Does a POST request to /mounts.

        Allows you to mount a view/namespace.

        Args:
            mount_options (MountOptions): TODO: type description here.
                Example: 

        Returns:
            void: Response from the API. Mount operation is successful.

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

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

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

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for create_mount.')
            if _context.response.status_code == 400:
                raise APIException('Validation errors.', _context)
            elif _context.response.status_code == 401:
                raise APIException('Invalid token.', _context)
            elif _context.response.status_code == 500:
                raise ErrorException('Unexpected error.', _context)
            self.validate_response(_context)

        except Exception as e:
            self.logger.error(e, exc_info=True)
            raise
예제 #2
0
    def create_volume(self,
                      volume_name,
                      volume_spec):
        """Does a PUT request to /volumes/{volumeName}.

        Use this API to create a new kubernetes persistent volume backed up by
        cohesity view.

        Args:
            volume_name (string): Name of the volume unique within the app
                instance.
            volume_spec (VolumeSpec): TODO: type description here. Example:

        Returns:
            void: Response from the API. Created.

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

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

            # Prepare query URL
            self.logger.info('Preparing query URL for create_volume.')
            _url_path = '/volumes/{volumeName}'
            _url_path = APIHelper.append_url_with_template_parameters(_url_path, {
                'volumeName': volume_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 create_volume.')
            _headers = {
                'content-type': 'application/json; charset=utf-8'
            }

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

            # Endpoint and global error handling using HTTP status codes.
            self.logger.info('Validating response for create_volume.')
            if _context.response.status_code == 401:
                raise APIException('Unauthorized.', _context)
            elif _context.response.status_code == 409:
                raise APIException('Volume already exists with different parameters.', _context)
            elif _context.response.status_code == 500:
                raise ErrorErrorException('Unexpected error.', _context)
            elif _context.response.status_code == 502:
                raise APIException('Bad Gateway.', _context)
            elif _context.response.status_code == 504:
                raise APIException('Gateway Timeout.', _context)
            self.validate_response(_context)

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