Beispiel #1
0
 def start(self):
     result = {"raw": {}, "summary": {}}
     pre_deploy_execution_start.send(self.__class__, execution=self)
     cluster = self.get_cluster()
     settings = Setting.get_db_settings()
     extra_vars = {
         "cluster_name": cluster.name,
         "cluster_domain": cluster.cluster_doamin_suffix
     }
     extra_vars.update(settings)
     extra_vars.update(cluster.configs)
     ignore_errors = False
     return_running = False
     message_client = MessageClient()
     message = {
         "item_id": cluster.item_id,
         "title": self.get_operation_name(),
         "content": "",
         "level": "INFO",
         "type": "SYSTEM"
     }
     try:
         if self.operation == "install":
             logger.info(msg="cluster: {} exec: {} ".format(
                 cluster, self.operation))
             cluster.change_status(Cluster.CLUSTER_STATUS_INSTALLING)
             result = self.on_install(extra_vars)
             cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
         elif self.operation == 'uninstall':
             logger.info(msg="cluster: {} exec: {} ".format(
                 cluster, self.operation))
             cluster.change_status(Cluster.CLUSTER_STATUS_DELETING)
             result = self.on_uninstall(extra_vars)
             cluster.change_status(Cluster.CLUSTER_STATUS_READY)
             kubeops_api.cluster_monitor.delete_cluster_redis_data(
                 cluster.name)
         elif self.operation == 'bigip-config':
             logger.info(msg="cluster: {} exec: {} ".format(
                 cluster, self.operation))
             ignore_errors = True
             result = self.on_f5_config(extra_vars)
         elif self.operation == 'upgrade':
             logger.info(msg="cluster: {} exec: {} ".format(
                 cluster, self.operation))
             cluster.change_status(Cluster.CLUSTER_STATUS_UPGRADING)
             package_name = self.params.get('package', None)
             package = Package.objects.get(name=package_name)
             extra_vars.update(package.meta.get('vars'))
             result = self.on_upgrade(extra_vars)
             if result.get('summary', {}).get('success', False):
                 cluster.upgrade_package(package_name)
             cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
         elif self.operation == 'scale':
             logger.info(msg="cluster: {} exec: {} ".format(
                 cluster, self.operation))
             ignore_errors = True
             return_running = True
             cluster.change_status(Cluster.CLUSTER_DEPLOY_TYPE_SCALING)
             result = self.on_scaling(extra_vars)
             cluster.exit_new_node()
             cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
         elif self.operation == 'add-worker':
             logger.info(msg="cluster: {} exec: {} ".format(
                 cluster, self.operation))
             ignore_errors = True
             return_running = True
             cluster.change_status(Cluster.CLUSTER_DEPLOY_TYPE_SCALING)
             result = self.on_add_worker(extra_vars)
             cluster.exit_new_node()
             cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
         elif self.operation == 'remove-worker':
             logger.info(msg="cluster: {} exec: {} ".format(
                 cluster, self.operation))
             ignore_errors = True
             return_running = True
             cluster.change_status(Cluster.CLUSTER_DEPLOY_TYPE_SCALING)
             result = self.on_remove_worker(extra_vars)
             if not result.get('summary', {}).get('success', False):
                 cluster.exit_new_node()
             else:
                 node_names = self.params.get('nodes', None)
                 cluster.change_to()
                 nodes = Node.objects.filter(name__in=node_names)
                 for node in nodes:
                     node.delete()
                 cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
         elif self.operation == 'restore':
             logger.info(msg="cluster: {} exec: {} ".format(
                 cluster, self.operation))
             cluster.change_status(Cluster.CLUSTER_STATUS_RESTORING)
             cluster_backup_id = self.params.get('clusterBackupId', None)
             result = self.on_restore(extra_vars, cluster_backup_id)
             cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
         elif self.operation == 'backup':
             logger.info(msg="cluster: {} exec: {} ".format(
                 cluster, self.operation))
             cluster.change_status(Cluster.CLUSTER_STATUS_BACKUP)
             cluster_storage_id = self.params.get('backupStorageId', None)
             result = self.on_backup(extra_vars)
             self.on_upload_backup_file(cluster_storage_id)
             cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
         if not result.get('summary', {}).get('success', False):
             message['content'] = self.get_content(False)
             message['level'] = 'WARNING'
             if not ignore_errors:
                 cluster.change_status(Cluster.CLUSTER_STATUS_ERROR)
             if return_running:
                 cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
             logger.error(msg=":cluster {} exec {} error".format(
                 cluster, self.operation),
                          exc_info=True)
         else:
             message['content'] = self.get_content(True)
         message_client.insert_message(message)
     except Exception as e:
         logger.error(msg=":cluster {} exec {} error".format(
             cluster, self.operation),
                      exc_info=True)
         cluster.change_status(Cluster.CLUSTER_STATUS_ERROR)
         message['content'] = self.get_content(False)
         message['level'] = 'WARNING'
         message_client.insert_message(message)
     post_deploy_execution_start.send(self.__class__,
                                      execution=self,
                                      result=result,
                                      ignore_errors=ignore_errors)
     return result
