本文整理汇总了Python中disco_aws_automation.DiscoAWS.remotecmd方法的典型用法代码示例。如果您正苦于以下问题:Python DiscoAWS.remotecmd方法的具体用法?Python DiscoAWS.remotecmd怎么用?Python DiscoAWS.remotecmd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类disco_aws_automation.DiscoAWS
的用法示例。
在下文中一共展示了DiscoAWS.remotecmd方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from disco_aws_automation import DiscoAWS [as 别名]
# 或者: from disco_aws_automation.DiscoAWS import remotecmd [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 == "create":
aws.disco_storage.create_ebs_snapshot(args.hostclass, args.size)
elif args.mode == "list":
for snapshot in aws.disco_storage.get_snapshots(args.hostclasses):
print("{0:26} {1:13} {2:9} {3} {4:4}".format(
snapshot.tags['hostclass'], snapshot.id, snapshot.status,
snapshot.start_time, snapshot.volume_size))
elif args.mode == "cleanup":
aws.disco_storage.cleanup_ebs_snapshots(args.keep)
elif args.mode == "capture":
instances = instances_from_args(aws, args)
if not instances:
logging.warning("No instances found")
for instance in instances:
return_code, output = aws.remotecmd(
instance, ["sudo /opt/wgen/bin/take_snapshot.sh"], user="snapshot")
if return_code:
raise Exception("Failed to snapshot instance {0}:\n {1}\n".format(instance, output))
logging.info("Successfully snapshotted %s", instance)
elif args.mode == "delete":
for snapshot_id in args.snapshots:
aws.disco_storage.delete_snapshot(snapshot_id)
elif args.mode == "update":
snapshot = aws.disco_storage.get_latest_snapshot(args.hostclass)
aws.autoscale.update_snapshot(args.hostclass, snapshot.id, snapshot.volume_size)
示例2: run
# 需要导入模块: from disco_aws_automation import DiscoAWS [as 别名]
# 或者: from disco_aws_automation.DiscoAWS import remotecmd [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 == "create":
product_line = aws.hostclass_option_default(args.hostclass, 'product_line', 'unknown')
aws.disco_storage.create_ebs_snapshot(args.hostclass, args.size, product_line, not args.unencrypted)
elif args.mode == "list":
for snapshot in aws.disco_storage.get_snapshots(args.hostclasses):
print("{0:26} {1:13} {2:9} {3} {4:4}".format(
snapshot.tags['hostclass'], snapshot.id, snapshot.status,
snapshot.start_time, snapshot.volume_size))
elif args.mode == "cleanup":
aws.disco_storage.cleanup_ebs_snapshots(args.keep)
elif args.mode == "capture":
if args.volume_id:
extra_snapshot_tags = None
if args.tags:
extra_snapshot_tags = dict(tag_item.split(':') for tag_item in args.tags)
snapshot_id = aws.disco_storage.take_snapshot(args.volume_id, snapshot_tags=extra_snapshot_tags)
print("Successfully created snapshot: {0}".format(snapshot_id))
else:
instances = instances_from_args(aws, args)
if not instances:
print("No instances found")
for instance in instances:
return_code, output = aws.remotecmd(
instance, ["sudo /opt/wgen/bin/take_snapshot.sh"], user="snapshot")
if return_code:
raise Exception("Failed to snapshot instance {0}:\n {1}\n".format(instance, output))
print("Successfully snapshotted {0}".format(instance))
elif args.mode == "delete":
for snapshot_id in args.snapshots:
aws.disco_storage.delete_snapshot(snapshot_id)
elif args.mode == "update":
if args.snapshot_id:
snapshot = aws.disco_storage.get_snapshot_from_id(args.snapshot_id)
else:
snapshot = aws.disco_storage.get_latest_snapshot(args.hostclass)
aws.discogroup.update_snapshot(snapshot.id, snapshot.volume_size, hostclass=args.hostclass)
示例3: run
# 需要导入模块: from disco_aws_automation import DiscoAWS [as 别名]
# 或者: from disco_aws_automation.DiscoAWS import remotecmd [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):
#.........这里部分代码省略.........