-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathinsert.py
More file actions
39 lines (31 loc) · 1.45 KB
/
insert.py
File metadata and controls
39 lines (31 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from lib.base_action import BaseAction
import sqlalchemy
class SQLInsertAction(BaseAction):
def __init__(self, config):
"""Creates a new BaseAction given a StackStorm config object (kwargs works too)
:param config: StackStorm configuration object for the pack
:returns: a new BaseAction
"""
super(SQLInsertAction, self).__init__(config)
def run(self, **kwargs):
"""Main entry point for the StackStorm actions to execute the operation.
:returns: the dns adapters and the number of network adapters to be
on the VM.
"""
kwargs_dict = dict(kwargs)
insert_data = self.get_del_arg('data', kwargs_dict)
insert_table = self.get_del_arg('table', kwargs_dict)
insert_schema = self.get_del_arg('schema', kwargs_dict)
if not isinstance(insert_data, list):
insert_data = [insert_data]
with self.db_connection(kwargs_dict) as conn:
# Get the Table to insert data into
sql_table = sqlalchemy.Table(insert_table,
self.meta,
autoload=True,
schema=insert_schema,
autoload_with=self.engine)
# Execute the insert query
# pylint: disable=unexpected-keyword-arg
conn.execute(sql_table.insert(inline=True), insert_data)
return True