|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -from __future__ import (absolute_import, division, print_function) |
| 15 | +from __future__ import absolute_import, division, print_function |
| 16 | + |
16 | 17 | __metaclass__ = type |
17 | 18 |
|
18 | | -DOCUMENTATION = ''' |
| 19 | +DOCUMENTATION = """ |
19 | 20 | lookup: cm_service |
20 | 21 | author: Webster Mudge (@wmudge) <[email protected]> |
21 | 22 | short_description: Get the details for a service on a CDP Datahub cluster |
|
83 | 84 | description: Value to return if no service is found on the cluster. |
84 | 85 | type: any |
85 | 86 | version: |
86 | | - description: Version number of the Cloudera Manager API. |
| 87 | + description: Version of the Cloudera Manager API. |
87 | 88 | type: string |
88 | | - default: v40 |
89 | 89 | agent_header: |
90 | 90 | description: Header string to identify the connection. |
91 | 91 | type: string |
92 | 92 | default: cm_service |
93 | 93 | notes: |
94 | 94 | - Requires C(cm_client). |
95 | | -''' |
| 95 | +""" |
96 | 96 |
|
97 | | -from ansible_collections.cloudera.cluster.plugins.module_utils.cm_controller_utils import ClouderaManagerLookupBase |
| 97 | +from ansible_collections.cloudera.cluster.plugins.module_utils.cm_controller_utils import ( |
| 98 | + ClouderaManagerLookupBase, |
| 99 | +) |
98 | 100 |
|
99 | 101 |
|
100 | 102 | class LookupModule(ClouderaManagerLookupBase): |
101 | 103 | def run(self, terms, variables=None, **kwargs): |
102 | 104 | self.set_options(var_options=variables, direct=kwargs) |
103 | | - |
| 105 | + |
104 | 106 | self.initialize_client() |
105 | | - all_services = {service['type']:service for service in self.get("%s/clusters/%s/services" % (self.get_option('version'), self.get_option('cluster')))} |
106 | | - |
| 107 | + all_services = { |
| 108 | + service["type"]: service |
| 109 | + for service in self.get( |
| 110 | + "/%s/clusters/%s/services" |
| 111 | + % (self.get_option("version"), self.get_option("cluster")) |
| 112 | + ) |
| 113 | + } |
| 114 | + |
107 | 115 | results = [] |
108 | 116 | for term in LookupModule._flatten(terms): |
109 | 117 | if term in all_services: |
110 | | - results.append(all_services[term] if self.get_option('detailed') else all_services[term]['name']) |
| 118 | + results.append( |
| 119 | + all_services[term] |
| 120 | + if self.get_option("detailed") |
| 121 | + else all_services[term]["name"] |
| 122 | + ) |
111 | 123 | else: |
112 | | - if self.get_option('default') is not None: |
113 | | - results.append(self.get_option('default')) |
114 | | - elif self.get_option('detailed'): |
| 124 | + if self.get_option("default") is not None: |
| 125 | + results.append(self.get_option("default")) |
| 126 | + elif self.get_option("detailed"): |
115 | 127 | results.append({}) |
116 | 128 | else: |
117 | 129 | results.append("") |
|
0 commit comments