Beispiel #2
0
    def start(self):
        result = {"raw": {}, "summary": {}}
        pre_deploy_execution_start.send(self.__class__, execution=self)
        cluster = self.get_cluster()
        settings = Setting.get_settings()
        extra_vars = {
            "cluster_name": cluster.name,
        }
        extra_vars.update(settings)
        extra_vars.update(cluster.configs)
        ignore_errors = False
        return_running = False

        if self.operation == "install":
            logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
            cluster.change_status(Cluster.CLUSTER_STATUS_INSTALLING)
            result = self.on_install(extra_vars)
            cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
        elif self.operation == 'uninstall':
            logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
            cluster.change_status(Cluster.CLUSTER_STATUS_DELETING)
            result = self.on_uninstall(extra_vars)
            cluster.change_status(Cluster.CLUSTER_STATUS_READY)
        elif self.operation == 'bigip-config':
            logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
            ignore_errors = True
            result = self.on_f5_config(extra_vars)
        elif self.operation == 'upgrade':
            logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
            cluster.change_status(Cluster.CLUSTER_STATUS_UPGRADING)
            package_name = self.params.get('package', None)
            package = Package.objects.get(name=package_name)
            extra_vars.update(package.meta.get('vars'))
            result = self.on_upgrade(extra_vars)
            cluster.upgrade_package(package_name)
            cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
        elif self.operation == 'scale':
            logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
            ignore_errors = True
            return_running = True
            cluster.change_status(Cluster.CLUSTER_DEPLOY_TYPE_SCALING)
            result = self.on_scaling(extra_vars)
            cluster.exit_new_node()
            cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
        elif self.operation == 'add-worker':
            logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
            ignore_errors = True
            return_running = True
            cluster.change_status(Cluster.CLUSTER_DEPLOY_TYPE_SCALING)
            result = self.on_add_worker(extra_vars)
            cluster.exit_new_node()
            cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
        elif self.operation == 'remove-worker':
            logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
            ignore_errors = True
            return_running = True
            cluster.change_status(Cluster.CLUSTER_DEPLOY_TYPE_SCALING)
            result = self.on_remove_worker(extra_vars)
            if not result.get('summary', {}).get('success', False):
                cluster.exit_new_node()
            else:
                node_name = self.params.get('node', None)
                cluster.change_to()
                node = Node.objects.get(name=node_name)
                node.delete()
                cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
        elif self.operation == 'restore':
            logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
            cluster.change_status(Cluster.CLUSTER_STATUS_RESTORING)
            cluster_backup_id = self.params.get('clusterBackupId', None)
            result = self.on_restore(extra_vars, cluster_backup_id)
            cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
        elif self.operation == 'backup':
            logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
            cluster.change_status(Cluster.CLUSTER_STATUS_BACKUP)
            cluster_storage_id = self.params.get('backupStorageId', None)
            result = self.on_backup(extra_vars)
            self.on_upload_backup_file(cluster_storage_id)
            cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
        if not result.get('summary', {}).get('success', False):
            if not ignore_errors:
                cluster.change_status(Cluster.CLUSTER_STATUS_ERROR)
            if return_running:
                cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
            logger.error(msg=":cluster {} exec {} error".format(cluster, self.operation), exc_info=True)
        post_deploy_execution_start.send(self.__class__, execution=self, result=result, ignore_errors=ignore_errors)
        return result
