Debian Codegraph @

os_vif/objects/network.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 from oslo_utils import versionutils
14 from oslo_versionedobjects import base
15 from oslo_versionedobjects import fields
16
17 from os_vif import objects
18 from os_vif.objects import base as osv_base
19
20
21 @base.VersionedObjectRegistry.register
22 class Network(osv_base.VersionedObject):
23 """Represents a network."""
24 # Version 1.0: Initial version
25 # Version 1.1: Added MTU field
26 VERSION = '1.1'
27
28 fields = {
29 'id': fields.UUIDField(),
30 'bridge': fields.StringField(),
31 'label': fields.StringField(),
32 'subnets': fields.ObjectField('SubnetList'),
33 'multi_host': fields.BooleanField(),
34 'should_provide_bridge': fields.BooleanField(),
35 'should_provide_vlan': fields.BooleanField(),
36 'bridge_interface': fields.StringField(nullable=True),
37 'vlan': fields.IntegerField(nullable=True),
38 'mtu': fields.IntegerField(nullable=True),
39 }
40
41 def __init__(self, **kwargs):
42 kwargs.setdefault('subnets', objects.subnet.SubnetList(objects=[]))
43 kwargs.setdefault('multi_host', False)
44 kwargs.setdefault('should_provide_bridge', False)
45 kwargs.setdefault('should_provide_vlan', False)
46 kwargs.setdefault('mtu', None)
47 super(Network, self).__init__(**kwargs)
48
49 def obj_make_compatible(self, primitive, target_version):
50 target_version = versionutils.convert_version_to_tuple(target_version)
51 if target_version < (1, 1) and 'mtu' in primitive:
52 del primitive['mtu']
53 super(Network, self).obj_make_compatible(primitive, '1.0')