Skip to content

Commit

Permalink
Merge pull request #504 from sudorandom/rename-some-of-the-things
Browse files Browse the repository at this point in the history
Use slcli command over sl
  • Loading branch information
sudorandom committed Mar 27, 2015
2 parents aaacca4 + 067e4fd commit 76edfc0
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 59 deletions.
6 changes: 3 additions & 3 deletions SoftLayer/CLI/call_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def cli(env, service, method, _id, mask, limit, offset):
\b
Examples:
sl call-api Account getObject
sl call-api Account getVirtualGuests --limit=10 --mask=id,hostname
sl call-api Virtual_Guest getObject --id=2710344
slcli call-api Account getObject
slcli call-api Account getVirtualGuests --limit=10 --mask=id,hostname
slcli call-api Virtual_Guest getObject --id=2710344
"""
result = env.client.call(service, method,
id=_id,
Expand Down
4 changes: 2 additions & 2 deletions SoftLayer/CLI/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_command(self, ctx, name):
@click.group(help="SoftLayer Command-line Client",
epilog="""To use most commands your SoftLayer
username and api_key need to be configured. The easiest way to do that is to
use: 'sl setup'""",
use: 'slcli setup'""",
cls=CommandLoader,
context_settings={'help_option_names': ['-h', '--help']})
@click.pass_context
Expand Down Expand Up @@ -178,7 +178,7 @@ def main():
except SoftLayer.SoftLayerAPIError as ex:
if 'invalid api token' in ex.faultString.lower():
print("Authentication Failed: To update your credentials,"
" use 'sl config setup'")
" use 'slcli config setup'")
exit_status = 1
else:
print(str(ex))
Expand Down
15 changes: 15 additions & 0 deletions SoftLayer/CLI/deprecated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
SoftLayer.CLI.deprecated
~~~~~~~~~~~~~~~~~~~~~~~~
Handles usage of the deprecated command name, 'sl'.
:license: MIT, see LICENSE for more details.
"""
from __future__ import print_function
import sys


def main():
"""Main function for the deprecated 'sl' command."""
print("ERROR: Use the 'slcli' command instead.", file=sys.stderr)
print("> slcli %s" % ' '.join(sys.argv[1:]), file=sys.stderr)
exit(-1)
2 changes: 1 addition & 1 deletion SoftLayer/CLI/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
Examples :
%s
""" % ('*'+'\n*'.join(META_CHOICES),
'sl metadata '+'\nsl metadata '.join(META_CHOICES))
'slcli metadata '+'\nslcli metadata '.join(META_CHOICES))


