예제 #1
0
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)
예제 #2
0
파일: k8s.py 프로젝트: penglongli/bk-bcs
 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)
예제 #3
0
 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
예제 #4
0
 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)
예제 #5
0
 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
예제 #6
0
 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
예제 #7
0
 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
예제 #8
0
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)
예제 #9
0
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)
예제 #10
0
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)