Skip to content

Commit

Permalink
Add Subscribed Libraries (#1437)
Browse files Browse the repository at this point in the history
vmware_content_library_info: Add Subscribed Libraries

SUMMARY
Add Subscribed Libraries to the module.
Fixes #1430
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
vmware_content_library_info
ADDITIONAL INFORMATION
  • Loading branch information
mariolenz authored Sep 6, 2022
1 parent 9b19531 commit ff41189
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- vmware_content_library_info - Add Subscribed Libraries (https://github.com/ansible-collections/community.vmware/issues/1430).
45 changes: 33 additions & 12 deletions plugins/modules/vmware_content_library_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,46 @@ def __init__(self, module):
"""Constructor."""
super(VmwareContentLibInfo, self).__init__(module)
self.content_service = self.api_client
self.local_content_libraries = self.content_service.content.LocalLibrary.list()
if self.local_content_libraries is None:
self.local_content_libraries = []

self.subscribed_content_libraries = self.content_service.content.SubscribedLibrary.list()
if self.subscribed_content_libraries is None:
self.subscribed_content_libraries = []

self.library_info = []

def get_all_content_libs(self):
"""Method to retrieve List of content libraries."""
self.module.exit_json(changed=False, content_libs=self.content_service.content.LocalLibrary.list())
content_libraries = self.local_content_libraries + self.subscribed_content_libraries

self.module.exit_json(changed=False, content_libs=content_libraries)

def get_content_lib_details(self, library_id):
"""Method to retrieve Details of contentlib with library_id"""
try:
lib_details = self.content_service.content.LocalLibrary.get(library_id)
except Exception as e:
self.module.fail_json(exists=False, msg="%s" % self.get_error_message(e))
lib_publish_info = dict(
persist_json_enabled=lib_details.publish_info.persist_json_enabled,
authentication_method=lib_details.publish_info.authentication_method,
publish_url=lib_details.publish_info.publish_url,
published=lib_details.publish_info.published,
user_name=lib_details.publish_info.user_name
)
lib_publish_info = None

if library_id in self.local_content_libraries:
try:
lib_details = self.content_service.content.LocalLibrary.get(library_id)
lib_publish_info = dict(
persist_json_enabled=lib_details.publish_info.persist_json_enabled,
authentication_method=lib_details.publish_info.authentication_method,
publish_url=lib_details.publish_info.publish_url,
published=lib_details.publish_info.published,
user_name=lib_details.publish_info.user_name
)
except Exception as e:
self.module.fail_json(exists=False, msg="%s" % self.get_error_message(e))
elif library_id in self.subscribed_content_libraries:
try:
lib_details = self.content_service.content.SubscribedLibrary.get(library_id)
except Exception as e:
self.module.fail_json(exists=False, msg="%s" % self.get_error_message(e))
else:
self.module.fail_json(exists=False, msg="Library %s not found." % library_id)

self.library_info.append(
dict(
library_name=lib_details.name,
Expand Down

0 comments on commit ff41189

Please sign in to comment.