Beispiel #3
0
    def start(self):
        result = {"raw": {}, "summary": {}}
        pre_deploy_execution_start.send(self.__class__, execution=self)
        cluster = self.get_cluster()
        hostname = Setting.objects.get(key='local_hostname')
        dns = DNS.objects.first()
        extra_vars = {
            "cluster_name": cluster.name,
            "local_hostname": hostname.value,
            "domain_suffix": cluster.cluster_doamin_suffix,
            "dns1": dns.dns1,
            "dns2": dns.dns2,
        }

        extra_vars.update(cluster.configs)
        ignore_errors = False
        return_running = False

        try:
            if self.operation == "install":
                logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
                cluster.change_status(Cluster.CLUSTER_STATUS_INSTALLING)
                result = self.on_install(extra_vars)
                cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
            elif self.operation == 'uninstall':
                logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
                cluster.change_status(Cluster.CLUSTER_STATUS_DELETING)
                result = self.on_uninstall(extra_vars)
                cluster.change_status(Cluster.CLUSTER_STATUS_READY)
            elif self.operation == 'bigip-config':
                logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
                ignore_errors = True
                result = self.on_f5_config(extra_vars)
            elif self.operation == 'upgrade':
                logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
                cluster.change_status(Cluster.CLUSTER_STATUS_UPGRADING)
                package_name = self.params.get('package', None)
                package = Package.objects.get(name=package_name)
                extra_vars.update(package.meta.get('vars'))
                result = self.on_upgrade(extra_vars)
                cluster.upgrade_package(package_name)
                cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
            elif self.operation == 'scale':
                logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
                ignore_errors = True
                return_running = True
                cluster.change_status(Cluster.CLUSTER_DEPLOY_TYPE_SCALING)
                result = self.on_scaling(extra_vars)
                cluster.exit_new_node()
                cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
            elif self.operation == 'add-worker':
                logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
                ignore_errors = True
                return_running = True
                cluster.change_status(Cluster.CLUSTER_DEPLOY_TYPE_ADDING)
                result = self.on_add_worker(extra_vars)
                cluster.exit_new_node()
                cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
            elif self.operation == 'restore':
                logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
                cluster.change_status(Cluster.CLUSTER_STATUS_RESTORING)
                cluster_backup_id = self.params.get('clusterBackupId', None)
                result = self.on_restore(extra_vars, cluster_backup_id)
                cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
            elif self.operation == 'backup':
                logger.info(msg="cluster: {} exec: {} ".format(cluster, self.operation))
                cluster.change_status(Cluster.CLUSTER_STATUS_BACKUP)
                cluster_storage_id = self.params.get('backupStorageId', None)
                result = self.on_backup(extra_vars)
                self.on_upload_backup_file(cluster_storage_id)
                cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)


        except Exception as e:
            if not ignore_errors:
                cluster.change_status(Cluster.CLUSTER_STATUS_ERROR)
            if return_running:
                cluster.change_status(Cluster.CLUSTER_STATUS_RUNNING)
            logger.error(msg=":cluster {} exec {} error".format(cluster, self.operation), exc_info=True)
            result['summary'] = {'error': 'Unexpect error occur: {}'.format(e)}
        post_deploy_execution_start.send(self.__class__, execution=self, result=result, ignore_errors=ignore_errors)
        return result