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
6 changes: 3 additions & 3 deletions SoftLayer/CLI/cdn/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def cli(env, account_id):
manager = SoftLayer.CDNManager(env.client)
account = manager.get_account(account_id)

table = formatting.KeyValueTable(['Name', 'Value'])
table.align['Name'] = 'r'
table.align['Value'] = 'l'
table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'

table.add_row(['id', account['id']])
table.add_row(['account_name', account['cdnAccountName']])
Expand Down
3 changes: 2 additions & 1 deletion SoftLayer/CLI/cdn/origin_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
@click.argument('content_url')
@click.option('--type',
help='The media type for this mapping (http, flash, wm, ...)',
default='http')
default='http',
show_default=True)
@click.option('--cname',
help='An optional CNAME to attach to the mapping')
@environment.pass_env
Expand Down
6 changes: 3 additions & 3 deletions SoftLayer/CLI/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def get_settings_from_client(client):

def config_table(settings):
"""Returns a config table."""
table = formatting.KeyValueTable(['Name', 'Value'])
table.align['Name'] = 'r'
table.align['Value'] = 'l'
table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'
table.add_row(['Username', settings['username'] or 'not set'])
table.add_row(['API Key', settings['api_key'] or 'not set'])
table.add_row(['Endpoint URL', settings['endpoint_url'] or 'not set'])
Expand Down
67 changes: 34 additions & 33 deletions SoftLayer/CLI/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"""
from __future__ import print_function
import logging
import os
import sys
import time
import types

import click
Expand All @@ -16,10 +18,12 @@
from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions
from SoftLayer.CLI import formatting
from SoftLayer import consts

# pylint: disable=too-many-public-methods, broad-except, unused-argument
# pylint: disable=redefined-builtin, super-init-not-called

START_TIME = time.time()
DEBUG_LOGGING_MAP = {
0: logging.CRITICAL,
1: logging.WARNING,
Expand Down Expand Up @@ -73,57 +77,44 @@ def get_command(self, ctx, name):
'auto_envvar_prefix': 'SLCLI'})
@click.option('--format',
default=DEFAULT_FORMAT,
show_default=True,
help="Output format",
type=click.Choice(VALID_FORMATS))
@click.option('--config', '-C',
required=False,
default=click.get_app_dir('softlayer', force_posix=True),
show_default=True,
help="Config file location",
type=click.Path(resolve_path=True))
@click.option('--debug',
required=False,
default=None,
help="Sets the debug noise level",
type=click.Choice(sorted([str(key) for key
in DEBUG_LOGGING_MAP.keys()])))
@click.option('--verbose', '-v',
help="Sets the debug noise level",
help="Sets the debug noise level, specify multiple times "
"for more verbosity.",
type=click.IntRange(0, 3, clamp=True),
count=True)
@click.option('--timings',
required=False,
is_flag=True,
help="Time each API call and display after results")
@click.option('--proxy',
required=False,
help="HTTP[S] proxy to be use to make API calls")
@click.option('--really / --not-really', '-y',
is_flag=True,
required=False,
help="Confirm all prompt actions")
@click.option('--fixtures / --no-fixtures',
envvar='SL_FIXTURES',
@click.option('--demo / --no-demo',
is_flag=True,
required=False,
help="Use fixtures instead of actually making API calls")
help="Use demo data instead of actually making API calls")
@click.version_option(prog_name="slcli (SoftLayer Command-line)")
@environment.pass_env
def cli(env,
format='table',
config=None,
debug=0,
verbose=0,
proxy=None,
really=False,
fixtures=False,
demo=False,
**kwargs):
"""Main click CLI entry-point."""

# Set logging level
if debug is not None:
verbose = int(debug)

if verbose:
if verbose > 0:
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler())
logger.setLevel(DEBUG_LOGGING_MAP.get(verbose, logging.DEBUG))
Expand All @@ -134,7 +125,7 @@ def cli(env,
env.format = format
if env.client is None:
# Environment can be passed in explicitly. This is used for testing
if fixtures:
if demo:
client = SoftLayer.BaseClient(
transport=SoftLayer.FixtureTransport(),
auth=None,
Expand All @@ -147,23 +138,33 @@ def cli(env,
)
env.client = client

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


@cli.resultcallback()
@environment.pass_env
def output_result(env, timings=False, *args, **kwargs):
"""Outputs the results returned by the CLI and also outputs timings."""

if timings and env.vars.get('_timings'):
timing_table = formatting.Table(['service', 'method', 'time'])

calls = env.vars['_timings'].get_last_calls()
for call, _, duration in calls:
timing_table.add_row([call.service, call.method, duration])

env.err(env.fmt(timing_table))
def output_diagnostics(env, verbose=0, **kwargs):
"""Output diagnostic information."""

if verbose > 0:
diagnostic_table = formatting.Table(['name', 'value'])
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))

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__)])

env.err(env.fmt(diagnostic_table))


def main(reraise_exceptions=False, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions SoftLayer/CLI/dns/record_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@click.option('--ttl',
type=click.INT,
default=7200,
show_default=True,
help='TTL value in seconds, such as 86400')
@environment.pass_env
def cli(env, zone, record, type, data, ttl):
Expand Down
8 changes: 4 additions & 4 deletions SoftLayer/CLI/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,9 @@ def iter_to_table(value):
def _format_dict(result):
"""Format dictionary responses into key-value table."""

table = KeyValueTable(['Name', 'Value'])
table.align['Name'] = 'r'
table.align['Value'] = 'l'
table = KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'

for key, value in result.items():
value = iter_to_table(value)
Expand All @@ -391,7 +391,7 @@ def _format_list(result):
if isinstance(result[0], dict):
return _format_list_objects(result)

table = Table(["Value"])
table = Table(['value'])
for item in result:
table.add_row([iter_to_table(item)])
return table
Expand Down
6 changes: 3 additions & 3 deletions SoftLayer/CLI/image/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def cli(env, identifier):
if child.get('datacenter'):
datacenters.append(utils.lookup(child, 'datacenter', 'name'))

table = formatting.KeyValueTable(['Name', 'Value'])
table.align['Name'] = 'r'
table.align['Value'] = 'l'
table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'

table.add_row(['id', image['id']])
table.add_row(['global_identifier',
Expand Down
6 changes: 4 additions & 2 deletions SoftLayer/CLI/image/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
@click.command()
@click.argument('name')
@click.argument('uri')
@click.option('--note', default="",
@click.option('--note',
default="",
help="The note to be applied to the imported template")
@click.option('--os-code', default="",
@click.option('--os-code',
default="",
help="The referenceCode of the operating system software"
" description for the imported VHD")
@environment.pass_env
Expand Down
6 changes: 3 additions & 3 deletions SoftLayer/CLI/iscsi/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def cli(env, identifier, password):
result = iscsi_mgr.get_iscsi(iscsi_id)
result = utils.NestedDict(result)

table = formatting.KeyValueTable(['Name', 'Value'])
table.align['Name'] = 'r'
table.align['Value'] = 'l'
table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'

table.add_row(['id', result['id']])
table.add_row(['serviceResourceName', result['serviceResourceName']])
Expand Down
6 changes: 3 additions & 3 deletions SoftLayer/CLI/loadbal/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def cli(env, identifier):

load_balancer = mgr.get_local_lb(loadbal_id)

table = formatting.KeyValueTable(['Name', 'Value'])
table.align['Name'] = 'l'
table.align['Value'] = 'l'
table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'l'
table.align['value'] = 'l'
table.add_row(['General properties', '----------'])
table.add_row([' ID', 'local:%s' % load_balancer['id']])
table.add_row([' IP Address', load_balancer['ipAddress']['ipAddress']])
Expand Down
4 changes: 2 additions & 2 deletions SoftLayer/CLI/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def get_network():
network = network_func()

table = formatting.KeyValueTable(['name', 'value'])
table.align['Name'] = 'r'
table.align['Value'] = 'l'
table.align['name'] = 'r'
table.align['value'] = 'l'
table.add_row(['mac addresses',
formatting.listing(network['mac_addresses'],
separator=',')])
Expand Down
2 changes: 2 additions & 0 deletions SoftLayer/CLI/mq/queue_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
@click.option('--visibility-interval',
type=click.INT,
default=30,
show_default=True,
help="Time in seconds that messages will re-appear after being "
"popped")
@click.option('--expiration',
type=click.INT,
default=604800,
show_default=True,
help="Time in seconds that messages will live")
@helpers.multi_option('--tag', '-g', help="Tags to add to the queue")
@environment.pass_env
Expand Down
2 changes: 2 additions & 0 deletions SoftLayer/CLI/mq/queue_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
@click.option('--visibility-interval',
type=click.INT,
default=30,
show_default=True,
help="Time in seconds that messages will re-appear after being "
"popped")
@click.option('--expiration',
type=click.INT,
default=604800,
show_default=True,
help="Time in seconds that messages will live")
@helpers.multi_option('--tag', '-g', help="Tags to add to the queue")
@environment.pass_env
Expand Down
1 change: 1 addition & 0 deletions SoftLayer/CLI/mq/queue_pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@click.argument('queue-name')
@click.option('--count',
default=1,
show_default=True,
type=click.INT,
help="Count of messages to pop")
@click.option('--delete-after',
Expand Down
2 changes: 2 additions & 0 deletions SoftLayer/CLI/mq/topic_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
@click.option('--visibility-interval',
type=click.INT,
default=30,
show_default=True,
help="Time in seconds that messages will re-appear after being "
"popped")
@click.option('--expiration',
type=click.INT,
default=604800,
show_default=True,
help="Time in seconds that messages will live")
@helpers.multi_option('--tag', '-g', help="Tags to add to the topic")
@environment.pass_env
Expand Down
6 changes: 3 additions & 3 deletions SoftLayer/CLI/rwhois/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def cli(env):
mgr = SoftLayer.NetworkManager(env.client)
result = mgr.get_rwhois()

table = formatting.KeyValueTable(['Name', 'Value'])
table.align['Name'] = 'r'
table.align['Value'] = 'l'
table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'
table.add_row(['Name', result['firstName'] + ' ' + result['lastName']])
table.add_row(['Company', result['companyName']])
table.add_row(['Abuse Email', result['abuseEmail']])
Expand Down
1 change: 1 addition & 0 deletions SoftLayer/CLI/server/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
@click.option('--billing',
type=click.Choice(['hourly', 'monthly']),
default='hourly',
show_default=True,
help="Billing rate")
@click.option('--postinstall', '-i', help="Post-install script to download")
@helpers.multi_option('--key', '-k',
Expand Down
6 changes: 3 additions & 3 deletions SoftLayer/CLI/server/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def cli(env, identifier, passwords, price):

hardware = SoftLayer.HardwareManager(env.client)

table = formatting.KeyValueTable(['Name', 'Value'])
table.align['Name'] = 'r'
table.align['Value'] = 'l'
table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'

hardware_id = helpers.resolve_id(hardware.resolve_ids,
identifier,
Expand Down
9 changes: 6 additions & 3 deletions SoftLayer/CLI/server/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@
@click.option('--memory', '-m', help='Filter by memory in gigabytes')
@click.option('--network', '-n', help='Filter by network port speed in Mbps')
@helpers.multi_option('--tag', help='Filter by tags')
@click.option('--sortby', help='Column to sort by', default='hostname')
@click.option('--sortby', help='Column to sort by',
default='hostname',
show_default=True)
@click.option('--columns',
callback=column_helper.get_formatter(COLUMNS),
help='Columns to display. Options: %s'
help='Columns to display. [options: %s]'
% ', '.join(column.name for column in COLUMNS),
default=','.join(DEFAULT_COLUMNS))
default=','.join(DEFAULT_COLUMNS),
show_default=True)
@environment.pass_env
def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network, tag,
columns):
Expand Down
2 changes: 1 addition & 1 deletion SoftLayer/CLI/sshkey/print.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def cli(env, identifier, out_file):
with open(path.expanduser(out_file), 'w') as pub_file:
pub_file.write(key['key'])

table = formatting.KeyValueTable(['Name', 'Value'])
table = formatting.KeyValueTable(['name', 'value'])
table.add_row(['id', key['id']])
table.add_row(['label', key.get('label')])
table.add_row(['notes', key.get('notes', '-')])
Expand Down
1 change: 1 addition & 0 deletions SoftLayer/CLI/ssl/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@click.command()
@click.option('--status',
default="all",
show_default=True,
type=click.Choice(['all', 'valid', 'expired']),
help="Show certificates with this status")
@click.option('--sortby',
Expand Down
Loading