|
|
66332a |
From 31548d184c977521dad5e6320c7a74ed732c19bb Mon Sep 17 00:00:00 2001
|
|
|
66332a |
From: dongchen126 <51401223+dongchen126@users.noreply.github.com>
|
|
|
66332a |
Date: Thu, 11 Jul 2019 14:05:58 +0800
|
|
|
66332a |
Subject: [PATCH 1/4] Update fence_aliyun.py
|
|
|
66332a |
|
|
|
66332a |
1.Import region provider to enable Alibaba cloud private zone functionality which support API endpoint access from intranet
|
|
|
66332a |
2.Add ram role functionality to improve security which disable AccessKey ID and Access Key Secret
|
|
|
66332a |
---
|
|
|
66332a |
agents/aliyun/fence_aliyun.py | 28 +++++++++++++++++++++-------
|
|
|
66332a |
1 file changed, 21 insertions(+), 7 deletions(-)
|
|
|
66332a |
|
|
|
66332a |
diff --git a/agents/aliyun/fence_aliyun.py b/agents/aliyun/fence_aliyun.py
|
|
|
66332a |
index d780e2ab..aea1ea8f 100644
|
|
|
66332a |
--- a/agents/aliyun/fence_aliyun.py
|
|
|
66332a |
+++ b/agents/aliyun/fence_aliyun.py
|
|
|
66332a |
@@ -15,6 +15,7 @@
|
|
|
66332a |
from aliyunsdkecs.request.v20140526.StartInstanceRequest import StartInstanceRequest
|
|
|
66332a |
from aliyunsdkecs.request.v20140526.StopInstanceRequest import StopInstanceRequest
|
|
|
66332a |
from aliyunsdkecs.request.v20140526.RebootInstanceRequest import RebootInstanceRequest
|
|
|
66332a |
+ from aliyunsdkcore.profile import region_provider
|
|
|
66332a |
except ImportError:
|
|
|
66332a |
pass
|
|
|
66332a |
|
|
|
66332a |
@@ -121,12 +122,20 @@ def define_new_opts():
|
|
|
66332a |
"required" : "0",
|
|
|
66332a |
"order" : 4
|
|
|
66332a |
}
|
|
|
66332a |
+ all_opt["ram_role"] = {
|
|
|
66332a |
+ "getopt": "m:",
|
|
|
66332a |
+ "longopt": "ram-role",
|
|
|
66332a |
+ "help": "-m, --ram-role=[name] Ram Role",
|
|
|
66332a |
+ "shortdesc": "Ram Role.",
|
|
|
66332a |
+ "required": "0",
|
|
|
66332a |
+ "order": 5
|
|
|
66332a |
+ }
|
|
|
66332a |
|
|
|
66332a |
# Main agent method
|
|
|
66332a |
def main():
|
|
|
66332a |
conn = None
|
|
|
66332a |
|
|
|
66332a |
- device_opt = ["port", "no_password", "region", "access_key", "secret_key"]
|
|
|
66332a |
+ device_opt = ["port", "no_password", "region", "access_key", "secret_key", "ram_role"]
|
|
|
66332a |
|
|
|
66332a |
atexit.register(atexit_handler)
|
|
|
66332a |
|
|
|
66332a |
@@ -144,13 +153,18 @@ def main():
|
|
|
66332a |
|
|
|
66332a |
run_delay(options)
|
|
|
66332a |
|
|
|
66332a |
- if "--region" in options and "--access-key" in options and "--secret-key" in options:
|
|
|
66332a |
+ if "--region" in options:
|
|
|
66332a |
region = options["--region"]
|
|
|
66332a |
- access_key = options["--access-key"]
|
|
|
66332a |
- secret_key = options["--secret-key"]
|
|
|
66332a |
- conn = client.AcsClient(access_key, secret_key, region)
|
|
|
66332a |
-
|
|
|
66332a |
-
|
|
|
66332a |
+ if "--access-key" in options and "--secret-key" in options:
|
|
|
66332a |
+ access_key = options["--access-key"]
|
|
|
66332a |
+ secret_key = options["--secret-key"]
|
|
|
66332a |
+ conn = client.AcsClient(access_key, secret_key, region)
|
|
|
66332a |
+ elif "--ram-role" in options:
|
|
|
66332a |
+ ram_role = options["--ram-role"]
|
|
|
66332a |
+ role = EcsRamRoleCredential(ram_role)
|
|
|
66332a |
+ conn = client.AcsClient(region_id=region, credential=role)
|
|
|
66332a |
+ region_provider.modify_point('Ecs', region, 'ecs.%s.aliyuncs.com' % region)
|
|
|
66332a |
+
|
|
|
66332a |
# Operate the fencing device
|
|
|
66332a |
result = fence_action(conn, options, set_power_status, get_power_status, get_nodes_list)
|
|
|
66332a |
sys.exit(result)
|
|
|
66332a |
|
|
|
66332a |
From 285d29d398bbf8f87da7acfde3f89f83b32fa586 Mon Sep 17 00:00:00 2001
|
|
|
66332a |
From: chen dong <51401223+dongchen126@users.noreply.github.com>
|
|
|
66332a |
Date: Thu, 11 Jul 2019 15:30:10 +0800
|
|
|
66332a |
Subject: [PATCH 2/4] Update fence_aliyun.xml
|
|
|
66332a |
|
|
|
66332a |
Add ram role for security
|
|
|
66332a |
Add region provider for private zone functionality
|
|
|
66332a |
---
|
|
|
66332a |
tests/data/metadata/fence_aliyun.xml | 5 +++++
|
|
|
66332a |
1 file changed, 5 insertions(+)
|
|
|
66332a |
|
|
|
66332a |
diff --git a/tests/data/metadata/fence_aliyun.xml b/tests/data/metadata/fence_aliyun.xml
|
|
|
66332a |
index b41d82bf..eecd6f4e 100644
|
|
|
66332a |
--- a/tests/data/metadata/fence_aliyun.xml
|
|
|
66332a |
+++ b/tests/data/metadata/fence_aliyun.xml
|
|
|
66332a |
@@ -33,6 +33,11 @@
|
|
|
66332a |
<content type="string" />
|
|
|
66332a |
<shortdesc lang="en">Secret Key.</shortdesc>
|
|
|
66332a |
</parameter>
|
|
|
66332a |
+ <parameter name="ram_role" unique="0" required="0">
|
|
|
66332a |
+ <getopt mixed="-m, --ram-role=[name]" />
|
|
|
66332a |
+ <content type="string" />
|
|
|
66332a |
+ <shortdesc lang="en">Ram Role.</shortdesc>
|
|
|
66332a |
+ </parameter>
|
|
|
66332a |
<parameter name="quiet" unique="0" required="0">
|
|
|
66332a |
<getopt mixed="-q, --quiet" />
|
|
|
66332a |
<content type="boolean" />
|
|
|
66332a |
|
|
|
66332a |
From d4de57fdb94eeee483988584086c5690c8967f76 Mon Sep 17 00:00:00 2001
|
|
|
66332a |
From: chen dong <51401223+dongchen126@users.noreply.github.com>
|
|
|
66332a |
Date: Wed, 24 Jul 2019 17:23:48 +0800
|
|
|
66332a |
Subject: [PATCH 3/4] Update fence_aliyun.py
|
|
|
66332a |
MIME-Version: 1.0
|
|
|
66332a |
Content-Type: text/plain; charset=UTF-8
|
|
|
66332a |
Content-Transfer-Encoding: 8bit
|
|
|
66332a |
|
|
|
66332a |
delet paramater “m”
|
|
|
66332a |
---
|
|
|
66332a |
agents/aliyun/fence_aliyun.py | 4 ++--
|
|
|
66332a |
1 file changed, 2 insertions(+), 2 deletions(-)
|
|
|
66332a |
|
|
|
66332a |
diff --git a/agents/aliyun/fence_aliyun.py b/agents/aliyun/fence_aliyun.py
|
|
|
66332a |
index aea1ea8f..3bc825fe 100644
|
|
|
66332a |
--- a/agents/aliyun/fence_aliyun.py
|
|
|
66332a |
+++ b/agents/aliyun/fence_aliyun.py
|
|
|
66332a |
@@ -123,9 +123,9 @@ def define_new_opts():
|
|
|
66332a |
"order" : 4
|
|
|
66332a |
}
|
|
|
66332a |
all_opt["ram_role"] = {
|
|
|
66332a |
- "getopt": "m:",
|
|
|
66332a |
+ "getopt": ":",
|
|
|
66332a |
"longopt": "ram-role",
|
|
|
66332a |
- "help": "-m, --ram-role=[name] Ram Role",
|
|
|
66332a |
+ "help": "--ram-role=[name] Ram Role",
|
|
|
66332a |
"shortdesc": "Ram Role.",
|
|
|
66332a |
"required": "0",
|
|
|
66332a |
"order": 5
|
|
|
66332a |
|
|
|
66332a |
From 367c17ef4f44b6cce2d10f0a220b55b02d0d631e Mon Sep 17 00:00:00 2001
|
|
|
66332a |
From: chen dong <51401223+dongchen126@users.noreply.github.com>
|
|
|
66332a |
Date: Wed, 24 Jul 2019 17:25:39 +0800
|
|
|
66332a |
Subject: [PATCH 4/4] Update fence_aliyun.xml
|
|
|
66332a |
|
|
|
66332a |
delete "m" parameter
|
|
|
66332a |
---
|
|
|
66332a |
tests/data/metadata/fence_aliyun.xml | 2 +-
|
|
|
66332a |
1 file changed, 1 insertion(+), 1 deletion(-)
|
|
|
66332a |
|
|
|
66332a |
diff --git a/tests/data/metadata/fence_aliyun.xml b/tests/data/metadata/fence_aliyun.xml
|
|
|
66332a |
index eecd6f4e..2de3a8aa 100644
|
|
|
66332a |
--- a/tests/data/metadata/fence_aliyun.xml
|
|
|
66332a |
+++ b/tests/data/metadata/fence_aliyun.xml
|
|
|
66332a |
@@ -34,7 +34,7 @@
|
|
|
66332a |
<shortdesc lang="en">Secret Key.</shortdesc>
|
|
|
66332a |
</parameter>
|
|
|
66332a |
<parameter name="ram_role" unique="0" required="0">
|
|
|
66332a |
- <getopt mixed="-m, --ram-role=[name]" />
|
|
|
66332a |
+ <getopt mixed="--ram-role=[name]" />
|
|
|
66332a |
<content type="string" />
|
|
|
66332a |
<shortdesc lang="en">Ram Role.</shortdesc>
|
|
|
66332a |
</parameter>
|