Skip to content

Commit 0edab58

Browse files
committed
fixes for cluster configuration
1 parent d68063b commit 0edab58

File tree

8 files changed

+51
-42
lines changed

8 files changed

+51
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ playbooks/tests/response*
2222
playbooks/tests/backup
2323
playbooks/tests/templates
2424
playbooks/tests/templates_export
25+
.idea

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace: cisco
22
name: catalystwan
3-
version: 0.2.2
3+
version: 0.2.3
44
readme: README.md
55
authors:
66
- Arkadiusz Cichon <acichon@cisco.com>

playbooks/tests/test_module_cluster_management.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
cisco.catalystwan.cluster_management:
1313
wait_until_configured_seconds: 300
1414
vmanage_id: "0"
15-
device_ip: "{{ (vmanage_instances | first).cluster_private_ip }}"
15+
system_ip: "{{ (vmanage_instances | first).system_ip }}"
16+
cluster_ip: "{{ (vmanage_instances | first).cluster_private_ip }}"
1617
username: "{{ (vmanage_instances | first).admin_username }}"
1718
password: "{{ (vmanage_instances | first).admin_password }}"
1819
persona: "{{ (vmanage_instances | first).persona }}"
@@ -27,7 +28,8 @@
2728
- name: Add remaining instances to cluster
2829
cisco.catalystwan.cluster_management:
2930
wait_until_configured_seconds: 1800
30-
device_ip: "{{ vmanage.cluster_private_ip }}"
31+
system_ip: "{{ vmanage.system_ip }}"
32+
cluster_ip: "{{ vmanage.cluster_private_ip }}"
3133
username: "{{ vmanage.admin_username }}"
3234
password: "{{ vmanage.admin_password }}"
3335
gen_csr: false
@@ -42,3 +44,6 @@
4244
loop: "{{ vmanage_instances[1:] }}"
4345
loop_control:
4446
loop_var: vmanage
47+
when: vmanage.cluster_private_ip is defined
48+
retries: 180
49+
delay: 10

plugins/module_utils/vmanage_module.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ def send_request_safely(
176176
send_func: Callable,
177177
response_key: str = None,
178178
fail_on_exception: bool = True,
179-
num_retries: int = 0,
180-
retry_interval_seconds: int = 1,
181179
**kwargs: Any,
182180
) -> None:
183181
"""
@@ -196,20 +194,8 @@ def send_request_safely(
196194
result.response[f"{response_key}"] = response
197195
result.changed = True
198196

199-
except (ManagerHTTPError, ManagerRequestException) as ex:
200-
if num_retries:
201-
time.sleep(retry_interval_seconds)
202-
self.send_request_safely(
203-
result,
204-
action_name,
205-
send_func,
206-
response_key,
207-
fail_on_exception,
208-
num_retries - 1,
209-
retry_interval_seconds,
210-
**kwargs,
211-
)
212-
elif fail_on_exception:
197+
except ManagerHTTPError as ex:
198+
if fail_on_exception:
213199
self.fail_json(
214200
msg=f"Could not perform '{action_name}' action.\nManager error: {ex.info}",
215201
exception=traceback.format_exc(),

plugins/modules/cluster_management.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
description:
2222
- Optional ID of vManage to edit. Don't set when adding new vManage instances to cluster.
2323
type: str
24-
device_ip:
24+
system_ip:
2525
description:
26-
- Added/edited device IP address.
26+
- Device system IP address.
27+
type: str
28+
cluster_ip:
29+
description:
30+
- Added/edited device cluster IP address.
2731
type: str
2832
username:
2933
description:
@@ -79,7 +83,8 @@
7983
cisco.catalystwan.cluster_management:
8084
wait_until_configured_seconds: 300
8185
vmanage_id: "0"
82-
device_ip: "1.1.1.1"
86+
system_ip: "100.100.100.100"
87+
cluster_ip: "1.1.1.1"
8388
username: "username"
8489
password: "password" # pragma: allowlist secret
8590
persona: "COMPUTE_AND_DATA"
@@ -91,7 +96,8 @@
9196
- name: "Add vManage to cluster"
9297
cisco.catalystwan.cluster_management:
9398
wait_until_configured_seconds: 300
94-
device_ip: "2.2.2.2"
99+
system_ip: "100.100.100.100"
100+
cluster_ip: "2.2.2.2"
95101
username: "username"
96102
password: "password" # pragma: allowlist secret
97103
gen_csr: false
@@ -102,9 +108,9 @@
102108
"""
103109

104110
import time
105-
from typing import Optional
111+
from typing import List, Optional
106112

107-
from catalystwan.endpoints.cluster_management import VManageSetup
113+
from catalystwan.endpoints.cluster_management import ConnectedDevice, VManageSetup
108114
from catalystwan.exceptions import ManagerRequestException
109115

110116
from ..module_utils.result import ModuleResult
@@ -127,12 +133,19 @@ def get_connected_devices(module, device_ip):
127133
return None
128134

129135

