summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authormasumotok <masumotok@nttdata.co.jp>2012-01-06 23:54:54 +0900
committermasumotok <masumotok@nttdata.co.jp>2012-01-13 15:24:28 +0900
commit8e57055cecef909b4d210baeedb5dad2d155a0a2 (patch)
tree8ff40760f9ae0ab6bcbce26149a8a54d742cbdef /bin
parent6d80851279052a30b98e465106f158cb2afdb6a5 (diff)
First implementation of bp/live-migration-resource-calc
Fix based on revewer's comment upgraded the migration version nova/db/sqlalchemy/migrate_repo/versions/069_block_migration.py rebase on master Change-Id: Ia762f8dec761c3d595bc6fcd39f127f6d92306d2
Diffstat (limited to 'bin')
-rwxr-xr-xbin/nova-manage107
1 files changed, 66 insertions, 41 deletions
diff --git a/bin/nova-manage b/bin/nova-manage
index 6147b1202..3636d99ee 100755
--- a/bin/nova-manage
+++ b/bin/nova-manage
@@ -980,7 +980,8 @@ class VmCommands(object):
instance['availability_zone'],
instance['launch_index'])
- def _migration(self, ec2_id, dest, block_migration=False):
+ def _migration(self, ec2_id, dest, block_migration=False,
+ disk_over_commit=False):
"""Migrates a running instance to a new machine.
:param ec2_id: instance id which comes from euca-describe-instance.
:param dest: destination host name.
@@ -1007,7 +1008,8 @@ class VmCommands(object):
"args": {"instance_id": instance_id,
"dest": dest,
"topic": FLAGS.compute_topic,
- "block_migration": block_migration}})
+ "block_migration": block_migration,
+ "disk_over_commit": disk_over_commit}})
print _('Migration of %s initiated.'
'Check its progress using euca-describe-instances.') % ec2_id
@@ -1022,11 +1024,14 @@ class VmCommands(object):
@args('--ec2_id', dest='ec2_id', metavar='<ec2 id>', help='EC2 ID')
@args('--dest', dest='dest', metavar='<Destanation>',
- help='destanation node')
- def block_migration(self, ec2_id, dest):
+ help='destanation node')
+ @args('--disk_over_commit', dest='disk_over_commit',
+ metavar='<overcommit flag>',
+ help='Allow overcommit (default Flase)')
+ def block_migration(self, ec2_id, dest, disk_over_commit=False):
"""Migrates a running instance to a new machine with storage data."""
- self._migration(ec2_id, dest, True)
+ self._migration(ec2_id, dest, True, disk_over_commit)
class ServiceCommands(object):
@@ -1091,8 +1096,11 @@ class ServiceCommands(object):
@args('--host', dest='host', metavar='<host>', help='Host')
def describe_resource(self, host):
- """Describes cpu/memory/hdd info for host."""
+ """Describes cpu/memory/hdd info for host.
+
+ :param host: hostname.
+ """
result = rpc.call(context.get_admin_context(),
FLAGS.scheduler_topic,
{"method": "show_host_resources",
@@ -1102,49 +1110,66 @@ class ServiceCommands(object):
print _('An unexpected error has occurred.')
print _('[Result]'), result
else:
- cpu = result['resource']['vcpus']
- mem = result['resource']['memory_mb']
- hdd = result['resource']['local_gb']
- cpu_u = result['resource']['vcpus_used']
- mem_u = result['resource']['memory_mb_used']
- hdd_u = result['resource']['local_gb_used']
-
+ # Printing a total and used_now
+ # (NOTE)The host name width 16 characters
+ print '%(a)-25s%(b)16s%(c)8s%(d)8s%(e)8s' % {"a": _('HOST'),
+ "b": _('PROJECT'),
+ "c": _('cpu'),
+ "d": _('mem(mb)'),
+ "e": _('hdd')}
+ print '%(a)-16s(total)%(b)26s%(c)8s%(d)8s' %\
+ {"a": host,
+ "b": result['resource']['vcpus'],
+ "c": result['resource']['memory_mb'],
+ "d": result['resource']['local_gb']}
+
+ print '%(a)-16s(used_now)%(b)23s%(c)8s%(d)8s' %\
+ {"a": host,
+ "b": result['resource']['vcpus_used'],
+ "c": result['resource']['memory_mb_used'],
+ "d": result['resource']['local_gb_used']}
+
+ # Printing a used_max
cpu_sum = 0
mem_sum = 0
hdd_sum = 0
- print 'HOST\t\t\tPROJECT\t\tcpu\tmem(mb)\tdisk(gb)'
- print '%s(total)\t\t\t%s\t%s\t%s' % (host, cpu, mem, hdd)
- print '%s(used_now)\t\t\t%s\t%s\t%s' % (host, cpu_u, mem_u, hdd_u)
- for p_id, val in result['usage'].items():
- cpu_sum += val['vcpus']
- mem_sum += val['memory_mb']
- hdd_sum += val['local_gb']
- print '%s(used_max)\t\t\t%s\t%s\t%s' % (host, cpu_sum,
- mem_sum, hdd_sum)
+ ctxt = context.get_admin_context()
+ instance_refs = db.instance_get_all_by_host(ctxt, host)
- for p_id, val in result['usage'].items():
- print '%s\t\t%s\t\t%s\t%s\t%s' % (host,
- p_id,
- val['vcpus'],
- val['memory_mb'],
- val['local_gb'])
+ project_ids = [i['project_id'] for i in instance_refs]
+ project_ids = list(set(project_ids))
+ usage = dict()
+ for project_id in project_ids:
+ vcpus = [i['vcpus'] for i in instance_refs \
+ if i['project_id'] == project_id]
- @args('--host', dest='host', metavar='<host>', help='Host')
- def update_resource(self, host):
- """Updates available vcpu/memory/disk info for host."""
+ mem = [i['memory_mb'] for i in instance_refs \
+ if i['project_id'] == project_id]
- ctxt = context.get_admin_context()
- service_refs = db.service_get_all_by_host(ctxt, host)
- if len(service_refs) <= 0:
- raise exception.Invalid(_('%s does not exist.') % host)
+ disk = [i['local_gb'] for i in instance_refs \
+ if i['project_id'] == project_id]
- service_refs = [s for s in service_refs if s['topic'] == 'compute']
- if len(service_refs) <= 0:
- raise exception.Invalid(_('%s is not compute node.') % host)
+ usage[project_id] = {
+ 'vcpus': reduce(lambda x, y: x + y, vcpus),
+ 'memory_mb': reduce(lambda x, y: x + y, mem),
+ 'local_gb': reduce(lambda x, y: x + y, disk)}
- rpc.call(ctxt,
- db.queue_get_for(ctxt, FLAGS.compute_topic, host),
- {"method": "update_available_resource"})
+ for p_id, val in usage.items():
+ cpu_sum += val['vcpus']
+ mem_sum += val['memory_mb']
+ hdd_sum += val['local_gb']
+ print '%(a)-16s(used_max)%(b)23s%(c)8s%(d)8s' % {"a": host,
+ "b": cpu_sum,
+ "c": mem_sum,
+ "d": hdd_sum}
+
+ for p_id, val in usage.items():
+ print '%(a)-25s%(b)16s%(c)8s%(d)8s%(e)8s' %\
+ {"a": host,
+ "b": p_id,
+ "c": val['vcpus'],
+ "d": val['memory_mb'],
+ "e": val['local_gb']}
class HostCommands(object):