def _args(self, data): args = [ data["forward_mode"], "--group", data["related_service_label"], ] # 获取zk zk_conf = cluster_resource.get_cc_zk_config(self.access_token, self.project_id, self.cluster_id) args += ["--zk", zk_conf["bcs_zookeeper"]] # 获取clusterzk,格式<编号>.<cluster_id>.bcscustom.com:2181 (多个地址逗号,分隔) # 这里编号的数量和master的数量一致 masters = cluster_resource.get_cluster_masters(self.access_token, self.project_id, self.cluster_id) cluster_zk_conf = [ f"{i}.{self.cluster_id.lower()}.bcscustom.com:2181" for i in range(1, len(masters) + 1) ] args += [ "--clusterzk", ",".join(cluster_zk_conf), "--zkpath", f"/etc/cluster/mesos/{self.cluster_id}/exportservice", "--bcszkaddr", zk_conf["bcs_zookeeper"], "--clusterid", self.cluster_id, ] return args
def cluster_masters(self, request, project_id, cluster_id): self.can_view_cluster(request, project_id, cluster_id) # 获取master masters = cluster_utils.get_cluster_masters(request.user.token.access_token, project_id, cluster_id) # 返回master对应的主机信息 # 因为先前 host_property_filter = { "condition": "OR", "rules": [ {"field": "bk_host_innerip", "operator": "equal", "value": info["inner_ip"]} for info in masters ], } username = settings.ADMIN_USERNAME cluster_masters = get_cmdb_hosts(username, request.project.cc_app_id, host_property_filter) return response.Response(cluster_masters)
def _get_cluster_master_ip_list(self, access_token, project_id, cluster_id): data = cluster_utils.get_cluster_masters(access_token, project_id, cluster_id) return [info["inner_ip"] for info in data]