Skip to content

Commit

Permalink
Add cluster service, role, role group modules (cloudera-labs#220)
Browse files Browse the repository at this point in the history
* Add service module
* Add service_info module
* Add service_types_info module
* Add service_config_info module
* Add service_config module
* Add service_role module
* Add service_role_info module
* Add service_role_config module
* Add service_role_config_info module
* Add service_role_config_group module
* Add service_role_config_group_info module
* Add service_role_config_group_config module
* Add service_role_config_group_config_info module
* Strip trailing forward slash and whitespace from the endpoint parameter
* Add HTTP proxy parameter and user agent header to common API object
* Update argument_spec signatures
* Add service, role output filtering
* Update API error handling messages
* Add wait_command for CM command polling
* Add function for parameter change sets
* Add cloudera.css to docsbuild and add doc format

Signed-off-by: Webster Mudge <wmudge@cloudera.com>
  • Loading branch information
wmudge authored May 8, 2024
1 parent 49ba400 commit 86b541c
Show file tree
Hide file tree
Showing 37 changed files with 7,692 additions and 58 deletions.
16 changes: 16 additions & 0 deletions docsbuild/cloudera.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright 2024 Cloudera, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

10 changes: 10 additions & 0 deletions plugins/doc_fragments/cm_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,14 @@ class ModuleDocFragment(object):
type: str
required: False
default: ClouderaFoundry
aliases:
- user_agent
proxy_server:
description:
- Set the HTTP/S proxy server when interacting with the CM API endpoint.
type: str
required: False
aliases:
- proxy
- http_proxy
"""
29 changes: 29 additions & 0 deletions plugins/doc_fragments/message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

class ModuleDocFragment(object):
DOCUMENTATION = r'''
options:
message:
description:
- Message to log for any changes to the entity.
type: str
required: False
default: "Managed by Ansible"
aliases:
- msg
'''
27 changes: 27 additions & 0 deletions plugins/doc_fragments/purge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

class ModuleDocFragment(object):
DOCUMENTATION = r'''
options:
purge:
description:
- Set all parameters to either their default or declared values.
type: bool
required: False
default: False
'''
38 changes: 25 additions & 13 deletions plugins/lookup/cm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import (absolute_import, division, print_function)
from __future__ import absolute_import, division, print_function

__metaclass__ = type

DOCUMENTATION = '''
DOCUMENTATION = """
lookup: cm_service
author: Webster Mudge (@wmudge) <wmudge@cloudera.com>
short_description: Get the details for a service on a CDP Datahub cluster
Expand Down Expand Up @@ -83,35 +84,46 @@
description: Value to return if no service is found on the cluster.
type: any
version:
description: Version number of the Cloudera Manager API.
description: Version of the Cloudera Manager API.
type: string
default: v40
agent_header:
description: Header string to identify the connection.
type: string
default: cm_service
notes:
- Requires C(cm_client).
'''
"""

from ansible_collections.cloudera.cluster.plugins.module_utils.cm_controller_utils import ClouderaManagerLookupBase
from ansible_collections.cloudera.cluster.plugins.module_utils.cm_controller_utils import (
ClouderaManagerLookupBase,
)


class LookupModule(ClouderaManagerLookupBase):
def run(self, terms, variables=None, **kwargs):
self.set_options(var_options=variables, direct=kwargs)

self.initialize_client()
all_services = {service['type']:service for service in self.get("%s/clusters/%s/services" % (self.get_option('version'), self.get_option('cluster')))}

all_services = {
service["type"]: service
for service in self.get(
"/%s/clusters/%s/services"
% (self.get_option("version"), self.get_option("cluster"))
)
}

results = []
for term in LookupModule._flatten(terms):
if term in all_services:
results.append(all_services[term] if self.get_option('detailed') else all_services[term]['name'])
results.append(
all_services[term]
if self.get_option("detailed")
else all_services[term]["name"]
)
else:
if self.get_option('default') is not None:
results.append(self.get_option('default'))
elif self.get_option('detailed'):
if self.get_option("default") is not None:
results.append(self.get_option("default"))
elif self.get_option("detailed"):
results.append({})
else:
results.append("")
Expand Down
2 changes: 1 addition & 1 deletion plugins/module_utils/cm_controller_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def initialize_client(self):

# If provided a CM API endpoint URL, use it directly
if self.get_option("endpoint"):
config.host = self.get_option("endpoint")
config.host = str(self.get_option("endpoint")).strip("/ ")
# Otherwise, run discovery on missing parts
else:
config.host = self._discover_endpoint(config)
Expand Down
Loading

0 comments on commit 86b541c

Please sign in to comment.