def all(self) -> List: request = TNCOClientRequest( method='GET', endpoint=self.endpoint, ).add_headers({'Accept': 'application/yaml,application/json'}) request.override_address = getattr(self, 'override_address') if hasattr(self, 'override_address') else None return self._exec_request_and_parse_yaml(request)
def render_raw(self, template_name: str, render_request: Dict) -> str: if render_request is None: render_request = {} endpoint = self._render_raw_endpoint(template_name) request = TNCOClientRequest(method='POST', endpoint=endpoint)\ .add_yaml_body(render_request)\ .add_headers({'Accept': 'text/plain'}) if self.override_address is not None: request.override_address = self.override_address return self._exec_request_and_parse_plaintext(request)
def render(self, template_name: str, render_request: Dict) -> Dict: if render_request is None: render_request = {} endpoint = self._render_endpoint(template_name) request = TNCOClientRequest(method='POST', endpoint=endpoint)\ .add_yaml_body(render_request)\ .add_headers({'Accept': 'application/yaml'}) if self.override_address is not None: request.override_address = self.override_address return self._exec_request_and_parse_yaml(request)
def get(self, name: str, effective: bool = None) -> Dict: query_params = {} if effective is not None: query_params['effective'] = effective request = TNCOClientRequest( method='GET', endpoint=build_relative_endpoint(base_endpoint=self.endpoint, id_value=name) ).add_headers({'Accept': 'application/yaml,application/json'})\ .add_query_params(query_params) request.override_address = getattr(self, 'override_address') if hasattr(self, 'override_address') else None return self._exec_request_and_parse_yaml(request)
def request_zen_api_key_access(self, username: str, api_key: str, zen_auth_address: str = None) -> Dict: body = {'username': username, 'api_key': api_key} request = TNCOClientRequest(method='POST', endpoint=None)\ .disable_auth_token()\ .add_json_body(body) request.override_address = zen_auth_address auth_response = self.base_client.make_request_for_json(request) return auth_response
def legacy_login(self, username: str, password: str, legacy_auth_address: str = None) -> Dict: body = {'username': username, 'password': password} try: request = TNCOClientRequest(method='POST', endpoint=self.legacy_login_endpoint)\ .disable_auth_token()\ .add_json_body(body) request.override_address = legacy_auth_address auth_response = self.base_client.make_request_for_json(request) except TNCOClientHttpError as e: if e.status_code == 404: logger.info( f'Failed to access login API at {self.legacy_login_endpoint}, responded with {e.status_code} status code...may be an older CP4NA orchestration environment, trying {self.older_legacy_login_endpoint}' ) request = TNCOClientRequest(method='POST', endpoint=self.older_legacy_login_endpoint)\ .disable_auth_token()\ .add_json_body(body) request.override_address = legacy_auth_address auth_response = self.base_client.make_request_for_json(request) else: raise return auth_response
def delete(self, name: str): request = TNCOClientRequest(method='DELETE', endpoint=build_relative_endpoint(id_value=name, base_endpoint=self.endpoint)) request.override_address = getattr(self, 'override_address') if hasattr(self, 'override_address') else None self._exec_request(request)
def update(self, descriptor: Dict): request = TNCOClientRequest(method='PUT', endpoint=build_relative_endpoint_from_data(data_dict=descriptor, id_attr='name', base_endpoint=self.endpoint) ).add_yaml_body(descriptor) request.override_address = getattr(self, 'override_address') if hasattr(self, 'override_address') else None self._exec_request(request)
def create(self, descriptor: Dict): request = TNCOClientRequest(method='POST', endpoint=self.endpoint).add_yaml_body(descriptor) request.override_address = getattr(self, 'override_address') if hasattr(self, 'override_address') else None self._exec_request(request)