| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 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 exception |
| 18 |
from os_vif.objects import base as osv_base |
| 19 |
|
| 20 |
|
| 21 |
def _get_common_version(object_name, max_version, min_version, exc_notmatch, |
| 22 |
exc_notsupported): |
| 23 |
"""Returns the accepted version from the loaded OVO registry""" |
| 24 |
reg = base.VersionedObjectRegistry.obj_classes() |
| 25 |
|
| 26 |
if object_name not in reg: |
| 27 |
raise exc_notmatch(name=object_name) |
| 28 |
|
| 29 |
gotvers = [] |
| 30 |
for regobj in reg[object_name]: |
| 31 |
gotvers.append(regobj.VERSION) |
| 32 |
got = versionutils.convert_version_to_tuple(regobj.VERSION) |
| 33 |
minwant = versionutils.convert_version_to_tuple(min_version) |
| 34 |
maxwant = versionutils.convert_version_to_tuple(max_version) |
| 35 |
|
| 36 |
if minwant <= got <= maxwant: |
| 37 |
return regobj.VERSION |
| 38 |
|
| 39 |
raise exc_notsupported(name=object_name, |
| 40 |
got_versions=",".join(gotvers), |
| 41 |
min_version=min_version, |
| 42 |
max_version=max_version) |
| 43 |
|
| 44 |
|
| 45 |
@base.VersionedObjectRegistry.register |
| 46 |
class HostPortProfileInfo(osv_base.VersionedObject, |
| 47 |
base.ComparableVersionedObject, |
| 48 |
osv_base.VersionedObjectPrintableMixin): |
| 49 |
""" |
| 50 |
Class describing a PortProfile class and its supported versions |
| 51 |
""" |
| 52 |
|
| 53 |
VERSION = "1.0" |
| 54 |
|
| 55 |
fields = { |
| 56 |
|
| 57 |
"profile_object_name": fields.StringField(), |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
"min_version": fields.StringField(), |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
"max_version": fields.StringField(), |
| 66 |
} |
| 67 |
|
| 68 |
def get_common_version(self): |
| 69 |
return _get_common_version(self.profile_object_name, |
| 70 |
self.max_version, |
| 71 |
self.min_version, |
| 72 |
exception.NoMatchingPortProfileClass, |
| 73 |
exception.NoSupportedPortProfileVersion) |
| 74 |
|
| 75 |
|
| 76 |
@base.VersionedObjectRegistry.register |
| 77 |
class HostVIFInfo(osv_base.VersionedObject, base.ComparableVersionedObject, |
| 78 |
osv_base.VersionedObjectPrintableMixin): |
| 79 |
""" |
| 80 |
Class describing a VIF class and its supported versions |
| 81 |
""" |
| 82 |
|
| 83 |
|
| 84 |
VERSION = "1.1" |
| 85 |
|
| 86 |
fields = { |
| 87 |
|
| 88 |
"vif_object_name": fields.StringField(), |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
"min_version": fields.StringField(), |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
"max_version": fields.StringField(), |
| 97 |
|
| 98 |
|
| 99 |
"supported_port_profiles": fields.ListOfObjectsField( |
| 100 |
"HostPortProfileInfo") |
| 101 |
} |
| 102 |
|
| 103 |
def obj_make_compatible(self, primitive, target_version): |
| 104 |
target_version = versionutils.convert_version_to_tuple(target_version) |
| 105 |
if target_version < (1, 1) and 'supported_port_profiles' in primitive: |
| 106 |
del primitive['supported_port_profiles'] |
| 107 |
super(HostVIFInfo, self).obj_make_compatible(primitive, '1.0') |
| 108 |
|
| 109 |
def get_common_version(self): |
| 110 |
return _get_common_version(self.vif_object_name, |
| 111 |
self.max_version, |
| 112 |
self.min_version, |
| 113 |
exception.NoMatchingVIFClass, |
| 114 |
exception.NoSupportedVIFVersion) |
| 115 |
|
| 116 |
|
| 117 |
@base.VersionedObjectRegistry.register |
| 118 |
class HostPluginInfo(osv_base.VersionedObject, base.ComparableVersionedObject, |
| 119 |
osv_base.VersionedObjectPrintableMixin): |
| 120 |
""" |
| 121 |
Class describing a plugin and its supported VIF classes |
| 122 |
""" |
| 123 |
|
| 124 |
VERSION = "1.0" |
| 125 |
|
| 126 |
fields = { |
| 127 |
|
| 128 |
"plugin_name": fields.StringField(), |
| 129 |
|
| 130 |
|
| 131 |
"vif_info": fields.ListOfObjectsField("HostVIFInfo"), |
| 132 |
} |
| 133 |
|
| 134 |
def has_vif(self, name): |
| 135 |
for vif in self.vif_info: |
| 136 |
if vif.vif_object_name == name: |
| 137 |
return True |
| 138 |
return False |
| 139 |
|
| 140 |
def get_vif(self, name): |
| 141 |
for vif in self.vif_info: |
| 142 |
if vif.vif_object_name == name: |
| 143 |
return vif |
| 144 |
|
| 145 |
raise exception.NoMatchingVIFClass(vif_name=name) |
| 146 |
|
| 147 |
def filter_vif_types(self, permitted_vif_type_names): |
| 148 |
new_vif_info = [] |
| 149 |
for vif in self.vif_info: |
| 150 |
if vif.vif_object_name in permitted_vif_type_names: |
| 151 |
new_vif_info.append(vif) |
| 152 |
self.vif_info = new_vif_info |
| 153 |
|
| 154 |
|
| 155 |
@base.VersionedObjectRegistry.register |
| 156 |
class HostInfo(osv_base.VersionedObject, base.ComparableVersionedObject, |
| 157 |
osv_base.VersionedObjectPrintableMixin): |
| 158 |
""" |
| 159 |
Class describing a host host and its supported plugin classes |
| 160 |
""" |
| 161 |
|
| 162 |
fields = { |
| 163 |
|
| 164 |
"plugin_info": fields.ListOfObjectsField("HostPluginInfo"), |
| 165 |
} |
| 166 |
|
| 167 |
def has_plugin(self, name): |
| 168 |
for plugin in self.plugin_info: |
| 169 |
if name == plugin.plugin_name: |
| 170 |
return True |
| 171 |
return False |
| 172 |
|
| 173 |
def get_plugin(self, name): |
| 174 |
for plugin in self.plugin_info: |
| 175 |
if name == plugin.plugin_name: |
| 176 |
return plugin |
| 177 |
|
| 178 |
raise exception.NoMatchingPlugin(plugin_name=name) |
| 179 |
|
| 180 |
def filter_vif_types(self, permitted_vif_type_names): |
| 181 |
new_plugins = [] |
| 182 |
for plugin in self.plugin_info: |
| 183 |
plugin.filter_vif_types(permitted_vif_type_names) |
| 184 |
if len(plugin.vif_info) == 0: |
| 185 |
continue |
| 186 |
new_plugins.append(plugin) |
| 187 |
self.plugin_info = new_plugins |