diff --git a/vmware_nsxlib/v3/cluster.py b/vmware_nsxlib/v3/cluster.py index 595543d1..f72633ee 100644 --- a/vmware_nsxlib/v3/cluster.py +++ b/vmware_nsxlib/v3/cluster.py @@ -197,14 +197,15 @@ class NSXRequestsHTTPProvider(AbstractHTTPProvider): session.mount('http://', adapter) session.mount('https://', adapter) - self.get_default_headers(session, provider) + self.get_default_headers(session, provider, + config.allow_overwrite_header) return session def is_connection_exception(self, exception): return isinstance(exception, requests_exceptions.ConnectionError) - def get_default_headers(self, session, provider): + def get_default_headers(self, session, provider, allow_overwrite_header): """Get the default headers that should be added to future requests""" session.default_headers = {} @@ -236,6 +237,10 @@ class NSXRequestsHTTPProvider(AbstractHTTPProvider): "headers %(hdr)s", {'url': provider.url, 'hdr': session.default_headers}) + # Add allow-overwrite if configured + if allow_overwrite_header: + session.default_headers['X-Allow-Overwrite'] = 'true' + class ClusterHealth(object): """Indicator of overall cluster health. diff --git a/vmware_nsxlib/v3/config.py b/vmware_nsxlib/v3/config.py index 47a754ec..e1935c81 100644 --- a/vmware_nsxlib/v3/config.py +++ b/vmware_nsxlib/v3/config.py @@ -68,7 +68,10 @@ class NsxLibConfig(object): :param dns_domain: Domain to use for building the hostnames. :param dhcp_profile_uuid: Currently unused and deprecated. Kept for backward compatibility. - + :param allow_overwrite_header: If True, a default header of + X-Allow-Overwrite:true will be added to all + the requests, to allow admin user to update/ + delete all entries. """ def __init__(self, @@ -90,7 +93,8 @@ class NsxLibConfig(object): plugin_ver=None, dns_nameservers=None, dns_domain='openstacklocal', - dhcp_profile_uuid=None): + dhcp_profile_uuid=None, + allow_overwrite_header=False): self.nsx_api_managers = nsx_api_managers self._username = username @@ -110,6 +114,7 @@ class NsxLibConfig(object): self.plugin_ver = plugin_ver self.dns_nameservers = dns_nameservers or [] self.dns_domain = dns_domain + self.allow_overwrite_header = allow_overwrite_header if dhcp_profile_uuid: # this is deprecated, and never used.