def update_node_list(access_token, project_id, cluster_id, data): url = f'{CC_HOST}/projects/{project_id}/clusters/{cluster_id}/nodes/' params = {"access_token": access_token} req_data = { "updates": data } return http_patch(url, params=params, json=req_data)
def update_prometheus(self, namespace, name, spec): headers = { "Authorization": f"Bearer {self.context['user_token']}", "Content-Type": "application/merge-patch+json", # patch的特殊type "X-BKAPI-AUTHORIZATION": json.dumps({"access_token": self.access_token, "project_id": self.project_id}), } url = f"{self.context['host']}/apis/monitoring.coreos.com/v1/namespaces/{namespace}/prometheuses/{name}" return http_patch(url, json=spec, headers=headers, raise_for_status=False)
def patch_statefulset(self, namespace, name, params): """针对statefulset的patch操作 """ url = '{host}/namespaces/{namespace}/statefulsets/{name}'.format( host=self.scheduler_host, namespace=namespace, name=name) headers = self.headers headers["Content-Type"] = "application/strategic-merge-patch+json" resp = http_patch(url, json=params, headers=headers) return resp
def update_prometheus(self, namespace, name, spec): context = self.get_context_or_raise() host = f"{self._bcs_server_host}{context['server_address_path']}".rstrip("/") headers = { "Authorization": f"Bearer {context['user_token']}", "Content-Type": "application/merge-patch+json", # patch的特殊type } url = f"{host}/apis/monitoring.coreos.com/v1/namespaces/{namespace}/prometheuses/{name}" return http_patch(url, json=spec, headers=headers, raise_for_status=False)
def scale_instance(self, namespace, name, instance_num): """扩缩容 """ url = '{host}/k8s/namespaces/{namespace}/deployments/{name}'.format( host=self.scheduler_host, namespace=namespace, name=name) headers = self.headers headers["Content-Type"] = "application/strategic-merge-patch+json" data = {"spec": {"replicas": int(instance_num)}} resp = http_patch(url, json=data, headers=headers) return resp
def create_node_labels(self, ip, labels): """添加节点标签 """ ip_data = self.get_hostname_by_ip(ips=[ip]) if not ip_data or not ip_data.get(ip): return {"code": ErrorCode.UnknownError, "message": u"没有查询到IP对应的hostname"} url = '{host}/nodes/{name}'.format( host=self.scheduler_host, name=ip_data[ip] ) data = {"metadata": {"labels": labels}} headers = copy.deepcopy(self.headers) headers["Content-Type"] = "application/strategic-merge-patch+json" result = http_patch(url, json=data, headers=headers) return result
def enable_agent(self, ip): """启用agent """ ip_data = self.get_hostname_by_ip(ips=[ip]) if not ip_data: return {"code": ErrorCode.UnknownError, "message": u"没有查询到IP对应的hostname"} url = '{host}/nodes/{name}'.format( host=self.scheduler_host, name=ip_data[ip] ) data = {"spec": {"unschedulable": False}} headers = copy.deepcopy(self.headers) headers['Content-Type'] = 'application/strategic-merge-patch+json' result = http_patch(url, json=data, headers=headers) return result
def update_node_list(access_token, project_id, cluster_id, data): url = f"{BCS_CC_API_PRE_URL}/projects/{project_id}/clusters/{cluster_id}/nodes/" params = {"access_token": access_token} req_data = {"updates": data} return http_patch(url, params=params, json=req_data)
def create_node(access_token, project_id, cluster_id, data): url = f"{BCS_CC_API_PRE_URL}/projects/{project_id}/clusters/{cluster_id}/nodes/" params = {"access_token": access_token} return http_patch(url, params=params, json=data)
def create_node(access_token, project_id, cluster_id, data): url = f'{CC_HOST}/projects/{project_id}/clusters/{cluster_id}/nodes/' params = {"access_token": access_token} return http_patch(url, params=params, json=data)