@click.command(help=HELP,
Expand Down
2 changes: 1 addition & 1 deletion SoftLayer/CLI/server/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@


@click.command(epilog="""See 'sl server create-options' for valid options.""")
@click.option('--domain', '-D', help="Domain portion of the FQDN")
@click.option('--hostname', '-H', help="Host portion of the FQDN")
@click.option('--domain', '-D', help="Domain portion of the FQDN")
@click.option('--size', '-s', help="Hardware size")
@click.option('--os', '-o', help="OS install code")
@click.option('--datacenter', '-d', help="Datacenter shortname")
Expand Down
2 changes: 1 addition & 1 deletion SoftLayer/CLI/ticket/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@click.option('--subject-id',
required=True,
help="""The subject id to use for the ticket,
issue 'sl ticket subjects' to get the list""")
issue 'slcli ticket subjects' to get the list""")
@click.option('--body', help="The ticket body")
@environment.pass_env
def cli(env, title, subject_id, body):
Expand Down
4 changes: 2 additions & 2 deletions SoftLayer/CLI/virt/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import click


@click.command(epilog="See 'sl vs create-options' for valid options")
@click.command(epilog="See 'slcli vs create-options' for valid options")
@click.option('--domain', '-D', help="Domain portion of the FQDN")
@click.option('--hostname', '-H', help="Host portion of the FQDN")
@click.option('--image',
help="Image GUID. See: 'sl image list' for reference")
help="Image GUID. See: 'slcli image list' for reference")
@click.option('--cpu', '-c', help="Number of CPU cores", type=click.INT)
@click.option('--memory', '-m', help="Memory in mebibytes", type=virt.MEM_TYPE)
@click.option('--os', '-o',
Expand Down
2 changes: 1 addition & 1 deletion SoftLayer/tests/CLI/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_auth_error(self, stdoutmock, climock):
self.assertRaises(SystemExit, core.main)

self.assertIn("Authentication Failed:", stdoutmock.getvalue())
self.assertIn("use 'sl config setup'", stdoutmock.getvalue())
self.assertIn("use 'slcli config setup'", stdoutmock.getvalue())


def recursive_subcommand_loader(root, path=''):
Expand Down
32 changes: 32 additions & 0 deletions SoftLayer/tests/CLI/deprecated_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
SoftLayer.tests.CLI.deprecated_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:license: MIT, see LICENSE for more details.
"""
import mock

from SoftLayer.CLI import deprecated
from SoftLayer import testing
from SoftLayer import utils


class EnvironmentTests(testing.TestCase):

def test_main(self):

with mock.patch('sys.stderr', new=utils.StringIO()) as fake_out:
ex = self.assertRaises(SystemExit, deprecated.main)
self.assertEqual(ex.code, -1)

self.assertIn("ERROR: Use the 'slcli' command instead.",
fake_out.getvalue())

def test_with_args(self):
with mock.patch('sys.stderr', new=utils.StringIO()) as fake_out:
with mock.patch('sys.argv', new=['sl', 'module', 'subcommand']):
ex = self.assertRaises(SystemExit, deprecated.main)
self.assertEqual(ex.code, -1)

self.assertIn("ERROR: Use the 'slcli' command instead.",
fake_out.getvalue())
9 changes: 0 additions & 9 deletions SoftLayer/tests/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ def test_env(self, get_client_settings):


class ClientMethods(testing.TestCase):
def test_help(self):
help(SoftLayer)
help(SoftLayer.Client)
client = SoftLayer.Client(
username='doesnotexist',
api_key='issurelywrong'
)
help(client)
help(client['SERVICE'])

def test_repr(self):
client = SoftLayer.Client(
Expand Down
26 changes: 13 additions & 13 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ functionality not fully documented here.

Configuration Setup
-------------------
To update the configuration, you can use `sl setup`.
To update the configuration, you can use `slcli setup`.
::

$ sl setup
$ slcli setup
Username []: username
API Key or Password []:
Endpoint (public|private|custom): public
Expand All @@ -35,10 +35,10 @@ To update the configuration, you can use `sl setup`.
:..............:..................................................................:
Are you sure you want to write settings to "/home/me/.softlayer"? [y/N]: y

To check the configuration, you can use `sl config show`.
To check the configuration, you can use `slcli config show`.
::

$ sl config show
$ slcli config show
:..............:..................................................................:
: Name : Value :
:..............:..................................................................:
Expand All @@ -58,7 +58,7 @@ To discover the available commands, simply type `sl`.
::

$ sl
Usage: sl [OPTIONS] COMMAND [ARGS]...
Usage: slcli [OPTIONS] COMMAND [ARGS]...

SoftLayer Command-line Client

Expand Down Expand Up @@ -99,14 +99,14 @@ To discover the available commands, simply type `sl`.
vs Virtual Servers.

To use most commands your SoftLayer username and api_key need to be
configured. The easiest way to do that is to use: 'sl setup'
configured. The easiest way to do that is to use: 'slcli setup'

As you can see, there are a number of commands/sections. To look at the list of
subcommands for virtual servers type `sl vs`. For example:
subcommands for virtual servers type `slcli vs`. For example:
::

$ sl vs
Usage: sl vs [OPTIONS] COMMAND [ARGS]...
$ slcli vs
Usage: slcli vs [OPTIONS] COMMAND [ARGS]...

Virtual Servers.

Expand Down Expand Up @@ -135,11 +135,11 @@ subcommands for virtual servers type `sl vs`. For example:
upgrade Upgrade a virtual server.

Finally, we can make an actual call. Let's list out the virtual servers on our
account by using `sl vs list`.
account by using `slcli vs list`.

::

$ sl vs list
$ slcli vs list
:.........:............:....................:.......:........:................:..............:....................:
: id : datacenter : host : cores : memory : primary_ip : backend_ip : active_transaction :
:.........:............:....................:.......:........:................:..............:....................:
Expand All @@ -149,8 +149,8 @@ account by using `sl vs list`.
Most commands will take in additional options/arguments. To see all available actions, use `--help`.
::

$ sl vs list --help
Usage: sl vs list [OPTIONS]
$ slcli vs list --help
Usage: slcli vs list [OPTIONS]

List virtual servers.

Expand Down
26 changes: 13 additions & 13 deletions docs/cli/vs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ using SoftLayer's command-line client.
:ref:`configured with valid SoftLayer credentials<cli>`.


First, let's list the current virtual servers with `sl vs list`.
First, let's list the current virtual servers with `slcli vs list`.
::

$ sl vs list
$ slcli vs list
:.....:............:.........................:.......:........:..............:.............:....................:........:
: id : datacenter : host : cores : memory : primary_ip : backend_ip : active_transaction : owner :
:.....:............:.........................:.......:........:..............:.............:....................:........:
Expand All @@ -26,11 +26,11 @@ First, let's list the current virtual servers with `sl vs list`.
We don't have any virtual servers yet! Let's fix that. Before we can create a
virtual server (VS), we need to know what options are available to us: RAM,
CPU, operating systems, disk sizes, disk types, datacenters, and so on.
Luckily, there's a simple command to show all options: `sl vs create-options`.
Luckily, there's a simple command to show all options: `slcli vs create-options`.

::

$ sl vs create-options
$ slcli vs create-options
:.................:...........................................................................................:
: Name : Value :
:.................:...........................................................................................:
Expand Down Expand Up @@ -112,11 +112,11 @@ Luckily, there's a simple command to show all options: `sl vs create-options`.

Here's the command to create a 2-core virtual server with 1GiB memory, running
Ubuntu 14.04 LTS, and that is billed on an hourly basis in the San Jose 1
datacenter using the command `sl vs create`.
datacenter using the command `slcli vs create`.

::

$ sl vs create --hostname=example --domain=softlayer.com --cpu 2 --memory 1024 -o UBUNTU_14_64 --datacenter=sjc01 --billing=hourly
$ slcli vs create --hostname=example --domain=softlayer.com --cpu 2 --memory 1024 -o UBUNTU_14_64 --datacenter=sjc01 --billing=hourly
This action will incur charges on your account. Continue? [y/N]: y
:.........:......................................:
: name : value :
Expand All @@ -132,7 +132,7 @@ instantly appear in your virtual server list now.

::

$ sl vs list
$ slcli vs list
:.........:............:.......................:.......:........:................:..............:....................:
: id : datacenter : host : cores : memory : primary_ip : backend_ip : active_transaction :
:.........:............:.......................:.......:........:................:..............:....................:
Expand All @@ -144,15 +144,15 @@ here's how:

::

$ sl vs ready 'example' --wait=600
$ slcli vs ready 'example' --wait=600
READY

When the previous command returns, you'll know that the virtual server has
finished the provisioning process and is ready to use. This is *very* useful
for chaining commands together.

Now that you have your virtual server, let's get access to it. To do that, use
the `sl vs detail` command. From the example below, you can see that the
the `slcli vs detail` command. From the example below, you can see that the
username is 'root' and password is 'ABCDEFGH'.

.. warning::
Expand All @@ -165,7 +165,7 @@ username is 'root' and password is 'ABCDEFGH'.

::

$ sl vs detail example --passwords
$ slcli vs detail example --passwords
:..............:...........................:
: Name : Value :
:..............:...........................:
Expand All @@ -188,12 +188,12 @@ username is 'root' and password is 'ABCDEFGH'.


There are many other commands to help manage virtual servers. To see them all,
use `sl help vs`.
use `slcli help vs`.

::

$ sl vs
Usage: sl vs [OPTIONS] COMMAND [ARGS]...
$ slcli vs
Usage: slcli vs [OPTIONS] COMMAND [ARGS]...

Virtual Servers.

Expand Down
2 changes: 1 addition & 1 deletion docs/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ locations.
The configuration file is INI-based and requires the `softlayer` section to be
present. The only required fields are `username` and `api_key`. You can
optionally supply the `endpoint_url` as well. This file is created
automatically by the `sl setup` command detailed here:
automatically by the `slcli setup` command detailed here:
:ref:`config_setup`.

*Config Example*
Expand Down
12 changes: 6 additions & 6 deletions docs/dev/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The command line parsing is currently based on `click <http://click.pocoo.org/>`

First Example
-------------
For the first example, we can create `sl table-example` by creating the following file at SoftLayer/CLI/table_example.py:
For the first example, we can create `slcli table-example` by creating the following file at SoftLayer/CLI/table_example.py:

::

Expand All @@ -36,7 +36,7 @@ For the first example, we can create `sl table-example` by creating the followin

return t

Then we need to register it so that `sl table-example` will know to route to this new module. We do that by adding ALL_ROUTES in SoftLayer/CLI/routes.py to include the following:
Then we need to register it so that `slcli table-example` will know to route to this new module. We do that by adding ALL_ROUTES in SoftLayer/CLI/routes.py to include the following:

::

Expand All @@ -47,17 +47,17 @@ Then we need to register it so that `sl table-example` will know to route to thi
Which gives us
::

$ sl table-example
$ slcli table-example
:.......:.......:
: col1 : col2 :
:.......:.......:
: test : test :
: test2 : test2 :
:.......:.......:

$ sl --format=raw table-example
test test
test2 test2
$ slcli --format=raw table-example
test test
test2 test2

Formatting of the data represented in the table is actually controlled upstream from the CLIRunnable's making supporting more data formats in the future easier.

Expand Down

0 comments on commit 76edfc0

Please sign in to comment.