def check_data(self): slz = serializers.CreateClusterSLZ( data=self.request.data, context={'project_id': self.project_id, 'access_token': self.access_token} ) slz.is_valid(raise_exception=True) self.data = slz.validated_data self.data['creator'] = self.username # 强制只有prod环境 self.data['environment'] = CLUSTER_ENVIRONMENT # 获取绑定的CMDB业务ID self.cc_app_id = self.project_info.get('cc_app_id') if not self.cc_app_id: raise error_codes.CheckFailed(_("当前项目没有绑定业务,不允许操作容器服务")) # NOTE: 选择第一个master节点作为中控机IP self.control_ip = self.data['master_ips'][:1] # 检查是否有权限操作IP cc_utils.check_ips(self.cc_app_id, self.username, self.data['master_ips']) self.area_info = self.get_area_info() self.data['area_id'] = self.area_info['id']
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']] cc_utils.check_ips(self.project_info['cc_app_id'], self.username, self.ip_list) # 检测IP是否被占用 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_nodes_with_response(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({})