Implementing Floating Ip Pools.

See vishy's nova branch: https://review.openstack.org/#change,2892

Change-Id: I6a5bec55edd21f659674f478282e65fd6b1b0b1e
This commit is contained in:
jakedahn 2012-01-09 14:49:12 -08:00
parent c747f153ec
commit d7fb1f33cc
8 changed files with 121 additions and 4 deletions

View File

@ -88,6 +88,8 @@ You'll find complete documentation on the shell by running
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.
floating-ip-pool-list
List all floating ip pools.
help Display help about this program or one of its
subcommands.
image-create Create a new image by taking a snapshot of a running

View File

@ -2,6 +2,7 @@ from novaclient import client
from novaclient.v1_1 import flavors
from novaclient.v1_1 import floating_ip_dns
from novaclient.v1_1 import floating_ips
from novaclient.v1_1 import floating_ip_pools
from novaclient.v1_1 import images
from novaclient.v1_1 import keypairs
from novaclient.v1_1 import limits
@ -46,6 +47,7 @@ class Client(object):
# extensions
self.floating_ips = floating_ips.FloatingIPManager(self)
self.floating_ip_dns = floating_ip_dns.FloatingIPDNSManager(self)
self.floating_ip_pools = floating_ip_pools.FloatingIPPoolManager(self)
self.volumes = volumes.VolumeManager(self)
self.volume_snapshots = volume_snapshots.SnapshotManager(self)
self.keypairs = keypairs.KeypairManager(self)

View File

@ -0,0 +1,34 @@
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import urllib
from novaclient import base
class FloatingIPPool(base.Resource):
def __repr__(self):
return "<FloatingIPPool: name=%s>" % self.name
class FloatingIPPoolManager(base.ManagerWithFind):
resource_class = FloatingIPPool
def list(self):
"""
Retrieve a list of all floating ip pools.
"""
return self._list('/os-floating-ip-pools', 'floating_ip_pools')

View File

@ -1,3 +1,4 @@
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
# Copyright 2011 OpenStack LLC.
# All Rights Reserved.
#
@ -33,11 +34,11 @@ class FloatingIPManager(base.ManagerWithFind):
"""
return self._list("/os-floating-ips", "floating_ips")
def create(self):
def create(self, pool=None):
"""
Create (allocate) a floating ip for a tenant
"""
return self._create("/os-floating-ips", {}, "floating_ip")
return self._create("/os-floating-ips", {'pool': pool}, "floating_ip")
def delete(self, floating_ip):
"""

View File

@ -963,7 +963,7 @@ def do_volume_snapshot_delete(cs, args):
def _print_floating_ip_list(floating_ips):
utils.print_list(floating_ips, ['Ip', 'Instance Id', 'Fixed Ip'])
utils.print_list(floating_ips, ['Ip', 'Instance Id', 'Fixed Ip', 'Pool'])
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
@ -982,9 +982,14 @@ def do_remove_floating_ip(cs, args):
server.remove_floating_ip(args.address)
@utils.arg('pool',
metavar='<floating_ip_pool>',
help='Name of Floating IP Pool. (Optional)',
nargs='?',
default=None)
def do_floating_ip_create(cs, args):
"""Allocate a floating IP for the current tenant."""
_print_floating_ip_list([cs.floating_ips.create()])
_print_floating_ip_list([cs.floating_ips.create(pool=args.pool)])
@utils.arg('address', metavar='<address>', help='IP of Floating Ip.')
@ -1002,6 +1007,11 @@ def do_floating_ip_list(cs, args):
_print_floating_ip_list(cs.floating_ips.list())
def do_floating_ip_pool_list(cs, args):
"""List all floating ip pools."""
utils.print_list(cs.floating_ip_pools.list(), ['name'])
def _print_dns_list(dns_entries):
utils.print_list(dns_entries, ['ip', 'zone', 'name'])

View File

@ -1,3 +1,4 @@
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
# Copyright 2011 OpenStack, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -352,6 +353,9 @@ class FakeHTTPClient(base_client.HTTPClient):
# Floating ips
#
def get_os_floating_ip_pools(self):
return (200, {'floating_ip_pools': [{'name': 'foo', 'name': 'bar'}]})
def get_os_floating_ips(self, **kw):
return (200, {'floating_ips': [
{'id': 1, 'fixed_ip': '10.0.0.1', 'ip': '11.0.0.1'},
@ -366,6 +370,16 @@ class FakeHTTPClient(base_client.HTTPClient):
def post_os_floating_ips(self, body, **kw):
return (202, self.get_os_floating_ips_1()[1])
def post_os_floating_ips(self, body):
if body.get('pool'):
return (200, {'floating_ip':
{'id': 1, 'fixed_ip': '10.0.0.1', 'ip': '11.0.0.1',
'pool': 'nova'}})
else:
return (200, {'floating_ip':
{'id': 1, 'fixed_ip': '10.0.0.1', 'ip': '11.0.0.1',
'pool': None}})
def delete_os_floating_ips_1(self, **kw):
return (204, None)

View File

@ -0,0 +1,31 @@
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from novaclient.v1_1 import floating_ip_pools
from tests import utils
from tests.v1_1 import fakes
cs = fakes.FakeClient()
class TestFloatingIPPools(utils.TestCase):
def test_list_floating_ips(self):
fl = cs.floating_ip_pools.list()
cs.assert_called('GET', '/os-floating-ip-pools')
[self.assertTrue(isinstance(f, floating_ip_pools.FloatingIPPool))
for f in fl]

View File

@ -1,3 +1,19 @@
# Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from novaclient.v1_1 import floating_ips
from tests import utils
from tests.v1_1 import fakes
@ -25,4 +41,11 @@ class FloatingIPsTest(utils.TestCase):
def test_create_floating_ip(self):
fl = cs.floating_ips.create()
cs.assert_called('POST', '/os-floating-ips')
self.assertEqual(fl.pool, None)
self.assertTrue(isinstance(fl, floating_ips.FloatingIP))
def test_create_floating_ip_with_pool(self):
fl = cs.floating_ips.create('foo')
cs.assert_called('POST', '/os-floating-ips')
self.assertEqual(fl.pool, 'nova')
self.assertTrue(isinstance(fl, floating_ips.FloatingIP))