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


Python DiscoAWS.stop方法代码示例

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


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

示例1: run

# 需要导入模块: from disco_aws_automation import DiscoAWS [as 别名]
# 或者: from disco_aws_automation.DiscoAWS import stop [as 别名]
def run():
    """Parses command line and dispatches the commands"""
    config = read_config()

    parser = get_parser()
    args = parser.parse_args()
    configure_logging(args.debug)

    environment_name = args.env or config.get("disco_aws", "default_environment")

    aws = DiscoAWS(config, environment_name=environment_name)
    if args.mode == "provision":
        hostclass_dicts = [{
            "sequence": 1,
            "hostclass": args.hostclass,
            "instance_type": args.instance_type,
            "extra_space": args.extra_space,
            "extra_disk": args.extra_disk,
            "iops": args.iops,
            "smoke_test": "no" if args.no_smoke else "yes",
            "ami": args.ami,
            "min_size": args.min_size,
            "desired_size": args.desired_size,
            "max_size": args.max_size,
            "chaos": "no" if args.no_chaos else None,
            "spotinst": args.spotinst,
            "spotinst_reserve": args.spotinst_reserve
        }]
        aws.spinup(hostclass_dicts, testing=args.testing)
    elif args.mode == "listhosts":
        instances = aws.instances_from_hostclass(args.hostclass) if args.hostclass else aws.instances()
        instances_filtered = [i for i in instances if i.state != u"terminated"]
        instances_sorted = sorted(instances_filtered, key=lambda i: (i.state, i.tags.get("hostclass", "-"),
                                                                     i.tags.get("hostname", "-")))
        instance_to_private_ip = {i.id: get_preferred_private_ip(i) for i in instances_sorted}
        most = args.all or args.most

        if args.ami_age or args.uptime or most:
            bake = DiscoBake(config, aws.connection)
            ami_dict = bake.list_amis_by_instance(instances)
            now = datetime.utcnow()

        for instance in instances_sorted:
            line = u"{0} {1:<30} {2:<15}".format(
                instance.id, instance.tags.get("hostclass", "-"),
                instance.ip_address or instance_to_private_ip[instance.id])
            if args.state or most:
                line += u" {0:<10}".format(instance.state)
            if args.hostname or most:
                line += u" {0:<1}".format("-" if instance.tags.get("hostname") is None else "y")
            if args.owner or most:
                line += u" {0:<11}".format(instance.tags.get("owner", u"-"))
            if args.instance_type or most:
                line += u" {0:<10}".format(instance.instance_type)
            if args.ami or most:
                line += u" {0:<12}".format(instance.image_id)
            if args.smoke or most:
                line += u" {0:<1}".format("-" if instance.tags.get("smoketest") is None else "y")
            if args.ami_age or most:
                creation_time = bake.get_ami_creation_time(ami_dict.get(instance.id))
                line += u" {0:<4}".format(DiscoBake.time_diff_in_hours(now, creation_time))
            if args.uptime or most:
                launch_time = dateutil_parser.parse(instance.launch_time)
                now_with_tz = now.replace(tzinfo=launch_time.tzinfo)  # use a timezone-aware `now`
                line += u" {0:<3}".format(DiscoBake.time_diff_in_hours(now_with_tz, launch_time))
            if args.private_ip or args.all:
                line += u" {0:<16}".format(instance_to_private_ip[instance.id])
            if args.availability_zone or args.all:
                line += u" {0:<12}".format(instance.placement)
            if args.productline or args.all:
                productline = instance.tags.get("productline", u"unknown")
                line += u" {0:<15}".format(productline if productline != u"unknown" else u"-")
            if args.securitygroup or args.all:
                line += u" {0:15}".format(instance.groups[0].name)
            print(line)

    elif args.mode == "terminate":
        instances = instances_from_args(aws, args)
        terminated_instances = aws.terminate(instances)
        print("Terminated: {0}".format(",".join([str(inst) for inst in terminated_instances])))
    elif args.mode == "stop":
        instances = instances_from_args(aws, args)
        stopped_instances = aws.stop(instances)
        print("Stopped: {0}".format(",".join([str(inst) for inst in stopped_instances])))
    elif args.mode == "exec":
        instances = instances_from_args(aws, args)
        exit_code = 0
        for instance in instances:
            _code, _stdout = aws.remotecmd(instance, [args.command], user=args.user, nothrow=True)
            sys.stdout.write(_stdout)
            exit_code = _code if _code else exit_code
        sys.exit(exit_code)
    elif args.mode == "exec-ssm":
        ssm = DiscoSSM(environment_name)
        if args.parameters:
            parsed_parameters = parse_ssm_parameters(args.parameters)
        else:
            parsed_parameters = None
        instances = [instance.id for instance in instances_from_args(aws, args)]
        if ssm.execute(instances, args.document, parameters=parsed_parameters, comment=args.comment):
#.........这里部分代码省略.........
开发者ID:amplifylitco,项目名称:asiaq,代码行数:103,代码来源:disco_aws.py


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