def main():
    logging.basicConfig(format="%(asctime)s - %(levelname)s - %(message)s")
    log.setLevel(logging.INFO)

    parser = argparse.ArgumentParser()
    parser.add_argument("-f",
                        "--from-region",
                        required=True,
                        help="Region to copy from")
    parser.add_argument("-t",
                        "--to-region",
                        action="append",
                        required=True,
                        dest="to_regions",
                        help="Regions to copy to")
    parser.add_argument("moz_instance_types",
                        metavar="moz_type",
                        nargs="+",
                        help="moz_instance_types to be copied")
    args = parser.parse_args()

    amis_to_copy = [
        get_ami(region=args.from_region, moz_instance_type=t)
        for t in args.moz_instance_types
    ]
    for ami in amis_to_copy:
        for r in args.to_regions:
            log.info("Copying %s (%s) to %s", ami.id, ami.tags.get("Name"), r)
            new_ami = copy_ami(ami, r)
            log.info("New AMI created. AMI ID: %s", new_ami.id)
예제 #2
0
def main():
    logging.basicConfig(format="%(asctime)s - %(levelname)s - %(message)s")
    log.setLevel(logging.INFO)

    parser = argparse.ArgumentParser()
    parser.add_argument("-f", "--from-region", required=True,
                        help="Region to copy from")
    parser.add_argument("-t", "--to-region", action="append", required=True,
                        dest="to_regions", help="Regions to copy to")
    parser.add_argument("moz_instance_types", metavar="moz_type", nargs="+",
                        help="moz_instance_types to be copied")
    args = parser.parse_args()

    amis_to_copy = [get_ami(region=args.from_region, moz_instance_type=t)
                    for t in args.moz_instance_types]
    for ami in amis_to_copy:
        for r in args.to_regions:
            log.info("Copying %s (%s) to %s", ami.id, ami.tags.get("Name"), r)
            new_ami = copy_ami(ami, r)
            log.info("New AMI created. AMI ID: %s", new_ami.id)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-c",
                        "--config",
                        required=True,
                        type=argparse.FileType('r'),
                        help="instance configuration to use")
    parser.add_argument("-r",
                        "--region",
                        help="region to use",
                        default="us-east-1")
    parser.add_argument("-k",
                        "--secrets",
                        type=argparse.FileType('r'),
                        required=True,
                        help="file where secrets can be found")
    parser.add_argument("-s", "--key-name", help="SSH key name", required=True)
    parser.add_argument("--ssh-key",
                        required=True,
                        help="SSH key to be used by Fabric")
    parser.add_argument("-i",
                        "--instance-data",
                        help="instance specific data",
                        type=argparse.FileType('r'),
                        required=True)
    parser.add_argument("--no-verify",
                        action="store_true",
                        help="Skip DNS related checks")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_const",
                        dest="log_level",
                        const=logging.DEBUG,
                        default=logging.INFO,
                        help="Increase logging verbosity")
    parser.add_argument("-l", "--loaned-to", help="Loaner contact e-mail")
    parser.add_argument("-b", "--bug", help="Loaner bug number")
    parser.add_argument("hosts",
                        metavar="host",
                        nargs="+",
                        help="hosts to be processed")
    parser.add_argument("--create-ami",
                        action="store_true",
                        help="Generate AMI and terminate the instance")
    parser.add_argument("--ignore-subnet-check",
                        action="store_true",
                        help="Do not check subnet IDs")
    parser.add_argument("-t",
                        "--copy-to-region",
                        action="append",
                        default=[],
                        dest="copy_to_regions",
                        help="Regions to copy AMI to")
    parser.add_argument(
        "--max-attempts",
        help="The number of attempts to try after each failure")

    args = parser.parse_args()

    logging.basicConfig(format="%(asctime)s - %(levelname)s - %(message)s",
                        level=args.log_level)

    try:
        config = json.load(args.config)[args.region]
    except KeyError:
        parser.error("unknown configuration")
    if not os.path.exists(args.ssh_key):
        parser.error("Cannot read %s" % args.ssh_key)

    secrets = json.load(args.secrets)
    deploypass = secrets["deploy_password"]

    instance_data = json.load(args.instance_data)
    if not args.no_verify:
        log.info("Sanity checking DNS entries...")
        verify(args.hosts, config, args.region, args.ignore_subnet_check)
    make_instances(names=args.hosts,
                   config=config,
                   region=args.region,
                   key_name=args.key_name,
                   ssh_key=args.ssh_key,
                   instance_data=instance_data,
                   deploypass=deploypass,
                   loaned_to=args.loaned_to,
                   loan_bug=args.bug,
                   create_ami=args.create_ami,
                   ignore_subnet_check=args.ignore_subnet_check,
                   max_attempts=args.max_attempts)
    for r in args.copy_to_regions:
        ami = get_ami(region=args.region, moz_instance_type=config["type"])
        log.info("Copying %s (%s) to %s", ami.id, ami.tags.get("Name"), r)
        new_ami = copy_ami(ami, r)
        log.info("New AMI created. AMI ID: %s", new_ami.id)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-c", "--config", required=True,
                        type=argparse.FileType('r'),
                        help="instance configuration to use")
    parser.add_argument("-r", "--region", help="region to use",
                        default="us-east-1")
    parser.add_argument("-k", "--secrets", type=argparse.FileType('r'),
                        required=True, help="file where secrets can be found")
    parser.add_argument("-s", "--key-name", help="SSH key name", required=True)
    parser.add_argument("--ssh-key", required=True,
                        help="SSH key to be used by Fabric")
    parser.add_argument("-i", "--instance-data", help="instance specific data",
                        type=argparse.FileType('r'), required=True)
    parser.add_argument("--no-verify", action="store_true",
                        help="Skip DNS related checks")
    parser.add_argument("-v", "--verbose", action="store_const",
                        dest="log_level", const=logging.DEBUG,
                        default=logging.INFO,
                        help="Increase logging verbosity")
    parser.add_argument("-l", "--loaned-to", help="Loaner contact e-mail")
    parser.add_argument("-b", "--bug", help="Loaner bug number")
    parser.add_argument("hosts", metavar="host", nargs="+",
                        help="hosts to be processed")
    parser.add_argument("--create-ami", action="store_true",
                        help="Generate AMI and terminate the instance")
    parser.add_argument("--ignore-subnet-check", action="store_true",
                        help="Do not check subnet IDs")
    parser.add_argument("-t", "--copy-to-region", action="append", default=[],
                        dest="copy_to_regions", help="Regions to copy AMI to")
    parser.add_argument("--max-attempts",
                        help="The number of attempts to try after each failure"
                        )

    args = parser.parse_args()

    logging.basicConfig(format="%(asctime)s - %(levelname)s - %(message)s",
                        level=args.log_level)

    try:
        config = json.load(args.config)[args.region]
    except KeyError:
        parser.error("unknown configuration")
    if not os.path.exists(args.ssh_key):
        parser.error("Cannot read %s" % args.ssh_key)

    secrets = json.load(args.secrets)
    deploypass = secrets["deploy_password"]

    instance_data = json.load(args.instance_data)
    if not args.no_verify:
        log.info("Sanity checking DNS entries...")
        verify(args.hosts, config, args.region, args.ignore_subnet_check)
    make_instances(names=args.hosts, config=config, region=args.region,
                   key_name=args.key_name, ssh_key=args.ssh_key,
                   instance_data=instance_data, deploypass=deploypass,
                   loaned_to=args.loaned_to, loan_bug=args.bug,
                   create_ami=args.create_ami,
                   ignore_subnet_check=args.ignore_subnet_check,
                   max_attempts=args.max_attempts)
    for r in args.copy_to_regions:
        ami = get_ami(region=args.region, moz_instance_type=config["type"])
        log.info("Copying %s (%s) to %s", ami.id, ami.tags.get("Name"), r)
        new_ami = copy_ami(ami, r)
        log.info("New AMI created. AMI ID: %s", new_ami.id)
