Permalink
Browse files

Made the output of `show` and `list` more useful.

  • Loading branch information...
1 parent b362faa commit f39367229cba57c56aff0da803e8009c1ed1fc89 @jacobian jacobian committed Feb 8, 2010
Showing with 33 additions and 5 deletions.
  1. +14 −0 cloudservers/servers.py
  2. +13 −4 cloudservers/shell.py
  3. +3 −0 tests/fakeserver.py
  4. +3 −1 tests/test_shell.py
@@ -90,6 +90,20 @@ def backup_schedule(self):
"""
return self.manager.api.backup_schedules.get(self)
+ @property
+ def public_ip(self):
+ """
+ Shortcut to get this server's primary public IP address.
+ """
+ return self.addresses['public'][0]
+
+ @property
+ def private_ip(self):
+ """
+ Shortcut to get this server's primary private IP address.
+ """
+ return self.addresses['private'][0]
+
class ServerManager(base.ManagerWithFind):
resource_class = Server
View
@@ -276,7 +276,7 @@ def do_ipgroup_delete(self, args):
def do_list(self, args):
"""List active servers."""
- print_list(self.cs.servers.list(), ['ID', 'Name', 'Status'])
+ print_list(self.cs.servers.list(), ['ID', 'Name', 'Status', 'Public IP', 'Private IP'])
@arg('--hard',
dest = 'reboot_type',
@@ -337,7 +337,16 @@ def do_root_password(self, args):
def do_show(self, args):
"""Show details about the given server."""
s = self.cs.servers.get(self._find_server(args.server))
- print_dict(s._info)
+
+ info = s._info.copy()
+ addresses = info.pop('addresses')
+ for addrtype in addresses:
+ info['%s ip' % addrtype] = ', '.join(addresses[addrtype])
+
+ info['flavor'] = self._find_flavor(info.pop('flavorId')).name
+ info['image'] = self._find_image(info.pop('imageId')).name
+
+ print_dict(info)
@arg('server', metavar='<server>', help='Name or ID of server.')
def do_delete(self, args):
@@ -366,7 +375,7 @@ def _find_flavor(self, flavor):
def _find_resource(self, manager, name_or_id):
"""Helper for the _find_* methods."""
try:
- if name_or_id.isdigit():
+ if isinstance(name_or_id, int) or name_or_id.isdigit():
return manager.get(int(name_or_id))
else:
return manager.find(name=name_or_id)
@@ -386,7 +395,7 @@ def print_list(objs, fields):
pt = prettytable.PrettyTable([f for f in fields], caching=False)
pt.aligns = ['l' for f in fields]
for o in objs:
- pt.add_row([getattr(o, f.lower().replace(' ', ''), '') for f in fields])
+ pt.add_row([getattr(o, f.lower().replace(' ', '_'), '') for f in fields])
pt.printt(sortby=fields[0])
def print_dict(d):
View
@@ -285,6 +285,9 @@ def get_images_detail(self, **kw):
def get_images_1(self, **kw):
return (200, {'image': self.get_images_detail()[1]['images'][0]})
+
+ def get_images_2(self, **kw):
+ return (200, {'image': self.get_images_detail()[1]['images'][1]})
def post_images(self, body, **kw):
assert_equal(body.keys(), ['image'])
View
@@ -164,7 +164,9 @@ def test_root_password():
def test_show():
shell('show 1234')
- assert_called('GET', '/servers/1234')
+ # XXX need a way to test multiple calls
+ # assert_called('GET', '/servers/1234')
+ assert_called('GET', '/images/2')
def test_delete():
shell('delete 1234')

0 comments on commit f393672

Please sign in to comment.