added new class Instances for managaging instances
added new method list in class Instances: # nova-manage instance list instance node type state launched image kernel ramdisk project user zone index i-00000547 XXXXXXX m1.small running 2011-02-18 08:36:37 ami-a03ndz0q ami-0isqekvw testing berendt None 0 i-00000548 XXXXXXX m1.small running 2011-02-18 08:37:17 ami-a03ndz0q ami-0isqekvw testing berendt None 1 i-00000549 XXXXXXX m1.small running 2011-02-18 08:37:52 ami-a03ndz0q ami-0isqekvw testing berendt None 2 # nova-manage instance list ares instance node type state launched image kernel ramdisk project user zone index i-00000c1c ares m1.tiny running 2011-02-26 22:51:40 ami-pus9dj84 ami-zhcv0yyx ami-av96fu30 testing berendt None 1 extended the method list in class FixedIps to lookup ip addresses assigned to a specified node: # nova-manage fixed list ares network IP address MAC address hostname host 192.168.3.0/24 192.168.3.6 02:16:3e:75:d7:9a i-00000c1c ares
This commit is contained in:
commit
ce205ea2c9
@ -446,10 +446,15 @@ class FixedIpCommands(object):
|
||||
def list(self, host=None):
|
||||
"""Lists all fixed ips (optionally by host) arguments: [host]"""
|
||||
ctxt = context.get_admin_context()
|
||||
if host == None:
|
||||
fixed_ips = db.fixed_ip_get_all(ctxt)
|
||||
else:
|
||||
fixed_ips = db.fixed_ip_get_all_by_host(ctxt, host)
|
||||
|
||||
try:
|
||||
if host == None:
|
||||
fixed_ips = db.fixed_ip_get_all(ctxt)
|
||||
else:
|
||||
fixed_ips = db.fixed_ip_get_all_by_host(ctxt, host)
|
||||
except exception.NotFound as ex:
|
||||
print "error: %s" % ex
|
||||
sys.exit(2)
|
||||
|
||||
print "%-18s\t%-15s\t%-17s\t%-15s\t%s" % (_('network'),
|
||||
_('IP address'),
|
||||
@ -466,9 +471,9 @@ class FixedIpCommands(object):
|
||||
host = instance['host']
|
||||
mac_address = instance['mac_address']
|
||||
print "%-18s\t%-15s\t%-17s\t%-15s\t%s" % (
|
||||
fixed_ip['network']['cidr'],
|
||||
fixed_ip['address'],
|
||||
mac_address, hostname, host)
|
||||
fixed_ip['network']['cidr'],
|
||||
fixed_ip['address'],
|
||||
mac_address, hostname, host)
|
||||
|
||||
|
||||
class FloatingIpCommands(object):
|
||||
@ -716,6 +721,49 @@ 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"""
|
||||
|
||||
@ -1002,7 +1050,8 @@ CATEGORIES = [
|
||||
('volume', VolumeCommands),
|
||||
('instance_type', InstanceTypeCommands),
|
||||
('image', ImageCommands),
|
||||
('flavor', InstanceTypeCommands)]
|
||||
('flavor', InstanceTypeCommands),
|
||||
('instance', InstanceCommands)]
|
||||
|
||||
|
||||
def lazy_match(name, key_value_tuples):
|
||||
|
@ -353,6 +353,11 @@ def fixed_ip_get_all(context):
|
||||
return IMPL.fixed_ip_get_all(context)
|
||||
|
||||
|
||||
def fixed_ip_get_all_by_host(context, host):
|
||||
"""Get all defined fixed ips used by a host."""
|
||||
return IMPL.fixed_ip_get_all_by_host(context, host)
|
||||
|
||||
|
||||
def fixed_ip_get_by_address(context, address):
|
||||
"""Get a fixed ip by address or raise if it does not exist."""
|
||||
return IMPL.fixed_ip_get_by_address(context, address)
|
||||
|
@ -672,6 +672,22 @@ def fixed_ip_get_all(context, session=None):
|
||||
return result
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def fixed_ip_get_all_by_host(context, host=None):
|
||||
session = get_session()
|
||||
|
||||
result = session.query(models.FixedIp).\
|
||||
join(models.FixedIp.instance).\
|
||||
filter_by(state=1).\
|
||||
filter_by(host=host).\
|
||||
all()
|
||||
|
||||
if not result:
|
||||
raise exception.NotFound(_('No fixed ips for this host defined'))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@require_context
|
||||
def fixed_ip_get_by_address(context, address, session=None):
|
||||
if not session:
|
||||
|
Loading…
Reference in New Issue
Block a user