From f0f253f14212e1658f62b3da68e854a6c65e137c Mon Sep 17 00:00:00 2001 From: Nicolas Vanheuverzwijn Date: Thu, 28 Nov 2019 17:00:33 -0500 Subject: [PATCH 1/4] doc: make sure we include physics term as well as electronic part in the release names --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eccfc25..9aca54a 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,6 @@ git checkout master && git branch -D 1.0.1 && git checkout 1.0.1 ``` Once the tag is pushed, reach the [release page](https://github.com/kronostechnologies/aws-snapshot-recovery/releases) via github and click "draft a new release". 1. Use the newly created tag (1.0.1 in this example) as the new version. -2. The release title should be related to electronic parts. major version (2.0.0, 3.0.0, etc.) must have one word title e.g. "Diodes". Minor and Patch version must have two word with the first word being the major release version title e.g. Diodes Gunn. Second word must be related to first word electronic part. +2. The release title should be related to electronic parts or physics in general. Major version (2.0.0, 3.0.0, etc.) must have one word title e.g. "Diodes". Minor and Patch version must have two word with the first word being the major release version title e.g. Diodes Gunn. Second word must be related to first word electronic part. 3. Describe what is in the new release 4. Add two binaries: `bin/aws-snapshot-recovery` and `bin/docker-aws-snapshot-recovery`. Make sure you are using the binary of the new version by checkouting the newly created tag (`git checkout 1.0.1`). From ddbf5ae6cbbe2be8e4e473e1f7df0451fbed5038 Mon Sep 17 00:00:00 2001 From: Nicolas Vanheuverzwijn Date: Tue, 24 Mar 2020 17:53:35 -0400 Subject: [PATCH 2/4] log: ssh login example with private key instead of public key --- bin/aws-snapshot-recovery | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/aws-snapshot-recovery b/bin/aws-snapshot-recovery index d82afb5..b997c31 100755 --- a/bin/aws-snapshot-recovery +++ b/bin/aws-snapshot-recovery @@ -242,7 +242,7 @@ if args.recover: instance = aws_ec2.describe_instances(InstanceIds=[instance['InstanceId']])['Reservations'][0]['Instances'][0] logging.debug('printing out login information') - print('you can login with: "ssh admin@{ip} -i {key}"'.format(ip=instance['PublicIpAddress'], key=config['ssh_public_key'])) + print('you can login with: "ssh admin@{ip} -i {key}"'.format(ip=instance['PublicIpAddress'], key=config['ssh_private_key'])) print('kill this script (ctrl+c) to terminate gracefully') if config['ssh_command']: print('executing ssh command "{cmd}"'.format(cmd=config['ssh_command'])) From 19c1382bfc8d3f3f957b7437cf4267607811e1e0 Mon Sep 17 00:00:00 2001 From: Nicolas Vanheuverzwijn Date: Tue, 24 Mar 2020 17:54:32 -0400 Subject: [PATCH 3/4] requirements: update pyyaml, botocore and pexpect --- bin/aws-snapshot-recovery | 4 ++-- requirements | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/aws-snapshot-recovery b/bin/aws-snapshot-recovery index b997c31..5458f46 100755 --- a/bin/aws-snapshot-recovery +++ b/bin/aws-snapshot-recovery @@ -12,7 +12,7 @@ import logging import getpass import time import signal -import pxssh +from pexpect import pxssh config = { 'aws_profile': 'default', @@ -51,7 +51,7 @@ def parse_configuration_file(config): configpath = pathlib.PosixPath('~/.config/aws-snapshot-recovery.yaml').expanduser() if configpath.exists(): with configpath.open() as stream: - config.update(yaml.load(stream)) + config.update(yaml.full_load(stream)) logging.debug('configuration file "{}" exist and has been parsed'.format(configpath)) else: logging.info('configuration file "{}" does not exist'.format(configpath)) diff --git a/requirements b/requirements index cfae003..6a15857 100644 --- a/requirements +++ b/requirements @@ -1,3 +1,3 @@ -boto3==1.9.64 -PyYAML==3.13 -pexpect==4.2 +boto3==1.12.28 +PyYAML==5.3.1 +pexpect==4.8 From a7e9f27e7b175a5e418cf53442bd2441e5a57ce6 Mon Sep 17 00:00:00 2001 From: Nicolas Vanheuverzwijn Date: Tue, 24 Mar 2020 17:56:12 -0400 Subject: [PATCH 4/4] feat: allow multiple options for ec2-security-group-id --- README.md | 4 ++-- bin/aws-snapshot-recovery | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9aca54a..5a01d2e 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ optional arguments: set the tag key to use when filtering with --name --filter-date-tagkey TAGNAME set the tag key to use when filtering with --date - --ec2-security-group-id ID + --ec2-security-group-id ID [ID ...] set the ec2 security group id --ec2-subnet-id ID set the ec2 subnet id --ec2-instance-type TYPE @@ -67,7 +67,7 @@ Define the ssh command to execute as soon as the ec2 is ready. When the command #### AWS_SNAPSHOT_RECOVERY_EC2_SECURITY_GROUP_ID Define the security group id. Default is the "default" security group. #### AWS_SNAPSHOT_RECOVERY_EC2_SUBNET_ID -Define the ec2 subnet id. Default will use the default subnet of the default vpc. +Define the ec2 subnet id. Can specify multiple value e.g. `sg-4391,sg-2184`. Default will use the default subnet of the default vpc. #### AWS_SNAPSHOT_RECOVERY_EC2_INSTANCE_TYPE Define the ec2 instance type. Default is "t2.micro". diff --git a/bin/aws-snapshot-recovery b/bin/aws-snapshot-recovery index 5458f46..147a1e8 100755 --- a/bin/aws-snapshot-recovery +++ b/bin/aws-snapshot-recovery @@ -21,7 +21,7 @@ config = { 'ssh_public_key': '/home/{0}/.ssh/{0}.pem.pub'.format(getpass.getuser()), 'ssh_private_key': '/home/{0}/.ssh/{0}.pem'.format(getpass.getuser()), 'ssh_command': False, - 'ec2_security_group_id': '', + 'ec2_security_group_id': [], 'ec2_subnet_id': '', 'ec2_instance_type': 't3.micro' } @@ -36,7 +36,7 @@ def parse_args(): parser.add_argument('--debug', action='store_true', help='greatly increase output verbosity') parser.add_argument('--filter-name-tagkey', metavar="TAGNAME", help='set the tag key to use when filtering with --name') parser.add_argument('--filter-date-tagkey', metavar="TAGNAME", help='set the tag key to use when filtering with --date') - parser.add_argument('--ec2-security-group-id', metavar="ID", help='set the ec2 security group id') + parser.add_argument('--ec2-security-group-id', metavar="ID", nargs='+', help='set the ec2 security group id') parser.add_argument('--ec2-subnet-id', metavar="ID", help='set the ec2 subnet id') parser.add_argument('--ec2-instance-type', metavar="TYPE", help='set the ec2 instance type') parser.add_argument('--ssh-public-key', metavar="PUBLIC_KEY", help='specify the ssh public key to use for login') @@ -60,17 +60,19 @@ def parse_configuration_file(config): def parse_configuration_environment(config): logging.debug('parsing environment variables') - def merge_environ_into_config(environment_variable, config_key): + def merge_environ_into_config(environment_variable, config_key, split = False): if environment_variable in os.environ: logging.debug('environment variable "{}" is set and will be used'.format(environment_variable)) config[config_key] = os.environ[environment_variable] + if split: + config[config_key] = config[config_key].split(split) merge_environ_into_config('AWS_SNAPSHOT_RECOVERY_FILTER_DATE_TAGKEY', 'filter_date_tagkey') merge_environ_into_config('AWS_SNAPSHOT_RECOVERY_FILTER_NAME_TAGKEY', 'filter_name_tagkey') merge_environ_into_config('AWS_SNAPSHOT_RECOVERY_SSH_PUBLIC_KEY', 'ssh_public_key') merge_environ_into_config('AWS_SNAPSHOT_RECOVERY_SSH_PRIVATE_KEY', 'ssh_private_key') merge_environ_into_config('AWS_SNAPSHOT_RECOVERY_SSH_COMMAND', 'ssh_command') - merge_environ_into_config('AWS_SNAPSHOT_RECOVERY_EC2_SECURITY_GROUP_ID', 'ec2_security_group_id') + merge_environ_into_config('AWS_SNAPSHOT_RECOVERY_EC2_SECURITY_GROUP_ID', 'ec2_security_group_id', ',') merge_environ_into_config('AWS_SNAPSHOT_RECOVERY_EC2_SUBNET_ID', 'ec2_subnet_id') merge_environ_into_config('AWS_SNAPSHOT_RECOVERY_EC2_INSTANCE_TYPE', 'ec2_instance_type') merge_environ_into_config('AWS_PROFILE', 'aws_profile') @@ -137,7 +139,7 @@ def create_instance(snapshot, ssh_public_key_content): instances = aws_ec2.run_instances( DisableApiTermination=False, InstanceInitiatedShutdownBehavior='terminate', - SecurityGroupIds=[config['ec2_security_group_id']] if config['ec2_security_group_id'] else [], + SecurityGroupIds=config['ec2_security_group_id'] if config['ec2_security_group_id'] else [], SubnetId=config['ec2_subnet_id'] if config['ec2_subnet_id'] else '', BlockDeviceMappings=[ {