def fetch_all_cluster_nodes(access_token: str) -> Dict: """ 获取所有集群中使用的主机信息 :return: {'ip': node_info} """ nodes = paas_cc.get_all_cluster_hosts( access_token, exclude_status_list=[CommonStatus.Removed]) return {n['inner_ip']: n for n in nodes}
def create(self): """添加节点 1. 检查节点是否可用 2. 触发OPS api """ # 校验集群edit权限 self.check_perm() # 校验数据 self.check_data() self.ip_list = [ip.split(',')[0] for ip in self.data['ip']] # 检测IP是否被占用 can_use_hosts(self.project_info["cc_app_id"], self.username, self.ip_list) self.project_nodes = paas_cc.get_all_cluster_hosts(self.access_token) self.check_node_ip() # 获取已经存在的IP,直接更新使用 removed_ips, remained_ips = self.get_removed_remained_ips() # 更新IP self.update_nodes(removed_ips) # 添加IP self.add_nodes(remained_ips) # 获取节点是否需要NAT cluster_info = self.get_cluster_info() self.need_nat = cluster_info.get('need_nat', True) # 现阶段平台侧不主动创建CMDB set&module,赋值为空列表 self.module_id_list = [] # 请求ops api with client.ContextActivityLogClient( project_id=self.project_id, user=self.username, resource_type=ACTIVITY_RESOURCE_TYPE, resource=','.join(self.ip_list)[:32], ).log_add(): # 更新所有节点为初始化中 node_info_list = self.update_cluster_nodes(self.ip_list) log = self.create_node_by_bcs(node_info_list) if not log.is_finished and log.is_polling: log.polling_task() return Response({})