From da8376cd77ca92979ff30bb82fb336ed9c1171d2 Mon Sep 17 00:00:00 2001 From: liupei Date: Thu, 30 May 2024 17:27:58 +0800 Subject: [PATCH] fence_aliyun: update order for new parameters && support filter for list-action && add credentials file support (cherry picked from commit 2e20c2299f7089c6baab54324163ce3100c22f92) --- ..._aliyun-add-credentials-file-support.patch | 94 +++++++++++++++++++ ...liyun-support-filter-for-list-action.patch | 76 +++++++++++++++ ...iyun-update-order-for-new-parameters.patch | 34 +++++++ fence-agents.spec | 10 +- 4 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 backport-fence_aliyun-add-credentials-file-support.patch create mode 100644 backport-fence_aliyun-support-filter-for-list-action.patch create mode 100644 backport-fence_aliyun-update-order-for-new-parameters.patch diff --git a/backport-fence_aliyun-add-credentials-file-support.patch b/backport-fence_aliyun-add-credentials-file-support.patch new file mode 100644 index 0000000..12c313d --- /dev/null +++ b/backport-fence_aliyun-add-credentials-file-support.patch @@ -0,0 +1,94 @@ +From 8dd4b65fb2c9b5f3db545f589a8914792f677cf2 Mon Sep 17 00:00:00 2001 +From: Oyvind Albrigtsen +Date: Tue, 2 Apr 2024 14:37:00 +0200 +Subject: [PATCH 39/46] fence_aliyun: add credentials file support + +--- + agents/aliyun/fence_aliyun.py | 31 ++++++++++++++++++++++++++-- + tests/data/metadata/fence_aliyun.xml | 9 ++++++++ + 2 files changed, 38 insertions(+), 2 deletions(-) + +diff --git a/agents/aliyun/fence_aliyun.py b/agents/aliyun/fence_aliyun.py +index 134cc5ab..b271eb0b 100644 +--- a/agents/aliyun/fence_aliyun.py ++++ b/agents/aliyun/fence_aliyun.py +@@ -150,20 +150,37 @@ def define_new_opts(): + "required": "0", + "order": 5 + } ++ all_opt["credentials_file"] = { ++ "getopt": ":", ++ "longopt": "credentials-file", ++ "help": "--credentials-file=[path] Path to aliyun-cli credentials file", ++ "shortdesc": "Path to credentials file", ++ "required": "0", ++ "order": 6 ++ } ++ all_opt["credentials_file_profile"] = { ++ "getopt": ":", ++ "longopt": "credentials-file-profile", ++ "help": "--credentials-file-profile=[profile] Credentials file profile", ++ "shortdesc": "Credentials file profile", ++ "required": "0", ++ "default": "default", ++ "order": 6 ++ } + all_opt["filter"] = { + "getopt": ":", + "longopt": "filter", + "help": "--filter=[key=value] Filter (e.g. InstanceIds=[\"i-XXYYZZAA1\",\"i-XXYYZZAA2\"]", + "shortdesc": "Filter for list-action.", + "required": "0", +- "order": 6 ++ "order": 7 + } + + # Main agent method + def main(): + conn = None + +- device_opt = ["port", "no_password", "region", "access_key", "secret_key", "ram_role", "filter"] ++ device_opt = ["port", "no_password", "region", "access_key", "secret_key", "ram_role", "credentials_file", "credentials_file_profile", "filter"] + + atexit.register(atexit_handler) + +@@ -191,6 +208,16 @@ def main(): + ram_role = options["--ram-role"] + role = EcsRamRoleCredential(ram_role) + conn = client.AcsClient(region_id=region, credential=role) ++ elif "--credentials-file" in options and "--credentials-file-profile" in options: ++ import os, configparser ++ try: ++ config = configparser.ConfigParser() ++ config.read(os.path.expanduser(options["--credentials-file"])) ++ access_key = config.get(options["--credentials-file-profile"], "aliyun_access_key_id") ++ secret_key = config.get(options["--credentials-file-profile"], "aliyun_access_key_secret") ++ conn = client.AcsClient(access_key, secret_key, region) ++ except Exception as e: ++ fail_usage("Failed: failed to read credentials file: %s" % e) + else: + fail_usage("Failed: User credentials are not set. Please set the Access Key and the Secret Key, or configure the RAM role.") + +diff --git a/tests/data/metadata/fence_aliyun.xml b/tests/data/metadata/fence_aliyun.xml +index a52de014..ea20f5f3 100644 +--- a/tests/data/metadata/fence_aliyun.xml ++++ b/tests/data/metadata/fence_aliyun.xml +@@ -38,6 +38,15 @@ + + Ram Role. + ++ ++ ++ Path to credentials file ++ ++ ++ ++ ++ Credentials file profile ++ + + + +-- +2.25.1 + diff --git a/backport-fence_aliyun-support-filter-for-list-action.patch b/backport-fence_aliyun-support-filter-for-list-action.patch new file mode 100644 index 0000000..1ad0362 --- /dev/null +++ b/backport-fence_aliyun-support-filter-for-list-action.patch @@ -0,0 +1,76 @@ +From 525789dcdcb1e89f8b3dd2438b2fc3b2277f5cfe Mon Sep 17 00:00:00 2001 +From: sunhui +Date: Sun, 23 Apr 2023 14:58:36 +0800 +Subject: [PATCH 07/46] fence_aliyun: support filter for list-action + +--- + agents/aliyun/fence_aliyun.py | 20 ++++++++++++++++++-- + tests/data/metadata/fence_aliyun.xml | 5 +++++ + 2 files changed, 23 insertions(+), 2 deletions(-) + +diff --git a/agents/aliyun/fence_aliyun.py b/agents/aliyun/fence_aliyun.py +index 1e9c790c..c7785a2b 100644 +--- a/agents/aliyun/fence_aliyun.py ++++ b/agents/aliyun/fence_aliyun.py +@@ -76,6 +76,14 @@ def get_nodes_list(conn, options): + result = {} + request = DescribeInstancesRequest() + request.set_PageSize(100) ++ ++ if "--filter" in options: ++ filter_key = options["--filter"].split("=")[0].strip() ++ filter_value = options["--filter"].split("=")[1].strip() ++ params = request.get_query_params() ++ params[filter_key] = filter_value ++ request.set_query_params(params) ++ + response = _send_request(conn, request) + if response is not None: + instance_list = response.get('Instances').get('Instance') +@@ -137,17 +145,25 @@ def define_new_opts(): + all_opt["ram_role"] = { + "getopt": ":", + "longopt": "ram-role", +- "help": "--ram-role=[name] Ram Role", ++ "help": "--ram-role=[name] Ram Role", + "shortdesc": "Ram Role.", + "required": "0", + "order": 5 + } ++ all_opt["filter"] = { ++ "getopt": ":", ++ "longopt": "filter", ++ "help": "--filter=[key=value] Filter (e.g. InstanceIds=[\"i-XXYYZZAA1\",\"i-XXYYZZAA2\"]", ++ "shortdesc": "Filter for list-action.", ++ "required": "0", ++ "order": 6 ++ } + + # Main agent method + def main(): + conn = None + +- device_opt = ["port", "no_password", "region", "access_key", "secret_key", "ram_role"] ++ device_opt = ["port", "no_password", "region", "access_key", "secret_key", "ram_role", "filter"] + + atexit.register(atexit_handler) + +diff --git a/tests/data/metadata/fence_aliyun.xml b/tests/data/metadata/fence_aliyun.xml +index 56d79204..b0671889 100644 +--- a/tests/data/metadata/fence_aliyun.xml ++++ b/tests/data/metadata/fence_aliyun.xml +@@ -38,6 +38,11 @@ + + Ram Role. + ++ ++ ++ ++ Filter for list-action. ++ + + + +-- +2.25.1 + diff --git a/backport-fence_aliyun-update-order-for-new-parameters.patch b/backport-fence_aliyun-update-order-for-new-parameters.patch new file mode 100644 index 0000000..11d77e5 --- /dev/null +++ b/backport-fence_aliyun-update-order-for-new-parameters.patch @@ -0,0 +1,34 @@ +From 860da80c03b4b154ca4495adb72b959e278d55b1 Mon Sep 17 00:00:00 2001 +From: Oyvind Albrigtsen +Date: Tue, 2 Apr 2024 16:46:16 +0200 +Subject: [PATCH 40/46] fence_aliyun: update order for new parameters + +--- + agents/aliyun/fence_aliyun.py | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/agents/aliyun/fence_aliyun.py b/agents/aliyun/fence_aliyun.py +index b271eb0b..788ac647 100644 +--- a/agents/aliyun/fence_aliyun.py ++++ b/agents/aliyun/fence_aliyun.py +@@ -165,7 +165,7 @@ def define_new_opts(): + "shortdesc": "Credentials file profile", + "required": "0", + "default": "default", +- "order": 6 ++ "order": 7 + } + all_opt["filter"] = { + "getopt": ":", +@@ -173,7 +173,7 @@ def define_new_opts(): + "help": "--filter=[key=value] Filter (e.g. InstanceIds=[\"i-XXYYZZAA1\",\"i-XXYYZZAA2\"]", + "shortdesc": "Filter for list-action.", + "required": "0", +- "order": 7 ++ "order": 8 + } + + # Main agent method +-- +2.25.1 + diff --git a/fence-agents.spec b/fence-agents.spec index 2801341..6cebd7a 100644 --- a/fence-agents.spec +++ b/fence-agents.spec @@ -6,7 +6,7 @@ Name: fence-agents Summary: Set of unified programs capable of host isolation ("fencing") Version: 4.12.1 -Release: 10 +Release: 11 License: GPLv2+ and LGPLv2+ Group: System Environment/Base URL: https://github.com/ClusterLabs/fence-agents @@ -22,6 +22,9 @@ Patch7: backport-fence_azure_arm-add-stack-cloud-support.patch Patch8: backport-azure_fence-use-correct-credential_scope-and-profile.patch Patch9: backport-spec-Migrate-to-SPDX-license.patch Patch10: backport-fence_eaton_ssh-new-fence-agent-for-Eaton-ePDU-G3-over-ssh.patch +Patch11: backport-fence_aliyun-support-filter-for-list-action.patch +Patch12: backport-fence_aliyun-add-credentials-file-support.patch +Patch13: backport-fence_aliyun-update-order-for-new-parameters.patch # skipped: pve, raritan, rcd-serial, virsh %global allfenceagents %(cat < - 4.12.1-11 +- fence_aliyun: support filter for list-action +- fence_aliyun: add credentials file support +- fence_aliyun: update order for new parameters + * Wed May 29 2024 liupei - 4.12.1-10 - spec: Migrate to SPDX license - fence_eaton_ssh: new fence agent for Eaton ePDU G3 over SSH -- Gitee