Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions SoftLayer/CLI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,5 @@
:license: MIT, see LICENSE for more details.
"""
# pylint: disable=w0401, invalid-name
import logging

from SoftLayer.CLI.helpers import * # NOQA

logger = logging.getLogger()
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.INFO)
45 changes: 29 additions & 16 deletions SoftLayer/CLI/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def get_command(self, ctx, name):
help="Config file location",
type=click.Path(resolve_path=True))
@click.option('--verbose', '-v',
help="Sets the debug noise level, specify multiple times "
"for more verbosity.",
help="Sets the debug noise level, specify multiple times for more verbosity.",
type=click.IntRange(0, 3, clamp=True),
count=True)
@click.option('--proxy',
Expand All @@ -115,10 +114,9 @@ def cli(env,
**kwargs):
"""Main click CLI entry-point."""

if verbose > 0:
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler())
logger.setLevel(DEBUG_LOGGING_MAP.get(verbose, logging.DEBUG))
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler())
logger.setLevel(DEBUG_LOGGING_MAP.get(verbose, logging.DEBUG))

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

env.vars['_start'] = time.time()
env.vars['_timings'] = SoftLayer.TimingTransport(env.client.transport)
env.vars['_timings'] = SoftLayer.DebugTransport(env.client.transport)
env.client.transport = env.vars['_timings']


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

if verbose > 0:
diagnostic_table = formatting.Table(['name', 'value'])
diagnostic_table.add_row(['execution_time',
'%fs' % (time.time() - START_TIME)])
diagnostic_table.add_row(['execution_time', '%fs' % (time.time() - START_TIME)])

api_call_value = []
for call, _, duration in env.vars['_timings'].get_last_calls():
api_call_value.append(
"%s::%s (%fs)" % (call.service, call.method, duration))
for call in env.client.transport.get_last_calls():
api_call_value.append("%s::%s (%fs)" % (call.service, call.method, call.end_time - call.start_time))

diagnostic_table.add_row(['api_calls', api_call_value])
diagnostic_table.add_row(['version', consts.USER_AGENT])
diagnostic_table.add_row(['python_version', sys.version])
diagnostic_table.add_row(['library_location',
os.path.dirname(SoftLayer.__file__)])
diagnostic_table.add_row(['library_location', os.path.dirname(SoftLayer.__file__)])

env.err(env.fmt(diagnostic_table))

if verbose > 1:
for call in env.client.transport.get_last_calls():
call_table = formatting.Table(['', '{}::{}'.format(call.service, call.method)])
nice_mask = ''
if call.mask is not None:
nice_mask = call.mask

call_table.add_row(['id', call.identifier])
call_table.add_row(['mask', nice_mask])
call_table.add_row(['filter', call.filter])
call_table.add_row(['limit', call.limit])
call_table.add_row(['offset', call.offset])
env.err(env.fmt(call_table))

if verbose > 2:
for call in env.client.transport.get_last_calls():
env.err(env.client.transport.print_reproduceable(call))


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

sys.exit(exit_status)
Expand Down
5 changes: 4 additions & 1 deletion SoftLayer/managers/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ def cancel_hardware(self, hardware_id, reason='unneeded', comment='', immediate=
reasons = self.get_cancellation_reasons()
cancel_reason = reasons.get(reason, reasons['unneeded'])
ticket_mgr = SoftLayer.TicketManager(self.client)
mask = 'mask[id, hourlyBillingFlag, billingItem[id], openCancellationTicket[id]]'
mask = 'mask[id, hourlyBillingFlag, billingItem[id], openCancellationTicket[id], activeTransaction]'
hw_billing = self.get_hardware(hardware_id, mask=mask)

if 'activeTransaction' in hw_billing:
raise SoftLayer.SoftLayerError("Unable to cancel hardware with running transaction")

if 'billingItem' not in hw_billing:
raise SoftLayer.SoftLayerError("Ticket #%s already exists for this server" %
hw_billing['openCancellationTicket']['id'])
Expand Down
Loading