def list_nodes(ctx, name, org, vdc): """Display nodes of a cluster that uses native Kubernetes provider.""" try: restore_session(ctx) client = ctx.obj['client'] if org is None and not client.is_sysadmin(): org = ctx.obj['profiles'].get('org_in_use') cluster = Cluster(client) cluster_info = cluster.get_cluster_info(name, org=org, vdc=vdc) if cluster_info.get(K8S_PROVIDER_KEY) != K8sProvider.NATIVE: raise CseClientError('Node commands are not supported by non ' 'native clusters.') all_nodes = cluster_info['master_nodes'] + cluster_info['nodes'] stdout(all_nodes, ctx, show_id=True) except Exception as e: stderr(e, ctx)
def delete_cluster(self, cluster_name): method = 'DELETE' uri = '%s/%s' % (self._uri, cluster_name) response = self.client._do_request_prim( method, uri, self.client._session, accept_type='application/*+json') try: result = process_response(response) except VcdResponseError as e: if e.error_message == ERROR_UNKNOWN: raise CseClientError("Invalid cluster/node name") else: raise e return result
def get_node_info(self, cluster_name, node_name): method = 'GET' uri = '%s/%s/%s/info' % (self._uri, cluster_name, node_name) response = self.client._do_request_prim( method, uri, self.client._session, contents=None, media_type=None, accept_type='application/*+json', auth=None) try: result = process_response(response) except VcdResponseError as e: if e.error_message == ERROR_UNKNOWN: raise CseClientError("Invalid cluster/node name") else: raise e return result
def get_config(self, cluster_name): method = 'GET' uri = '%s/%s/config' % (self._uri, cluster_name) response = self.client._do_request_prim(method, uri, self.client._session, contents=None, media_type=None, accept_type='text/x-yaml', auth=None) if response.status_code == requests.codes.ok: return response.content.decode('utf-8').replace('\\n', '\n')[1:-1] try: response_to_exception(response) except VcdResponseError as e: if e.error_message == ERROR_UNKNOWN: raise CseClientError("Invalid cluster name") else: raise e