-
Notifications
You must be signed in to change notification settings - Fork 187
Support content_view_environment_id for host and hostgroup #1977
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
jeremylenz
wants to merge
1
commit into
theforeman:develop
Choose a base branch
from
jeremylenz:deprecate-cv-lce-params
base: develop
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.
+71
−1
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| minor_changes: | ||
| - host, hostgroup - internally convert ``content_view``/``lifecycle_environment`` | ||
| to content view environment ID for compatibility with newer Katello API versions | ||
| (https://github.com/theforeman/foreman-ansible-modules/pull/1977) |
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 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -312,11 +312,13 @@ def __init__(self, **kwargs): | |||||||||||||||
| kickstart_repository=dict(type='entity', scope=['organization'], optional_scope=['lifecycle_environment', 'content_view'], | ||||||||||||||||
| resource_type='repositories'), | ||||||||||||||||
| content_view=dict(type='entity', scope=['organization'], optional_scope=['lifecycle_environment']), | ||||||||||||||||
| content_view_environment_id=dict(type='int', invisible=True), | ||||||||||||||||
| content_view_environment_ids=dict(type='list', elements='int', invisible=True), | ||||||||||||||||
| activation_keys=dict(no_log=False), | ||||||||||||||||
| ) | ||||||||||||||||
| foreman_spec.update(kwargs.pop('foreman_spec', {})) | ||||||||||||||||
| required_plugins = kwargs.pop('required_plugins', []) + [ | ||||||||||||||||
| ('katello', ['activation_keys', 'content_source', 'lifecycle_environment', 'kickstart_repository', 'content_view']), | ||||||||||||||||
| ('katello', ['activation_keys', 'content_source', 'lifecycle_environment', 'kickstart_repository', 'content_view', 'content_view_environment_id']), | ||||||||||||||||
| ('openscap', ['openscap_proxy']), | ||||||||||||||||
| ] | ||||||||||||||||
| mutually_exclusive = kwargs.pop('mutually_exclusive', []) + [['medium', 'kickstart_repository']] | ||||||||||||||||
|
|
@@ -326,6 +328,9 @@ def run(self, **kwargs): | |||||||||||||||
| entity = self.lookup_entity('entity') | ||||||||||||||||
|
|
||||||||||||||||
| if not self.desired_absent: | ||||||||||||||||
| if 'content_view' in self.foreman_params or 'lifecycle_environment' in self.foreman_params: | ||||||||||||||||
| self._convert_cv_lce_to_cve(entity) | ||||||||||||||||
|
|
||||||||||||||||
| if 'activation_keys' in self.foreman_params: | ||||||||||||||||
| if 'parameters' not in self.foreman_params: | ||||||||||||||||
| parameters = [param for param in (entity or {}).get('parameters', []) if param['name'] != 'kt_activation_keys'] | ||||||||||||||||
|
|
@@ -343,6 +348,67 @@ def run(self, **kwargs): | |||||||||||||||
|
|
||||||||||||||||
| return super(HostMixin, self).run(**kwargs) | ||||||||||||||||
|
|
||||||||||||||||
| def _convert_cv_lce_to_cve(self, entity): | ||||||||||||||||
| resource = inflector.pluralize(self.entity_name) | ||||||||||||||||
| _filtered, unsupported = self.foremanapi.validate_payload(resource, 'create', {'content_view_id': 1}) | ||||||||||||||||
| if 'content_view_id' not in unsupported: | ||||||||||||||||
| return | ||||||||||||||||
|
|
||||||||||||||||
| if entity: | ||||||||||||||||
| entity_cves = entity.get('content_view_environments', []) | ||||||||||||||||
| if len(entity_cves) > 1: | ||||||||||||||||
| self.fail_json( | ||||||||||||||||
| msg="This {0} has multiple content view environments. " | ||||||||||||||||
| "The 'content_view' and 'lifecycle_environment' parameters " | ||||||||||||||||
| "cannot safely update it — they would overwrite the existing " | ||||||||||||||||
| "multi-CV assignment.".format(self.entity_name) | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| self.lookup_entity('content_view') | ||||||||||||||||
| self.lookup_entity('lifecycle_environment') | ||||||||||||||||
|
|
||||||||||||||||
| cv = self.foreman_params.get('content_view') | ||||||||||||||||
| lce = self.foreman_params.get('lifecycle_environment') | ||||||||||||||||
|
Comment on lines
+367
to
+371
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.
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| cv_id = cv['id'] if cv else None | ||||||||||||||||
| lce_id = lce['id'] if lce else None | ||||||||||||||||
|
|
||||||||||||||||
| if entity and cv_id is None: | ||||||||||||||||
| cv_id = entity.get('content_view_id') | ||||||||||||||||
| if cv_id is None: | ||||||||||||||||
| entity_cves = entity.get('content_view_environments', []) | ||||||||||||||||
| if entity_cves: | ||||||||||||||||
| cv_id = entity_cves[0].get('content_view', {}).get('id') | ||||||||||||||||
| if entity and lce_id is None: | ||||||||||||||||
| lce_id = entity.get('lifecycle_environment_id') | ||||||||||||||||
|
jeremylenz marked this conversation as resolved.
|
||||||||||||||||
| if lce_id is None: | ||||||||||||||||
| entity_cves = entity.get('content_view_environments', []) | ||||||||||||||||
| if entity_cves: | ||||||||||||||||
| lce_id = entity_cves[0].get('lifecycle_environment', {}).get('id') | ||||||||||||||||
|
|
||||||||||||||||
| if cv_id is None or lce_id is None: | ||||||||||||||||
| self.fail_json(msg="Both 'content_view' and 'lifecycle_environment' must be provided together.") | ||||||||||||||||
|
|
||||||||||||||||
| org_id = self.lookup_entity('organization')['id'] if 'organization' in self.foreman_params else None | ||||||||||||||||
| if org_id is None and entity: | ||||||||||||||||
| org_id = entity.get('organization_id') | ||||||||||||||||
|
|
||||||||||||||||
| cve = self.find_content_view_environment(cv_id, lce_id, org_id) | ||||||||||||||||
|
|
||||||||||||||||
| self.foreman_spec['content_view']['ensure'] = False | ||||||||||||||||
| self.foreman_spec['lifecycle_environment']['ensure'] = False | ||||||||||||||||
|
|
||||||||||||||||
| if resource == 'hosts': | ||||||||||||||||
| current_cve_ids = [] | ||||||||||||||||
| if entity: | ||||||||||||||||
| current_cve_ids = [e['id'] for e in entity.get('content_facet_attributes', {}).get('content_view_environments', [])] | ||||||||||||||||
| if [cve['id']] != current_cve_ids: | ||||||||||||||||
| self.foreman_params['content_view_environment_ids'] = [cve['id']] | ||||||||||||||||
| else: | ||||||||||||||||
| current_cve_id = entity.get('content_view_environment_id') if entity else None | ||||||||||||||||
| if cve['id'] != current_cve_id: | ||||||||||||||||
| self.foreman_params['content_view_environment_id'] = cve['id'] | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| class ForemanAnsibleModule(AnsibleModule): | ||||||||||||||||
| """ Baseclass for all foreman related Ansible modules. | ||||||||||||||||
|
|
||||||||||||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given it's not exposed to the user, we need to flag them as "plugin required"