def main():
    parser = argparse.ArgumentParser()
    parser.set_defaults(
        region="us-west-1",
        key_name=None,
    )
    parser.add_argument("-c", "--config", required=True,
                        help="instance configuration to use")
    parser.add_argument("-r", "--region", help="region to use",
                        default="us-east-1")
    parser.add_argument("--ssh-key", help="SSH key file", required=True)
    parser.add_argument("--key-name", help="SSH key name", required=True)
    parser.add_argument('--keep-volume', action='store_true',
                        help="Don't delete target volume")
    parser.add_argument('--keep-host-instance', action='store_true',
                        help="Don't delete host instance")
    parser.add_argument('--user', default='root')
    parser.add_argument('--puppetize', action="store_true",
                        help="Puppetize the AMI")
    parser.add_argument('--instance-config', type=argparse.FileType('r'),
                        help="Path to instance config file")
    parser.add_argument('--instance-data', type=argparse.FileType('r'),
                        help="Path to instance data file")
    parser.add_argument('--secrets', type=argparse.FileType('r'),
                        help="Path to secrets file")
    parser.add_argument('--certificate',
                        help="Path to AMI encryptiion certificate")
    parser.add_argument('--pkey',
                        help="Path to AMI encryptiion privte key")
    parser.add_argument('--ami-name-prefix', help="AMI name prefix")
    parser.add_argument("-t", "--copy-to-region", action="append", default=[],
                        dest="copy_to_regions", help="Regions to copy AMI to")
    parser.add_argument("-v", "--verbose", action="store_const",
                        default=logging.INFO, const=logging.DEBUG,
                        dest="log_level", help="Verbose logging")
    parser.add_argument("host", metavar="host", nargs=1,
                        help="Temporary hostname")

    args = parser.parse_args()

    logging.basicConfig(level=args.log_level)
    logging.getLogger("boto").setLevel(logging.INFO)
    logging.getLogger("paramiko").setLevel(logging.INFO)
    instance_config = None
    instance_data = None
    deploypass = None
    dns_required = False

    try:
        ami_config = json.load(open("%s/%s.json" % (AMI_CONFIGS_DIR,
                                                    args.config)))[args.region]
        if args.instance_config:
            instance_config = json.load(args.instance_config)[args.region]
        if args.instance_data:
            instance_data = json.load(args.instance_data)
        if args.secrets:
            deploypass = json.load(args.secrets)["deploy_password"]

    except KeyError:
        parser.error("unknown configuration")
        raise
    except IOError:
        parser.error("Cannot read")
        raise

    if args.puppetize:
        dns_required = True
        for attr in ("instance_config", "instance_data", "secrets"):
            if not getattr(args, attr):
                parser.error("{} is required for puppetizing AMIs".format(attr))
        if ami_config.get("root_device_type") == "instance-store":
            for attr in ("certificate", "pkey"):
                if not getattr(args, attr):
                    parser.error(
                        "{} is required for S3-backed AMIs".format(attr))

    host_instance = run_instance(region=args.region, hostname=args.host[0],
                                 config=ami_config, key_name=args.key_name,
                                 user=args.user, key_filename=args.ssh_key,
                                 dns_required=dns_required)
    ami = create_ami(host_instance=host_instance, args=args, config=ami_config,
                     instance_config=instance_config, ssh_key=args.key_name,
                     instance_data=instance_data, deploypass=deploypass,
                     cert=args.certificate, pkey=args.pkey,
                     ami_name_prefix=args.ami_name_prefix,
                     key_filename=args.ssh_key)

    for r in args.copy_to_regions:
        log.info("Copying %s (%s) to %s", ami.id, ami.tags.get("Name"), r)
        new_ami = copy_ami(ami, r)
        log.info("New AMI created. AMI ID: %s", new_ami.id)
