mirror of
https://github.com/nmasur/dotfiles
synced 2025-07-05 22:00:14 +00:00
reset git history
This commit is contained in:
16
bin/connect_aws/Dockerfile
Normal file
16
bin/connect_aws/Dockerfile
Normal file
@ -0,0 +1,16 @@
|
||||
FROM alpine:latest
|
||||
|
||||
COPY requirements.txt /
|
||||
|
||||
RUN apk update && \
|
||||
apk add \
|
||||
openssh \
|
||||
python \
|
||||
py-pip \
|
||||
&& \
|
||||
pip install -r requirements.txt
|
||||
|
||||
COPY connect_cloud.sh /
|
||||
COPY connect_cloud.py /
|
||||
|
||||
ENTRYPOINT ["/connect_cloud.sh"]
|
85
bin/connect_aws/connect_cloud.py
Executable file
85
bin/connect_aws/connect_cloud.py
Executable file
@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""Connect to Cloud instances"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
import boto3
|
||||
|
||||
# Initiate the parser
|
||||
parser = argparse.ArgumentParser("Type the name of the connection you want")
|
||||
parser.add_argument('profile', metavar='P', nargs='?',
|
||||
help='an account to use')
|
||||
parser.add_argument('environment', metavar='E', nargs='?',
|
||||
help='an environment to specify')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Get AWS credentials profile
|
||||
profile_map = {
|
||||
'gs' : {
|
||||
'profile': 'ghoststory',
|
||||
'prod': 'id_rsa_gstory_prod.pem',
|
||||
'dev': 'id_rsa_gstory_prod.pem',
|
||||
'username': 'centos',
|
||||
},
|
||||
'di' : {
|
||||
'profile': 't2indies',
|
||||
'prod': 'disintegration-prod.pem',
|
||||
'dev': 'disintegration-dev.pem',
|
||||
'username': 'centos',
|
||||
},
|
||||
'pd' : {
|
||||
'profile': 't2indies',
|
||||
'prod': 't2indies-prod.pem',
|
||||
'dev': 't2indies-dev.pem',
|
||||
'username': 'centos',
|
||||
},
|
||||
'corp' : {
|
||||
'profile': 't2corp',
|
||||
'prod': 'take2games-corp.pem',
|
||||
'dev': 'take2games-corp.pem',
|
||||
'username': 'ec2-user',
|
||||
},
|
||||
'ksp' : {
|
||||
'profile': 'kerbal',
|
||||
'prod': 'kerbal_prod_key.pem',
|
||||
'dev': 'kerbal_dev_key.pem',
|
||||
'username': 'centos',
|
||||
},
|
||||
}
|
||||
profile_dict = profile_map.get(args.profile)
|
||||
profile = profile_dict['profile']
|
||||
|
||||
# Connect to AWS
|
||||
session = boto3.Session(profile_name=profile)
|
||||
client = session.client('ec2', verify=False)
|
||||
|
||||
response = client.describe_instances()
|
||||
|
||||
print(len(response['Reservations']), "total instances\n")
|
||||
|
||||
matched_instances = []
|
||||
for instance_wrapper in response['Reservations']:
|
||||
instance = instance_wrapper['Instances'][0]
|
||||
is_matched_env = False
|
||||
is_matched_role = False
|
||||
for tag in instance.get('Tags', []):
|
||||
if tag['Key'] == "site_env" and args.environment in tag['Value']:
|
||||
is_matched_env = True
|
||||
if tag['Key'] == "role" and tag['Value'] == 'host':
|
||||
is_matched_role = True
|
||||
if tag['Key'] == "Name":
|
||||
instance['Name'] = tag['Value']
|
||||
if is_matched_env and is_matched_role:
|
||||
matched_instances.append(instance)
|
||||
|
||||
for instance in matched_instances:
|
||||
print(instance['Name'])
|
||||
print(instance['PublicIpAddress'])
|
||||
print("")
|
||||
|
||||
with open("aws_connect", 'w') as outfile:
|
||||
outfile.write("ssh-keyscan {} >> ~/.ssh/known_hosts\n".format(matched_instances[0]['PublicIpAddress']))
|
||||
outfile.write("ssh -i ~/.ssh/{} {}@{}".format(profile_dict[args.environment], profile_dict['username'], matched_instances[0]['PublicIpAddress']))
|
||||
os.chmod("aws_connect", 0o755)
|
5
bin/connect_aws/connect_cloud.sh
Executable file
5
bin/connect_aws/connect_cloud.sh
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
python connect_cloud.py "$@"
|
||||
|
||||
/aws_connect
|
8
bin/connect_aws/requirements.txt
Normal file
8
bin/connect_aws/requirements.txt
Normal file
@ -0,0 +1,8 @@
|
||||
boto3==1.9.239
|
||||
botocore==1.12.239
|
||||
docutils==0.15.2
|
||||
jmespath==0.9.4
|
||||
python-dateutil==2.8.0
|
||||
s3transfer==0.2.1
|
||||
six==1.12.0
|
||||
urllib3==1.25.6
|
Reference in New Issue
Block a user