@@ -24,8 +24,6 @@ def list_stacks(client):
2424 """
2525 List all stacks
2626 """
27- client = obj ['client' ]
28-
2927 click .echo ('Getting stacks ... ' )
3028 print_summary ('Stack' , client .list_stacks ())
3129
@@ -38,8 +36,6 @@ def launch_stack(client, blueprint_title, stack_title):
3836 """
3937 Launch a stack from a blueprint
4038 """
41- client = obj ['client' ]
42-
4339 blueprint_id = get_blueprint_id (client , blueprint_title )
4440
4541 click .echo ('Launching stack "{0}" from blueprint "{1}"' .format (stack_title ,
@@ -74,8 +70,6 @@ def stack_history(client, stack_title, length):
7470 """
7571 Print recent history for a stack
7672 """
77- client = obj ['client' ]
78-
7973 stack_id = get_stack_id (client , stack_title )
8074 history = client .get_stack_history (stack_id )
8175 for event in history [0 :min (length , len (history ))]:
@@ -89,8 +83,6 @@ def stack_hostnames(client, stack_title):
8983 """
9084 Print hostnames for a stack
9185 """
92- client = obj ['client' ]
93-
9486 stack_id = get_stack_id (client , stack_title )
9587 hosts = client .get_stack_hosts (stack_id )
9688
@@ -106,8 +98,6 @@ def delete_stack(client, stack_title):
10698 """
10799 Delete a stack. PERMANENT AND DESTRUCTIVE!!!
108100 """
109- client = obj ['client' ]
110-
111101 stack_id = get_stack_id (client , stack_title )
112102
113103 click .confirm ('Really delete stack {0}?' .format (stack_title ), abort = True )
@@ -126,8 +116,6 @@ def perform_action(client, stack_title, action):
126116 """
127117 Perform an action on a stack
128118 """
129- client = obj ['client' ]
130-
131119 stack_id = get_stack_id (client , stack_title )
132120
133121 # Prompt for confirmation if need be
@@ -148,6 +136,7 @@ def print_command_output(json_blob):
148136
149137
150138@stacks .command (name = 'run' )
139+ @pass_client
151140@click .pass_context
152141@click .argument ('stack_title' )
153142@click .argument ('host_target' )
@@ -157,12 +146,10 @@ def print_command_output(json_blob):
157146@click .option ('-t' , '--timeout' , type = click .INT , default = 120 ,
158147 help = 'The amount of time to wait for the command in seconds. '
159148 'Ignored if used without the -w option.' )
160- def run_command (ctx , stack_title , host_target , command , wait , timeout ):
149+ def run_command (ctx , client , stack_title , host_target , command , wait , timeout ):
161150 """
162151 Run a command on all hosts in the stack
163152 """
164- client = ctx .obj ['client' ]
165-
166153 stack_id = get_stack_id (client , stack_title )
167154
168155 resp = client .run_command (stack_id , host_target , command )
@@ -200,8 +187,6 @@ def get_command_output(client, command_id):
200187 """
201188 Get the status and output of a command
202189 """
203- client = obj ['client' ]
204-
205190 resp = client .get_command (command_id )
206191
207192 if resp ['status' ] != 'finished' :
@@ -232,8 +217,6 @@ def list_stack_logs(client, stack_title):
232217 """
233218 Get a list of stack logs
234219 """
235- client = obj ['client' ]
236-
237220 stack_id = get_stack_id (client , stack_title )
238221
239222 print_logs (client , stack_id )
@@ -248,8 +231,6 @@ def stack_logs(client, stack_title, log_type, lines):
248231 """
249232 Get logs for a stack
250233 """
251- client = obj ['client' ]
252-
253234 stack_id = get_stack_id (client , stack_title )
254235
255236 split_arg = log_type .split ('.' )
@@ -273,3 +254,41 @@ def stack_logs(client, stack_title, log_type, lines):
273254 print_logs (client , stack_id )
274255
275256 raise click .UsageError ('Invalid log' )
257+
258+
259+ @stacks .group (name = 'access-rules' )
260+ def stack_access_rules ():
261+ """
262+ Perform actions on stack access rules
263+ """
264+ pass
265+
266+
267+ def print_access_rules (components ):
268+ title = 'Access Rule'
269+ num_components = len (components )
270+
271+ if num_components != 1 :
272+ title += 's'
273+
274+ click .echo ('## {0} {1}' .format (num_components , title ))
275+
276+ for item in components :
277+ click .echo ('- Name: {0}' .format (item .get ('name' )))
278+ click .echo (' Description: {0}' .format (item ['description' ]))
279+ click .echo (' Group ID: {0}' .format (item ['group_id' ]))
280+ click .echo (' Host Definition: {0}' .format (item ['blueprint_host_definition' ]['title' ]))
281+
282+ # Print a newline after each entry
283+ click .echo ()
284+
285+
286+ @stack_access_rules .command (name = 'list' )
287+ @pass_client
288+ @click .argument ('stack_title' )
289+ def list_access_rules (client , stack_title ):
290+ stack_id = get_stack_id (client , stack_title )
291+
292+ rules = client .list_access_rules (stack_id )
293+
294+ print_access_rules (rules )
0 commit comments