Skip to content

Commit a845e44

Browse files
Merge pull request #960 from allmightyspiff/xport-enhancements
Xport enhancements + Adds print_reproduceable method to Rest and XML transports. + Adds more fine grained verbose controls. + Removes a lot of ugly output
2 parents f8f743a + e520056 commit a845e44

File tree

6 files changed

+324
-99
lines changed

6 files changed

+324
-99
lines changed

SoftLayer/CLI/__init__.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,5 @@
66
:license: MIT, see LICENSE for more details.
77
"""
88
# pylint: disable=w0401, invalid-name
9-
import logging
109

1110
from SoftLayer.CLI.helpers import * # NOQA
12-
13-
logger = logging.getLogger()
14-
logger.addHandler(logging.StreamHandler())
15-
logger.setLevel(logging.INFO)

SoftLayer/CLI/core.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ def get_command(self, ctx, name):
8888
help="Config file location",
8989
type=click.Path(resolve_path=True))
9090
@click.option('--verbose', '-v',
91-
help="Sets the debug noise level, specify multiple times "
92-
"for more verbosity.",
91+
help="Sets the debug noise level, specify multiple times for more verbosity.",
9392
type=click.IntRange(0, 3, clamp=True),
9493
count=True)
9594
@click.option('--proxy',
@@ -115,10 +114,9 @@ def cli(env,
115114
**kwargs):
116115
"""Main click CLI entry-point."""
117116

118-
if verbose > 0:
119-
logger = logging.getLogger()
120-
logger.addHandler(logging.StreamHandler())
121-
logger.setLevel(DEBUG_LOGGING_MAP.get(verbose, logging.DEBUG))
117+
logger = logging.getLogger()
118+
logger.addHandler(logging.StreamHandler())
119+
logger.setLevel(DEBUG_LOGGING_MAP.get(verbose, logging.DEBUG))
122120

123121
# Populate environement with client and set it as the context object
124122
env.skip_confirmations = really
@@ -127,7 +125,7 @@ def cli(env,
127125
env.ensure_client(config_file=config, is_demo=demo, proxy=proxy)
128126

129127
env.vars['_start'] = time.time()
130-
env.vars['_timings'] = SoftLayer.TimingTransport(env.client.transport)
128+
env.vars['_timings'] = SoftLayer.DebugTransport(env.client.transport)
131129
env.client.transport = env.vars['_timings']
132130

133131

@@ -138,22 +136,37 @@ def output_diagnostics(env, verbose=0, **kwargs):
138136

139137
if verbose > 0:
140138
diagnostic_table = formatting.Table(['name', 'value'])
141-
diagnostic_table.add_row(['execution_time',
142-
'%fs' % (time.time() - START_TIME)])
139+
diagnostic_table.add_row(['execution_time', '%fs' % (time.time() - START_TIME)])
143140

144141
api_call_value = []
145-
for call, _, duration in env.vars['_timings'].get_last_calls():
146-
api_call_value.append(
147-
"%s::%s (%fs)" % (call.service, call.method, duration))
142+
for call in env.client.transport.get_last_calls():
143+
api_call_value.append("%s::%s (%fs)" % (call.service, call.method, call.end_time - call.start_time))
148144

149145
diagnostic_table.add_row(['api_calls', api_call_value])
150146
diagnostic_table.add_row(['version', consts.USER_AGENT])
151147
diagnostic_table.add_row(['python_version', sys.version])
152-
diagnostic_table.add_row(['library_location',
153-
os.path.dirname(SoftLayer.__file__)])
148+
diagnostic_table.add_row(['library_location', os.path.dirname(SoftLayer.__file__)])
154149

155150
env.err(env.fmt(diagnostic_table))
156151

152+
if verbose > 1:
153+
for call in env.client.transport.get_last_calls():
154+
call_table = formatting.Table(['', '{}::{}'.format(call.service, call.method)])
155+
nice_mask = ''
156+
if call.mask is not None:
157+
nice_mask = call.mask
158+
159+
call_table.add_row(['id', call.identifier])
160+
call_table.add_row(['mask', nice_mask])
161+
call_table.add_row(['filter', call.filter])
162+
call_table.add_row(['limit', call.limit])
163+
call_table.add_row(['offset', call.offset])
164+
env.err(env.fmt(call_table))
165+
166+
if verbose > 2:
167+
for call in env.client.transport.get_last_calls():
168+
env.err(env.client.transport.print_reproduceable(call))
169+
157170

158171
def main(reraise_exceptions=False, **kwargs):
159172
"""Main program. Catches several common errors and displays them nicely."""
@@ -163,8 +176,7 @@ def main(reraise_exceptions=False, **kwargs):
163176
cli.main(**kwargs)
164177
except SoftLayer.SoftLayerAPIError as ex:
165178
if 'invalid api token' in ex.faultString.lower():
166-
print("Authentication Failed: To update your credentials,"
167-
" use 'slcli config setup'")
179+
print("Authentication Failed: To update your credentials, use 'slcli config setup'")
168180
exit_status = 1
169181
else:
170182
print(str(ex))
@@ -184,6 +196,7 @@ def main(reraise_exceptions=False, **kwargs):
184196
print(str(traceback.format_exc()))
185197
print("Feel free to report this error as it is likely a bug:")
186198
print(" https://github.com/softlayer/softlayer-python/issues")
199+
print("The following snippet should be able to reproduce the error")
187200
exit_status = 1
188201

189202
sys.exit(exit_status)

SoftLayer/managers/hardware.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ def cancel_hardware(self, hardware_id, reason='unneeded', comment='', immediate=
7878
reasons = self.get_cancellation_reasons()
7979
cancel_reason = reasons.get(reason, reasons['unneeded'])
8080
ticket_mgr = SoftLayer.TicketManager(self.client)
81-
mask = 'mask[id, hourlyBillingFlag, billingItem[id], openCancellationTicket[id]]'
81+
mask = 'mask[id, hourlyBillingFlag, billingItem[id], openCancellationTicket[id], activeTransaction]'
8282
hw_billing = self.get_hardware(hardware_id, mask=mask)
8383

84+
if 'activeTransaction' in hw_billing:
85+
raise SoftLayer.SoftLayerError("Unable to cancel hardware with running transaction")
86+
8487
if 'billingItem' not in hw_billing:
8588
raise SoftLayer.SoftLayerError("Ticket #%s already exists for this server" %
8689
hw_billing['openCancellationTicket']['id'])

0 commit comments

Comments
 (0)