Adds nova client support for nova-manage floating command
Adds the following commands: - nova floating-ip-bulk-list - nova floating-ip-bulk-create - nova floating-ip-bulk-delete Change-Id: Ia183a7a478d23fee3552d43a866ba96abb7472b2 Implements: blueprint apis-for-nova-manage
This commit is contained in:
parent
18deaf4791
commit
4e3aa56fe7
|
@ -26,6 +26,7 @@ from novaclient.v1_1 import volume_snapshots
|
|||
from novaclient.v1_1 import volume_types
|
||||
from novaclient.v1_1 import services
|
||||
from novaclient.v1_1 import fixed_ips
|
||||
from novaclient.v1_1 import floating_ips_bulk
|
||||
|
||||
|
||||
class Client(object):
|
||||
|
@ -90,6 +91,7 @@ class Client(object):
|
|||
self.hypervisors = hypervisors.HypervisorManager(self)
|
||||
self.services = services.ServiceManager(self)
|
||||
self.fixed_ips = fixed_ips.FixedIPsManager(self)
|
||||
self.floating_ips_bulk = floating_ips_bulk.FloatingIPBulkManager(self)
|
||||
|
||||
# Add in any extensions...
|
||||
if extensions:
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2012 IBM
|
||||
# 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.
|
||||
|
||||
"""
|
||||
Bulk Floating IPs interface
|
||||
"""
|
||||
from novaclient import base
|
||||
|
||||
|
||||
class FloatingIP(base.Resource):
|
||||
def __repr__(self):
|
||||
return "<FloatingIP: %s>" % self.address
|
||||
|
||||
|
||||
class FloatingIPBulkManager(base.ManagerWithFind):
|
||||
resource_class = FloatingIP
|
||||
|
||||
def list(self, host=None):
|
||||
"""
|
||||
List all floating IPs
|
||||
"""
|
||||
if host is None:
|
||||
return self._list('/os-floating-ips-bulk', 'floating_ip_info')
|
||||
else:
|
||||
return self._list('/os-floating-ips-bulk/%s' % host,
|
||||
'floating_ip_info')
|
||||
|
||||
def create(self, ip_range, pool=None, interface=None):
|
||||
"""
|
||||
Create floating IPs by range
|
||||
"""
|
||||
body = {"floating_ips_bulk_create": {'ip_range': ip_range}}
|
||||
if pool is not None:
|
||||
body['floating_ips_bulk_create']['pool'] = pool
|
||||
if interface is not None:
|
||||
body['floating_ips_bulk_create']['interface'] = interface
|
||||
|
||||
return self._create('/os-floating-ips-bulk', body,
|
||||
'floating_ips_bulk_create')
|
||||
|
||||
def delete(self, ip_range):
|
||||
"""
|
||||
Delete floating IPs by range
|
||||
"""
|
||||
body = {"ip_range": ip_range}
|
||||
return self._update('/os-floating-ips-bulk/delete', body)
|
|
@ -1425,6 +1425,33 @@ def do_floating_ip_pool_list(cs, _args):
|
|||
utils.print_list(cs.floating_ip_pools.list(), ['name'])
|
||||
|
||||
|
||||
@utils.arg('--host', dest='host', metavar='<host>', default=None,
|
||||
help='Filter by host')
|
||||
def do_floating_ip_bulk_list(cs, args):
|
||||
"""List all floating ips"""
|
||||
utils.print_list(cs.floating_ips_bulk.list(args.host), ['project_id',
|
||||
'address',
|
||||
'instance_uuid',
|
||||
'pool',
|
||||
'interface'])
|
||||
|
||||
|
||||
@utils.arg('ip_range', metavar='<range>', help='Address range to create')
|
||||
@utils.arg('--pool', dest='pool', metavar='<pool>', default=None,
|
||||
help='Pool for new Floating IPs')
|
||||
@utils.arg('--interface', metavar='<interface>', default=None,
|
||||
help='Interface for new Floating IPs')
|
||||
def do_floating_ip_bulk_create(cs, args):
|
||||
"""Bulk create floating ips by range"""
|
||||
cs.floating_ips_bulk.create(args.ip_range, args.pool, args.interface)
|
||||
|
||||
|
||||
@utils.arg('ip_range', metavar='<range>', help='Address range to delete')
|
||||
def do_floating_ip_bulk_delete(cs, args):
|
||||
"""Bulk delete floating ips by range"""
|
||||
cs.floating_ips_bulk.delete(args.ip_range)
|
||||
|
||||
|
||||
def _print_dns_list(dns_entries):
|
||||
utils.print_list(dns_entries, ['ip', 'name', 'domain'])
|
||||
|
||||
|
|
|
@ -615,6 +615,31 @@ class FakeHTTPClient(base_client.HTTPClient):
|
|||
def delete_os_floating_ip_dns_testdomain_entries_testname(self, **kw):
|
||||
return (200, None)
|
||||
|
||||
def get_os_floating_ips_bulk(self, **kw):
|
||||
return (200, {'floating_ip_info': [
|
||||
{'id': 1, 'fixed_ip': '10.0.0.1', 'ip': '11.0.0.1'},
|
||||
{'id': 2, 'fixed_ip': '10.0.0.2', 'ip': '11.0.0.2'},
|
||||
]})
|
||||
|
||||
def get_os_floating_ips_bulk_testHost(self, **kw):
|
||||
return (200, {'floating_ip_info': [
|
||||
{'id': 1, 'fixed_ip': '10.0.0.1', 'ip': '11.0.0.1'},
|
||||
{'id': 2, 'fixed_ip': '10.0.0.2', 'ip': '11.0.0.2'},
|
||||
]})
|
||||
|
||||
def post_os_floating_ips_bulk(self, **kw):
|
||||
params = kw.get('body').get('floating_ips_bulk_create')
|
||||
pool = params.get('pool', 'defaultPool')
|
||||
interface = params.get('interface', 'defaultInterface')
|
||||
return (200, {'floating_ips_bulk_create':
|
||||
{'ip_range': '192.168.1.0/30',
|
||||
'pool': pool,
|
||||
'interface': interface}})
|
||||
|
||||
def put_os_floating_ips_bulk_delete(self, **kw):
|
||||
ip_range = kw.get('body').get('ip_range')
|
||||
return (200, {'floating_ips_bulk_delete': ip_range})
|
||||
|
||||
#
|
||||
# Images
|
||||
#
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2012 IBM
|
||||
# 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_bulk
|
||||
from tests import utils
|
||||
from tests.v1_1 import fakes
|
||||
|
||||
|
||||
cs = fakes.FakeClient()
|
||||
|
||||
|
||||
class FloatingIPsBulkTest(utils.TestCase):
|
||||
|
||||
def test_list_floating_ips_bulk(self):
|
||||
fl = cs.floating_ips_bulk.list()
|
||||
cs.assert_called('GET', '/os-floating-ips-bulk')
|
||||
[self.assertTrue(isinstance(f, floating_ips_bulk.FloatingIP))
|
||||
for f in fl]
|
||||
|
||||
def test_list_floating_ips_bulk_host_filter(self):
|
||||
fl = cs.floating_ips_bulk.list('testHost')
|
||||
cs.assert_called('GET', '/os-floating-ips-bulk/testHost')
|
||||
[self.assertTrue(isinstance(f, floating_ips_bulk.FloatingIP))
|
||||
for f in fl]
|
||||
|
||||
def test_create_floating_ips_bulk(self):
|
||||
fl = cs.floating_ips_bulk.create('192.168.1.0/30')
|
||||
body = {'floating_ips_bulk_create': {'ip_range': '192.168.1.0/30'}}
|
||||
cs.assert_called('POST', '/os-floating-ips-bulk', body)
|
||||
self.assertEqual(fl.ip_range,
|
||||
body['floating_ips_bulk_create']['ip_range'])
|
||||
|
||||
def test_create_floating_ips_bulk_with_pool_and_host(self):
|
||||
fl = cs.floating_ips_bulk.create('192.168.1.0/30', 'poolTest',
|
||||
'interfaceTest')
|
||||
body = {'floating_ips_bulk_create':
|
||||
{'ip_range': '192.168.1.0/30', 'pool': 'poolTest',
|
||||
'interface': 'interfaceTest'}}
|
||||
cs.assert_called('POST', '/os-floating-ips-bulk', body)
|
||||
self.assertEqual(fl.ip_range,
|
||||
body['floating_ips_bulk_create']['ip_range'])
|
||||
self.assertEqual(fl.pool,
|
||||
body['floating_ips_bulk_create']['pool'])
|
||||
self.assertEqual(fl.interface,
|
||||
body['floating_ips_bulk_create']['interface'])
|
||||
|
||||
def test_delete_floating_ips_bulk(self):
|
||||
fl = cs.floating_ips_bulk.delete('192.168.1.0/30')
|
||||
body = {'ip_range': '192.168.1.0/30'}
|
||||
cs.assert_called('PUT', '/os-floating-ips-bulk/delete', body)
|
||||
self.assertEqual(fl['floating_ips_bulk_delete'], body['ip_range'])
|
|
@ -386,6 +386,29 @@ class ShellTest(utils.TestCase):
|
|||
self.run_command('dns-domains')
|
||||
self.assert_called('GET', '/os-floating-ip-dns')
|
||||
|
||||
def test_floating_ip_bulk_list(self):
|
||||
self.run_command('floating-ip-bulk-list')
|
||||
self.assert_called('GET', '/os-floating-ips-bulk')
|
||||
|
||||
def test_floating_ip_bulk_create(self):
|
||||
self.run_command('floating-ip-bulk-create 10.0.0.1/24')
|
||||
self.assert_called('POST', '/os-floating-ips-bulk',
|
||||
{'floating_ips_bulk_create':
|
||||
{'ip_range': '10.0.0.1/24'}})
|
||||
|
||||
def test_floating_ip_bulk_create_host_and_interface(self):
|
||||
self.run_command('floating-ip-bulk-create 10.0.0.1/24 --pool testPool \
|
||||
--interface ethX')
|
||||
self.assert_called('POST', '/os-floating-ips-bulk',
|
||||
{'floating_ips_bulk_create':
|
||||
{'ip_range': '10.0.0.1/24',
|
||||
'pool': 'testPool', 'interface': 'ethX'}})
|
||||
|
||||
def test_floating_ip_bulk_delete(self):
|
||||
self.run_command('floating-ip-bulk-delete 10.0.0.1/24')
|
||||
self.assert_called('PUT', '/os-floating-ips-bulk/delete',
|
||||
{'ip_range': '10.0.0.1/24'})
|
||||
|
||||
def test_usage_list(self):
|
||||
self.run_command('usage-list --start 2000-01-20 --end 2005-02-01')
|
||||
self.assert_called('GET',
|
||||
|
|
Loading…
Reference in New Issue