Add a new base mixin for Floating IP

Change-Id: I1c0f61db4e549bca6233231230c24a5c453d1a00
Closes-Bug: 1687935
This commit is contained in:
Enol Fernandez 2017-08-23 10:23:05 +01:00
parent 3647b2bbf0
commit f29d0803a9
3 changed files with 22 additions and 4 deletions

View File

@ -72,6 +72,7 @@ class Controller(base.Controller):
if pools:
for p in pools:
occi_ip_pools.append(os_network.OSFloatingIPPool(p["name"]))
occi_ip_pools.append(os_network.os_floatingip_pool)
return occi_ip_pools
def index(self, req):

View File

@ -20,13 +20,26 @@ from ooi.occi.infrastructure import network_link
from ooi.openstack import helpers
class OSFloatingIPPool(mixin.Mixin):
class OSFloatingIPPoolBase(mixin.Mixin):
def __init__(self, pool=None, depends=[]):
location = "floatingippool/%s" % pool if pool else "floatingippool/"
sch = "network/floatingippool" if pool else "network"
scheme = helpers.build_scheme(sch)
term = pool if pool else "floatingippool"
title = pool if pool else "Floating IP pool base mixin"
super(OSFloatingIPPoolBase, self).__init__(
scheme, term, title, location=location, depends=depends,
applies=[network_link.NetworkInterface.kind])
os_floatingip_pool = OSFloatingIPPoolBase()
class OSFloatingIPPool(OSFloatingIPPoolBase):
scheme = helpers.build_scheme("network/floatingippool")
def __init__(self, pool=None):
location = "floatingippool/%s" % pool
super(OSFloatingIPPool, self).__init__(self.scheme, pool, pool,
location=location)
super(OSFloatingIPPool, self).__init__(pool, [os_floatingip_pool])
class OSNetworkInterface(network_link.NetworkInterface):

View File

@ -147,6 +147,10 @@ class TestOSNetworkInterface(base.TestCase):
if isinstance(m, os_network.OSFloatingIPPool):
self.assertEqual("foo", m.term)
self.assertEqual("floatingippool/foo", m.location)
self.assertEqual([network_link.NetworkInterface.kind],
m.applies)
self.assertEqual([os_network.os_floatingip_pool],
m.depends)
has_pool = True
break
self.assertTrue(has_pool)