From a0421812b281f0bdb4b512c8b600d08bf6dd7c35 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Tue, 25 Dec 2018 11:17:10 +0200 Subject: [PATCH] Add configuration for policy realization retries Change-Id: I3cbaeb324f05e48772a8ac13991f3660d65eb5c8 --- vmware_nsxlib/v3/__init__.py | 3 ++- vmware_nsxlib/v3/config.py | 8 +++++++- vmware_nsxlib/v3/policy_resources.py | 8 ++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/vmware_nsxlib/v3/__init__.py b/vmware_nsxlib/v3/__init__.py index 5f0f708e..c39a99a1 100644 --- a/vmware_nsxlib/v3/__init__.py +++ b/vmware_nsxlib/v3/__init__.py @@ -395,7 +395,8 @@ class NsxPolicyLib(NsxLibBase): else: self.nsx_api = None self.nsx_version = self.get_version() - args = (self.policy_api, self.nsx_api, self.nsx_version) + args = (self.policy_api, self.nsx_api, self.nsx_version, + self.nsxlib_config) # Initialize all the different resources self.domain = policy_resources.NsxPolicyDomainApi(*args) diff --git a/vmware_nsxlib/v3/config.py b/vmware_nsxlib/v3/config.py index 2d1100a3..71333dbc 100644 --- a/vmware_nsxlib/v3/config.py +++ b/vmware_nsxlib/v3/config.py @@ -82,6 +82,9 @@ class NsxLibConfig(object): -- Additional parameters which are relevant only for the Policy manager: :param allow_passthrough: If True, use nsx manager api for cases which are not supported by the policy manager api. + :param realization_max_attempts: Maximum number of times to retry while + waiting for a resource to be realized. +. """ def __init__(self, @@ -107,7 +110,9 @@ class NsxLibConfig(object): allow_overwrite_header=False, rate_limit_retry=True, cluster_unavailable_retry=False, - allow_passthrough=False): + allow_passthrough=False, + # TODO(asarfaty): reduce the default once plugin is stable + realization_max_attempts=50): self.nsx_api_managers = nsx_api_managers self._username = username @@ -131,6 +136,7 @@ class NsxLibConfig(object): self.rate_limit_retry = rate_limit_retry self.cluster_unavailable_retry = cluster_unavailable_retry self.allow_passthrough = allow_passthrough + self.realization_max_attempts = realization_max_attempts if dhcp_profile_uuid: # this is deprecated, and never used. diff --git a/vmware_nsxlib/v3/policy_resources.py b/vmware_nsxlib/v3/policy_resources.py index 7a611158..0a681d4d 100644 --- a/vmware_nsxlib/v3/policy_resources.py +++ b/vmware_nsxlib/v3/policy_resources.py @@ -49,10 +49,11 @@ class NsxPolicyResourceBase(object): """ SINGLE_ENTRY_ID = 'entry' - def __init__(self, policy_api, nsx_api, version): + def __init__(self, policy_api, nsx_api, version, nsxlib_config): self.policy_api = policy_api self.nsx_api = nsx_api self.version = version + self.nsxlib_config = nsxlib_config @property def entry_def(self): @@ -190,11 +191,10 @@ class NsxPolicyResourceBase(object): Return the realization info, or raise an error """ - # TODO(asarfaty): add configurations for sleep/attempts? if sleep is None: - sleep = 1 + sleep = 0.5 if max_attempts is None: - max_attempts = 200 + max_attempts = self.nsxlib_config.realization_max_attempts test_num = 0 while test_num < max_attempts: