From 6cd80668be76f8ebad51f418fbaa5b313e20b356 Mon Sep 17 00:00:00 2001 From: kksat <22549266+kksat@users.noreply.github.com> Date: Fri, 19 Apr 2024 14:05:21 +0000 Subject: [PATCH] Release galaxy-1.27.0 Signed-off-by: kksat <22549266+kksat@users.noreply.github.com> --- README.md | 5 +- docs/CHANGELOG.md | 203 ++++++++++-------- galaxy.yml | 14 +- playbooks/sample_test_sap_btp.yml | 111 ++++++++++ .../btp_global_account_assignments_info.py | 90 ++++++++ plugins/action/btp_global_account_info.py | 97 +++++++++ plugins/action/btp_subaccount.py | 126 +++++++++++ plugins/action/btp_subaccounts_info.py | 75 +++++++ .../btp_global_account_assignments_info.py | 78 +++++++ plugins/modules/btp_subaccount.py | 193 +++++++++++++++++ plugins/modules/btp_subaccounts_info.py | 136 ++++++++++++ 11 files changed, 1033 insertions(+), 95 deletions(-) create mode 100644 playbooks/sample_test_sap_btp.yml create mode 100644 plugins/action/btp_global_account_assignments_info.py create mode 100644 plugins/action/btp_subaccount.py create mode 100644 plugins/action/btp_subaccounts_info.py create mode 100644 plugins/modules/btp_global_account_assignments_info.py create mode 100644 plugins/modules/btp_subaccount.py create mode 100644 plugins/modules/btp_subaccounts_info.py diff --git a/README.md b/README.md index 454e69c..db6cdf9 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,10 @@ Added documentation website [docs.galaxy.saponrhel.org>](https://docs.galaxy.sap Added modules to manage SAP BTP resources. -- sap.sap operations.btp_global_account_info +- sap.sap_operations.btp_global_account_info +- sap.sap_operations.btp_global_account_assignments_info +- sap.sap_operations.btp_subaccount +- sap.sap_operations.btp_subaccounts_info Added modules to manage SAP BTP Cloud Foundry. diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 38e6350..f90527b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,122 +2,141 @@ **Topics** -- v1\.26\.0 +- v1\.27\.0 - Release Summary + - Minor Changes - New Modules -- v1\.25\.0 +- v1\.26\.0 - Release Summary -- v1\.24\.0 +- v1\.25\.0 - Release Summary -- v1\.23\.1 +- v1\.24\.0 - Release Summary +- v1\.23\.1 + - Release Summary - Major Changes - v1\.23\.0 - - Release Summary + - Release Summary - Major Changes - v1\.22\.1 - - Release Summary - - Minor Changes -- v1\.22\.0 - Release Summary + - Minor Changes +- v1\.22\.0 + - Release Summary - v1\.21\.0 - v1\.20\.0 - - Release Summary + - Release Summary - Major Changes - v1\.19\.0 - - Release Summary + - Release Summary - Major Changes - v1\.18\.0 - v1\.17\.0 - - Release Summary + - Release Summary - Major Changes - v1\.16\.0 - v1\.15\.1 - - Release Summary - - Minor Changes -- v1\.15\.0 - Release Summary + - Minor Changes +- v1\.15\.0 + - Release Summary - Major Changes - v1\.14\.1 - - Release Summary - - Minor Changes + - Release Summary + - Minor Changes - v1\.14\.0 - v1\.13\.0 - - Release Summary + - Release Summary - Major Changes - v1\.12\.0 - - Release Summary -- v1\.11\.0 - Release Summary - - Minor Changes -- v1\.10\.0 +- v1\.11\.0 - Release Summary -- v1\.9\.1 - - Release Summary - Minor Changes -- v1\.9\.0 +- v1\.10\.0 + - Release Summary +- v1\.9\.1 - Release Summary + - Minor Changes +- v1\.9\.0 + - Release Summary - Major Changes - v1\.3\.2 - - Release Summary - - Minor Changes -- v1\.3\.1 - Release Summary - Minor Changes -- v1\.3\.0 +- v1\.3\.1 - Release Summary - Minor Changes -- v1\.2\.2 +- v1\.3\.0 - Release Summary - Minor Changes -- v1\.2\.1 +- v1\.2\.2 - Release Summary - Minor Changes -- v1\.2\.0 +- v1\.2\.1 - Release Summary + - Minor Changes +- v1\.2\.0 + - Release Summary - Major Changes - v1\.1\.2 - - Release Summary - - Minor Changes -- v1\.1\.1 - Release Summary - Minor Changes -- v1\.1\.0 +- v1\.1\.1 - Release Summary -- v1\.0\.5 - - Release Summary - Minor Changes -- v1\.0\.4 +- v1\.1\.0 + - Release Summary +- v1\.0\.5 - Release Summary - - Major Changes - Minor Changes -- v1\.0\.3 +- v1\.0\.4 - Release Summary + - Major Changes - Minor Changes -- v1\.0\.2 +- v1\.0\.3 - Release Summary + - Minor Changes +- v1\.0\.2 + - Release Summary - Major Changes - v1\.0\.0 - - Release Summary + - Release Summary - Major Changes - -## v1\.26\.0 + +## v1\.27\.0 ### Release Summary Feature release + +### Minor Changes + +* Add tags to collection metadata +* Update collection description + ### New Modules -* sap\.sap\_operations\.btp\_global\_account\_info \- Get information about a SAP BTP global account\. +* sap\.sap\_operations\.btp\_global\_account\_assignments\_info \- Fetches global account assignments information from SAP BTP\. +* sap\.sap\_operations\.btp\_subaccount \- Manage SAP BTP global account subaccounts +* sap\.sap\_operations\.btp\_subaccounts\_info \- Fetches information about SAP BTP subaccounts + + +## v1\.26\.0 + + +### Release Summary + +Feature release ## v1\.25\.0 - + ### Release Summary Feature release @@ -125,7 +144,7 @@ Feature release ## v1\.24\.0 - + ### Release Summary Feature release @@ -133,7 +152,7 @@ Feature release ## v1\.23\.1 - + ### Release Summary Documentation release @@ -146,7 +165,7 @@ Documentation release ## v1\.23\.0 - + ### Release Summary Maintenance release @@ -159,12 +178,12 @@ Maintenance release ## v1\.22\.1 - + ### Release Summary Documentation release - + ### Minor Changes * generate CHANGELOG in MD format @@ -173,7 +192,7 @@ Documentation release ## v1\.22\.0 - + ### Release Summary Feature release @@ -184,7 +203,7 @@ Feature release ## v1\.20\.0 - + ### Release Summary Feature release @@ -197,7 +216,7 @@ Feature release ## v1\.19\.0 - + ### Release Summary Feature release @@ -213,7 +232,7 @@ Feature release ## v1\.17\.0 - + ### Release Summary Feature release @@ -229,12 +248,12 @@ Feature release ## v1\.15\.1 - + ### Release Summary Bugfix release - + ### Minor Changes * Update documentation for several modules @@ -242,7 +261,7 @@ Bugfix release ## v1\.15\.0 - + ### Release Summary Feature release @@ -255,12 +274,12 @@ Feature release ## v1\.14\.1 - + ### Release Summary Bug fix release - + ### Minor Changes * Fix ansible\-lint errors @@ -272,7 +291,7 @@ Bug fix release ## v1\.13\.0 - + ### Release Summary Feature release @@ -285,7 +304,7 @@ Feature release ## v1\.12\.0 - + ### Release Summary Feature release @@ -293,12 +312,12 @@ Feature release ## v1\.11\.0 - + ### Release Summary Feature release - + ### Minor Changes * Add role pcs\_config\_checks @@ -306,7 +325,7 @@ Feature release ## v1\.10\.0 - + ### Release Summary Feature release @@ -314,12 +333,12 @@ Feature release ## v1\.9\.1 - + ### Release Summary Bug fix release - + ### Minor Changes * Fix bug with hana\_update role @@ -328,7 +347,7 @@ Bug fix release ## v1\.9\.0 - + ### Release Summary Lifecycle release @@ -346,12 +365,12 @@ Lifecycle release ## v1\.3\.2 - + ### Release Summary Bugfix release - + ### Minor Changes * Resolve sanity errors for python 2\.7 and lower versions of python 3 @@ -359,12 +378,12 @@ Bugfix release ## v1\.3\.1 - + ### Release Summary Bugfix release - + ### Minor Changes * Resolve syntax issues with hana\_update role @@ -372,12 +391,12 @@ Bugfix release ## v1\.3\.0 - + ### Release Summary Feature release - + ### Minor Changes * Add functionality to release different content to AAP and Ansible galaxy @@ -387,12 +406,12 @@ Feature release ## v1\.2\.2 - + ### Release Summary Feature release - + ### Minor Changes * Small changes to role argument\_specs \- fixes documentation linting errors @@ -400,12 +419,12 @@ Feature release ## v1\.2\.1 - + ### Release Summary Feature release - + ### Minor Changes * Collection automatically uploaded to Ansible Galaxy and AAP @@ -413,7 +432,7 @@ Feature release ## v1\.2\.0 - + ### Release Summary Feature release @@ -426,12 +445,12 @@ Feature release ## v1\.1\.2 - + ### Release Summary Bug Fix Release - + ### Minor Changes * Fix issue with role prepare @@ -439,12 +458,12 @@ Bug Fix Release ## v1\.1\.1 - + ### Release Summary Bug Fix Release - + ### Minor Changes * Fix issue with module host\_info \- module failed if SAP HANA databases installed \(incorrect indexing\) @@ -455,7 +474,7 @@ Bug Fix Release ## v1\.1\.0 - + ### Release Summary Feature Release @@ -463,12 +482,12 @@ Feature Release ## v1\.0\.5 - + ### Release Summary Bug fix release - + ### Minor Changes * Documentation added for roles hana\_update and prepare @@ -476,7 +495,7 @@ Bug fix release ## v1\.0\.4 - + ### Release Summary Two roles are added hana\_update and prepare @@ -487,7 +506,7 @@ Two roles are added hana\_update and + ### Minor Changes * GitHub action to publish collection @@ -495,12 +514,12 @@ Two roles are added hana\_update and ## v1\.0\.3 - + ### Release Summary Using changelog fragments to build collection changelog\. - + ### Minor Changes * Improvements in the collection build and publish process\. @@ -509,7 +528,7 @@ Using changelog fragments to build collection changelog\. ## v1\.0\.2 - + ### Release Summary First release of SAP Operations collection\. @@ -526,7 +545,7 @@ First release of SAP Operations collection\. ## v1\.0\.0 - + ### Release Summary First release of SAP Operations collection\. diff --git a/galaxy.yml b/galaxy.yml index d9331ce..690d942 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -24,7 +24,7 @@ namespace: sap name: sap_operations -version: 1.26.0 +version: 1.27.0 readme: README.md @@ -32,7 +32,7 @@ authors: - Ondra Machacek - Kirill Satarin (@kksat) -description: Ansible collection to handle day 2 operational SAP administration tasks. +description: Ansible collection to automate SAP operations license: - GPL-3.0-only @@ -42,6 +42,16 @@ license_file: "" tags: - linux - sap + - hana + - hdb + - abap + - netweaver + - btp + - cloudfoundry + - saphostagent + - azure + - cloud + - pacemaker dependencies: {} diff --git a/playbooks/sample_test_sap_btp.yml b/playbooks/sample_test_sap_btp.yml new file mode 100644 index 0000000..2a2ace4 --- /dev/null +++ b/playbooks/sample_test_sap_btp.yml @@ -0,0 +1,111 @@ +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2024 Red Hat, Project Atmosphere +# +# Copyright 2024 Red Hat, Project Atmosphere +# +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU +# General Public License as published by the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# 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. +# +# You should have received a copy of the GNU General Public License along with this program. +# If not, see . + +--- +- name: Test + hosts: localhost + gather_facts: true + environment: + OBJC_DISABLE_INITIALIZE_FORK_SAFETY: "YES" # this is required only for macOs to avoid the error + vars: + random_seed: "{{ lookup('ansible.builtin.env', 'USER') + ansible_hostname }}" + max_int: 2147483647 + random_string: "{{ max_int | ansible.builtin.random(seed=random_seed)}}" + cis_service_name: "cis-{{ random_string }}" + cis_key_name: "cis-key-{{ random_string }}" + subaccount_subdomain: "ansible-subdomain-{{ random_string }}" + subaccount_description: "Subaccount managed by ansible" + subaccount_display_name: "ansible-subaccount-{{ random_string }}" + subaccount_admins: [] + subaccount_region: us10 + + pre_tasks: + - name: Make sure cis service instance is present + sap.sap_operations.cf_service_instance: + username: "{{ lookup('ansible.builtin.env', 'BTP_LOGIN') }}" + password: "{{ lookup('ansible.builtin.env', 'BTP_PASSWORD') }}" + api_endpoint: "{{ lookup('ansible.builtin.env', 'BTP_API_ENDPOINT') }}" + name: "{{ cis_service_name }}" + service: cis + service_plan: central + space: dev + parameters: + grantType: password + register: cis_service + + - name: Make sure cis service instance service key is present + sap.sap_operations.cf_service_instance_key: + username: "{{ lookup('ansible.builtin.env', 'BTP_LOGIN') }}" + password: "{{ lookup('ansible.builtin.env', 'BTP_PASSWORD') }}" + api_endpoint: "{{ lookup('ansible.builtin.env', 'BTP_API_ENDPOINT') }}" + service_instance_name: "{{ cis_service_name }}" + key_name: "{{ cis_key_name }}" + register: cis_service_key + + tasks: + - name: Test btp_global_account_info action plugin (expand is true) + sap.sap_operations.btp_global_account_info: + login: "{{ lookup('ansible.builtin.env', 'BTP_LOGIN') }}" + password: "{{ lookup('ansible.builtin.env', 'BTP_PASSWORD') }}" + api_endpoint: https://accounts-service.cfapps.eu10.hana.ondemand.com + authorize_service_url: "https://accounts-service.cfapps.eu10.hana.ondemand.com/oauth/authorize" + client_id: "{{ cis_service_key.cf_service_instance_key.entity.credentials.uaa.clientid }}" + client_secret: "{{ cis_service_key.cf_service_instance_key.entity.credentials.uaa.clientsecret }}" + token_service_url: "{{ cis_service_key.cf_service_instance_key.entity.credentials.uaa.url }}/oauth/token" + expand: true + register: result_expand_true + + - name: Get SAP BTP global account assignments + sap.sap_operations.btp_global_account_assignments_info: + login: "{{ lookup('ansible.builtin.env', 'BTP_LOGIN') }}" + password: "{{ lookup('ansible.builtin.env', 'BTP_PASSWORD') }}" + api_endpoint: https://entitlements-service.cfapps.eu10.hana.ondemand.com + authorize_service_url: "https://entitlements-service.cfapps.eu10.hana.ondemand.com/oauth/authorize" + client_id: "{{ cis_service_key.cf_service_instance_key.entity.credentials.uaa.clientid }}" + client_secret: "{{ cis_service_key.cf_service_instance_key.entity.credentials.uaa.clientsecret }}" + token_service_url: "{{ cis_service_key.cf_service_instance_key.entity.credentials.uaa.url }}/oauth/token" + + - name: Get SAP BTP subaccounts + sap.sap_operations.btp_subaccounts_info: + login: "{{ lookup('ansible.builtin.env', 'BTP_LOGIN') }}" + password: "{{ lookup('ansible.builtin.env', 'BTP_PASSWORD') }}" + api_endpoint: https://accounts-service.cfapps.eu10.hana.ondemand.com + authorize_service_url: "https://accounts-service.cfapps.eu10.hana.ondemand.com/oauth/authorize" + client_id: "{{ cis_service_key.cf_service_instance_key.entity.credentials.uaa.clientid }}" + client_secret: "{{ cis_service_key.cf_service_instance_key.entity.credentials.uaa.clientsecret }}" + token_service_url: "{{ cis_service_key.cf_service_instance_key.entity.credentials.uaa.url }}/oauth/token" + + - name: Create SAP BTP subaccount + sap.sap_operations.btp_subaccount: + login: "{{ lookup('ansible.builtin.env', 'BTP_LOGIN') }}" + password: "{{ lookup('ansible.builtin.env', 'BTP_PASSWORD') }}" + api_endpoint: https://accounts-service.cfapps.eu10.hana.ondemand.com + authorize_service_url: "https://accounts-service.cfapps.eu10.hana.ondemand.com/oauth/authorize" + client_id: "{{ cis_service_key.cf_service_instance_key.entity.credentials.uaa.clientid }}" + client_secret: "{{ cis_service_key.cf_service_instance_key.entity.credentials.uaa.clientsecret }}" + token_service_url: "{{ cis_service_key.cf_service_instance_key.entity.credentials.uaa.url }}/oauth/token" + beta_enabled: true + description: "{{ subaccount_description }}" + display_name: "{{ subaccount_display_name }}" + region: "{{ subaccount_region }}" + subaccount_admins: "{{ subaccount_admins }}" + subdomain: "{{ subaccount_subdomain }}" + register: new_subaccount diff --git a/plugins/action/btp_global_account_assignments_info.py b/plugins/action/btp_global_account_assignments_info.py new file mode 100644 index 0000000..6ba9f82 --- /dev/null +++ b/plugins/action/btp_global_account_assignments_info.py @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- +# +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2024 Red Hat, Project Atmosphere +# +# Copyright 2024 Red Hat, Project Atmosphere +# +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU +# General Public License as published by the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# 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. +# +# You should have received a copy of the GNU General Public License along with this program. +# If not, see . + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + + +from ansible_collections.sap.sap_operations.plugins.action.btp_global_account_info import ( + BTPAccountsServiceClient, + BTPActionModule, + plugin_failed, + btp_required_together, + btp_argument_spec, +) + + +def run_plugin( + client: BTPAccountsServiceClient, + token: str, + include_auto_managed_plans: bool = True, + entitled_services_only: bool = True, +) -> dict: + btp_global_account_assignments_info, err = client.get_global_account_assignments( + token=token, + include_auto_managed_plans=include_auto_managed_plans, + entitled_services_only=entitled_services_only, + ) + if err is not None: + return plugin_failed( + err, msg="Could not get global account assignments information" + ) + + return { + "failed": False, + "changed": False, + "btp_global_account_assignments_info": dict( + btp_global_account_assignments_info + ), + } + + +class ActionModule(BTPActionModule): + _VALID_ARGS = BTPActionModule._VALID_ARGS.union( + [ + "include_auto_managed_plans", + "entitled_services_only", + ] + ) + + def run(self, tmp=None, task_vars=None): + super().run(tmp, task_vars) + + action_argument_spec = dict( + include_auto_managed_plans=dict(type="bool", required=False, default=True), + entitled_services_only=dict(type="bool", required=False, default=True), + ) + argument_spec = dict(**btp_argument_spec, **action_argument_spec) + self.validate_argument_spec( + argument_spec=argument_spec, required_together=btp_required_together + ) + include_auto_managed_plans = self._task.args.get("include_auto_managed_plans") + entitled_services_only = self._task.args.get("entitled_services_only") + + return run_plugin( + client=self.client, + token=self.oauth_client.token, + include_auto_managed_plans=include_auto_managed_plans, + entitled_services_only=entitled_services_only, + ) diff --git a/plugins/action/btp_global_account_info.py b/plugins/action/btp_global_account_info.py index f0e2ef6..b25581e 100644 --- a/plugins/action/btp_global_account_info.py +++ b/plugins/action/btp_global_account_info.py @@ -116,6 +116,103 @@ def get_global_account( ) return BTPGlobalAccount(**json.loads(response.text)), None + def get_global_account_assignments( + self, + token: str, + **kwargs, + ): + url_params = "" + if not HAS_REQUESTS_LIBRARY: + return None, BTPAPIError( + msg=missing_required_lib("requests"), + exception=REQUESTS_LIBRARY_IMPORT_ERROR, + ) + if kwargs.get("include_auto_managed_plans"): + url_params += "&includeAutoManagedPlans=true" + if kwargs.get("entitled_services_only"): + url_params += "&entitledServicesOnly=true" + try: + response = requests.get( + f"{self.url}/entitlements/v1/assignments?directoryGUID=7abf6926-f5da-467e-975a-cf2473680127" + url_params, + headers=get_headers(token), + timeout=60, + ) + response.raise_for_status() + except requests.exceptions.HTTPError: + return None, BTPAPIError( + response=response.text, + status_code=response.status_code, + ) + return BTPGlobalAccount(**json.loads(response.text)), None + + def get_subaccounts( + self, + token: str, + ): + + url_params = "" + if not HAS_REQUESTS_LIBRARY: + return None, BTPAPIError( + msg=missing_required_lib("requests"), + exception=REQUESTS_LIBRARY_IMPORT_ERROR, + ) + try: + response = requests.get( + f"{self.url}/accounts/v1/subaccounts?derivedAuthorizations=any" + url_params, + headers=get_headers(token), + timeout=60, + ) + response.raise_for_status() + except requests.exceptions.HTTPError: + return None, BTPAPIError( + response=response.text, + status_code=response.status_code, + ) + subaccounts = json.loads(response.text)["value"] + return subaccounts, None + + def create_subaccount(self, token: str, **kwargs): + body = {} + if kwargs.get("beta_enabled") is not None: + body["betaEnabled"] = kwargs["beta_enabled"] + + if kwargs.get("description") is not None: + body["description"] = kwargs["description"] + + if kwargs.get("display_name") is not None: + body["displayName"] = kwargs["display_name"] + + if kwargs.get("region") is not None: + body["region"] = kwargs["region"] + + if kwargs.get("subdomain") is not None: + body["subdomain"] = kwargs["subdomain"] + + if kwargs.get("subaccount_admins") is not None: + body["subaccountAdmins"] = kwargs["subaccount_admins"] + + body["usedForProduction"] = "USED_FOR_PRODUCTION" + + if not HAS_REQUESTS_LIBRARY: + return None, BTPAPIError( + msg=missing_required_lib("requests"), + exception=REQUESTS_LIBRARY_IMPORT_ERROR, + ) + try: + response = requests.post( + f"{self.url}/accounts/v1/subaccounts", + headers=get_headers(token), + json=body, + timeout=60, + ) + response.raise_for_status() + except requests.exceptions.HTTPError: + return None, BTPAPIError( + response=response.text, + status_code=response.status_code, + ) + return BTPGlobalAccount(**json.loads(response.text)), None + import traceback from abc import ABC, abstractmethod diff --git a/plugins/action/btp_subaccount.py b/plugins/action/btp_subaccount.py new file mode 100644 index 0000000..e96bc2c --- /dev/null +++ b/plugins/action/btp_subaccount.py @@ -0,0 +1,126 @@ +# -*- coding: utf-8 -*- +# +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2024 Red Hat, Project Atmosphere +# +# Copyright 2024 Red Hat, Project Atmosphere +# +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU +# General Public License as published by the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# 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. +# +# You should have received a copy of the GNU General Public License along with this program. +# If not, see . + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + + +from ansible_collections.sap.sap_operations.plugins.action.btp_global_account_info import ( + BTPAccountsServiceClient, + BTPActionModule, + plugin_failed, + btp_required_together, + btp_argument_spec, +) + + +def run_plugin( + client: BTPAccountsServiceClient, + token: str, + **kwargs, +) -> dict: + description = kwargs.get("description") + beta_enabled = kwargs.get("beta_enabled") + display_name = kwargs.get("display_name") + region = kwargs.get("region") + subaccount_admins = kwargs.get("subaccount_admins") + subdomain = kwargs.get("subdomain") + + btp_subaccounts_info, err = client.get_subaccounts( + token=token, + ) + if err is not None: + return plugin_failed(err, msg="Could not get subaccounts") + + subaccount = None + for subacc in btp_subaccounts_info: + if subdomain == subacc.get("subdomain"): + subaccount = subacc + + if subaccount is not None: + return {"failed": False, "changed": False, "btp_subaccount": subaccount} + + btp_subaccount, err = client.create_subaccount( + token=token, + description=description, + beta_enabled=beta_enabled, + display_name=display_name, + region=region, + subaccount_admins=subaccount_admins, + subdomain=subdomain, + ) + if err is not None: + return plugin_failed(err, msg="Could not get subaccounts") + + return { + "failed": False, + "changed": True, + "btp_subaccount": dict(btp_subaccount), + } + + +class ActionModule(BTPActionModule): + _VALID_ARGS = BTPActionModule._VALID_ARGS.union( + [ + "description", + "beta_enabled", + "display_name", + "region", + "subaccount_admins", + "subdomain", + ] + ) + + def run(self, tmp=None, task_vars=None): + super().run(tmp, task_vars) + + action_argument_spec = dict( + description=dict(type="str", required=True), + beta_enabled=dict(type="bool", default=True, required=False), + display_name=dict(type="str", required=True), + region=dict(type="str", required=True), + subaccount_admins=dict(type="list", elements="str", required=True), + subdomain=dict(type="str", required=True), + ) + argument_spec = dict(**btp_argument_spec, **action_argument_spec) + self.validate_argument_spec( + argument_spec=argument_spec, required_together=btp_required_together + ) + description = self._task.args.get("description") + beta_enabled = self._task.args.get("beta_enabled") + display_name = self._task.args.get("display_name") + region = self._task.args.get("region") + subaccount_admins = self._task.args.get("subaccount_admins") + subdomain = self._task.args.get("subdomain") + + return run_plugin( + client=self.client, + token=self.oauth_client.token, + description=description, + beta_enabled=beta_enabled, + display_name=display_name, + region=region, + subaccount_admins=subaccount_admins, + subdomain=subdomain, + ) diff --git a/plugins/action/btp_subaccounts_info.py b/plugins/action/btp_subaccounts_info.py new file mode 100644 index 0000000..788f082 --- /dev/null +++ b/plugins/action/btp_subaccounts_info.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- +# +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2024 Red Hat, Project Atmosphere +# +# Copyright 2024 Red Hat, Project Atmosphere +# +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU +# General Public License as published by the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# 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. +# +# You should have received a copy of the GNU General Public License along with this program. +# If not, see . + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + + +from ansible_collections.sap.sap_operations.plugins.action.btp_global_account_info import ( + BTPAccountsServiceClient, + BTPActionModule, + plugin_failed, + btp_required_together, + btp_argument_spec, +) + + +def run_plugin( + client: BTPAccountsServiceClient, + token: str, +) -> dict: + btp_subaccounts_info, err = client.get_subaccounts( + token=token, + ) + if err is not None: + return plugin_failed(err, msg="Could not get subaccounts") + + return { + "failed": False, + "changed": False, + "btp_subaccounts_info": btp_subaccounts_info, + } + + +class ActionModule(BTPActionModule): + _VALID_ARGS = BTPActionModule._VALID_ARGS.union( + [ + "include_auto_managed_plans", + "entitled_services_only", + ] + ) + + def run(self, tmp=None, task_vars=None): + super().run(tmp, task_vars) + + action_argument_spec = dict() + argument_spec = dict(**btp_argument_spec, **action_argument_spec) + self.validate_argument_spec( + argument_spec=argument_spec, required_together=btp_required_together + ) + + return run_plugin( + client=self.client, + token=self.oauth_client.token, + ) diff --git a/plugins/modules/btp_global_account_assignments_info.py b/plugins/modules/btp_global_account_assignments_info.py new file mode 100644 index 0000000..42d4d82 --- /dev/null +++ b/plugins/modules/btp_global_account_assignments_info.py @@ -0,0 +1,78 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2024 Red Hat, Project Atmosphere +# +# Copyright 2024 Red Hat, Project Atmosphere +# +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU +# General Public License as published by the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# 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. +# +# You should have received a copy of the GNU General Public License along with this program. +# If not, see . + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +DOCUMENTATION = r""" +--- +module: btp_global_account_assignments_info + +extends_documentation_fragment: + - sap.sap_operations.sap_btp_action_plugin + - sap.sap_operations.community + - sap.sap_operations.action_plugin + +author: + - Kirill Satarin (@kksat) + +short_description: Fetches global account assignments information from SAP BTP. +version_added: 1.27.0 +description: + - This module fetches global account assignments information from SAP Business Technology Platform (BTP). + - It can filter the results based on whether to include auto-managed plans and/or only entitled services. + +options: + include_auto_managed_plans: + description: + - Whether to include auto-managed plans in the fetched information. + type: bool + required: False + default: True + entitled_services_only: + description: + - Whether to fetch information for only those services that the account is entitled to. + type: bool + required: False + default: True +""" + +EXAMPLES = r""" +--- +- name: Fetch global account assignments information including auto-managed plans and entitled services only + sap.sap_operations.btp_global_account_info: + include_auto_managed_plans: true + entitled_services_only: true + +- name: Fetch global account assignments information excluding auto-managed plans + sap.sap_operations.btp_global_account_info: + include_auto_managed_plans: false + entitled_services_only: true + +- name: Fetch global account assignments information for all services, including those not entitled + sap.sap_operations.btp_global_account_info: + include_auto_managed_plans: true + entitled_services_only: false +""" diff --git a/plugins/modules/btp_subaccount.py b/plugins/modules/btp_subaccount.py new file mode 100644 index 0000000..f4fcdc4 --- /dev/null +++ b/plugins/modules/btp_subaccount.py @@ -0,0 +1,193 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2024 Red Hat, Project Atmosphere +# +# Copyright 2024 Red Hat, Project Atmosphere +# +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU +# General Public License as published by the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# 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. +# +# You should have received a copy of the GNU General Public License along with this program. +# If not, see . + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + + +DOCUMENTATION = r""" +--- +module: btp_subaccount + +extends_documentation_fragment: + - sap.sap_operations.sap_btp_action_plugin + - sap.sap_operations.community + - sap.sap_operations.action_plugin + +author: + - Kirill Satarin (@kksat) + +short_description: Manage SAP BTP global account subaccounts +version_added: 1.27.0 +description: + - This module allows managing SAP BTP global account subaccounts, including creation and information retrieval. + - Subaccount will not be updated if there is already subaccount with same subdomain. + - It is not yet possible to remove existing subaccount with this plugin + +options: + description: + description: + - Description of the subaccount to be created or managed. + required: true + type: str + beta_enabled: + description: + - Specifies if the subaccount should have beta features enabled. + required: false + default: true + type: bool + display_name: + description: + - The display name for the subaccount. + required: true + type: str + region: + description: + - The region where the subaccount will be created. + required: true + type: str + subaccount_admins: + description: + - A list of emails for the subaccount administrators. + required: true + type: list + elements: str + subdomain: + description: + - The subdomain for the subaccount + - Should be globally unique + required: true + type: str +""" + +EXAMPLES = r""" +--- +- name: Create a new subaccount in SAP BTP + sap.sap_operations.btp_subaccount: + description: "Development environment" + beta_enabled: true + display_name: "Dev Environment" + region: "eu10" + subaccount_admins: + - "admin@example.com" + subdomain: "dev-env" +""" + + +RETURN = r""" +--- +btp_subaccount: + description: The result of the Ansible plugin operation, containing details about the subaccount. + returned: success + type: dict + sample: + betaEnabled: true + contentAutomationState: null + contentAutomationStateDetails: null + createdBy: null + createdDate: 1713452527495 + description: "Subaccount managed by ansible" + displayName: "ansible-subaccount-1775088641" + globalAccountGUID: "7hbf5926-fh9a-4b7e-9b5a-cf3hls6s7" + guid: "42fss8ec-r75b-4n0l-b5;e-c8b40dd9d839" + modifiedDate: 1713452550559 + parentGUID: "7hbf5926-4hda-4b7e-9b5a-cfl8ls6s7" + parentType: "ROOT" + region: "us10" + state: "OK" + stateMessage: "Subaccount created." + subdomain: "ansible-subdomain-1775088641" + technicalName: "42fss8ec-r75b-4n0l-b5;e-c8b40dd9d839" + usedForProduction: "USED_FOR_PRODUCTION" + contains: + betaEnabled: + description: Indicates if the beta features are enabled for the subaccount. + returned: always + type: bool + contentAutomationState: + description: The state of content automation for the subaccount, if applicable. + returned: when applicable + type: str + createdBy: + description: The identifier of the user who created the subaccount. + returned: when available + type: str + createdDate: + description: The timestamp when the subaccount was created. + returned: always + type: str + description: + description: A brief description of the subaccount. + returned: always + type: str + displayName: + description: The display name of the subaccount. + returned: always + type: str + globalAccountGUID: + description: The GUID of the global account to which the subaccount belongs. + returned: always + type: str + guid: + description: The unique identifier of the subaccount. + returned: always + type: str + modifiedDate: + description: The timestamp when the subaccount was last modified. + returned: always + type: str + parentGUID: + description: The GUID of the parent account. + returned: always + type: str + parentType: + description: The type of the parent account. + returned: always + type: str + region: + description: The region in which the subaccount is located. + returned: always + type: str + state: + description: The current state of the subaccount. + returned: always + type: str + stateMessage: + description: A message providing additional details about the state of the subaccount. + returned: always + type: str + subdomain: + description: The subdomain assigned to the subaccount. + returned: always + type: str + technicalName: + description: The technical name of the subaccount. + returned: always + type: str + usedForProduction: + description: Indicates whether the subaccount is used for production purposes. + returned: always + type: str +""" diff --git a/plugins/modules/btp_subaccounts_info.py b/plugins/modules/btp_subaccounts_info.py new file mode 100644 index 0000000..cd55572 --- /dev/null +++ b/plugins/modules/btp_subaccounts_info.py @@ -0,0 +1,136 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2024 Red Hat, Project Atmosphere +# +# Copyright 2024 Red Hat, Project Atmosphere +# +# This program is free software: you can redistribute it and/or modify it under the terms of the GNU +# General Public License as published by the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# 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. +# +# You should have received a copy of the GNU General Public License along with this program. +# If not, see . + +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +DOCUMENTATION = r""" +--- +module: btp_subaccounts_info + +extends_documentation_fragment: + - sap.sap_operations.sap_btp_action_plugin + - sap.sap_operations.community + - sap.sap_operations.action_plugin + +author: + - Kirill Satarin (@kksat) + +short_description: Fetches information about SAP BTP subaccounts +version_added: 1.27.0 +description: + - This module fetches information about SAP Business Technology Platform (BTP) subaccounts. + - It uses the BTP Accounts Service API to retrieve the information. +options: + include_auto_managed_plans: + description: + - Whether to include subaccounts with auto-managed plans in the results. + type: bool + required: false + default: false + entitled_services_only: + description: + - Whether to return only subaccounts that are entitled to use services. + type: bool + required: false + default: false +""" + +EXAMPLES = r""" +--- +- name: Fetch BTP subaccounts information + sap.sap_operations.btp_subaccounts_info: + include_auto_managed_plans: true + entitled_services_only: false +""" + + +RETURN = r""" +--- +btp_subaccounts_info: + description: A list of subaccounts with their details. + returned: success + type: list + elements: dict + contains: + betaEnabled: + description: Indicates if the beta features are enabled for the subaccount. + type: bool + contentAutomationState: + description: The state of content automation, if applicable. + returned: if exists + type: str + contentAutomationStateDetails: + description: Detailed information about the content automation state, if applicable. + returned: if exists + type: str + createdBy: + description: The identifier of the user who created the subaccount, if available. + returned: if exists + type: str + createdDate: + description: The creation date of the subaccount in milliseconds since epoch. + type: int + description: + description: A description of the subaccount. + type: str + displayName: + description: The display name of the subaccount. + type: str + globalAccountGUID: + description: The GUID of the global account to which the subaccount belongs. + type: str + guid: + description: The unique identifier of the subaccount. + type: str + modifiedDate: + description: The last modification date of the subaccount in milliseconds since epoch. + type: int + parentGUID: + description: The GUID of the parent entity of the subaccount. + type: str + parentType: + description: The type of the parent entity (e.g., ROOT). + type: str + region: + description: The region where the subaccount is located. + type: str + state: + description: The current state of the subaccount (e.g., OK). + type: str + stateMessage: + description: A message providing more details about the state of the subaccount. + type: str + subdomain: + description: The subdomain assigned to the subaccount. + type: str + technicalName: + description: The technical name of the subaccount. + type: str + usedForProduction: + description: Indicates if the subaccount is used for production purposes. + type: str + sample: 'USED_FOR_PRODUCTION' +"""