Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue 297 servicegroup servicegroupmember binding #363

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions tests/integration/targets/lbvserver/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gather_facts/no
netscaler/cpx/
netscaler/vpx/
Loading