Beispiel #1
0
    def delete_cluster_via_bcs(self):
        # 获取集群下对应的master ip
        master_ip_list = self.get_cluster_master()
        params = {
            'project_id': self.project_id,
            'cluster_id': self.cluster_id,
            'cc_app_id': self.cc_app_id,
            'host_ips': master_ip_list,
            'project_code': self.project_info['english_name'],
            'username': self.username,
        }
        # 创建记录
        log = ClusterInstallLog.objects.create(
            project_id=self.project_id,
            cluster_id=self.cluster_id,
            token=self.access_token,
            status=CommonStatus.Removing,
            params=json.dumps(params),
            operator=self.username,
            oper_type=ClusterOperType.ClusterRemove,
            is_polling=True,
        )
        # NOTE: 因为后端的任务调度引擎针对删除集群的流程,跳过异常;因此,当出现调用接口异常时,也跳过异常处理
        try:
            task_info = ops.delete_cluster(
                self.access_token,
                self.project_id,
                self.kind_name,
                self.cluster_id,
                master_ip_list,
                self.control_ip,
                self.cc_app_id,
                self.username,
                self.websvr,
                self.config,
                platform=self.config.pop("platform", "gcloud_v3"),
            )
            if task_info.get("code") != ErrorCode.NoError:
                logger.warning(
                    "调用删除集群流程失败,项目ID: %s, 集群ID: %s, error: %s",
                    self.project_id,
                    self.cluster_id,
                    task_info.get("message"),
                )
                self.delete_cluster(self.cluster_id)
                return
        except Exception as e:
            logger.error("调用删除集群流程异常,error: %s", e)
            self.delete_cluster(self.cluster_id)
            return

        data = task_info.get('data') or {}
        task_id = data.get('task_id')
        if not task_id:
            raise error_codes.APIError(
                _("获取标准运维任务ID失败,返回任务ID为{},请联系管理员处理").format(task_id))
        log.set_task_id(task_id)
        self.save_task_url(log, data)
        return log
Beispiel #2
0
 def delete_cluster_via_bcs(self):
     # 获取集群下对应的master ip
     master_ip_list = self.get_cluster_master()
     params = {
         'project_id': self.project_id,
         'cluster_id': self.cluster_id,
         'cc_app_id': self.cc_app_id,
         'host_ips': master_ip_list,
         'project_code': self.project_info['english_name'],
         'username': self.username
     }
     # 创建记录
     log = ClusterInstallLog.objects.create(
         project_id=self.project_id,
         cluster_id=self.cluster_id,
         token=self.access_token,
         status=CommonStatus.Removing,
         params=json.dumps(params),
         operator=self.username,
         oper_type=ClusterOperType.ClusterRemove,
         is_polling=True,
     )
     task_info = ops.delete_cluster(self.access_token, self.project_id,
                                    self.kind_name, self.cluster_id,
                                    master_ip_list, self.control_ip,
                                    self.cc_app_id, self.username,
                                    self.websvr, self.config)
     if task_info.get('code') != ErrorCode.NoError:
         log.set_finish_polling_status(True, False,
                                       CommonStatus.RemoveFailed)
         self.update_cluster_status(status=CommonStatus.RemoveFailed)
         raise error_codes.APIError(task_info.get('message'))
     data = task_info.get('data') or {}
     task_id = data.get('task_id')
     if not task_id:
         raise error_codes.APIError(
             _("获取标准运维任务ID失败,返回任务ID为{},请联系管理员处理").format(task_id))
     log.set_task_id(task_id)
     self.save_task_url(log, data)
     return log