Skip to content

Commit 8f55369

Browse files
fixed merge conflict
2 parents ef96801 + 8c87513 commit 8f55369

File tree

13 files changed

+183
-12
lines changed

13 files changed

+183
-12
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# https://docs.travis-ci.com/user/languages/python/#python-37-and-higher
2-
dist: xenial
2+
dist: bionic
33
language: python
44
sudo: false
55
matrix:
@@ -12,7 +12,7 @@ matrix:
1212
env: TOX_ENV=py37
1313
- python: "3.8"
1414
env: TOX_ENV=py38
15-
- python: "pypy3.5"
15+
- python: "pypy3"
1616
env: TOX_ENV=pypy3
1717
- python: "3.6"
1818
env: TOX_ENV=analysis

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ chechuironman <chechuironman@gmail.com>
66
Christopher Gallo <chrisagallo@gmail.com>
77
David Ibarra <dtibarra@gmail.com>
88
Hans Kristian Moen <hans@ububeet.(none)>
9+
Ian Sutton <ians@openbsd.org>
910
Jake Williams <jwilliams@softlayer.com>
1011
Jason Johnson <spligak@gmail.com>
1112
Kevin Landreth <klandreth@softlayer.com>

SoftLayer/CLI/block/duplicate.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,16 @@
5454
type=click.Choice(['hourly', 'monthly']),
5555
default='monthly',
5656
help="Optional parameter for Billing rate (default to monthly)")
57+
@click.option('--dependent-duplicate',
58+
type=click.BOOL,
59+
default=False,
60+
show_default=True,
61+
help='Whether or not this duplicate will be a dependent duplicate '
62+
'of the origin volume.')
5763
@environment.pass_env
5864
def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
59-
duplicate_iops, duplicate_tier, duplicate_snapshot_size, billing):
65+
duplicate_iops, duplicate_tier, duplicate_snapshot_size, billing,
66+
dependent_duplicate):
6067
"""Order a duplicate block storage volume."""
6168
block_manager = SoftLayer.BlockStorageManager(env.client)
6269

@@ -75,7 +82,8 @@ def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
7582
duplicate_iops=duplicate_iops,
7683
duplicate_tier_level=duplicate_tier,
7784
duplicate_snapshot_size=duplicate_snapshot_size,
78-
hourly_billing_flag=hourly_billing_flag
85+
hourly_billing_flag=hourly_billing_flag,
86+
dependent_duplicate=dependent_duplicate
7987
)
8088
except ValueError as ex:
8189
raise exceptions.ArgumentError(str(ex))

SoftLayer/CLI/core.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import click
1616

17+
import requests
1718
import SoftLayer
1819
from SoftLayer.CLI import environment
1920
from SoftLayer.CLI import exceptions
@@ -31,6 +32,7 @@
3132
3: logging.DEBUG
3233
}
3334

35+
PROG_NAME = "slcli (SoftLayer Command-line)"
3436
VALID_FORMATS = ['table', 'raw', 'json', 'jsonraw']
3537
DEFAULT_FORMAT = 'raw'
3638
if sys.stdout.isatty():
@@ -69,6 +71,28 @@ def get_command(self, ctx, name):
6971
return module
7072

7173

