Skip to content

Commit fc2f83c

Browse files
committed
Merge branch 'master' of github.com:softlayer/softlayer-python
2 parents 57fdef8 + ff5808d commit fc2f83c

102 files changed

Lines changed: 374 additions & 357 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

SoftLayer/CLI/call_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ def cli(env, service, method, parameters, _id, mask, limit, offset):
3131
mask=mask,
3232
limit=limit,
3333
offset=offset)
34-
return formatting.iter_to_table(result)
34+
env.fout(formatting.iter_to_table(result))

SoftLayer/CLI/cdn/detail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ def cli(env, account_id):
2929
table.add_row(['notes',
3030
account.get('cdnAccountNote', formatting.blank())])
3131

32-
return table
32+
env.fout(table)

SoftLayer/CLI/cdn/list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ def cli(env, sortby):
4040
])
4141

4242
table.sortby = sortby
43-
return table
43+
env.fout(table)

SoftLayer/CLI/cdn/origin_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ def cli(env, account_id):
2525
origin.get('cname', formatting.blank()),
2626
origin['originUrl']])
2727

28-
return table
28+
env.fout(table)

SoftLayer/CLI/columns.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
SoftLayer.CLI.columns
3+
~~~~~~~~~~~~~~~~~~~~~~
4+
Utilties for user-defined columns
5+
6+
:license: MIT, see LICENSE for more details.
7+
"""
8+
import click
9+
10+
from SoftLayer import utils
11+
12+
# pylint: disable=unused-argument
13+
14+
15+
class ColumnFormatter(object):
16+
"""Maps each column using a function"""
17+
def __init__(self):
18+
self.columns = []
19+
self.column_funcs = []
20+
21+
def add_column(self, name, func):
22+
"""Add a new column along with a formatting function."""
23+
self.columns.append(name)
24+
self.column_funcs.append(func)
25+
26+
def row(self, data):
27+
"""Return a formatted row for the given data."""
28+
for column in self.column_funcs:
29+
if callable(column):
30+
yield column(data)
31+
else:
32+
yield utils.lookup(data, *column)
33+
34+
35+
def get_formatter(column_map):
36+
"""This function returns a callback to use with click options.
37+
38+
The retuend function parses a comma-separated value and returns a new
39+
ColumnFormatter.
40+
41+
:param column_map: a dictionary of the form: {col_name: function}.
42+
"""
43+
44+
def validate(ctx, param, value):
45+
"""Click validation function."""
46+
try:
47+
formatter = ColumnFormatter()
48+
for column in [col.strip() for col in value.split(',')]:
49+
if column in column_map:
50+
formatter.add_column(column, column_map[column])
51+
else:
52+
formatter.add_column(column, (column,))
53+
54+
return formatter
55+
except ValueError:
56+
raise click.BadParameter('rolls need to be in format NdM')
57+
58+
return validate

SoftLayer/CLI/config/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
from SoftLayer.CLI import formatting
55

66

7+
def _resolve_transport(transport):
8+
"""recursively look for transports which refer to other transports."""
9+
nested_transport = getattr(transport, 'transport', None)
10+
if nested_transport is not None:
11+
return nested_transport
12+
13+
return _resolve_transport(nested_transport)
14+
15+
716
def get_settings_from_client(client):
817
"""Pull out settings from a SoftLayer.BaseClient instance.
918
@@ -21,9 +30,10 @@ def get_settings_from_client(client):
2130
except AttributeError:
2231
pass
2332

33+
transport = _resolve_transport(client.transport)
2434
try:
25-
settings['timeout'] = client.transport.transport.timeout
26-
settings['endpoint_url'] = client.transport.transport.endpoint_url
35+
settings['timeout'] = transport.timeout
36+
settings['endpoint_url'] = transport.endpoint_url
2737
except AttributeError:
2838
pass
2939

SoftLayer/CLI/config/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def cli(env):
8888
finally:
8989
config_fd.close()
9090

91-
return "Configuration Updated Successfully"
91+
env.fout("Configuration Updated Successfully")
9292

9393

9494
def get_user_input(env):

SoftLayer/CLI/config/show.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ def cli(env):
1313
"""Show current configuration."""
1414

1515
settings = config.get_settings_from_client(env.client)
16-
return config.config_table(settings)
16+
env.fout(config.config_table(settings))

SoftLayer/CLI/core.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
# pylint: disable=too-many-public-methods, broad-except, unused-argument
2020
# pylint: disable=redefined-builtin, super-init-not-called
2121

22-
# Disable the cyclic import error. This is handled by an inline import.
23-
# pylint: disable=cyclic-import
24-
2522
DEBUG_LOGGING_MAP = {
2623
0: logging.CRITICAL,
2724
1: logging.WARNING,
@@ -147,24 +144,21 @@ def cli(env,
147144
proxy=proxy,
148145
config_file=config,
149146
)
150-
151-
client.transport = SoftLayer.TimingTransport(client.transport)
152147
env.client = client
153148

149+
env.vars['timings'] = SoftLayer.TimingTransport(env.client.transport)
150+
env.client.transport = env.vars['timings']
151+
154152

155153
@cli.resultcallback()
156154
@environment.pass_env
157-
def output_result(env, result, timings=False, **kwargs):
155+
def output_result(env, timings=False, *args, **kwargs):
158156
"""Outputs the results returned by the CLI and also outputs timings."""
159157

160-
output = env.fmt(result)
161-
if output:
162-
env.out(output)
163-
164-
if timings:
158+
if timings and env.vars.get('timings'):
165159
timing_table = formatting.Table(['service', 'method', 'time'])
166160

167-
calls = env.client.transport.get_last_calls()
161+
calls = env.vars['timings'].get_last_calls()
168162
for call, _, duration in calls:
169163
timing_table.add_row([call.service, call.method, duration])
170164

SoftLayer/CLI/dns/record_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ def cli(env, zone, data, record, ttl, type):
4646
record['data']
4747
])
4848

49-
return table
49+
env.fout(table)

0 commit comments

Comments
 (0)