-
Notifications
You must be signed in to change notification settings - Fork 183
activation key: add support for multi cv #1935
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| minor_changes: | ||
| - activation_key - add ``content_view_environments`` parameter to support multi CV (https://github.com/theforeman/foreman-ansible-modules/pull/1935) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,13 @@ | |
| description: | ||
| - Name of the content view | ||
| type: str | ||
| content_view_environments: | ||
| description: | ||
| - List of content view environments to add to activation key. | ||
| - Mutually exclusive with C(content_view) and C(lifecycle_environment). | ||
| type: list | ||
| elements: str | ||
| version_added: 5.8.0 | ||
| subscriptions: | ||
| description: | ||
| - List of subscriptions that include either Name, Pool ID, or Upstream Pool ID. | ||
|
|
@@ -183,6 +190,24 @@ | |
| auto_attach: false | ||
| release_version: 7Server | ||
| service_level: Standard | ||
|
|
||
| - name: "Create client activation key with multiple content views" | ||
| theforeman.foreman.activation_key: | ||
| username: "admin" | ||
| password: "changeme" | ||
| server_url: "https://foreman.example.com" | ||
| name: "Clients" | ||
| organization: "Default Organization" | ||
| content_view_environments: | ||
| - prod/base_rhel_9 | ||
| - test/third_party | ||
| host_collections: | ||
| - rhel9-servers | ||
| - rhel9-production | ||
| - rhel9-third-party-test | ||
| auto_attach: false | ||
| release_version: 9 | ||
| service_level: Standard | ||
| ''' | ||
|
|
||
| RETURN = ''' | ||
|
|
@@ -227,6 +252,7 @@ def main(): | |
| description=dict(), | ||
| lifecycle_environment=dict(type='entity', flat_name='environment_id', scope=['organization']), | ||
| content_view=dict(type='entity', scope=['organization']), | ||
| content_view_environments=dict(type='list', elements='str'), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I tried implementing CV Environments for hosts in #1866, I used an "entity list", not a string list here (as CV Environments are entities that you can search for etc). However, now that you did it differently, I wonder what's the most "correct" way is.
Error with your code: Error with my code: I think paying an API request just to validate the label is too much, so I'd go with your solution, but wanted to highlight the possibility nevertheless
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should also say that I based my work on how the API currently does things. Right now, the API lets you pass in a list of content-view-environment labels or a list of environment IDs (entities). I implemented the first one. The second one would push things more toward an entity-list approach, like you mentioned. TBH, I just went with the more pragmatic option because I want to use this feature soon and needed something that works. I played around with an entity-list version for a bit, but since I didn’t have the time or the deeper knowledge of the code, I decided to drop it for now. |
||
| host_collections=dict(type='entity_list', scope=['organization']), | ||
| auto_attach=dict(type='bool'), | ||
| release_version=dict(), | ||
|
|
@@ -237,6 +263,10 @@ def main(): | |
| purpose_role=dict(), | ||
| purpose_addons=dict(type='list', elements='str'), | ||
| ), | ||
| mutually_exclusive=[ | ||
| ['lifecycle_environment', 'content_view_environments'], | ||
| ['content_view', 'content_view_environments'] | ||
| ], | ||
| argument_spec=dict( | ||
| subscriptions=dict(type='list', elements='dict', options=dict( | ||
| name=dict(), | ||
|
|
@@ -273,6 +303,20 @@ def main(): | |
| if not module.desired_absent: | ||
| module.lookup_entity('host_collections') | ||
| host_collections = module.foreman_params.pop('host_collections', None) | ||
|
|
||
| content_view_environments = module.foreman_params.pop('content_view_environments', None) | ||
| content_view = module.foreman_params.get("content_view") | ||
| lifecycle_environment = module.foreman_params.get("lifecycle_environment") | ||
| # only use content view environments if content view and lifecycle environment are not specified | ||
| if content_view_environments is not None and content_view is None and lifecycle_environment is None: | ||
| desired_content_view_environments = set(content_view_environments) | ||
| if not entity: | ||
| current_content_view_environments = set() | ||
| else: | ||
| current_content_view_environments = set(entity.get('content_view_environment_labels', '').split(",")) | ||
| if desired_content_view_environments != current_content_view_environments: | ||
| module.foreman_params["content_view_environments"] = sorted(list(desired_content_view_environments)) | ||
|
|
||
| activation_key = module.run() | ||
|
|
||
| # only update subscriptions of newly created or updated AKs | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.