Fix definition of subnet object to not be untyped strings
The subnet object fields are currently all just untyped strings. These should all be formally defined objects or fields with type checking Change-Id: Id6ee8b1e89bf3e292406b2c7a4b6f8686e8e0da7
This commit is contained in:
parent
11af752a5a
commit
d8b14f110e
|
@ -12,7 +12,9 @@
|
||||||
|
|
||||||
|
|
||||||
def register_all():
|
def register_all():
|
||||||
|
__import__('os_vif.objects.fixed_ip')
|
||||||
__import__('os_vif.objects.instance_info')
|
__import__('os_vif.objects.instance_info')
|
||||||
__import__('os_vif.objects.network')
|
__import__('os_vif.objects.network')
|
||||||
|
__import__('os_vif.objects.route')
|
||||||
__import__('os_vif.objects.subnet')
|
__import__('os_vif.objects.subnet')
|
||||||
__import__('os_vif.objects.vif')
|
__import__('os_vif.objects.vif')
|
||||||
|
|
|
@ -62,3 +62,7 @@ class VIFVHostUserMode(fields.Enum):
|
||||||
|
|
||||||
class VIFVHostUserModeField(fields.BaseEnumField):
|
class VIFVHostUserModeField(fields.BaseEnumField):
|
||||||
AUTO_TYPE = VIFVHostUserMode()
|
AUTO_TYPE = VIFVHostUserMode()
|
||||||
|
|
||||||
|
|
||||||
|
class ListOfIPAddressField(fields.AutoTypedField):
|
||||||
|
AUTO_TYPE = fields.List(fields.IPAddress())
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
# 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 oslo_versionedobjects import base
|
||||||
|
from oslo_versionedobjects import fields
|
||||||
|
|
||||||
|
from os_vif.objects import fields as osv_fields
|
||||||
|
|
||||||
|
|
||||||
|
@base.VersionedObjectRegistry.register
|
||||||
|
class FixedIP(base.VersionedObject):
|
||||||
|
"""Represents a fixed IP."""
|
||||||
|
# Version 1.0: Initial version
|
||||||
|
VERSION = '1.0'
|
||||||
|
|
||||||
|
fields = {
|
||||||
|
'address': fields.IPAddressField(),
|
||||||
|
'floating_ips': osv_fields.ListOfIPAddressField(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@base.VersionedObjectRegistry.register
|
||||||
|
class FixedIPList(base.VersionedObject, base.ObjectListBase):
|
||||||
|
# Version 1.0: Initial version
|
||||||
|
VERSION = '1.0'
|
||||||
|
|
||||||
|
fields = {
|
||||||
|
'objects': fields.ListOfObjectsField('FixedIP'),
|
||||||
|
}
|
|
@ -13,6 +13,8 @@
|
||||||
from oslo_versionedobjects import base
|
from oslo_versionedobjects import base
|
||||||
from oslo_versionedobjects import fields
|
from oslo_versionedobjects import fields
|
||||||
|
|
||||||
|
from os_vif import objects
|
||||||
|
|
||||||
|
|
||||||
@base.VersionedObjectRegistry.register
|
@base.VersionedObjectRegistry.register
|
||||||
class Network(base.VersionedObject):
|
class Network(base.VersionedObject):
|
||||||
|
@ -24,7 +26,7 @@ class Network(base.VersionedObject):
|
||||||
'id': fields.UUIDField(),
|
'id': fields.UUIDField(),
|
||||||
'bridge': fields.StringField(),
|
'bridge': fields.StringField(),
|
||||||
'label': fields.StringField(),
|
'label': fields.StringField(),
|
||||||
'subnets': fields.ObjectField('SubnetList', nullable=True),
|
'subnets': fields.ObjectField('SubnetList'),
|
||||||
'multi_host': fields.BooleanField(),
|
'multi_host': fields.BooleanField(),
|
||||||
'should_provide_bridge': fields.BooleanField(),
|
'should_provide_bridge': fields.BooleanField(),
|
||||||
'should_provide_vlan': fields.BooleanField(),
|
'should_provide_vlan': fields.BooleanField(),
|
||||||
|
@ -39,7 +41,7 @@ class Network(base.VersionedObject):
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
kwargs.setdefault('subnets', [])
|
kwargs.setdefault('subnets', objects.subnet.SubnetList(objects=[]))
|
||||||
kwargs.setdefault('multi_host', False)
|
kwargs.setdefault('multi_host', False)
|
||||||
kwargs.setdefault('should_provide_bridge', False)
|
kwargs.setdefault('should_provide_bridge', False)
|
||||||
kwargs.setdefault('should_provide_vlan', False)
|
kwargs.setdefault('should_provide_vlan', False)
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
# 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 oslo_versionedobjects import base
|
||||||
|
from oslo_versionedobjects import fields
|
||||||
|
|
||||||
|
|
||||||
|
@base.VersionedObjectRegistry.register
|
||||||
|
class Route(base.VersionedObject):
|
||||||
|
"""Represents a route."""
|
||||||
|
# Version 1.0: Initial version
|
||||||
|
VERSION = '1.0'
|
||||||
|
|
||||||
|
fields = {
|
||||||
|
'cidr': fields.IPNetworkField(),
|
||||||
|
'gateway': fields.IPAddressField(),
|
||||||
|
'interface': fields.StringField(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@base.VersionedObjectRegistry.register
|
||||||
|
class RouteList(base.VersionedObject, base.ObjectListBase):
|
||||||
|
# Version 1.0: Initial version
|
||||||
|
VERSION = '1.0'
|
||||||
|
|
||||||
|
fields = {
|
||||||
|
'objects': fields.ListOfObjectsField('Route'),
|
||||||
|
}
|
|
@ -10,11 +10,11 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import netaddr
|
|
||||||
|
|
||||||
from oslo_versionedobjects import base
|
from oslo_versionedobjects import base
|
||||||
from oslo_versionedobjects import fields
|
from oslo_versionedobjects import fields
|
||||||
|
|
||||||
|
from os_vif.objects import fields as osv_fields
|
||||||
|
|
||||||
|
|
||||||
@base.VersionedObjectRegistry.register
|
@base.VersionedObjectRegistry.register
|
||||||
class Subnet(base.VersionedObject):
|
class Subnet(base.VersionedObject):
|
||||||
|
@ -23,31 +23,14 @@ class Subnet(base.VersionedObject):
|
||||||
VERSION = '1.0'
|
VERSION = '1.0'
|
||||||
|
|
||||||
fields = {
|
fields = {
|
||||||
'cidr': fields.StringField(nullable=True),
|
'cidr': fields.IPNetworkField(),
|
||||||
'dns': fields.ListOfStringsField(),
|
'dns': osv_fields.ListOfIPAddressField(),
|
||||||
'gateway': fields.StringField(),
|
'gateway': fields.IPAddressField(),
|
||||||
'ips': fields.ListOfStringsField(),
|
'ips': fields.ObjectField("FixedIPList"),
|
||||||
'routes': fields.ListOfStringsField(),
|
'routes': fields.ObjectField("RouteList"),
|
||||||
'version': fields.IntegerField(nullable=True),
|
'dhcp_server': fields.IPAddressField(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, cidr=None, dns=None, gateway=None, ips=None,
|
|
||||||
routes=None, **kwargs):
|
|
||||||
|
|
||||||
dns = dns or set()
|
|
||||||
ips = ips or set()
|
|
||||||
routes = routes or set()
|
|
||||||
version = kwargs.pop('version', None)
|
|
||||||
|
|
||||||
if cidr and not version:
|
|
||||||
version = netaddr.IPNetwork(cidr).version
|
|
||||||
super(Subnet, self).__init__(cidr=cidr, dns=dns, gateway=gateway,
|
|
||||||
ips=ips, routes=routes, version=version)
|
|
||||||
|
|
||||||
def as_netaddr(self):
|
|
||||||
"""Convenience function to get cidr as a netaddr object."""
|
|
||||||
return netaddr.IPNetwork(self.cidr)
|
|
||||||
|
|
||||||
|
|
||||||
@base.VersionedObjectRegistry.register
|
@base.VersionedObjectRegistry.register
|
||||||
class SubnetList(base.VersionedObject, base.ObjectListBase):
|
class SubnetList(base.VersionedObject, base.ObjectListBase):
|
||||||
|
|
Loading…
Reference in New Issue