def list_api_resource_arbitrary(self, group, version): try: return self.api_client.call_api( '/apis/{}/{}'.format(group, version), 'GET', {}, [], { 'Accept': self.api_client.select_header_accept([ 'application/json', 'application/yaml', 'application/vnd.kubernetes.protobuf' ]), 'Content-Type': self.api_client.select_header_content_type([ 'application/json', 'application/yaml', 'application/vnd.kubernetes.protobuf' ]) }, body=None, post_params=[], files={}, response_type='V1APIResourceList', auth_settings=['BearerToken'], async_req=None, _return_http_data_only=True, _preload_content=True, _request_timeout=None, collection_formats={}) except ApiException as e: if e.reason == 'Not Found': log.error( 'The resource definition with the specified group and version was not found' ) return None log.error('{}'.format(add_indent(e.body))) raise ProvisioningError(e)
def list_api_resources(self, version): try: return self.api_client.call_api( resource_path='/api/{}'.format(version), method='GET', header_params={ 'Accept': self.api_client.select_header_accept([ 'application/json', 'application/yaml', 'application/vnd.kubernetes.protobuf' ]), 'Content-Type': self.api_client.select_header_content_type([ 'application/json', 'application/yaml', 'application/vnd.kubernetes.protobuf' ]) }, response_type='V1APIResourceList', auth_settings=['BearerToken'], _return_http_data_only=True, _preload_content=True, ) except ApiException as e: if e.reason == 'Not Found': log.error( 'The resource definition with the specified version was not found' ) return None log.error('{}'.format(add_indent(e.body))) raise ProvisioningError(e)
def replace(self, parameters): try: if self.kind in ['custom_resource_definition']: self.body['metadata']['resourceVersion'] = parameters[ 'resourceVersion'] return self.api.replace_custom_resource_definition( self.name, self.body, ) if self.kind in ['service', 'service_account']: if 'spec' in self.body: self.body['spec']['ports'] = parameters.get('ports') return getattr(self.api, 'patch_namespaced_{}'.format( self.kind))(name=self.name, body=self.body, namespace=self.namespace) if hasattr(self.api, "replace_namespaced_{}".format(self.kind)): return getattr(self.api, 'replace_namespaced_{}'.format( self.kind))(name=self.name, body=self.body, namespace=self.namespace) return getattr(self.api, 'replace_{}'.format(self.kind))(name=self.name, body=self.body) except ApiException as e: log.error( 'Exception when calling "replace_namespaced_{}": {}'.format( self.kind, add_indent(e.body))) raise ProvisioningError(e)
def delete(self): self._validate() try: if self.namespace: return self.api.delete_namespaced_custom_object( self.group, self.version, self.namespace, self.plural, self.name, body=client.V1DeleteOptions( propagation_policy='Foreground')) return self.api.delete_cluster_custom_object( self.group, self.version, self.plural, self.name, body=client.V1DeleteOptions(propagation_policy='Foreground')) except ApiException as e: if e.reason == 'Not Found': return None log.error('{}'.format(add_indent(e.body))) raise ProvisioningError(e)
def replace(self, _): self._validate() try: if self.namespace: return self.api.patch_namespaced_custom_object( self.group, self.version, self.namespace, self.plural, self.name, self.body) return self.api.patch_cluster_custom_object( self.group, self.version, self.plural, self.name, self.body) except ApiException as e: log.error('{}'.format(add_indent(e.body))) raise ProvisioningError(e)
def get(self): try: if hasattr(self.api, "read_namespaced_{}".format(self.kind)): response = getattr(self.api, 'read_namespaced_{}'.format( self.kind))(self.name, namespace=self.namespace) else: response = getattr(self.api, 'read_{}'.format(self.kind))(self.name) except ApiException as e: if e.reason == 'Not Found': return None log.error('Exception when calling "read_namespaced_{}": {}'.format( self.kind, add_indent(e.body))) raise ProvisioningError(e) return response
def get(self): self._validate() try: if self.namespace: return self.api.get_namespaced_custom_object( self.group, self.version, self.namespace, self.plural, self.name ) return self.api.get_cluster_custom_object(self.group, self.version, self.plural, self.name) except ApiException as e: if e.reason == 'Not Found': return None log.error('{}'.format(add_indent(e.body))) raise ProvisioningError(e)
def replace(self, parameters): self._validate() if 'resourceVersion' in parameters: self.body['metadata']['resourceVersion'] = parameters[ 'resourceVersion'] try: if self.namespace: return self.api.replace_namespaced_custom_object( self.group, self.version, self.namespace, self.plural, self.name, self.body) return self.api.replace_cluster_custom_object( self.group, self.version, self.plural, self.name, self.body) except ApiException as e: log.error('{}'.format(add_indent(e.body))) raise ProvisioningError(e)
def create(self): try: if hasattr(self.api, "create_namespaced_{}".format(self.kind)): return getattr(self.api, 'create_namespaced_{}'.format( self.kind))(body=self.body, namespace=self.namespace) return getattr(self.api, 'create_{}'.format(self.kind))(body=self.body) except ApiException as e: log.error( 'Exception when calling "create_namespaced_{}": {}'.format( self.kind, add_indent(e.body))) raise ProvisioningError(e) except ValueError as e: log.error(e) # WORKAROUND https://github.com/kubernetes-client/gen/issues/52 if self.kind not in ['custom_resource_definition']: raise e
def delete(self): try: if hasattr(self.api, "delete_namespaced_{}".format(self.kind)): return getattr(self.api, 'delete_namespaced_{}'.format( self.kind))(name=self.name, body=client.V1DeleteOptions( propagation_policy='Foreground'), namespace=self.namespace) return getattr(self.api, 'delete_{}'.format(self.kind))( name=self.name, body=client.V1DeleteOptions(propagation_policy='Foreground')) except ApiException as e: if e.reason == 'Not Found': return None log.error( 'Exception when calling "delete_namespaced_{}": {}'.format( self.kind, add_indent(e.body))) raise ProvisioningError(e)
def replace(self, parameters): try: if self.kind in [ 'service', 'custom_resource_definition', 'pod_disruption_budget' ]: if 'resourceVersion' in parameters: self.body['metadata']['resourceVersion'] = parameters[ 'resourceVersion'] if self.kind in ['service']: if 'clusterIP' not in self.body[ 'spec'] and 'clusterIP' in parameters: self.body['spec']['clusterIP'] = parameters['clusterIP'] if self.kind in ['custom_resource_definition']: return self.api.replace_custom_resource_definition( self.name, self.body, ) if self.kind in ['service_account']: return getattr(self.api, 'patch_namespaced_{}'.format( self.kind))(name=self.name, body=self.body, namespace=self.namespace) if hasattr(self.api, "replace_namespaced_{}".format(self.kind)): return getattr(self.api, 'replace_namespaced_{}'.format( self.kind))(name=self.name, body=self.body, namespace=self.namespace) return getattr(self.api, 'replace_{}'.format(self.kind))(name=self.name, body=self.body) except ApiException as e: if self.kind in ['pod_disruption_budget'] and e.status == 422: return self.re_create() log.error( 'Exception when calling "replace_namespaced_{}": {}'.format( self.kind, add_indent(e.body))) raise ProvisioningError(e)