From 4154b903646c9b52efbd956fb74479a3dff00df2 Mon Sep 17 00:00:00 2001
From: Anthony Young <sleepsonthefloor@gmail.com>
Date: Tue, 11 Oct 2011 04:07:08 +0000
Subject: [PATCH 1/3] Add cli for floating ips

---
 README.rst               |  5 +++++
 novaclient/v1_1/shell.py | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/README.rst b/README.rst
index 1916a79b8..49ce67bca 100644
--- a/README.rst
+++ b/README.rst
@@ -71,6 +71,7 @@ You'll find complete documentation on the shell by running
     Positional arguments:
       <subcommand>
         add-fixed-ip        Add a new fixed IP address to a servers network.
+        add-floating-ip     Add a floating IP address to a server.
         backup              Backup a server.
         backup-schedule     Show or edit the backup schedule for a server.
         backup-schedule-delete
@@ -79,6 +80,9 @@ You'll find complete documentation on the shell by running
         delete              Immediately shut down and delete a server.
         flavor-list         Print a list of available 'flavors' (sizes of
                             servers).
+        floating-ip-create  Allocate a floating IP to the current tenant.
+        floating-ip-delete  De-allocate a floating IP from the current tenant.
+        floating-ip-list    List allocated floating IPs for the current tenant.
         help                Display help about this program or one of its
                             subcommands.
         image-create        Create a new image by taking a snapshot of a running
@@ -97,6 +101,7 @@ You'll find complete documentation on the shell by running
         reboot              Reboot a server.
         rebuild             Shutdown, re-image, and re-boot a server.
         remove-fixed-ip     Remove an IP address from a server.
+        remove-floating-ip  Remove a floating IP address from a server.
         rename              Rename a server.
         rescue              Rescue a server.
         resize              Resize a server.
diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py
index 6b83292e5..17bca90db 100644
--- a/novaclient/v1_1/shell.py
+++ b/novaclient/v1_1/shell.py
@@ -703,3 +703,39 @@ def do_remove_fixed_ip(cs, args):
     """Remove an IP address from a server."""
     server = _find_server(cs, args.server)
     server.remove_fixed_ip(args.address)
+
+
+@utils.arg('server', metavar='<server>', help='Name or ID of server.')
+@utils.arg('address', metavar='<address>', help='IP Address.')
+def do_add_floating_ip(cs, args):
+    """Add a floating IP address to a server."""
+    server = _find_server(cs, args.server)
+    server.add_floating_ip(args.address)
+
+
+@utils.arg('server', metavar='<server>', help='Name or ID of server.')
+@utils.arg('address', metavar='<address>', help='IP Address.')
+def do_remove_floating_ip(cs, args):
+    """Remove a floating IP address from a server."""
+    server = _find_server(cs, args.server)
+    server.remove_floating_ip(args.address)
+
+
+def do_floating_ip_create(cs, args):
+    """Allocate a floating IP for the current tenant."""
+    cs.floating_ips.create()
+
+
+@utils.arg('address', metavar='<address>', help='IP of Floating Ip.')
+def do_floating_ip_delete(cs, args):
+    """De-allocate a floating IP."""
+    floating_ips = cs.floating_ips.list()
+    for floating_ip in floating_ips:
+        if floating_ip.ip == args.address:
+            return cs.floating_ips.delete(floating_ip.id)
+
+
+def do_floating_ip_list(cs, args):
+    """List floating ips for this tenant."""
+    utils.print_list(cs.floating_ips.list(), ['Ip', 'Instance Id', \
+                        'Fixed Ip'])

From 9a5a7c9253c500bbaa9ad52fe9a9f31aee7b01e8 Mon Sep 17 00:00:00 2001
From: Anthony Young <sleepsonthefloor@gmail.com>
Date: Tue, 11 Oct 2011 04:18:30 +0000
Subject: [PATCH 2/3] raise exception if floating_ip is not found in
 floating-ip-delete

---
 novaclient/v1_1/shell.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py
index 17bca90db..66a5ef8da 100644
--- a/novaclient/v1_1/shell.py
+++ b/novaclient/v1_1/shell.py
@@ -733,6 +733,7 @@ def do_floating_ip_delete(cs, args):
     for floating_ip in floating_ips:
         if floating_ip.ip == args.address:
             return cs.floating_ips.delete(floating_ip.id)
+    raise exceptions.CommandError("Floating ip %s not found.", args.address)
 
 
 def do_floating_ip_list(cs, args):

From 48e10643b39276af194b947e7bb295fc2e688dd5 Mon Sep 17 00:00:00 2001
From: Anthony Young <sleepsonthefloor@gmail.com>
Date: Tue, 11 Oct 2011 07:54:33 +0000
Subject: [PATCH 3/3] display floating ip on create

---
 novaclient/v1_1/shell.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py
index 66a5ef8da..7849c2087 100644
--- a/novaclient/v1_1/shell.py
+++ b/novaclient/v1_1/shell.py
@@ -705,6 +705,10 @@ def do_remove_fixed_ip(cs, args):
     server.remove_fixed_ip(args.address)
 
 
+def _print_floating_ip_list(floating_ips):
+    utils.print_list(floating_ips, ['Ip', 'Instance Id', 'Fixed Ip'])
+
+
 @utils.arg('server', metavar='<server>', help='Name or ID of server.')
 @utils.arg('address', metavar='<address>', help='IP Address.')
 def do_add_floating_ip(cs, args):
@@ -723,7 +727,7 @@ def do_remove_floating_ip(cs, args):
 
 def do_floating_ip_create(cs, args):
     """Allocate a floating IP for the current tenant."""
-    cs.floating_ips.create()
+    _print_floating_ip_list([cs.floating_ips.create()])
 
 
 @utils.arg('address', metavar='<address>', help='IP of Floating Ip.')
@@ -738,5 +742,4 @@ def do_floating_ip_delete(cs, args):
 
 def do_floating_ip_list(cs, args):
     """List floating ips for this tenant."""
-    utils.print_list(cs.floating_ips.list(), ['Ip', 'Instance Id', \
-                        'Fixed Ip'])
+    _print_floating_ip_list(cs.floating_ips.list())