-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.py
156 lines (114 loc) · 4.5 KB
/
entrypoint.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import sys
from workflow import Workflow
from awsboto import start_instance, stop_instance, search_instances, save_config, instance_to_string, load_config
def ec2_gen_search(wf):
# The Workflow instance will be passed to the function
# you call from `Workflow.run`
config = load_config()
# Your imports here if you want to catch import errors
# Get args from Workflow as normalized Unicode
if len(wf.args) > 0:
query = wf.args[0]
argname = wf.args[2]
wf.logger.debug(argname)
wf.logger.debug(query)
instances = search_instances(query)
if len(instances) > 0:
for i in instances:
# Add an item to Alfred feedback
if config['ip_type'] == 'private' and argname == 'ip_address':
val = getattr(i, 'private_ip_address')
else:
val = getattr(i, argname)
if not val:
val = "No public IP exists. Is the instance running?"
wf.add_item(str(instance_to_string(i)), str(i.instance_type) + ", " + str(i.key_name),
arg=val,
valid=True,)
else:
wf.add_item('None found', 'Item subtitle', arg="NO IP", valid=True)
# Send output to Alfred
wf.send_feedback()
def ec2_start_search(wf):
# The Workflow instance will be passed to the function
# you call from `Workflow.run`
# Your imports here if you want to catch import errors
# Get args from Workflow as normalized Unicode
if len(wf.args) > 0:
query = wf.args[0]
# wf.logger.debug("Alfred Args Sent: " + str(wf.args) + "length=" + str(len(wf.args)))
# Do stuff here ...
instances = search_instances(query)
if len(instances) > 0:
for i in instances:
# Add an item to Alfred feedback
wf.add_item(str(instance_to_string(i)), str(i.instance_type) + ", " + str(i.key_name),
arg=i.id,
valid=True,)
else:
wf.add_item('None found', 'Item subtitle', arg="NO IP", valid=True)
# Send output to Alfred
wf.send_feedback()
def ec2_stop_instance(id):
wf.logger.debug(wf.args)
if len(wf.args) > 0:
id = wf.args[0]
wf.logger.debug(stop_instance(id))
wf.add_item('None found', 'Item subtitle',
arg="Instance started", valid=True)
wf.send_feedback()
def ec2_start_instance(id):
wf.logger.debug(wf.args)
if len(wf.args) > 0:
id = wf.args[0]
wf.logger.debug(start_instance(id))
wf.add_item('None found', 'Item subtitle',
arg="Instance started", valid=True)
wf.send_feedback()
def aws_save_config(wf):
# The Workflow instance will be passed to the function
# you call from `Workflow.run`
# Your imports here if you want to catch import errors
# or if the modules/packages are in a directory added via `Workflow(libraries=...)`
# Get args from Workflow, already in normalised Unicode
# global QUERY
# QUERY = query.lower()
if len(wf.args) > 0:
query = wf.args[0]
# wf.logger.debug("Alfred Args Sent: " + str(wf.args) + "lenght=" + str(len(wf.args)))
save_config(query)
# Send output to Alfred
wf.add_item('Press enter to save.', arg='saved', valid=True)
wf.send_feedback()
# wf = Workflow()
# sys.exit(wf.run(main))
def ec2_search(wf):
# The Workflow instance will be passed to the function
# you call from `Workflow.run`
# Your imports here if you want to catch import errors
# Get args from Workflow as normalized Unicode
if len(wf.args) > 0:
query = wf.args[0]
# wf.logger.debug("Alfred Args Sent: " + str(wf.args) + "length=" + str(len(wf.args)))
# Do stuff here ...
instances = search_instances(query)
if len(instances) > 0:
for i in instances:
# Add an item to Alfred feedback
if i.ip_address is not None:
ip = i.ip_address
else:
ip = "No IP Address"
wf.add_item(str(instance_to_string(i)), str(i.instance_type) + ", " + str(i.key_name),
arg=ip,
valid=True,)
else:
wf.add_item('None found', 'Item subtitle', arg="NO IP", valid=True)
# Send output to Alfred
wf.send_feedback()
if __name__ == "__main__":
wf = Workflow()
f = wf.args[1] # args expected: <query> <subcmd>
thismodule = sys.modules[__name__]
fref = getattr(thismodule, f)
sys.exit(wf.run(fref))