Skip to content

Commit 7a31b11

Browse files
authored
Merge pull request #68 from StackStorm-Exchange/user_data_fix
Allow user to pass "user_data" parameter to the ec2_run_instances action
2 parents bf62506 + 053d04e commit 7a31b11

6 files changed

Lines changed: 41 additions & 5 deletions

File tree

CHANGES.md

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

3+
## 1.1.0
4+
5+
- Fix ``ec2_run_instances`` action so ``user_data`` parameter passed to this action takes
6+
precedence over user data which is specified via ``st2_user_data`` config option.
7+
8+
This way user can override / provide custom user data on per action invocation basis.
9+
10+
- Add additional log statements under debug log level which log which boto method / function
11+
is called and with which arguments when ``debug`` config option is set to ``True``. This helps
12+
with debugging / troubleshooting various pack related issues.
13+
314
## 1.0.3
415

516
- Fixed issue with create_vm and destroy_vm workflows using snake_case for CamelCase params

actions/lib/action.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ def __init__(self, config):
2222
'aws_access_key_id': None,
2323
'aws_secret_access_key': None
2424
}
25+
self.user_data_file = config.get('st2_user_data', None)
26+
self.debug = config.get('debug', False)
27+
2528
self.userdata = None
2629

27-
if config.get('st2_user_data', None):
30+
# Read in default user data
31+
if self.user_data_file:
2832
try:
29-
with open(config['st2_user_data'], 'r') as fp:
33+
with open(self.user_data_file, 'r') as fp:
3034
self.userdata = fp.read()
3135
except IOError as e:
3236
self.logger.error(e)
@@ -148,10 +152,20 @@ def do_method(self, module_path, cls, action, **kwargs):
148152
raise ValueError('Invalid or missing credentials (aws_access_key_id,'
149153
'aws_secret_access_key) or region')
150154

155+
if self.debug:
156+
method_fqdn = '%s.%s.%s' % (module_path, cls, action)
157+
self.logger.debug('Calling method "%s" with kwargs: %s' % (method_fqdn, str(kwargs)))
158+
151159
resultset = getattr(obj, action)(**kwargs)
152160
formatted = self.resultsets.formatter(resultset)
153161
return formatted if isinstance(formatted, list) else [formatted]
154162

155163
def do_function(self, module_path, action, **kwargs):
156164
module = __import__(module_path)
165+
166+
if self.debug:
167+
function_fqdn = '%s.%s' % (module_path, action)
168+
self.logger.debug('Calling function "%s" with kwargs: %s' % (function_fqdn,
169+
str(kwargs)))
170+
157171
return getattr(module, action)(**kwargs)

actions/run.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ def run(self, **kwargs):
1616
'''
1717
aws_action = kwargs.pop('action')
1818
module_path = kwargs.pop('module_path')
19-
if aws_action == 'run_instances':
20-
kwargs['user_data'] = self.st2_user_data()
19+
if aws_action == 'run_instances' and not kwargs.get('user_data', None):
20+
# Include default user_data from config (if set)
21+
user_data = self.st2_user_data()
22+
23+
if user_data:
24+
self.logger.info('Passing in default user_data specified as st2_user_data config '
25+
'option (%s file)' % (self.user_data_file))
26+
kwargs['user_data'] = self.st2_user_data()
2127
if aws_action == 'create_tags':
2228
# Skip "Tags" parameter and pass "tags" as is unless it is a string.
2329
if 'Tags' not in kwargs and isinstance(kwargs.get('tags'), str):

aws.yaml.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ aws_access_key_id: access_key
33
aws_secret_access_key: secret_key
44
region: us-east-1
55
st2_user_data: /opt/stackstorm/packs/aws/actions/scripts/bootstrap_user.sh
6+
debug: true
67

78
service_notifications_sensor:
89
host: localhost

config.schema.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
st2_user_data:
1818
description: "The file for all invocations of the 'aws.ec2_run_instances' action"
1919
type: "string"
20+
debug:
21+
type: "boolean"
22+
description: "Set to True to log every boto method / function invocation"
23+
default: false
2024
service_notifications_sensor:
2125
type: object
2226
properties:

pack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ keywords:
2020
- lambda
2121
- kinesis
2222

23-
version : 1.0.3
23+
version : 1.1.0
2424
author : StackStorm, Inc.
2525
email : info@stackstorm.com

0 commit comments

Comments
 (0)