-
Notifications
You must be signed in to change notification settings - Fork 0
Multi-tenancy support #59
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
Open
ppiwowa-csco
wants to merge
7
commits into
main
Choose a base branch
from
tenant-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
47a85b4
Tenants management modules and roles
ppiwowa-csco 02507f4
Update filters for multitenant
ppiwowa-csco 4996d35
Support multitenancy in modules
ppiwowa-csco dd1e17b
Set tenancy mode with cluster management
ppiwowa-csco 76e0c76
Linters
ppiwowa-csco 2445141
Merge branch 'main' into tenant-module
ppiwowa-csco b32dd72
Review fixes
ppiwowa-csco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,26 @@ | |
- A dict containing the services of cluster device, | ||
such as Cisco Software-Defined Application Visibility and Control. | ||
type: dict | ||
tenancy: | ||
description: | ||
- Dictionary to configure tenancy settings. | ||
type: dict | ||
required: false | ||
suboptions: | ||
mode: | ||
description: | ||
- Tenancy mode for the cluster. | ||
choices: ['single', 'multi'] | ||
type: str | ||
clusterid: | ||
description: | ||
- Unique identifier for the cluster in tenancy context. | ||
type: str | ||
domain: | ||
description: | ||
- Domain name associated with the tenancy. | ||
type: str | ||
|
||
author: | ||
- Przemyslaw Susko ([email protected]) | ||
extends_documentation_fragment: | ||
|
@@ -105,12 +125,18 @@ | |
services: | ||
sd-avc: | ||
server: false | ||
|
||
- name: Create a cluster with tenancy configuration | ||
cluster_management: | ||
tenancy: | ||
mode: multi | ||
domain: "domain" | ||
""" | ||
|
||
import time | ||
from typing import List, Optional | ||
|
||
from catalystwan.endpoints.cluster_management import ConnectedDevice, VManageSetup | ||
from catalystwan.endpoints.cluster_management import ConnectedDevice, TenancyMode, VManageSetup | ||
from catalystwan.exceptions import ManagerRequestException | ||
|
||
from ..module_utils.result import ModuleResult | ||
|
@@ -160,12 +186,12 @@ def run_module(): | |
module_args = dict( | ||
wait_until_configured_seconds=dict(type="int", default=0), | ||
vmanage_id=dict(type=str), | ||
system_ip=dict(type=str, required=True), | ||
cluster_ip=dict(type=str, required=True), | ||
username=dict(type=str, required=True), | ||
password=dict(type=str, no_log=True, required=True), | ||
system_ip=dict(type=str), | ||
cluster_ip=dict(type=str), | ||
username=dict(type=str), | ||
password=dict(type=str, no_log=True), | ||
gen_csr=dict(type=bool, aliases=["genCSR"]), | ||
persona=dict(type=str, choices=["COMPUTE_AND_DATA", "COMPUTE", "DATA"], required=True), | ||
persona=dict(type=str, choices=["COMPUTE_AND_DATA", "COMPUTE", "DATA"]), | ||
services=dict( | ||
type="dict", | ||
options=dict( | ||
|
@@ -178,56 +204,113 @@ def run_module(): | |
), | ||
), | ||
), | ||
tenancy=dict( | ||
type="dict", | ||
options=dict( | ||
mode=dict(type="str", choices=["single", "multi"]), | ||
clusterid=dict(type="str"), | ||
domain=dict(type="str"), | ||
), | ||
required=False, | ||
), | ||
) | ||
|
||
module = AnsibleCatalystwanModule(argument_spec=module_args, session_reconnect_retries=180) | ||
required_together = [("system_ip", "cluster_ip", "username", "password", "persona")] | ||
|
||
mutually_exclusive = [("tenancy", ("system_ip", "cluster_ip", "username", "password", "persona"))] | ||
|
||
required_one_of = mutually_exclusive | ||
|
||
module = AnsibleCatalystwanModule( | ||
argument_spec=module_args, | ||
session_reconnect_retries=180, | ||
required_together=required_together, | ||
mutually_exclusive=mutually_exclusive, | ||
required_one_of=required_one_of, | ||
) | ||
module.session.request_timeout = 60 | ||
result = ModuleResult() | ||
|
||
vmanage_id = module.params.get("vmanage_id") | ||
system_ip = module.params.get("system_ip") | ||
cluster_ip = module.params.get("cluster_ip") | ||
|
||
if is_device_connected_to_cluster(module, system_ip, cluster_ip): | ||
result.changed = False | ||
result.msg = f"Device {cluster_ip} already configured" | ||
module.exit_json(**result.model_dump(mode="json")) | ||
|
||
payload = VManageSetup( | ||
vmanage_id=vmanage_id, | ||
device_ip=cluster_ip, | ||
username=module.params.get("username"), | ||
password=module.params.get("password"), | ||
persona=module.params.get("persona"), | ||
services=module.params.get("services"), | ||
) | ||
if module.params.get("vmanage_id"): | ||
vmanage_id = module.params.get("vmanage_id") | ||
system_ip = module.params.get("system_ip") | ||
cluster_ip = module.params.get("cluster_ip") | ||
|
||
if vmanage_id: | ||
module.send_request_safely( | ||
result, | ||
action_name="Cluster Management: Edit vManage", | ||
send_func=module.session.endpoints.cluster_management.edit_vmanage, | ||
payload=payload, | ||
response_key="edit_vmanage", | ||
if is_device_connected_to_cluster(module, system_ip, cluster_ip): | ||
result.changed = False | ||
result.msg = f"Device {cluster_ip} already configured" | ||
module.exit_json(**result.model_dump(mode="json")) | ||
|
||
payload = VManageSetup( | ||
vmanage_id=vmanage_id, | ||
device_ip=cluster_ip, | ||
username=module.params.get("username"), | ||
password=module.params.get("password"), | ||
persona=module.params.get("persona"), | ||
services=module.params.get("services"), | ||
) | ||
else: | ||
module.send_request_safely( | ||
result, | ||
action_name="Cluster Management: Add vManage", | ||
send_func=module.session.endpoints.cluster_management.add_vmanage, | ||
payload=payload, | ||
response_key="add_vmanage", | ||
|
||
if vmanage_id: | ||
module.send_request_safely( | ||
result, | ||
action_name="Cluster Management: Edit vManage", | ||
send_func=module.session.endpoints.cluster_management.edit_vmanage, | ||
payload=payload, | ||
response_key="edit_vmanage", | ||
) | ||
else: | ||
module.send_request_safely( | ||
result, | ||
action_name="Cluster Management: Add vManage", | ||
send_func=module.session.endpoints.cluster_management.add_vmanage, | ||
payload=payload, | ||
response_key="add_vmanage", | ||
) | ||
|
||
if result.changed: | ||
wait_until_configured_seconds = module.params.get("wait_until_configured_seconds") | ||
if wait_until_configured_seconds: | ||
error_msg = wait_for_connected_device(module, system_ip, cluster_ip, wait_until_configured_seconds) | ||
if error_msg: | ||
module.fail_json(msg=f"Error during vManage configuration: {error_msg}") | ||
result.msg = "Successfully updated requested vManage configuration." | ||
else: | ||
result.msg = "No changes to vManage configuration applied." | ||
|
||
if module.params.get("tenancy"): | ||
tenancy_mode: TenancyMode = module.get_response_safely( | ||
module.session.endpoints.cluster_management.get_tenancy_mode | ||
) | ||
|
||
if result.changed: | ||
wait_until_configured_seconds = module.params.get("wait_until_configured_seconds") | ||
if wait_until_configured_seconds: | ||
error_msg = wait_for_connected_device(module, system_ip, cluster_ip, wait_until_configured_seconds) | ||
if error_msg: | ||
module.fail_json(msg=f"Error during vManage configuration: {error_msg}") | ||
result.msg = "Successfully updated requested vManage configuration." | ||
else: | ||
result.msg = "No changes to vManage configuration applied." | ||
if tenancy_mode.mode == "MultiTenant" and module.params.get("tenancy").get("mode") != "multi": | ||
module.fail_json(msg="Switching from MultiTenancy to SingleTenancy is forbidden") | ||
|
||
elif tenancy_mode.mode == "SingleTenant" and module.params.get("tenancy").get("mode") != "single": | ||
new_tennacy = TenancyMode( | ||
mode="MultiTenant", | ||
domain=module.params.get("tenancy").get("domain"), | ||
clusterid=module.params.get("tenancy").get("clusterid"), | ||
) | ||
|
||
module.send_request_safely( | ||
result, | ||
action_name="Cluster Management: Tenancy Mode", | ||
send_func=module.session.endpoints.cluster_management.set_tenancy_mode, | ||
payload=new_tennacy, | ||
response_key=tenancy_mode, | ||
) | ||
|
||
if result.changed: | ||
wait_until_configured_seconds = module.params.get("wait_until_configured_seconds") | ||
if wait_until_configured_seconds: | ||
# wait for manager to restart | ||
time.sleep(60) | ||
module.session.wait_server_ready(timeout=(wait_until_configured_seconds)) | ||
result.msg = "Successfully updated requested vManage configuration. vManage was restarted" | ||
else: | ||
result.msg = "Successfully updated requested vManage configuration. vManage will be restarted" | ||
else: | ||
result.msg = "No changes to vManage configuration applied." | ||
|
||
module.exit_json(**result.model_dump(mode="json")) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.