130-
def wait_for_connected_devices(module, device_ip, timeout) -> Optional[str]:
136+
def is_device_connected_to_cluster(module, system_ip, cluster_ip):
137+
connected_devices: List[ConnectedDevice] = get_connected_devices(module, cluster_ip)
138+
for device in connected_devices:
139+
if device["device_id"] == system_ip:
140+
return True
141+
return False
142+
143+
144+
def wait_for_connected_device(module, system_ip, cluster_ip, timeout) -> Optional[str]:
131145
start = time.time()
132146
while True:
133147
try:
134-
connected_devices = get_connected_devices(module, device_ip)
135-
if connected_devices:
148+
if is_device_connected_to_cluster(module, system_ip, cluster_ip):
136149
return None
137150
if (time.time() - start) > timeout:
138151
return f"reached timeout of {timeout}s"
@@ -147,7 +160,8 @@ def run_module():
147160
module_args = dict(
148161
wait_until_configured_seconds=dict(type="int", default=0),
149162
vmanage_id=dict(type=str),
150-
device_ip=dict(type=str, required=True),
163+
system_ip=dict(type=str, required=True),
164+
cluster_ip=dict(type=str, required=True),
151165
username=dict(type=str, required=True),
152166
password=dict(type=str, no_log=True, required=True),
153167
gen_csr=dict(type=bool, aliases=["genCSR"]),
@@ -167,20 +181,21 @@ def run_module():
167181
)
168182

169183
module = AnsibleCatalystwanModule(argument_spec=module_args, session_reconnect_retries=180)
184+
module.session.request_timeout = 60
170185
result = ModuleResult()
171186

172187
vmanage_id = module.params.get("vmanage_id")
173-
device_ip = module.params.get("device_ip")
188+
system_ip = module.params.get("system_ip")
189+
cluster_ip = module.params.get("cluster_ip")
174190

175-
connected_devices = get_connected_devices(module, device_ip)
176-
if connected_devices:
191+
if is_device_connected_to_cluster(module, system_ip, cluster_ip):
177192
result.changed = False
178-
result.msg = f"Device {device_ip} already configured"
193+
result.msg = f"Device {cluster_ip} already configured"
179194
module.exit_json(**result.model_dump(mode="json"))
180195

181196
payload = VManageSetup(
182197
vmanage_id=vmanage_id,
183-
device_ip=device_ip,
198+
device_ip=cluster_ip,
184199
username=module.params.get("username"),
185200
password=module.params.get("password"),
186201
persona=module.params.get("persona"),
@@ -196,21 +211,18 @@ def run_module():
196211
response_key="edit_vmanage",
197212
)
198213
else:
199-
module.session.request_timeout = 60
200214
module.send_request_safely(
201215
result,
202216
action_name="Cluster Management: Add vManage",
203217
send_func=module.session.endpoints.cluster_management.add_vmanage,
204218
payload=payload,
205219
response_key="add_vmanage",
206-
num_retries=30,
207-
retry_interval_seconds=10,
208220
)
209221

210222
if result.changed:
211223
wait_until_configured_seconds = module.params.get("wait_until_configured_seconds")
212224
if wait_until_configured_seconds:
213-
error_msg = wait_for_connected_devices(module, device_ip, wait_until_configured_seconds)
225+
error_msg = wait_for_connected_device(module, system_ip, cluster_ip, wait_until_configured_seconds)
214226
if error_msg:
215227
module.fail_json(msg=f"Error during vManage configuration: {error_msg}")
216228
result.msg = "Successfully updated requested vManage configuration."

roles/cluster/tasks/main.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
cisco.catalystwan.cluster_management:
1111
wait_until_configured_seconds: 300
1212
vmanage_id: "0"
13-
device_ip: "{{ (vmanage_instances | first).cluster_private_ip }}"
13+
system_ip: "{{ (vmanage_instances | first).system_ip }}"
14+
cluster_ip: "{{ (vmanage_instances | first).cluster_private_ip }}"
1415
username: "{{ (vmanage_instances | first).admin_username }}"
1516
password: "{{ (vmanage_instances | first).admin_password }}"
1617
persona: "{{ (vmanage_instances | first).persona }}"
@@ -23,7 +24,8 @@
2324
- name: Add remaining instances to cluster
2425
cisco.catalystwan.cluster_management:
2526
wait_until_configured_seconds: 1800
26-
device_ip: "{{ vmanage.cluster_private_ip }}"
27+
system_ip: "{{ vmanage.system_ip }}"
28+
cluster_ip: "{{ vmanage.cluster_private_ip }}"
2729
username: "{{ vmanage.admin_username }}"
2830
password: "{{ vmanage.admin_password }}"
2931
gen_csr: false
@@ -37,3 +39,5 @@
3739
loop_control:
3840
loop_var: vmanage
3941
when: vmanage.cluster_private_ip is defined
42+
retries: 180
43+
delay: 10

roles/health_checks/tasks/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
url: "{{ (vmanage_instances | first).mgmt_public_ip }}"
1414
username: "{{ (vmanage_instances | first).admin_username }}"
1515
password: "{{ (vmanage_instances | first).admin_password }}"
16+
retries: 20
1617

1718
- name: "Health check: orchestrator connections - verifies if all have state up"
1819
cisco.catalystwan.health_checks:

roles/onboarding_controllers/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
- name: Add vSmart devices
2323
cisco.catalystwan.devices_controllers:
24-
device_ip: "{{ device_item.transport_public_ip }}"
24+
device_ip: "{{ device_item.mgmt_public_ip }}"
2525
username: "{{ device_item.admin_username }}"
2626
password: "{{ device_item.admin_password }}"
2727
hostname: "{{ device_item.hostname }}"
@@ -39,7 +39,7 @@
3939

4040
- name: Add vBond devices
4141
cisco.catalystwan.devices_controllers:
42-
device_ip: "{{ device_item.transport_public_ip }}"
42+
device_ip: "{{ device_item.mgmt_public_ip }}"
4343
username: "{{ device_item.admin_username }}"
4444
password: "{{ device_item.admin_password }}"
4545
hostname: "{{ device_item.hostname }}"

0 commit comments

Comments
 (0)