예제 #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.set_defaults(
        region="us-west-1",
        key_name=None,
    )
    parser.add_argument("-c", "--config", required=True,
                        help="instance configuration to use")
    parser.add_argument("-r", "--region", help="region to use",
                        default="us-east-1")
    parser.add_argument("--ssh-key", help="SSH key file", required=True)
    parser.add_argument("--key-name", help="SSH key name", required=True)
    parser.add_argument('--keep-volume', action='store_true',
                        help="Don't delete target volume")
    parser.add_argument('--keep-host-instance', action='store_true',
                        help="Don't delete host instance")
    parser.add_argument('--user', default='root')
    parser.add_argument('--puppetize', action="store_true",
                        help="Puppetize the AMI")
    parser.add_argument('--instance-config', type=argparse.FileType('r'),
                        help="Path to instance config file")
    parser.add_argument('--instance-data', type=argparse.FileType('r'),
                        help="Path to instance data file")
    parser.add_argument('--secrets', type=argparse.FileType('r'),
                        help="Path to secrets file")
    parser.add_argument('--certificate',
                        help="Path to AMI encryptiion certificate")
    parser.add_argument('--pkey',
                        help="Path to AMI encryptiion privte key")
    parser.add_argument('--ami-name-prefix', help="AMI name prefix")
    parser.add_argument("-t", "--copy-to-region", action="append", default=[],
                        dest="copy_to_regions", help="Regions to copy AMI to")
    parser.add_argument("-v", "--verbose", action="store_const",
                        default=logging.INFO, const=logging.DEBUG,
                        dest="log_level", help="Verbose logging")
    parser.add_argument("host", metavar="host", nargs=1,
                        help="Temporary hostname")

    args = parser.parse_args()

    logging.basicConfig(level=args.log_level)
    logging.getLogger("boto").setLevel(logging.INFO)
    logging.getLogger("paramiko").setLevel(logging.INFO)
    instance_config = None
    instance_data = None
    deploypass = None
    dns_required = False

    try:
        ami_config = json.load(open("%s/%s.json" % (AMI_CONFIGS_DIR,
                                                    args.config)))[args.region]
        if args.instance_config:
            instance_config = json.load(args.instance_config)[args.region]
        if args.instance_data:
            instance_data = json.load(args.instance_data)
        if args.secrets:
            deploypass = json.load(args.secrets)["deploy_password"]

    except KeyError:
        parser.error("unknown configuration")
        raise
    except IOError:
        parser.error("Cannot read")
        raise

    if args.puppetize:
        dns_required = True
        for attr in ("instance_config", "instance_data", "secrets"):
            if not getattr(args, attr):
                parser.error("{} is required for puppetizing AMIs".format(attr))
        if ami_config.get("root_device_type") == "instance-store":
            for attr in ("certificate", "pkey"):
                if not getattr(args, attr):
                    parser.error(
                        "{} is required for S3-backed AMIs".format(attr))

    host_instance = run_instance(region=args.region, hostname=args.host[0],
                                 config=ami_config, key_name=args.key_name,
                                 user=args.user, key_filename=args.ssh_key,
                                 dns_required=dns_required)
    ami = create_ami(host_instance=host_instance, args=args, config=ami_config,
                     instance_config=instance_config, ssh_key=args.key_name,
                     instance_data=instance_data, deploypass=deploypass,
                     cert=args.certificate, pkey=args.pkey,
                     ami_name_prefix=args.ami_name_prefix,
                     key_filename=args.ssh_key)

    for r in args.copy_to_regions:
        log.info("Copying %s (%s) to %s", ami.id, ami.tags.get("Name"), r)
        new_ami = copy_ami(ami, r)
        log.info("New AMI created. AMI ID: %s", new_ami.id)