Skip to content

Commit 53fd42e

Browse files
author
Clark Perkins
committed
Removed the rest of the references to obj, added access rules
1 parent 3c957b5 commit 53fd42e

File tree

4 files changed

+44
-28
lines changed

4 files changed

+44
-28
lines changed

blueprints/.keep

Whitespace-only changes.

stackdio/cli/mixins/formulas.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ def list_formulas(client):
1919
"""
2020
List all formulas
2121
"""
22-
client = obj['client']
23-
2422
click.echo('Getting formulas ... ')
2523
print_summary('Formula', client.list_formulas())
2624

@@ -35,8 +33,6 @@ def import_formula(client, uri, username, password):
3533
"""
3634
Import a formula
3735
"""
38-
client = obj['client']
39-
4036
if username and not password:
4137
raise click.UsageError('You must provide a password when providing a username')
4238

@@ -62,8 +58,6 @@ def delete_formula(client, uri):
6258
"""
6359
Delete a formula
6460
"""
65-
client = obj['client']
66-
6761
formula_id = get_formula_id(client, uri)
6862

6963
click.confirm('Really delete formula {0}?'.format(uri), abort=True)

stackdio/cli/mixins/stacks.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

stackdio/cli/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17+
18+
import sys
1719
import time
1820
from functools import update_wrapper
1921

@@ -65,11 +67,12 @@ def decorator(args=None, sleep_time=2, max_time=120):
6567

6668
current_time = 0
6769

70+
click.echo('.', nl=False, file=sys.stderr)
6871
success = func(*args)
6972
while not success and current_time < max_time:
7073
current_time += sleep_time
7174
time.sleep(sleep_time)
72-
click.echo('.', nl=False)
75+
click.echo('.', nl=False, file=sys.stderr)
7376
success = func(*args)
7477

7578
if not success:

0 commit comments

Comments
 (0)