Skip to content

Commit

Permalink
Removed sshmaster CLI option; added CLI version checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Dougal Ballantyne committed Jul 1, 2014
1 parent 9eaf774 commit 0d61420
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 186 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ everything is done using CloudFormation or resources within AWS.

### Installation

The current working version is cfncluster-0.0.5. The CLI is written in python and uses BOTO for AWS actions. You can install the CLI with the following command:
The current working version is cfncluster-0.0.8. The CLI is written in python and uses BOTO for AWS actions. You can install the CLI with the following command:

#### Linux/OSX

Expand Down Expand Up @@ -77,7 +77,4 @@ Once all of those settings contain valid values, you can launch the cluster by r
```
$ cfncluster create mycluster
```
Once the cluster reaches the "CREATE_COMPLETE" status, you can connect using your normal SSH client/settings or via the cfncluster CLI.
```
$ cfncluster sshmaster mycluster
```
Once the cluster reaches the "CREATE_COMPLETE" status, you can connect using your normal SSH client/settings. For more details on connecting to EC2 instances, check the EC2 User Guide - http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-connect-to-instance-linux.html#using-ssh-client
73 changes: 0 additions & 73 deletions cli/cfncluster/cfncluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import boto.exception
import time
import os
import paramiko
import socket
import interactive
import logging

import cfnconfig
Expand Down Expand Up @@ -277,74 +275,3 @@ def delete(args):
print('\nExiting...')
sys.exit(0)

def sshmaster(args):
stack = ('cfncluster-' + args.cluster_name)
config = cfnconfig.CfnClusterConfig(args)
cfnconn = boto.cloudformation.connect_to_region(config.region,aws_access_key_id=config.aws_access_key_id,
aws_secret_access_key=config.aws_secret_access_key)
outputs = cfnconn.describe_stacks(stack)[0].outputs
if args.useprivateip:
hostname = [ o for o in outputs if o.key == 'MasterPrivateIP' ][0].value
else:
hostname = [ o for o in outputs if o.key == 'MasterPublicIP' ][0].value
port = 22

try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((hostname, port))
except Exception, e:
print '*** Connect failed: ' + str(e)
traceback.print_exc()
sys.exit(1)

try:
t = paramiko.Transport(sock)
try:
t.start_client()
except paramiko.SSHException:
print '*** SSH negotiation failed.'
sys.exit(1)

try:
keys = paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
except IOError:
try:
keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
except IOError:
print '*** Unable to open host keys file'
keys = {}

# check server's host key -- this is important.
key = t.get_remote_server_key()
if not keys.has_key(hostname):
print '*** WARNING: Unknown host key!'
elif not keys[hostname].has_key(key.get_name()):
print '*** WARNING: Unknown host key!'
elif keys[hostname][key.get_name()] != key:
print '*** WARNING: Host key has changed!!!'
sys.exit(1)
else:
print '*** Host key OK.'

key = paramiko.RSAKey.from_private_key_file(config.key_location)
username = 'ec2-user'
t.auth_publickey(username, key)

chan = t.open_session()
chan.get_pty()
chan.invoke_shell()
print '*** Here we go!'
print
interactive.interactive_shell(chan)
chan.close()
t.close()

except Exception, e:
print '*** Caught exception: ' + str(e.__class__) + ': ' + str(e)
##traceback.print_exc()
try:
t.close()
except:
pass
sys.exit(1)

16 changes: 16 additions & 0 deletions cli/cfncluster/cfnconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import inspect
import pkg_resources
import logging
import json
import urllib2

class CfnClusterConfig:

Expand Down Expand Up @@ -57,6 +59,20 @@ def __init__(self, args):
self.__cluster_template = __config.get('global', 'cluster_template')
self.__cluster_section = ('cluster %s' % self.__cluster_template)

# Check if package updates should be checked
try:
self.__update_check = __config.get('global', 'update_check')
except ConfigParser.NoOptionError:
self.__update_check = True

if self.__update_check == True:
try:
__latest = json.loads(urllib2.urlopen("http://pypi.python.org/pypi/cfncluster/json").read())['info']['version']
if self.version < __latest:
print('warning: There is a newer version %s of cfncluster available.' % __latest)
except Exception:
pass

# Get the EC2 keypair name to be used, exit if not set
try:
self.key_name = __config.get(self.__cluster_section, 'key_name')
Expand Down
10 changes: 0 additions & 10 deletions cli/cfncluster/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ def list(args):
def delete(args):
cfncluster.delete(args)

def sshmaster(args):
cfncluster.sshmaster(args)

def instances(args):
cfncluster.instances(args)

Expand Down Expand Up @@ -123,13 +120,6 @@ def main():
help='show the status of cfncluster with the provided name.')
pinstances.set_defaults(func=instances)

psshmaster = subparsers.add_parser('sshmaster', help='ssh to Master instance')
psshmaster.add_argument("cluster_name", type=str, default=None,
help='ssh to the Master of the cfncluster with the provided name.')
psshmaster.add_argument("--privateip", action='store_true', dest="useprivateip",
help='connect to the private IP of the MasterServer')
psshmaster.set_defaults(func=sshmaster)

args = parser.parse_args()
logging.debug(args)
args.func(args)
2 changes: 2 additions & 0 deletions cli/cfncluster/examples/config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
[global]
# Default cluster config section.
cluster_template = default
# Check for updates
update_check = false

[aws]
# This is the AWS credentials section (required).
Expand Down
97 changes: 0 additions & 97 deletions cli/cfncluster/interactive.py

This file was deleted.

2 changes: 1 addition & 1 deletion cli/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def read(fname):
url = ("https://github.com/awslabs/cfncluster"),
license = "Amazon Software License",
packages = find_packages(),
install_requires=['boto >= 2.28.0', 'paramiko >= 1.14.0', 'argparse'],
install_requires=['boto', 'argparse'],
entry_points=dict(console_scripts=console_scripts),
include_package_data = True,
zip_safe = False,
Expand Down

0 comments on commit 0d61420

Please sign in to comment.