Merge "Refactor version dependant attributes in policy"
This commit is contained in:
commit
2ab32ceb5c
|
@ -229,12 +229,23 @@ class ResourceDef(object):
|
||||||
for attr in attr_list:
|
for attr in attr_list:
|
||||||
self._set_attr_if_supported(body, attr)
|
self._set_attr_if_supported(body, attr)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def version_dependant_attr_map(self):
|
||||||
|
"""Specify version depenand attributes and supporting NSX version
|
||||||
|
|
||||||
|
Resources that contain version dependant attributes should specify
|
||||||
|
attribute name and first supporting version in map returned from
|
||||||
|
this call.
|
||||||
|
"""
|
||||||
|
return {}
|
||||||
|
|
||||||
def _version_dependant_attr_supported(self, attr):
|
def _version_dependant_attr_supported(self, attr):
|
||||||
"""Check if a version dependent attr is supported on current NSX
|
"""Check if a version dependent attr is supported on current NSX
|
||||||
|
|
||||||
For each resource def, there could be some attributes which only exist
|
For each resource def, there could be some attributes which only exist
|
||||||
on NSX after certain versions. This abstract method provides a skeleton
|
on NSX after certain versions. These attrs should be defined on def
|
||||||
to define version requirements of version-dependent attributes.
|
level via version_dependant_attr_map, where map value indicates NSX
|
||||||
|
version that first exposes the support.
|
||||||
|
|
||||||
By design, Devs should use _set_attr_if_supported() to add any attrs
|
By design, Devs should use _set_attr_if_supported() to add any attrs
|
||||||
that are only known to NSX after a certain version. This method works
|
that are only known to NSX after a certain version. This method works
|
||||||
|
@ -246,6 +257,21 @@ class ResourceDef(object):
|
||||||
any version dependent attr unknown to this lib should be excluded
|
any version dependent attr unknown to this lib should be excluded
|
||||||
for security and safety reasons.
|
for security and safety reasons.
|
||||||
"""
|
"""
|
||||||
|
supporting_version = self.version_dependant_attr_map.get(attr)
|
||||||
|
if not supporting_version:
|
||||||
|
LOG.warning("Supporting version not defined for attr %s. Assuming "
|
||||||
|
"no support", attr)
|
||||||
|
return False
|
||||||
|
|
||||||
|
if (version.LooseVersion(self.nsx_version) >=
|
||||||
|
version.LooseVersion(supporting_version)):
|
||||||
|
return True
|
||||||
|
|
||||||
|
LOG.warning(
|
||||||
|
"Ignoring %s for %s %s: this feature is not supported."
|
||||||
|
"Current NSX version: %s. Minimum supported version: %s",
|
||||||
|
attr, self.resource_type, self.attrs.get('name', ''),
|
||||||
|
self.nsx_version, supporting_version)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -472,19 +498,9 @@ class Tier1Def(RouterDef):
|
||||||
route_adv.set_obj_dict(obj_dict['route_advertisement_types'])
|
route_adv.set_obj_dict(obj_dict['route_advertisement_types'])
|
||||||
return route_adv
|
return route_adv
|
||||||
|
|
||||||
def _version_dependant_attr_supported(self, attr):
|
@property
|
||||||
# Attributes supported after 3.0.0
|
def version_dependant_attr_map(self):
|
||||||
if attr in ['pool_allocation']:
|
return {'pool_allocation': nsx_constants.NSX_VERSION_3_0_0}
|
||||||
if (version.LooseVersion(self.nsx_version) >=
|
|
||||||
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
LOG.warning(
|
|
||||||
"Attribute %s is not supported. Current NSX version %s, "
|
|
||||||
"minimum supported version %s",
|
|
||||||
attr, self.nsx_version, nsx_constants.NSX_VERSION_3_0_0)
|
|
||||||
return False
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class RouterLocaleServiceDef(ResourceDef):
|
class RouterLocaleServiceDef(ResourceDef):
|
||||||
|
@ -509,6 +525,10 @@ class Tier0LocaleServiceDef(RouterLocaleServiceDef):
|
||||||
def path_ids(self):
|
def path_ids(self):
|
||||||
return ('tenant', 'tier0_id', 'service_id')
|
return ('tenant', 'tier0_id', 'service_id')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def version_dependant_attr_map(self):
|
||||||
|
return {'route_redistribution_config': nsx_constants.NSX_VERSION_3_0_0}
|
||||||
|
|
||||||
def path_defs(self):
|
def path_defs(self):
|
||||||
return (TenantDef, Tier0Def)
|
return (TenantDef, Tier0Def)
|
||||||
|
|
||||||
|
@ -525,19 +545,6 @@ class Tier0LocaleServiceDef(RouterLocaleServiceDef):
|
||||||
else config)
|
else config)
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def _version_dependant_attr_supported(self, attr):
|
|
||||||
if (version.LooseVersion(self.nsx_version) >=
|
|
||||||
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
|
||||||
if attr == 'route_redistribution_config':
|
|
||||||
return True
|
|
||||||
|
|
||||||
LOG.warning(
|
|
||||||
"Ignoring %s for %s %s: this feature is not supported."
|
|
||||||
"Current NSX version: %s. Minimum supported version: %s",
|
|
||||||
attr, self.resource_type, self.attrs.get('name', ''),
|
|
||||||
self.nsx_version, nsx_constants.NSX_VERSION_3_0_0)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class Tier1LocaleServiceDef(RouterLocaleServiceDef):
|
class Tier1LocaleServiceDef(RouterLocaleServiceDef):
|
||||||
|
|
||||||
|
@ -914,22 +921,11 @@ class SegmentDef(BaseSegmentDef):
|
||||||
def path_defs(self):
|
def path_defs(self):
|
||||||
return (TenantDef,)
|
return (TenantDef,)
|
||||||
|
|
||||||
def _version_dependant_attr_supported(self, attr):
|
@property
|
||||||
if (version.LooseVersion(self.nsx_version) >=
|
def version_dependant_attr_map(self):
|
||||||
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
return {'metadata_proxy_id': nsx_constants.NSX_VERSION_3_0_0,
|
||||||
if attr in ('metadata_proxy_id',
|
'dhcp_server_config_id': nsx_constants.NSX_VERSION_3_0_0,
|
||||||
'dhcp_server_config_id',
|
'admin_state': nsx_constants.NSX_VERSION_3_0_0}
|
||||||
'admin_state'):
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
LOG.warning(
|
|
||||||
"Ignoring %s for %s %s: this feature is not supported."
|
|
||||||
"Current NSX version: %s. Minimum supported version: %s",
|
|
||||||
attr, self.resource_type, self.attrs.get('name', ''),
|
|
||||||
self.nsx_version, nsx_constants.NSX_VERSION_3_0_0)
|
|
||||||
return False
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_obj_dict(self):
|
def get_obj_dict(self):
|
||||||
body = super(SegmentDef, self).get_obj_dict()
|
body = super(SegmentDef, self).get_obj_dict()
|
||||||
|
@ -1134,20 +1130,10 @@ class SegmentPortDef(ResourceDef):
|
||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def _version_dependant_attr_supported(self, attr):
|
@property
|
||||||
if (version.LooseVersion(self.nsx_version) >=
|
def version_dependant_attr_map(self):
|
||||||
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
return {'hyperbus_mode': nsx_constants.NSX_VERSION_3_0_0,
|
||||||
if attr == 'hyperbus_mode':
|
'admin_state': nsx_constants.NSX_VERSION_3_0_0}
|
||||||
return True
|
|
||||||
if attr == 'admin_state':
|
|
||||||
return True
|
|
||||||
|
|
||||||
LOG.warning(
|
|
||||||
"Ignoring %s for %s %s: this feature is not supported."
|
|
||||||
"Current NSX version: %s. Minimum supported version: %s",
|
|
||||||
attr, self.resource_type, self.attrs.get('name', ''),
|
|
||||||
self.nsx_version, nsx_constants.NSX_VERSION_3_0_0)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class SegmentBindingMapDefBase(ResourceDef):
|
class SegmentBindingMapDefBase(ResourceDef):
|
||||||
|
@ -1443,18 +1429,9 @@ class IpPoolBlockSubnetDef(IpPoolSubnetDef):
|
||||||
self._set_attr_if_supported(body, 'start_ip')
|
self._set_attr_if_supported(body, 'start_ip')
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def _version_dependant_attr_supported(self, attr):
|
@property
|
||||||
if (version.LooseVersion(self.nsx_version) >=
|
def version_dependant_attr_map(self):
|
||||||
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
return {'start_ip': nsx_constants.NSX_VERSION_3_0_0}
|
||||||
if attr == 'start_ip':
|
|
||||||
return True
|
|
||||||
|
|
||||||
LOG.warning(
|
|
||||||
"Ignoring %s for %s %s: this feature is not supported."
|
|
||||||
"Current NSX version: %s. Minimum supported version: %s",
|
|
||||||
attr, self.resource_type, self.attrs.get('name', ''),
|
|
||||||
self.nsx_version, nsx_constants.NSX_VERSION_3_0_0)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class IpPoolStaticSubnetDef(IpPoolSubnetDef):
|
class IpPoolStaticSubnetDef(IpPoolSubnetDef):
|
||||||
|
@ -1762,18 +1739,9 @@ class SecurityPolicyRuleBaseDef(ResourceDef):
|
||||||
rule_def.set_obj_dict(rule_dict)
|
rule_def.set_obj_dict(rule_dict)
|
||||||
return rule_def
|
return rule_def
|
||||||
|
|
||||||
def _version_dependant_attr_supported(self, attr):
|
@property
|
||||||
if attr == 'service_entries':
|
def version_dependant_attr_map(self):
|
||||||
if (version.LooseVersion(self.nsx_version) >=
|
return {'service_entries': nsx_constants.NSX_VERSION_3_0_0}
|
||||||
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
|
||||||
return True
|
|
||||||
LOG.warning(
|
|
||||||
"Ignoring %s for %s %s: this feature is not supported."
|
|
||||||
"Current NSX version: %s. Minimum supported version: %s",
|
|
||||||
attr, self.resource_type, self.attrs.get('name', ''),
|
|
||||||
self.nsx_version, nsx_constants.NSX_VERSION_3_0_0)
|
|
||||||
return False
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class CommunicationMapEntryDef(SecurityPolicyRuleBaseDef):
|
class CommunicationMapEntryDef(SecurityPolicyRuleBaseDef):
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
from distutils import version
|
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from vmware_nsxlib.v3 import nsx_constants
|
from vmware_nsxlib.v3 import nsx_constants
|
||||||
from vmware_nsxlib.v3.policy import constants
|
from vmware_nsxlib.v3.policy import constants
|
||||||
|
@ -343,18 +341,9 @@ class LBVirtualServerDef(ResourceDef):
|
||||||
self._set_attrs_if_supported(body, ['access_list_control'])
|
self._set_attrs_if_supported(body, ['access_list_control'])
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def _version_dependant_attr_supported(self, attr):
|
@property
|
||||||
if (version.LooseVersion(self.nsx_version) >=
|
def version_dependant_attr_map(self):
|
||||||
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
return {'access_list_control': nsx_constants.NSX_VERSION_3_0_0}
|
||||||
if attr == 'access_list_control':
|
|
||||||
return True
|
|
||||||
|
|
||||||
LOG.warning(
|
|
||||||
"Ignoring %s for %s %s: this feature is not supported. "
|
|
||||||
"Current NSX version: %s. Minimum supported version: %s",
|
|
||||||
attr, self.resource_type, self.attrs.get('name', ''),
|
|
||||||
self.nsx_version, nsx_constants.NSX_VERSION_3_0_0)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class ClientSSLProfileBindingDef(object):
|
class ClientSSLProfileBindingDef(object):
|
||||||
|
@ -448,20 +437,9 @@ class LBServiceDef(ResourceDef):
|
||||||
self._set_attrs_if_supported(body, ['relax_scale_validation'])
|
self._set_attrs_if_supported(body, ['relax_scale_validation'])
|
||||||
return body
|
return body
|
||||||
|
|
||||||
def _version_dependant_attr_supported(self, attr):
|
@property
|
||||||
if (version.LooseVersion(self.nsx_version) >=
|
def version_dependant_attr_map(self):
|
||||||
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
|
return {'relax_scale_validation': nsx_constants.NSX_VERSION_3_0_0}
|
||||||
if attr == 'relax_scale_validation':
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
LOG.warning(
|
|
||||||
"Ignoring %s for %s %s: this feature is not supported."
|
|
||||||
"Current NSX version: %s. Minimum supported version: %s",
|
|
||||||
attr, self.resource_type, self.attrs.get('name', ''),
|
|
||||||
self.nsx_version, nsx_constants.NSX_VERSION_3_0_0)
|
|
||||||
return False
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
class LBServiceStatisticsDef(ResourceDef):
|
class LBServiceStatisticsDef(ResourceDef):
|
||||||
|
|
Loading…
Reference in New Issue