Added commands to work with keypairs

This commit is contained in:
Pavel Shkitin 2011-10-05 16:25:31 +04:00
parent 16b083ddca
commit 0ce3f97910
3 changed files with 43 additions and 2 deletions

View File

@ -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].

View File

@ -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:

View File

@ -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='<name>', help='Name of key.')
@utils.arg('--pub_key', metavar='<pub_key>', 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='<name>', 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)