当前位置: 首页>>代码示例>>Python>>正文


Python TaskHelper.nodes_to_startorstop方法代码示例

本文整理汇总了Python中nailgun.task.task.TaskHelper.nodes_to_startorstop方法的典型用法代码示例。如果您正苦于以下问题:Python TaskHelper.nodes_to_startorstop方法的具体用法?Python TaskHelper.nodes_to_startorstop怎么用?Python TaskHelper.nodes_to_startorstop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nailgun.task.task.TaskHelper的用法示例。


在下文中一共展示了TaskHelper.nodes_to_startorstop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_deploy_msgs

# 需要导入模块: from nailgun.task.task import TaskHelper [as 别名]
# 或者: from nailgun.task.task.TaskHelper import nodes_to_startorstop [as 别名]
    def make_deploy_msgs(self,cluster,supertask,deploymsg,status):
        #ebs_rolelist=["gangliasrv","nagiossrv","gangliacli","nagioscli"]
        task_messages=[]
        ebs_rolelist=["keepalived","onecmdb","activemq","redis","nagios","ganglia","mysql","cloudmaster","clmrs","octopus","cmagent","x86master","rabbitmq","cmgather","monitor","AlarmApp","autoAlarm","ceilometer","PerformancePM","notify"]
        if status== 1:
           ebs_rolelist=["notify","PerformancePM","ceilometer","autoAlarm","AlarmApp","monitor","cmgather","rabbitmq","x86master","cmagent","octopus","clmrs","cloudmaster","mysql","ganglia","nagios","redis","activemq","onecmdb","keepalived"]
        
        #获取当前集群下所有处于已就绪的节点
        nodes_to_startorstop=TaskHelper.nodes_to_startorstop(cluster)
        #获取所有节点的所有角色集合
        nodes_roles=[]
        for node in nodes_to_startorstop:
            nodes_roles.extend(node.roles)
        nodes_roles=list(set(nodes_roles))
        
        logger.info(deploymsg)
        for role in nodes_roles:
            if role in ebs_rolelist:
               task_deployment = supertask.create_subtask(TASK_NAMES.deployment)
               db().commit()
               newdeploymsg=copy.deepcopy(deploymsg)
               newdeploymsg['respond_to']="start_stop_resp"
               newdeploymsg['args']['task_uuid']=task_deployment.uuid
               deployment_infos=[]
               for deployment_info in deploymsg['args']['deployment_info']:
                   if deployment_info["role"] != role:
                      newdeploymsg['args']['deployment_info'].remove(deployment_info)
                   else:
                     if status == 2:
                        deployment_info[role]['action']="start"
                        logger.info(u"匹配到角色{0},节点id {1},开始启动...".format(role,deployment_info["ip"]))
                     else:
                        deployment_info[role]['action']="stop"
                        logger.info(u"匹配到角色{0},节点id {1},开始停止...".format(role,deployment_info["ip"]))
                     deployment_infos.append(deployment_info) 
               newdeploymsg['args']['deployment_info']=deployment_infos
               task_messages.append(newdeploymsg)
               task_deployment = objects.Task.get_by_uid(
                        task_deployment.id,
                        fail_if_not_found=True,
                        lock_for_update=True
                    )
               # if failed to generate task message for orchestrator
               # then task is already set to error
               if task_deployment.status == TASK_STATUSES.error:
                  return supertask

               task_deployment.cache = newdeploymsg
               db().commit()
               self.update_cluster_role_status(cluster,role,status)
        
        new_task_messages=[]
        logger.info(len(task_messages))
        for ebsrole in ebs_rolelist:
            for task in task_messages:
                if task['args']['deployment_info'][0]['role'] == ebsrole:
                   new_task_messages.append(task)
        return new_task_messages
开发者ID:yxh1990,项目名称:fuel-cloudmaster,代码行数:60,代码来源:cloudStartall.py

示例2: execute

# 需要导入模块: from nailgun.task.task import TaskHelper [as 别名]
# 或者: from nailgun.task.task.TaskHelper import nodes_to_startorstop [as 别名]

#.........这里部分代码省略.........
            # 完整的部署信息会导致集群启动和停止的失败(因为只发送给错误节点).
            logger.info(u"执行部署变更操作,开始操作cluster_deploy_msg表")
            data = {}
            data["cluster_id"] = self.cluster.id
            data["cluster_deploymsg"] = jsonutils.dumps(deployment_message)
            clusterdeploymsg = db().query(ClusterdeployMsg).filter_by(cluster_id=self.cluster.id).first()

            if clusterdeploymsg:
                if self.cluster.status == CLUSTER_STATUSES.new:
                    objects.ClusterdeployMsgObject.update(
                        clusterdeploymsg, {"cluster_deploymsg": data["cluster_deploymsg"]}
                    )
            else:
                objects.ClusterdeployMsgCollection.create(data)

            task_deployment = objects.Task.get_by_uid(task_deployment.id, fail_if_not_found=True, lock_for_update=True)
            # if failed to generate task message for orchestrator
            # then task is already set to error
            if task_deployment.status == TASK_STATUSES.error:
                return supertask

            task_deployment.cache = deployment_message
            db().commit()
            task_messages.append(deployment_message)
        else:
            pass
        if len(nodes_to_delete) <= 0 and len(nodes_to_deploy) <= 0:
            # 这里不能单纯用nodes_to_deploy是否为空来判断是启动或者停止
            # 因为nodes_to_delete不为空而nodes_to_deploy为空的话依然会
            # 执行下面的代码,此种情况程序会出现异常

            oprolename = web.cookies().get("oprolename")
            opaction = web.cookies().get("opaction")
            nodes_to_startorstop = TaskHelper.nodes_to_startorstop(self.cluster)
            if oprolename != "all":
                logger.info(u"这里执行的是单角色启动或者停止部署")
                task_deployment = supertask.create_subtask(TASK_NAMES.deployment)

                # we should have task committed for processing in other threads
                # openstack定制化环境点击部署变更和启动,停止按钮没有执行
                # 此程序,而是直接通过调用/opt/start.py执行
                # 目前只有cloudmaster和ebs环境会执行此处代码
                db().commit()

                deployment_message = self._call_silently(
                    task_deployment, tasks.DeploymentTask, nodes_to_startorstop, method_name="message"
                )
                deploymsg = deployment_message
                deploymsg["respond_to"] = "start_stop_resp"
                deploymsg["args"]["task_uuid"] = task_deployment.uuid
                # deployment_info[]是列表,这个列表中含有的元素都是字典
                # 角色下面的label参数就只是在此处添加和修改的.
                deployment_info_old_list = deploymsg["args"]["deployment_info"]
                deployment_info_list = []
                nodeuids = []
                for key, item in groupby(deployment_info_old_list, itemgetter("uid")):
                    nodeuids.append(key)

                deployment_info_list = deployment_info_old_list[0 : len(nodeuids)]
                # 此处删除和启动停止无关的角色信息
                deploymsg["args"]["deployment_info"] = []
                for i in range(len(deployment_info_list)):
                    deployment_info = deployment_info_list[i]
                    deployment_info["role"] = oprolename
                    deployment_info["uid"] = nodeuids[i]
                    deploymsg["args"]["deployment_info"].append(deployment_info)
开发者ID:yxh1990,项目名称:fuel-cloudmaster,代码行数:70,代码来源:manager.py


注:本文中的nailgun.task.task.TaskHelper.nodes_to_startorstop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。