Skip to content

Commit

Permalink
Merge branch 'master' into 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nvanheuverzwijn committed Mar 24, 2020
2 parents 5eb71a1 + a7e9f27 commit 6847a2b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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".

Expand Down Expand Up @@ -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`).
18 changes: 10 additions & 8 deletions bin/aws-snapshot-recovery
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import logging
import getpass
import time
import signal
import pxssh
from pexpect import pxssh

config = {
'aws_profile': 'default',
Expand All @@ -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'
}
Expand All @@ -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')
Expand All @@ -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))
Expand All @@ -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')
Expand Down Expand Up @@ -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=[
{
Expand Down Expand Up @@ -242,7 +244,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']))
Expand Down
6 changes: 3 additions & 3 deletions requirements
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6847a2b

Please sign in to comment.