74+
def get_latest_version():
75+
"""Gets the latest version of the Softlayer library."""
76+
try:
77+
result = requests.get('https://pypi.org/pypi/SoftLayer/json')
78+
json_result = result.json()
79+
latest = 'v{}'.format(json_result['info']['version'])
80+
except Exception:
81+
latest = "Unable to get version from pypi."
82+
return latest
83+
84+
85+
def get_version_message(ctx, param, value):
86+
"""Gets current and latest release versions message."""
87+
if not value or ctx.resilient_parsing:
88+
return
89+
current = SoftLayer.consts.VERSION
90+
latest = get_latest_version()
91+
click.secho("Current: {prog} {current}\nLatest: {prog} {latest}".format(
92+
prog=PROG_NAME, current=current, latest=latest))
93+
ctx.exit()
94+
95+
7296
@click.group(help="SoftLayer Command-line Client",
7397
epilog="""To use most commands your SoftLayer
7498
username and api_key need to be configured. The easiest way to do that is to
@@ -103,7 +127,8 @@ def get_command(self, ctx, name):
103127
is_flag=True,
104128
required=False,
105129
help="Use demo data instead of actually making API calls")
106-
@click.version_option(prog_name="slcli (SoftLayer Command-line)")
130+
@click.option('--version', is_flag=True, expose_value=False, is_eager=True, callback=get_version_message,
131+
help="Show version information.")
107132
@environment.pass_env
108133
def cli(env,
109134
format='table',

SoftLayer/CLI/file/duplicate.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,16 @@
5252
type=click.Choice(['hourly', 'monthly']),
5353
default='monthly',
5454
help="Optional parameter for Billing rate (default to monthly)")
55+
@click.option('--dependent-duplicate',
56+
type=click.BOOL,
57+
default=False,
58+
show_default=True,
59+
help='Whether or not this duplicate will be a dependent duplicate'
60+
'of the origin volume.')
5561
@environment.pass_env
5662
def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
57-
duplicate_iops, duplicate_tier, duplicate_snapshot_size, billing):
63+
duplicate_iops, duplicate_tier, duplicate_snapshot_size, billing,
64+
dependent_duplicate):
5865
"""Order a duplicate file storage volume."""
5966
file_manager = SoftLayer.FileStorageManager(env.client)
6067

@@ -73,7 +80,8 @@ def cli(env, origin_volume_id, origin_snapshot_id, duplicate_size,
7380
duplicate_iops=duplicate_iops,
7481
duplicate_tier_level=duplicate_tier,
7582
duplicate_snapshot_size=duplicate_snapshot_size,
76-
hourly_billing_flag=hourly_billing_flag
83+
hourly_billing_flag=hourly_billing_flag,
84+
dependent_duplicate=dependent_duplicate
7785
)
7886
except ValueError as ex:
7987
raise exceptions.ArgumentError(str(ex))

SoftLayer/CLI/user/permissions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@click.argument('identifier')
1212
@environment.pass_env
1313
def cli(env, identifier):
14-
"""User Permissions. TODO change to list all permissions, and which users have them"""
14+
"""User Permissions."""
1515

1616
mgr = SoftLayer.UserManager(env.client)
1717
user_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'username')

SoftLayer/managers/storage_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,8 @@ def prepare_replicant_order_object(manager, snapshot_schedule, location,
789789

790790
def prepare_duplicate_order_object(manager, origin_volume, iops, tier,
791791
duplicate_size, duplicate_snapshot_size,
792-
volume_type, hourly_billing_flag=False):
792+
volume_type, hourly_billing_flag=False,
793+
dependent_duplicate=False):
793794
"""Prepare the duplicate order to submit to SoftLayer_Product::placeOrder()
794795
795796
:param manager: The File or Block manager calling this function
@@ -800,6 +801,8 @@ def prepare_duplicate_order_object(manager, origin_volume, iops, tier,
800801
:param duplicate_snapshot_size: The size for the duplicate snapshot space
801802
:param volume_type: The type of the origin volume ('file' or 'block')
802803
:param hourly_billing_flag: Billing type, monthly (False) or hourly (True)
804+
:param dependent_duplicate: Duplicate type, normal (False) or dependent
805+
duplicate (True)
803806
:return: Returns the order object to be passed to the
804807
placeOrder() method of the Product_Order service
805808
"""
@@ -904,6 +907,9 @@ def prepare_duplicate_order_object(manager, origin_volume, iops, tier,
904907
if volume_is_performance:
905908
duplicate_order['iops'] = iops
906909

910+
if dependent_duplicate:
911+
duplicate_order['isDependentDuplicateFlag'] = 1
912+
907913
return duplicate_order
908914

909915

docs/cli/hardware.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,16 @@ Provides some basic functionality to order a server. `slcli order` has a more fu
4141
:prog: hw edit
4242
:show-nested:
4343

44-
When setting port speed, use "-1" to indicate best possible configuration. Using 10/100/1000/10000 on a server with a redundant interface may result the interface entering a degraded state. See `setPublicNetworkInterfaceSpeed <http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/setPublicNetworkInterfaceSpeed/>`_ for more information.
44+
**Note :** Using multiple ' **:** ' can cause an error.
45+
46+
$ slcli hw edit 123456 --tag "cloud:service:db2whoc, cloud:svcplan:flex, cloud:svcenv:prod, cloud:bmixenv:fra"
47+
48+
TransportError(0): ('Connection aborted.',
4549

50+
RemoteDisconnected('Remote end closed connection without response',))
51+
52+
53+
When setting port speed, use "-1" to indicate best possible configuration. Using 10/100/1000/10000 on a server with a redundant interface may result the interface entering a degraded state. See `setPublicNetworkInterfaceSpeed <http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/setPublicNetworkInterfaceSpeed/>`_ for more information.
4654

4755
.. click:: SoftLayer.CLI.hardware.list:cli
4856
:prog: hw list

tests/CLI/core_tests.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import click
1111
import mock
1212

13+
from requests.models import Response
1314
import SoftLayer
1415
from SoftLayer.CLI import core
1516
from SoftLayer.CLI import environment
@@ -52,6 +53,28 @@ def test_diagnostics(self):
5253
self.assertIn('"python_version"', result.output)
5354
self.assertIn('"library_location"', result.output)
5455

56+
@mock.patch('requests.get')
57+
def test_get_latest_version(self, request_get):
58+
response = Response()
59+
response.status_code = 200
60+
response.json = mock.MagicMock(return_value={"info": {"version": "1.1.1"}})
61+
request_get.return_value = response
62+
version = core.get_latest_version()
63+
self.assertIn('1.1.1', version)
64+
65+
@mock.patch('requests.get')
66+
def test_unable_get_latest_version(self, request_get):
67+
request_get.side_effect = Exception
68+
version = core.get_latest_version()
69+
self.assertIn('Unable', version)
70+
71+
@mock.patch('SoftLayer.CLI.core.get_latest_version')
72+
def test_get_version_message(self, get_latest_version_mock):
73+
get_latest_version_mock.return_value = '1.1.1'
74+
env = environment.Environment()
75+
result = self.run_command(['--version'], env=env)
76+
self.assert_no_fail(result)
77+
5578

5679
class CoreMainTests(testing.TestCase):
5780

tests/CLI/modules/block_tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,8 @@ def test_duplicate_order_hourly_billing(self, order_mock):
642642
duplicate_size=250, duplicate_iops=None,
643643
duplicate_tier_level=2,
644644
duplicate_snapshot_size=20,
645-
hourly_billing_flag=True)
645+
hourly_billing_flag=True,
646+
dependent_duplicate=False)
646647
self.assert_no_fail(result)
647648
self.assertEqual(result.output,
648649
'Order #24602 placed successfully!\n'

0 commit comments

Comments
 (0)