Merge pull request #128 from UnmeshG/master
Added support to specify few more boot options.
This commit is contained in:
commit
e4a0e2411b
novaclient/v1_1
@ -25,7 +25,8 @@ class BootingManagerWithFind(base.ManagerWithFind):
|
||||
def _boot(self, resource_url, response_key, name, image, flavor,
|
||||
meta=None, files=None, zone_blob=None, userdata=None,
|
||||
reservation_id=None, return_raw=False, min_count=None,
|
||||
max_count=None, security_groups=None, key_name=None):
|
||||
max_count=None, security_groups=None, key_name=None,
|
||||
availability_zone=None):
|
||||
"""
|
||||
Create (boot) a new server.
|
||||
|
||||
@ -49,6 +50,7 @@ class BootingManagerWithFind(base.ManagerWithFind):
|
||||
:param security_groups: list of security group names
|
||||
:param key_name: (optional extension) name of keypair to inject into
|
||||
the instance
|
||||
:param availability_zone: The :class:`Zone`.
|
||||
"""
|
||||
body = {"server": {
|
||||
"name": name,
|
||||
@ -95,5 +97,7 @@ class BootingManagerWithFind(base.ManagerWithFind):
|
||||
'contents': data.encode('base64'),
|
||||
})
|
||||
|
||||
if availability_zone:
|
||||
body["server"]["availability_zone"] = availability_zone
|
||||
return self._create(resource_url, body, response_key,
|
||||
return_raw=return_raw)
|
||||
|
@ -327,7 +327,7 @@ class ServerManager(local_base.BootingManagerWithFind):
|
||||
def create(self, name, image, flavor, meta=None, files=None,
|
||||
zone_blob=None, reservation_id=None, min_count=None,
|
||||
max_count=None, security_groups=None, userdata=None,
|
||||
key_name=None):
|
||||
key_name=None, availability_zone=None):
|
||||
# TODO: (anthony) indicate in doc string if param is an extension
|
||||
# and/or optional
|
||||
"""
|
||||
@ -352,7 +352,8 @@ class ServerManager(local_base.BootingManagerWithFind):
|
||||
string.
|
||||
:param reservation_id: a UUID for the set of servers being requested.
|
||||
:param key_name: (optional extension) name of previously created
|
||||
keypair to inject into the instance
|
||||
keypair to inject into the instance.
|
||||
:param availability_zone: The :class:`Zone`.
|
||||
"""
|
||||
if not min_count:
|
||||
min_count = 1
|
||||
@ -364,7 +365,8 @@ class ServerManager(local_base.BootingManagerWithFind):
|
||||
meta=meta, files=files, userdata=userdata,
|
||||
zone_blob=zone_blob, reservation_id=reservation_id,
|
||||
min_count=min_count, max_count=max_count,
|
||||
security_groups=security_groups, key_name=key_name)
|
||||
security_groups=security_groups, key_name=key_name,
|
||||
availability_zone=availability_zone)
|
||||
|
||||
def update(self, server, name=None):
|
||||
"""
|
||||
|
@ -82,8 +82,27 @@ def _boot(cs, args, reservation_id=None, min_count=None, max_count=None):
|
||||
except IOError, e:
|
||||
raise exceptions.CommandError("Can't open '%s': %s" % (keyfile, e))
|
||||
|
||||
if args.user_data:
|
||||
try:
|
||||
user_data = open(args.user_data)
|
||||
except IOError, e:
|
||||
raise exceptions.CommandError("Can't open '%s': %s" % \
|
||||
(args.user_data, e))
|
||||
else:
|
||||
user_data = None
|
||||
|
||||
if args.availability_zone:
|
||||
availability_zone = args.availability_zone
|
||||
else:
|
||||
availability_zone = None
|
||||
|
||||
if args.security_groups:
|
||||
security_groups = args.security_groups.split(',')
|
||||
else:
|
||||
security_groups = None
|
||||
return (args.name, image, flavor, metadata, files,
|
||||
reservation_id, min_count, max_count)
|
||||
reservation_id, min_count, max_count, user_data, \
|
||||
availability_zone, security_groups)
|
||||
|
||||
|
||||
@utils.arg('--flavor',
|
||||
@ -115,16 +134,32 @@ def _boot(cs, args, reservation_id=None, min_count=None, max_count=None):
|
||||
"Looks in ~/.ssh for a key, "\
|
||||
"or takes an explicit <path> to one.")
|
||||
@utils.arg('name', metavar='<name>', help='Name for the new server')
|
||||
@utils.arg('--user_data',
|
||||
default=None,
|
||||
metavar='<user-data>',
|
||||
help="user data file to pass to be exposed by the metadata server.")
|
||||
@utils.arg('--availability_zone',
|
||||
default=None,
|
||||
metavar='<availability-zone>',
|
||||
help="zone id.")
|
||||
@utils.arg('--security_groups',
|
||||
default=None,
|
||||
metavar='<security_groups>',
|
||||
help="comma separated list of security group names.")
|
||||
def do_boot(cs, args):
|
||||
"""Boot a new server."""
|
||||
name, image, flavor, metadata, files, reservation_id, \
|
||||
min_count, max_count = _boot(cs, args)
|
||||
min_count, max_count, user_data, availability_zone, \
|
||||
security_groups = _boot(cs, args)
|
||||
|
||||
server = cs.servers.create(args.name, image, flavor,
|
||||
meta=metadata,
|
||||
files=files,
|
||||
min_count=min_count,
|
||||
max_count=max_count)
|
||||
max_count=max_count,
|
||||
userdata=user_data,
|
||||
availability_zone=availability_zone,
|
||||
security_groups=security_groups)
|
||||
|
||||
info = server._info
|
||||
|
||||
@ -194,7 +229,8 @@ def do_zone_boot(cs, args):
|
||||
min_count = args.min_instances
|
||||
max_count = args.max_instances
|
||||
name, image, flavor, metadata, \
|
||||
files, reservation_id, min_count, max_count = \
|
||||
files, reservation_id, min_count, max_count,\
|
||||
user_data, availability_zone, security_groups = \
|
||||
_boot(cs, args,
|
||||
reservation_id=reservation_id,
|
||||
min_count=min_count,
|
||||
@ -237,6 +273,7 @@ def do_image_list(cs, args):
|
||||
"""Print a list of available images to boot from."""
|
||||
utils.print_list(cs.images.list(), ['ID', 'Name', 'Status'])
|
||||
|
||||
|
||||
@utils.arg('image',
|
||||
metavar='<image>',
|
||||
help="Name or ID of image")
|
||||
@ -244,7 +281,7 @@ def do_image_list(cs, args):
|
||||
metavar='<action>',
|
||||
choices=['set', 'delete'],
|
||||
help="Actions: 'set' or 'delete'")
|
||||
@utils.arg('metadata',
|
||||
@utils.arg('metadata',
|
||||
metavar='<key=value>',
|
||||
nargs='+',
|
||||
action='append',
|
||||
@ -253,12 +290,12 @@ def do_image_list(cs, args):
|
||||
def do_image_meta(cs, args):
|
||||
"""Set or Delete metadata on an image."""
|
||||
image = _find_image(cs, args.image)
|
||||
metadata = {}
|
||||
metadata = {}
|
||||
for metadatum in args.metadata[0]:
|
||||
# Can only pass the key in on 'delete'
|
||||
# So this doesn't have to have '='
|
||||
if metadatum.find('=') > -1:
|
||||
(key, value) = metadatum.split('=',1)
|
||||
(key, value) = metadatum.split('=', 1)
|
||||
else:
|
||||
key = metadatum
|
||||
value = None
|
||||
@ -270,12 +307,14 @@ def do_image_meta(cs, args):
|
||||
elif args.action == 'delete':
|
||||
cs.images.delete_meta(image, metadata.keys())
|
||||
|
||||
|
||||
def _print_image(image):
|
||||
links = image.links
|
||||
info = image._info.copy()
|
||||
info.pop('links')
|
||||
utils.print_dict(info)
|
||||
|
||||
|
||||
@utils.arg('image',
|
||||
metavar='<image>',
|
||||
help="Name or ID of image")
|
||||
@ -284,6 +323,7 @@ def do_image_show(cs, args):
|
||||
image = _find_image(cs, args.image)
|
||||
_print_image(image)
|
||||
|
||||
|
||||
@utils.arg('image', metavar='<image>', help='Name or ID of image.')
|
||||
def do_image_delete(cs, args):
|
||||
"""
|
||||
@ -523,6 +563,7 @@ def do_image_create(cs, args):
|
||||
server = _find_server(cs, args.server)
|
||||
cs.servers.create_image(server, args.name)
|
||||
|
||||
|
||||
@utils.arg('server',
|
||||
metavar='<server>',
|
||||
help="Name or ID of server")
|
||||
@ -544,7 +585,7 @@ def do_meta(cs, args):
|
||||
# Can only pass the key in on 'delete'
|
||||
# So this doesn't have to have '='
|
||||
if metadatum.find('=') > -1:
|
||||
(key, value) = metadatum.split('=',1)
|
||||
(key, value) = metadatum.split('=', 1)
|
||||
else:
|
||||
key = metadatum
|
||||
value = None
|
||||
|
Loading…
x
Reference in New Issue
Block a user