Skip to content

Commit 306d57f

Browse files
committed
Add secified_target parameter to all actions
1 parent 485ab15 commit 306d57f

22 files changed

+77
-7
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v1.2.0
4+
* Add `specified_target` parameter to all actions.
5+
36
## v1.1.0
47

58
* Update acos_client, which this pack depends on, version from v1.4.6 to v2.6.0

actions/acoslib/action.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class BaseAction(Action):
99
DEFAULT_AXAPI_VERSION = acos.AXAPI_30
1010

1111
# These are the parameters for acos pack, not used by the ACOS Client
12-
PARAMS_FOR_PACK = ['appliance', 'action', 'object_path', 'one_target']
12+
PARAMS_FOR_PACK = ['appliance', 'action', 'object_path', 'one_target', 'specified_target']
1313

1414
def __init__(self, config):
1515
super(BaseAction, self).__init__(config)
@@ -18,9 +18,12 @@ def __init__(self, config):
1818

1919
self.config = config
2020

21-
def login(self, appliance):
21+
def login(self, appliance, specified_target=None):
2222
try:
23-
config = next(x for x in self.config['appliance'] if x['target'] == appliance)
23+
if specified_target:
24+
config = specified_target
25+
else:
26+
config = next(x for x in self.config['appliance'] if x['target'] == appliance)
2427
return acos.Client(config['target'],
2528
config['api_version'],
2629
config['userid'],

actions/add_slb_server.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ parameters:
3636
type: string
3737
description: The appliance information to connect, which is specified at the 'appliance' parameter in the configuration.
3838
required: true
39+
specified_target:
40+
type: object
41+
description: "Specify the target dynamically, (key: 'target', 'api_version', 'userid', 'passwd')"

actions/add_slb_server_port.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ parameters:
3636
type: string
3737
description: The appliance information to connect, which is specified at the 'appliance' parameter in the configuration.
3838
required: true
39+
specified_target:
40+
type: object
41+
description: "Specify the target dynamically, (key: 'target', 'api_version', 'userid', 'passwd')"

actions/add_slb_service_group.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ parameters:
5555
type: string
5656
description: The appliance information to connect, which is specified at the 'appliance' parameter in the configuration.
5757
required: true
58+
specified_target:
59+
type: object
60+
description: "Specify the target dynamically, (key: 'target', 'api_version', 'userid', 'passwd')"

actions/add_slb_service_group_member.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ parameters:
4141
type: string
4242
description: The appliance information to connect, which is specified at the 'appliance' parameter in the configuration.
4343
required: true
44+
specified_target:
45+
type: object
46+
description: "Specify the target dynamically, (key: 'target', 'api_version', 'userid', 'passwd')"

actions/add_slb_virtual_server.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ parameters:
4141
type: string
4242
description: The appliance information to connect, which is specified at the 'appliance' parameter in the configuration.
4343
required: true
44+
specified_target:
45+
type: object
46+
description: "Specify the target dynamically, (key: 'target', 'api_version', 'userid', 'passwd')"

actions/add_slb_virtual_server_port.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,6 @@ parameters:
7171
type: string
7272
description: The appliance information to connect, which is specified at the 'appliance' parameter in the configuration.
7373
required: true
74+
specified_target:
75+
type: object
76+
description: "Specify the target dynamically, (key: 'target', 'api_version', 'userid', 'passwd')"

actions/ax_action_runner.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55

66
class AXActionRunner(BaseAction):
7-
def do_run(self, action, object_path, target, **kwargs):
8-
client = self.login(target)
7+
def do_run(self, action, object_path, appliance, specified_target, **kwargs):
8+
target = appliance
9+
if specified_target:
10+
target = specified_target.get("target")
11+
client = self.login(appliance, specified_target)
912
if client:
1013
try:
1114
# transforms user parameters as needed
@@ -25,8 +28,12 @@ def do_run(self, action, object_path, target, **kwargs):
2528
return (False, '[%s] Failed to initilaize Client object of acos_client' % target)
2629

2730
def run(self, action, object_path, one_target, **kwargs):
28-
if one_target or kwargs.get('appliance'):
29-
return self.do_run(action, object_path, kwargs.get('appliance'), **kwargs)
31+
if one_target or kwargs.get('appliance') or kwargs.get('specified_target'):
32+
return self.do_run(
33+
action,
34+
object_path,
35+
**kwargs
36+
)
3037
else:
3138
results = []
3239
for config in self.config['appliance']:

actions/del_slb_server.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ parameters:
2525
type: string
2626
description: The appliance information to connect, which is specified at the 'appliance' parameter in the configuration.
2727
required: true
28+
specified_target:
29+
type: object
30+
description: "Specify the target dynamically, (key: 'target', 'api_version', 'userid', 'passwd')"

0 commit comments

Comments
 (0)