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


Python DiscoAWS.instances方法代码示例

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


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

示例1: test_instances_from_amis

# 需要导入模块: from disco_aws_automation import DiscoAWS [as 别名]
# 或者: from disco_aws_automation.DiscoAWS import instances [as 别名]
 def test_instances_from_amis(self, mock_config, **kwargs):
     '''test get instances using ami ids '''
     aws = DiscoAWS(config=mock_config, environment_name=TEST_ENV_NAME)
     instance = create_autospec(boto.ec2.instance.Instance)
     instance.id = "i-123123aa"
     instances = [instance]
     aws.instances = MagicMock(return_value=instances)
     self.assertEqual(aws.instances_from_amis('ami-12345678'), instances)
     aws.instances.assert_called_with(filters={"image_id": 'ami-12345678'}, instance_ids=None)
开发者ID:amplifylitco,项目名称:asiaq,代码行数:11,代码来源:test_disco_aws.py

示例2: test_instances_from_amis_with_group_name

# 需要导入模块: from disco_aws_automation import DiscoAWS [as 别名]
# 或者: from disco_aws_automation.DiscoAWS import instances [as 别名]
 def test_instances_from_amis_with_group_name(self, mock_config, **kwargs):
     '''test get instances using ami ids in a specified group name'''
     aws = DiscoAWS(config=mock_config, environment_name=TEST_ENV_NAME)
     instance = create_autospec(boto.ec2.instance.Instance)
     instance.id = "i-123123aa"
     instances = [instance]
     aws.instances_from_asgs = MagicMock(return_value=instances)
     aws.instances = MagicMock(return_value=instances)
     self.assertEqual(aws.instances_from_amis('ami-12345678', group_name='test_group'), instances)
     aws.instances_from_asgs.assert_called_with(['test_group'])
开发者ID:amplifylitco,项目名称:asiaq,代码行数:12,代码来源:test_disco_aws.py

示例3: test_instances_from_amis_with_launch_date

# 需要导入模块: from disco_aws_automation import DiscoAWS [as 别名]
# 或者: from disco_aws_automation.DiscoAWS import instances [as 别名]
    def test_instances_from_amis_with_launch_date(self, mock_config, **kwargs):
        '''test get instances using ami ids and with date after a specified date time'''
        aws = DiscoAWS(config=mock_config, environment_name=TEST_ENV_NAME)
        now = datetime.utcnow()

        instance1 = create_autospec(boto.ec2.instance.Instance)
        instance1.id = "i-123123aa"
        instance1.launch_time = str(now + timedelta(minutes=10))
        instance2 = create_autospec(boto.ec2.instance.Instance)
        instance2.id = "i-123123ff"
        instance2.launch_time = str(now - timedelta(days=1))
        instances = [instance1, instance2]

        aws.instances = MagicMock(return_value=instances)
        self.assertEqual(aws.instances_from_amis('ami-12345678', launch_time=now),
                         [instance1])
        aws.instances.assert_called_with(filters={"image_id": 'ami-12345678'}, instance_ids=None)
开发者ID:amplifylitco,项目名称:asiaq,代码行数:19,代码来源:test_disco_aws.py

示例4: run

# 需要导入模块: from disco_aws_automation import DiscoAWS [as 别名]
# 或者: from disco_aws_automation.DiscoAWS import instances [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.instances方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。