diff --git a/README.rst b/README.rst index 1916a79b8..9c4a0f959 100644 --- a/README.rst +++ b/README.rst @@ -92,6 +92,9 @@ You'll find complete documentation on the shell by running ipgroup-delete Delete an IP group. ipgroup-list Show IP groups. ipgroup-show Show details about a particular IP group. + keypair-add Create a new key pair for use with instances + keypair-delete Delete keypair by its id + keypair-list Show a list of keypairs for a user list List active servers. migrate Migrate a server to a new host in the same zone. reboot Reboot a server. @@ -113,6 +116,7 @@ You'll find complete documentation on the shell by running zone-info Show the capabilities for this Zone. zone-list List all the immediate Child Zones. + Optional arguments: --username USERNAME Defaults to env[NOVA_USERNAME]. --apikey APIKEY Defaults to env[NOVA_API_KEY]. diff --git a/novaclient/v1_1/keypairs.py b/novaclient/v1_1/keypairs.py index 76b65a80c..24f3bbedc 100644 --- a/novaclient/v1_1/keypairs.py +++ b/novaclient/v1_1/keypairs.py @@ -16,6 +16,7 @@ """ Keypair interface (1.1 extension). """ +import os from novaclient import base @@ -50,7 +51,7 @@ class KeypairManager(base.ManagerWithFind): Create a keypair :param name: name for the keypair to create - :param public_key: existing public key to import + :param public_key: path to a public ssh key. """ body = {'keypair': {'name': name}} if public_key: diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 6b83292e5..86fbfeac7 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -207,7 +207,7 @@ def do_zone_boot(cs, args): min_count=min_count, max_count=max_count) print "Reservation ID=", reservation_id - + def _translate_flavor_keys(collection): convert = [('ram', 'memory_mb'), ('disk', 'local_gb')] @@ -703,3 +703,39 @@ def do_remove_fixed_ip(cs, args): """Remove an IP address from a server.""" server = _find_server(cs, args.server) server.remove_fixed_ip(args.address) + + +@utils.arg('name', metavar='', help='Name of key.') +@utils.arg('--pub_key', metavar='', help='Path to a public ssh key.', default=None) +def do_keypair_add(cs, args): + """Create a new key pair for use with instances""" + name = args.name + pub_key = args.pub_key + + if pub_key: + try: + with open(pub_key) as f: + pub_key = f.read() + except IOError, e: + raise exceptions.CommandError("Can't open or read '%s': %s" % (pub_key, e)) + + keypair = cs.keypairs.create(name, pub_key) + + if not pub_key: + private_key = keypair.private_key + print private_key + + +@utils.arg('name', metavar='', help='Keypair name to delete.') +def do_keypair_delete(cs, args): + """Delete keypair by its id""" + name = args.name + cs.keypairs.delete(name) + + +def do_keypair_list(cs, args): + """Print a list of keypairs for a user""" + keypairs = cs.keypairs.list() + columns = ['Name', 'Fingerprint'] + utils.print_list(keypairs, columns) +