Skip to content

Commit

Permalink
fixed issue #297 related to lbvserver_servicegroup_binding
Browse files Browse the repository at this point in the history
Signed-off-by: Sumanth Lingappa <[email protected]>
  • Loading branch information
sumanth-lingappa committed Feb 9, 2024
1 parent b1b6fbb commit e422308
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
19 changes: 16 additions & 3 deletions plugins/module_utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,15 @@ def create_resource(client, resource_name, resource_module_params, action=None):


@trace
def get_bindprimary_key(binding_name, binding_members):
def get_bindprimary_key(binding_name, binding_member):
bindprimary_key = NITRO_RESOURCE_MAP[binding_name]["bindprimary_key"]

# `ip` and `servername` are the two possible bind_primary_keys for `servicegroup_servicegroupmember_binding` resource.
if binding_name == "servicegroup_servicegroupmember_binding":
for x in binding_members:
if bindprimary_key == "ip" and ("ip" not in x or x["ip"] == ""):
if bindprimary_key == "ip":
if "ip" not in binding_member or binding_member["ip"] == "0.0.0.0":
bindprimary_key = "servername"
elif "servername" in binding_member and binding_member["servername"]:
bindprimary_key = "servername"

return bindprimary_key
Expand Down Expand Up @@ -349,6 +351,17 @@ def delete_resource(client, resource_name, resource_module_params):
resource_name
)
return False, err
if resource_name == "lbvserver_servicegroup_binding":
if arg_key == "servicename":
# Reason: {'errorcode': 1092, 'message': 'Arguments cannot both be specified [serviceName, serviceGroupName]', 'severity': 'ERROR'}
if "servicegroupname" in resource_module_params:
if resource_module_params["servicegroupname"]:
continue
else:
err = "ERROR: `servicegroupname` cannnot be empty for the resource `{}`".format(
resource_name
)
return False, err

try:
args[arg_key] = resource_module_params[arg_key]
Expand Down
27 changes: 17 additions & 10 deletions plugins/module_utils/module_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,21 +454,20 @@ def add_bindings(self, binding_name, desired_bindings):
def update_bindings(
self,
binding_name,
bindprimary_key,
to_be_updated_bindprimary_keys,
desired_bindings,
existing_bindings,
):
for b in list(to_be_updated_bindprimary_keys):
desired_binding = {}
for x in desired_bindings:
if b == x[bindprimary_key]:
if b == x[get_bindprimary_key(binding_name, x)]:
desired_binding = x
break

existing_binding = {}
for x in existing_bindings:
if b == x[bindprimary_key]:
if b == x[get_bindprimary_key(binding_name, x)]:
existing_binding = x
break

Expand Down Expand Up @@ -548,7 +547,6 @@ def sync_single_binding(self, binding_name):
binding_module_params = self.module.params[binding_name]
binding_mode = binding_module_params["mode"]
desired_binding_members = binding_module_params["binding_members"]
bindprimary_key = get_bindprimary_key(binding_name, desired_binding_members)
log("INFO: Binding mode is `%s`" % binding_mode)
log("DEBUG: Desired binding members: %s" % desired_binding_members)

Expand All @@ -557,11 +555,19 @@ def sync_single_binding(self, binding_name):
self.return_failure(err)

desired_binding_members_bindprimary_keys = {
x[bindprimary_key] for x in desired_binding_members
x[get_bindprimary_key(binding_name, x)] for x in desired_binding_members
}
existing_binding_members_bindprimary_keys = {
x[bindprimary_key] for x in existing_bindings
x[get_bindprimary_key(binding_name, x)] for x in existing_bindings
}
log(
"DEBUG: Existing binding members bindprimary keys: %s"
% existing_binding_members_bindprimary_keys
)
log(
"DEBUG: Desired binding members bindprimary keys: %s"
% desired_binding_members_bindprimary_keys
)
to_be_deleted_bindprimary_keys = (
existing_binding_members_bindprimary_keys
- desired_binding_members_bindprimary_keys
Expand Down Expand Up @@ -611,7 +617,7 @@ def sync_single_binding(self, binding_name):
resource_module_params=self.resource_module_params,
)
existing_binding_members_bindprimary_keys = {
x[bindprimary_key] for x in existing_bindings
x[get_bindprimary_key(binding_name, x)] for x in existing_bindings
}
to_be_deleted_bindprimary_keys = (
existing_binding_members_bindprimary_keys
Expand All @@ -624,7 +630,10 @@ def sync_single_binding(self, binding_name):

to_be_deleted_bindings = []
for b in existing_bindings:
if b[bindprimary_key] in to_be_deleted_bindprimary_keys:
if (
b[get_bindprimary_key(binding_name, b)]
in to_be_deleted_bindprimary_keys
):
to_be_deleted_bindings.append(b)

if to_be_deleted_bindprimary_keys:
Expand All @@ -636,7 +645,6 @@ def sync_single_binding(self, binding_name):
if to_be_updated_bindprimary_keys:
self.update_bindings(
binding_name=binding_name,
bindprimary_key=bindprimary_key,
to_be_updated_bindprimary_keys=to_be_updated_bindprimary_keys,
desired_bindings=desired_binding_members,
existing_bindings=existing_bindings,
Expand All @@ -657,7 +665,6 @@ def sync_single_binding(self, binding_name):
if to_be_updated_bindprimary_keys:
self.update_bindings(
binding_name=binding_name,
bindprimary_key=bindprimary_key,
to_be_updated_bindprimary_keys=to_be_updated_bindprimary_keys,
desired_bindings=desired_binding_members,
existing_bindings=existing_bindings,
Expand Down

0 comments on commit e422308

Please sign in to comment.