diff options
| author | Ken Pepple <ken.pepple@gmail.com> | 2011-04-21 10:29:11 -0700 |
|---|---|---|
| committer | Ken Pepple <ken.pepple@gmail.com> | 2011-04-21 10:29:11 -0700 |
| commit | f205dcf659697adaae0d85a042ea2ea7ffe5c1c7 (patch) | |
| tree | b2da90f0cb240450bc30b9d6ebc3c703145b9bb6 /bin | |
| parent | dfcdafde2dc202aa3325cd1cea8d809f56fdde57 (diff) | |
| parent | c796920198305e101c75bcbf4e027ba9e81975d7 (diff) | |
| download | nova-f205dcf659697adaae0d85a042ea2ea7ffe5c1c7.tar.gz nova-f205dcf659697adaae0d85a042ea2ea7ffe5c1c7.tar.xz nova-f205dcf659697adaae0d85a042ea2ea7ffe5c1c7.zip | |
rebase trunk
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/nova-compute | 6 | ||||
| -rwxr-xr-x | bin/nova-manage | 162 |
2 files changed, 78 insertions, 90 deletions
diff --git a/bin/nova-compute b/bin/nova-compute index 95fa393b1..cd7c78def 100755 --- a/bin/nova-compute +++ b/bin/nova-compute @@ -28,11 +28,11 @@ import sys # If ../nova/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... -possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), +POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, os.pardir)) -if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): - sys.path.insert(0, possible_topdir) +if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')): + sys.path.insert(0, POSSIBLE_TOPDIR) gettext.install('nova', unicode=1) diff --git a/bin/nova-manage b/bin/nova-manage index 6789efba8..2c06767f1 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -58,7 +58,6 @@ import gettext import glob import json import os -import re import sys import time @@ -66,11 +65,11 @@ import IPy # If ../nova/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... -possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), +POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, os.pardir)) -if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): - sys.path.insert(0, possible_topdir) +if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')): + sys.path.insert(0, POSSIBLE_TOPDIR) gettext.install('nova', unicode=1) @@ -449,7 +448,7 @@ class FixedIpCommands(object): ctxt = context.get_admin_context() try: - if host == None: + if host is None: fixed_ips = db.fixed_ip_get_all(ctxt) else: fixed_ips = db.fixed_ip_get_all_by_host(ctxt, host) @@ -499,7 +498,7 @@ class FloatingIpCommands(object): """Lists all floating ips (optionally by host) arguments: [host]""" ctxt = context.get_admin_context() - if host == None: + if host is None: floating_ips = db.floating_ip_get_all(ctxt) else: floating_ips = db.floating_ip_get_all_by_host(ctxt, host) @@ -570,6 +569,49 @@ class NetworkCommands(object): class VmCommands(object): """Class for mangaging VM instances.""" + def list(self, host=None): + """Show a list of all instances + + :param host: show all instance on specified host. + :param instance: show specificed instance. + """ + print "%-10s %-15s %-10s %-10s %-19s %-12s %-12s %-12s" \ + " %-10s %-10s %-10s %-5s" % ( + _('instance'), + _('node'), + _('type'), + _('state'), + _('launched'), + _('image'), + _('kernel'), + _('ramdisk'), + _('project'), + _('user'), + _('zone'), + _('index')) + + if host is None: + instances = db.instance_get_all(context.get_admin_context()) + else: + instances = db.instance_get_all_by_host( + context.get_admin_context(), host) + + for instance in instances: + print "%-10s %-15s %-10s %-10s %-19s %-12s %-12s %-12s" \ + " %-10s %-10s %-10s %-5d" % ( + instance['hostname'], + instance['host'], + instance['instance_type'], + instance['state_description'], + instance['launched_at'], + instance['image_id'], + instance['kernel_id'], + instance['ramdisk_id'], + instance['project_id'], + instance['user_id'], + instance['availability_zone'], + instance['launch_index']) + def live_migration(self, ec2_id, dest): """Migrates a running instance to a new machine. @@ -701,15 +743,6 @@ class ServiceCommands(object): {"method": "update_available_resource"}) -class LogCommands(object): - def request(self, request_id, logfile='/var/log/nova.log'): - """Show all fields in the log for the given request. Assumes you - haven't changed the log format too much. - ARGS: request_id [logfile]""" - lines = utils.execute("cat %s | grep '\[%s '" % (logfile, request_id)) - print re.sub('#012', "\n", "\n".join(lines)) - - class DbCommands(object): """Class for managing the database.""" @@ -725,49 +758,6 @@ class DbCommands(object): print migration.db_version() -class InstanceCommands(object): - """Class for managing instances.""" - - def list(self, host=None, instance=None): - """Show a list of all instances""" - print "%-10s %-15s %-10s %-10s %-19s %-12s %-12s %-12s" \ - " %-10s %-10s %-10s %-5s" % ( - _('instance'), - _('node'), - _('type'), - _('state'), - _('launched'), - _('image'), - _('kernel'), - _('ramdisk'), - _('project'), - _('user'), - _('zone'), - _('index')) - - if host == None: - instances = db.instance_get_all(context.get_admin_context()) - else: - instances = db.instance_get_all_by_host( - context.get_admin_context(), host) - - for instance in instances: - print "%-10s %-15s %-10s %-10s %-19s %-12s %-12s %-12s" \ - " %-10s %-10s %-10s %-5d" % ( - instance['hostname'], - instance['host'], - instance['instance_type'], - instance['state_description'], - instance['launched_at'], - instance['image_id'], - instance['kernel_id'], - instance['ramdisk_id'], - instance['project_id'], - instance['user_id'], - instance['availability_zone'], - instance['launch_index']) - - class VolumeCommands(object): """Methods for dealing with a cloud in an odd state""" @@ -818,11 +808,11 @@ class VolumeCommands(object): class InstanceTypeCommands(object): """Class for managing instance types / flavors.""" - def _print_instance_types(self, n, val): + def _print_instance_types(self, name, val): deleted = ('', ', inactive')[val["deleted"] == 1] print ("%s: Memory: %sMB, VCPUS: %s, Storage: %sGB, FlavorID: %s, " "Swap: %sGB, RXTX Quota: %sGB, RXTX Cap: %sMB%s") % ( - n, val["memory_mb"], val["vcpus"], val["local_gb"], + name, val["memory_mb"], val["vcpus"], val["local_gb"], val["flavorid"], val["swap"], val["rxtx_quota"], val["rxtx_cap"], deleted) @@ -873,12 +863,12 @@ class InstanceTypeCommands(object): """Lists all active or specific instance types / flavors arguments: [name]""" try: - if name == None: + if name is None: inst_types = instance_types.get_all_types() elif name == "--all": inst_types = instance_types.get_all_types(True) else: - inst_types = instance_types.get_instance_type(name) + inst_types = instance_types.get_instance_type_by_name(name) except exception.DBError, e: _db_error(e) if isinstance(inst_types.values()[0], dict): @@ -894,20 +884,17 @@ class ImageCommands(object): def __init__(self, *args, **kwargs): self.image_service = utils.import_object(FLAGS.image_service) - def _register(self, image_type, disk_format, container_format, + def _register(self, container_format, disk_format, path, owner, name=None, is_public='T', architecture='x86_64', kernel_id=None, ramdisk_id=None): - meta = {'is_public': True, + meta = {'is_public': (is_public == 'T'), 'name': name, - 'disk_format': disk_format, 'container_format': container_format, + 'disk_format': disk_format, 'properties': {'image_state': 'available', - 'owner_id': owner, - 'type': image_type, + 'project_id': owner, 'architecture': architecture, - 'image_location': 'local', - 'is_public': (is_public == 'T')}} - print image_type, meta + 'image_location': 'local'}} if kernel_id: meta['properties']['kernel_id'] = int(kernel_id) if ramdisk_id: @@ -932,16 +919,18 @@ class ImageCommands(object): ramdisk_id = self.ramdisk_register(ramdisk, owner, None, is_public, architecture) self.image_register(image, owner, name, is_public, - architecture, kernel_id, ramdisk_id) + architecture, 'ami', 'ami', + kernel_id, ramdisk_id) def image_register(self, path, owner, name=None, is_public='T', - architecture='x86_64', kernel_id=None, ramdisk_id=None, - disk_format='ami', container_format='ami'): + architecture='x86_64', container_format='bare', + disk_format='raw', kernel_id=None, ramdisk_id=None): """Uploads an image into the image_service arguments: path owner [name] [is_public='T'] [architecture='x86_64'] + [container_format='bare'] [disk_format='raw'] [kernel_id=None] [ramdisk_id=None] - [disk_format='ami'] [container_format='ami']""" - return self._register('machine', disk_format, container_format, path, + """ + return self._register(container_format, disk_format, path, owner, name, is_public, architecture, kernel_id, ramdisk_id) @@ -950,7 +939,7 @@ class ImageCommands(object): """Uploads a kernel into the image_service arguments: path owner [name] [is_public='T'] [architecture='x86_64'] """ - return self._register('kernel', 'aki', 'aki', path, owner, name, + return self._register('aki', 'aki', path, owner, name, is_public, architecture) def ramdisk_register(self, path, owner, name=None, is_public='T', @@ -958,7 +947,7 @@ class ImageCommands(object): """Uploads a ramdisk into the image_service arguments: path owner [name] [is_public='T'] [architecture='x86_64'] """ - return self._register('ramdisk', 'ari', 'ari', path, owner, name, + return self._register('ari', 'ari', path, owner, name, is_public, architecture) def _lookup(self, old_image_id): @@ -975,16 +964,17 @@ class ImageCommands(object): 'ramdisk': 'ari'} container_format = mapping[old['type']] disk_format = container_format + if container_format == 'ami' and not old.get('kernelId'): + container_format = 'bare' + disk_format = 'raw' new = {'disk_format': disk_format, 'container_format': container_format, - 'is_public': True, + 'is_public': old['isPublic'], 'name': old['imageId'], 'properties': {'image_state': old['imageState'], - 'owner_id': old['imageOwnerId'], + 'project_id': old['imageOwnerId'], 'architecture': old['architecture'], - 'type': old['type'], - 'image_location': old['imageLocation'], - 'is_public': old['isPublic']}} + 'image_location': old['imageLocation']}} if old.get('kernelId'): new['properties']['kernel_id'] = self._lookup(old['kernelId']) if old.get('ramdiskId'): @@ -1018,7 +1008,7 @@ class ImageCommands(object): if (FLAGS.image_service == 'nova.image.local.LocalImageService' and directory == os.path.abspath(FLAGS.images_path)): new_dir = "%s_bak" % directory - os.move(directory, new_dir) + os.rename(directory, new_dir) os.mkdir(directory) directory = new_dir for fn in glob.glob("%s/*/info.json" % directory): @@ -1030,7 +1020,7 @@ class ImageCommands(object): machine_images[image_path] = image_metadata else: other_images[image_path] = image_metadata - except Exception as exc: + except Exception: print _("Failed to load %(fn)s.") % locals() # NOTE(vish): do kernels and ramdisks first so images self._convert_images(other_images) @@ -1049,13 +1039,11 @@ CATEGORIES = [ ('network', NetworkCommands), ('vm', VmCommands), ('service', ServiceCommands), - ('log', LogCommands), ('db', DbCommands), ('volume', VolumeCommands), ('instance_type', InstanceTypeCommands), ('image', ImageCommands), - ('flavor', InstanceTypeCommands), - ('instance', InstanceCommands)] + ('flavor', InstanceTypeCommands)] def lazy_match(name, key_value_tuples): |
