def get_command_status(self, category, namespace, name, params): """查询命令执行状态 """ url = "{host}/mesos/command/{category}/{ns}/{name}".format( host=self.scheduler_host, category=category, ns=namespace, name=name) return http_get(url, params=params, headers=self.headers)
def list_hpa(self, namespace=None): """获取HPA列表 """ if namespace: url = f'{self.api_host}/v4/scheduler/mesos/crd/namespaces/{namespace}/autoscaler' else: url = f'{self.api_host}/v4/scheduler/mesos/crd/autoscaler' result = http_get(url, headers=self.headers) return result
def get_project_master_list(access_token, project_id): if getattr(settings, "BCS_CC_GET_PROJECT_MASTERS", None): path = settings.BCS_CC_GET_PROJECT_MASTERS.format( project_id=project_id) url = f"{BCS_CC_API_PRE_URL}{path}" else: url = f"{BCS_CC_API_PRE_URL}/projects/{project_id}/masters/" params = {"access_token": access_token} return http_get(url, params=params)
def get_node(access_token, project_id, node_id, cluster_id=""): if getattr(settings, "BCS_CC_OPER_PROJECT_NODE", None): path = settings.BCS_CC_OPER_PROJECT_NODE.format(project_id=project_id, node_id=node_id) url = f"{BCS_CC_API_PRE_URL}{path}" else: url = f"{BCS_CC_API_PRE_URL}/projects/{project_id}/nodes/{node_id}/" params = {"access_token": access_token, "cluster_id": cluster_id} return http_get(url, params=params)
def get_all_nodes(access_token): """获取配置中心所有Node """ url = f'{CC_HOST}/v1/nodes/all_node_list/' params = {"desire_all_data": 1} headers = { "X-BKAPI-AUTHORIZATION": json.dumps({"access_token": access_token}) } return http_get(url, params=params, headers=headers)
def get_cluster_snapshot(access_token, project_id, cluster_id): """获取集群快照""" if getattr(settings, "BCS_CC_CLUSTER_CONFIG", None): path = settings.BCS_CC_CLUSTER_CONFIG.format(cluster_id=cluster_id) url = f"{BCS_CC_API_PRE_URL}{path}" else: url = f"{BCS_CC_API_PRE_URL}/v1/clusters/{cluster_id}/cluster_config" params = {"access_token": access_token} return http_get(url, params=params)
def get_custom_resource(self, name, namespace, group="clb.bmsf.tencent.com", apiversion="v1", plural="clbingresses"): url = f"{self.scheduler_host}/mesos/customresources/{group}/{apiversion}/namespaces/{namespace}/{plural}/{name}" # noqa result = http_get(url, headers=self.headers) return self._handle_custom_resource_result(result)
def get_node(access_token, project_id, node_id, cluster_id=""): if getattr(settings, 'BCS_CC_OPER_PROJECT_NODE', None): path = settings.BCS_CC_OPER_PROJECT_NODE.format(project_id=project_id, node_id=node_id) url = f'{CC_HOST}{path}' else: url = f'{CC_HOST}/projects/{project_id}/nodes/{node_id}/' params = {"access_token": access_token, "cluster_id": cluster_id} return http_get(url, params=params)
def get_task_result(self, task_id): url = '{host}/tasks/{task_id}'.format( host=self.cluster_keeper_host, task_id=task_id, ) data = { 'project_id': self.project_id, } return http_get(url, params=data, headers=self.headers)
def get_base_cluster_config(access_token, project_id, params): """获取集群基本配置""" if getattr(settings, "BCS_CC_CLUSTER_CONFIG", None): path = settings.BCS_CC_CLUSTER_CONFIG.format(cluster_id="null") url = f"{BCS_CC_API_PRE_URL}{path}" else: url = f"{BCS_CC_API_PRE_URL}/v1/clusters/version_config/" headers = {"X-BKAPI-AUTHORIZATION": json.dumps({"access_token": access_token, "project_id": project_id})} return http_get(url, params=params, headers=headers)
def get_tls_cert_list(self): """获取tls证书列表""" self.url = self.url_cert_list.format(prefix=TICKET_API_PREFIX, project_code=self.project_code) self.query = {'permission': 'USE', 'certType': 'tls', 'pageSize': '10000'} resp = http_get(self.url, params=self.query, **self.kwargs) self.methord = 'GET' self.handle_error_msg(resp) return resp
def get_deployment(self, params): """查询deployment """ url = '{host}/query/k8s/dynamic/clusters/{cluster_id}/deployment'.format( host=self.storage_host, cluster_id=self.cluster_id ) resp = http_get(url, params=params, headers=self.headers) return resp
def get_rs(self, params): """查询rs """ url = '{host}/query/k8s/dynamic/clusters/{cluster_id}/replicaset'.format( host=self.storage_host, cluster_id=self.cluster_id ) resp = http_get(url, params=params, headers=self.headers) return resp
def verify_bk_token(self, bk_token): """校验是否""" url = f"{settings.BK_PAAS_INNER_HOST}/login/accounts/is_login/" params = {"bk_token": bk_token} resp = http_get(url, params=params) if resp.get("result") is not True: raise NoAuthError(resp.get("message", "")) return resp["data"]["username"]
def get_node_list(access_token, project_id, cluster_id, params=()): if getattr(settings, 'BCS_CC_GET_PROJECT_NODES', None): path = settings.BCS_CC_GET_PROJECT_NODES.format(project_id=project_id) url = f'{CC_HOST}{path}' else: url = f'{CC_HOST}/projects/{project_id}/nodes/' params = dict(params) params.update({"access_token": access_token, "cluster_id": cluster_id}) return http_get(url, params=params)
def get_project_master_list(access_token, project_id): if getattr(settings, 'BCS_CC_GET_PROJECT_MASTERS', None): path = settings.BCS_CC_GET_PROJECT_MASTERS.format( project_id=project_id) url = f'{CC_HOST}{path}' else: url = f'{CC_HOST}/projects/{project_id}/masters/' params = {"access_token": access_token} return http_get(url, params=params)
def get_client_credentials(self, bcs_cluster_id: str) -> dict: """获取证书, user_token, server_address_path """ url = f'{self.rest_host}/{bcs_cluster_id}/client_credentials' params = {'access_token': self.access_token} result = http_get(url, params=params, raise_for_status=False) return result
def get_targets(project_id, cluster_id, dedup=True): """获取集群的targets """ url = "{host}/api/v1/targets".format(host=settings.THANOS_HOST) # 同时限制项目ID,集群ID,防止越权 headers = {"X-Tenant-Project-Id": project_id, "X-Tenant-Cluster-Id": cluster_id} params = {"dedup": dedup, "state": "active"} resp = http_get(url, params=params, headers=headers, timeout=30, auth=AUTH) return resp
def get_project_cluster_resource(access_token): """获取所有项目、集群信息 """ url = f'{CC_HOST}/v1/projects/resource/' headers = { "X-BKAPI-AUTHORIZATION": json.dumps({ "access_token": access_token }) } return http_get(url, headers=headers)
def get_area_info(access_token, area_id): """查询指定区域的信息 """ url = f'{CC_HOST}/areas/{area_id}/' headers = { "X-BKAPI-AUTHORIZATION": json.dumps({ "access_token": access_token }) } return http_get(url, headers=headers)
def get_cluster_snapshot(access_token, project_id, cluster_id): """ 获取集群快照 """ if getattr(settings, 'BCS_CC_CLUSTER_CONFIG', None): path = settings.BCS_CC_CLUSTER_CONFIG.format(cluster_id=cluster_id) url = f'{CC_HOST}{path}' else: url = f'{CC_HOST}/v1/clusters/{cluster_id}/cluster_config' params = {"access_token": access_token} return http_get(url, params=params)
def get_zk_config(access_token, project_id, cluster_id): cluster = get_cluster(access_token, project_id, cluster_id) if cluster.get('code') != 0: raise error_codes.APIError(cluster.get('message')) environment = cluster['data']['environment'] url = f'{CC_HOST}/zk_config/' params = {'access_token': access_token, 'environment': environment} zk_config = http_get(url, params=params, timeout=20) return zk_config
def list_service_monitor(self, namespace=None): context = self.get_context_or_raise() host = f"{self._bcs_server_host}{context['server_address_path']}".rstrip("/") headers = {"Authorization": f"Bearer {context['user_token']}"} if namespace: url = f"{host}/apis/monitoring.coreos.com/v1/namespaces/{namespace}/servicemonitors" else: url = f"{host}/apis/monitoring.coreos.com/v1/servicemonitors" return http_get(url, headers=headers, raise_for_status=False)
def get_register_tokens(self, bke_cluster_id: str) -> dict: url = f"{self.rest_host}/{bke_cluster_id}/register_tokens" params = {"access_token": self.access_token} result = http_get(url, params=params, raise_for_status=False, headers=self._headers_for_bcs_agent_api) return result
def get_statefulset(self, params): """查询statefulset # TODO: 同样需要上报到storage """ url = '{host}/query/k8s/dynamic/clusters/{cluster_id}/statefulset'.format( host=self.storage_host, cluster_id=self.cluster_id ) resp = http_get(url, params=params, headers=self.headers) return resp
def get_daemonset(self, params): """查询daemonset TODO: 现阶段daemonset还没有上报到storage,接口还不可用 """ url = '{host}/query/k8s/dynamic/clusters/{cluster_id}/daemonset'.format( host=self.storage_host, cluster_id=self.cluster_id ) resp = http_get(url, params=params, headers=self.headers) return resp
def get_client_credentials(self, bke_cluster_id): """获取证书, user_token, server_address_path """ url = f"{self.rest_host}/{bke_cluster_id}/client_credentials" params = {"access_token": self.access_token} result = http_get(url, params=params, raise_for_status=False, headers=self._headers_for_bcs_agent_api) return result
def get_all_clusters(access_token, project_id, limit=None, offset=None, desire_all_data=0): url = f'{CC_HOST}/projects/{project_id}/clusters/' params = {'access_token': access_token} if limit: params['limit'] = limit if offset: params['offset'] = offset if desire_all_data: params['desire_all_data'] = desire_all_data return http_get(url, params=params)
def get_all_clusters(access_token, project_id, limit=None, offset=None, desire_all_data=0): url = f"{BCS_CC_API_PRE_URL}/projects/{project_id}/clusters/" params = {"access_token": access_token} if limit: params["limit"] = limit if offset: params["offset"] = offset # NOTE: 现阶段都是查询全量集群的场景 params["desire_all_data"] = 1 return http_get(url, params=params)
def verify_bk_token(self, bk_token): """校验是否 """ url = f'{settings.BK_PAAS_HOST}/login/accounts/is_login/' params = {'bk_token': bk_token} resp = http_get(url, params=params) if resp.get('result') is not True: raise NoAuthError(resp.get('message', '')) return resp['data']['username']