|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
|
|
3
|
|
|
import inspect |
|
4
|
|
|
import yaml |
|
5
|
|
|
import re |
|
6
|
|
|
import digitalocean |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
def get_methods(module): |
|
10
|
|
|
functions = {} |
|
11
|
|
|
pattern = re.compile('[^_].*') |
|
12
|
|
|
for member in dir(module): |
|
13
|
|
|
foo = getattr(module,member) |
|
14
|
|
|
if inspect.ismethod(foo): |
|
15
|
|
|
if pattern.match(member): |
|
16
|
|
|
functions[member] = {} |
|
17
|
|
|
argspec = inspect.getargspec(foo) |
|
18
|
|
|
if argspec.defaults is not None: |
|
19
|
|
|
functions[member] = dict(zip(argspec.args[-len(argspec.defaults):],argspec.defaults)) |
|
20
|
|
|
for arg in argspec.args: |
|
21
|
|
|
if arg not in functions[member] and arg is not 'self': |
|
22
|
|
|
functions[member][arg] = 'required' |
|
23
|
|
|
return functions |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
def generate_meta(actions, pack): |
|
27
|
|
|
|
|
28
|
|
|
for action in actions: |
|
29
|
|
|
parameters = {} |
|
30
|
|
|
action_meta = { |
|
31
|
|
|
"name": "", |
|
32
|
|
|
"parameters": { |
|
33
|
|
|
"action": { |
|
34
|
|
|
"type": "string", |
|
35
|
|
|
"immutable": True, |
|
36
|
|
|
"default": action} |
|
37
|
|
|
}, |
|
38
|
|
|
"runner_type": "run-python", |
|
39
|
|
|
"description": "", |
|
40
|
|
|
"enabled": True, |
|
41
|
|
|
"entry_point": "do.py"} |
|
42
|
|
|
|
|
43
|
|
|
action_meta["name"] = "%s" % action |
|
44
|
|
|
for parameter in actions[action]: |
|
45
|
|
|
parameters[parameter] = {"type": "string"} |
|
46
|
|
|
if isinstance(actions[action][parameter], bool): |
|
47
|
|
|
parameters[parameter]['type'] = "boolean" |
|
48
|
|
|
if actions[action][parameter] is not None: |
|
49
|
|
|
if actions[action][parameter] == 'required': |
|
50
|
|
|
parameters[parameter]['required'] = True |
|
51
|
|
|
else: |
|
52
|
|
|
parameters[parameter]['default'] = actions[action][parameter] |
|
53
|
|
|
action_meta['parameters'].update(parameters) |
|
54
|
|
|
filename = pack + "/actions/" + action + ".yaml" |
|
55
|
|
|
fh = open(filename, 'w') |
|
56
|
|
|
fh.write(yaml.dump(action_meta, default_flow_style=False)) |
|
57
|
|
|
fh.close() |
|
58
|
|
|
|
|
59
|
|
|
actions = get_methods(digitalocean.Manager) |
|
60
|
|
|
|
|
61
|
|
|
generate_meta(actions, 'digitalocean') |
|
62
|
|
|
|