Skip to content

Commit 4cff83c

Browse files
some final touches, ended up auto-translating commands so they conform with the hypen delimiter like the rest of the slcli
1 parent 0d22da9 commit 4cff83c

File tree

5 files changed

+43
-18
lines changed

5 files changed

+43
-18
lines changed

SoftLayer/CLI/virt/capacity/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111

1212

1313
class CapacityCommands(click.MultiCommand):
14-
"""Loads module for capacity related commands."""
14+
"""Loads module for capacity related commands.
15+
16+
Will automatically replace _ with - where appropriate.
17+
I'm not sure if this is better or worse than using a long list of manual routes, so I'm trying it here.
18+
CLI/virt/capacity/create_guest.py -> slcli vs capacity create-guest
19+
"""
1520

1621
def __init__(self, **attrs):
1722
click.MultiCommand.__init__(self, **attrs)
@@ -24,13 +29,14 @@ def list_commands(self, ctx):
2429
if filename == '__init__.py':
2530
continue
2631
if filename.endswith('.py'):
27-
commands.append(filename[:-3])
32+
commands.append(filename[:-3].replace("_", "-"))
2833
commands.sort()
2934
return commands
3035

3136
def get_command(self, ctx, cmd_name):
3237
"""Get command for click."""
3338
path = "%s.%s" % (__name__, cmd_name)
39+
path = path.replace("-", "_")
3440
module = importlib.import_module(path)
3541
return getattr(module, 'cli')
3642

SoftLayer/CLI/virt/capacity/create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
""" and not cancelable until the contract is expired.""", fg='red'))
1313
@click.option('--name', '-n', required=True, prompt=True,
1414
help="Name for your new reserved capacity")
15-
@click.option('--backend_router_id', '-b', required=True, prompt=True,
15+
@click.option('--backend_router_id', '-b', required=True, prompt=True, type=int,
1616
help="backendRouterId, create-options has a list of valid ids to use.")
1717
@click.option('--flavor', '-f', required=True, prompt=True,
1818
help="Capacity keyname (C1_2X2_1_YEAR_TERM for example).")
19-
@click.option('--instances', '-i', required=True, prompt=True,
19+
@click.option('--instances', '-i', required=True, prompt=True, type=int,
2020
help="Number of VSI instances this capacity reservation can support.")
2121
@click.option('--test', is_flag=True,
2222
help="Do not actually create the virtual server")

SoftLayer/CLI/virt/capacity/create_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def cli(env):
1414
"""List options for creating Reserved Capacity"""
1515
manager = CapacityManager(env.client)
1616
items = manager.get_create_options()
17-
# pp(items)
17+
1818
items.sort(key=lambda term: int(term['capacity']))
1919
table = formatting.Table(["KeyName", "Description", "Term", "Default Hourly Price Per Instance"],
2020
title="Reserved Capacity Options")

SoftLayer/fixtures/SoftLayer_Product_Package.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -789,131 +789,152 @@
789789
getItems = [
790790
{
791791
'id': 1234,
792+
'keyName': 'KeyName01',
792793
'capacity': '1000',
793794
'description': 'Public & Private Networks',
794795
'itemCategory': {'categoryCode': 'Uplink Port Speeds'},
795796
'prices': [{'id': 1122,
797+
'hourlyRecurringFee': 0.0,
796798
'categories': [{'id': 26,
797799
'name': 'Uplink Port Speeds',
798800
'categoryCode': 'port_speed'}]}],
799801
},
800802
{
801803
'id': 2233,
804+
'keyName': 'KeyName02',
802805
'capacity': '1000',
803806
'description': 'Public & Private Networks',
804807
'itemCategory': {'categoryCode': 'Uplink Port Speeds'},
805808
'prices': [{'id': 4477,
809+
'hourlyRecurringFee': 0.0,
806810
'categories': [{'id': 26,
807811
'name': 'Uplink Port Speeds',
808812
'categoryCode': 'port_speed'}]}],
809813
},
810814
{
811815
'id': 1239,
816+
'keyName': 'KeyName03',
812817
'capacity': '2',
813818
'description': 'RAM',
814819
'itemCategory': {'categoryCode': 'RAM'},
815820
'prices': [{'id': 1133,
821+
'hourlyRecurringFee': 0.0,
816822
'categories': [{'id': 3,
817823
'name': 'RAM',
818824
'categoryCode': 'ram'}]}],
819825
},
820826
{
821827
'id': 1240,
828+
'keyName': 'KeyName014',
822829
'capacity': '4',
823830
'units': 'PRIVATE_CORE',
824831
'description': 'Computing Instance (Dedicated)',
825832
'itemCategory': {'categoryCode': 'Computing Instance'},
826833
'prices': [{'id': 1007,
834+
'hourlyRecurringFee': 0.0,
827835
'categories': [{'id': 80,
828836
'name': 'Computing Instance',
829837
'categoryCode': 'guest_core'}]}],
830838
},
831839
{
832840
'id': 1250,
841+
'keyName': 'KeyName015',
833842
'capacity': '4',
834843
'units': 'CORE',
835844
'description': 'Computing Instance',
836845
'itemCategory': {'categoryCode': 'Computing Instance'},
837846
'prices': [{'id': 1144,
838847
'locationGroupId': None,
848+
'hourlyRecurringFee': 0.0,
839849
'categories': [{'id': 80,
840850
'name': 'Computing Instance',
841851
'categoryCode': 'guest_core'}]}],
842852
},
843853
{
844854
'id': 112233,
855+
'keyName': 'KeyName016',
845856
'capacity': '55',
846857
'units': 'CORE',
847858
'description': 'Computing Instance',
848859
'itemCategory': {'categoryCode': 'Computing Instance'},
849860
'prices': [{'id': 332211,
850861
'locationGroupId': 1,
862+
'hourlyRecurringFee': 0.0,
851863
'categories': [{'id': 80,
852864
'name': 'Computing Instance',
853865
'categoryCode': 'guest_core'}]}],
854866
},
855867
{
856868
'id': 4439,
869+
'keyName': 'KeyName017',
857870
'capacity': '1',
858871
'description': '1 GB iSCSI Storage',
859872
'itemCategory': {'categoryCode': 'iscsi'},
860-
'prices': [{'id': 2222}],
873+
'prices': [{'id': 2222, 'hourlyRecurringFee': 0.0}],
861874
},
862875
{
863876
'id': 1121,
877+
'keyName': 'KeyName081',
864878
'capacity': '20',
865879
'description': '20 GB iSCSI snapshot',
866880
'itemCategory': {'categoryCode': 'iscsi_snapshot_space'},
867-
'prices': [{'id': 2014}],
881+
'prices': [{'id': 2014, 'hourlyRecurringFee': 0.0}],
868882
},
869883
{
870884
'id': 4440,
885+
'keyName': 'KeyName019',
871886
'capacity': '4',
872887
'description': '4 Portable Public IP Addresses',
873888
'itemCategory': {'categoryCode': 'sov_sec_ip_addresses_pub'},
874-
'prices': [{'id': 4444}],
889+
'prices': [{'id': 4444, 'hourlyRecurringFee': 0.0}],
875890
},
876891
{
877892
'id': 8880,
893+
'keyName': 'KeyName0199',
878894
'capacity': '8',
879895
'description': '8 Portable Public IP Addresses',
880896
'itemCategory': {'categoryCode': 'sov_sec_ip_addresses_pub'},
881-
'prices': [{'id': 8888}],
897+
'prices': [{'id': 8888, 'hourlyRecurringFee': 0.0}],
882898
},
883899
{
884900
'id': 44400,
901+
'keyName': 'KeyName0155',
885902
'capacity': '4',
886903
'description': '4 Portable Private IP Addresses',
887904
'itemCategory': {'categoryCode': 'sov_sec_ip_addresses_priv'},
888-
'prices': [{'id': 44441}],
905+
'prices': [{'id': 44441, 'hourlyRecurringFee': 0.0}],
889906
},
890907
{
891908
'id': 88800,
909+
'keyName': 'KeyName0144',
892910
'capacity': '8',
893911
'description': '8 Portable Private IP Addresses',
894912
'itemCategory': {'categoryCode': 'sov_sec_ip_addresses_priv'},
895-
'prices': [{'id': 88881}],
913+
'prices': [{'id': 88881, 'hourlyRecurringFee': 0.0}],
896914
},
897915
{
898916
'id': 10,
917+
'keyName': 'KeyName0341',
899918
'capacity': '0',
900919
'description': 'Global IPv4',
901920
'itemCategory': {'categoryCode': 'global_ipv4'},
902-
'prices': [{'id': 11}],
921+
'prices': [{'id': 11, 'hourlyRecurringFee': 0.0}],
903922
},
904923
{
905924
'id': 66464,
925+
'keyName': 'KeyName0211',
906926
'capacity': '64',
907927
'description': '/64 Block Portable Public IPv6 Addresses',
908928
'itemCategory': {'categoryCode': 'static_ipv6_addresses'},
909-
'prices': [{'id': 664641}],
929+
'prices': [{'id': 664641, 'hourlyRecurringFee': 0.0}],
910930
},
911931
{
912932
'id': 610,
933+
'keyName': 'KeyName031',
913934
'capacity': '0',
914935
'description': 'Global IPv6',
915936
'itemCategory': {'categoryCode': 'global_ipv6'},
916-
'prices': [{'id': 611}],
937+
'prices': [{'id': 611, 'hourlyRecurringFee': 0.0}],
917938
}]
918939

919940
getItemPricesISCSI = [

tests/CLI/modules/vs_capacity_tests.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,17 @@ def test_create(self):
5555
self.assert_no_fail(result)
5656

5757
def test_create_options(self):
58-
item_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
59-
item_mock.return_value = SoftLayer_Product_Package.getItems_RESERVED_CAPACITY
6058
result = self.run_command(['vs', 'capacity', 'create_options'])
6159
self.assert_no_fail(result)
6260

6361
def test_create_guest_test(self):
64-
result = self.run_command(['vs', 'capacity', 'create_guest', '--capacity-id=3103', '--primary-disk=25',
62+
result = self.run_command(['vs', 'capacity', 'create-guest', '--capacity-id=3103', '--primary-disk=25',
6563
'-H ABCDEFG', '-D test_list.com', '-o UBUNTU_LATEST_64', '-kTest 1', '--test'])
6664
self.assert_no_fail(result)
6765

6866
def test_create_guest(self):
6967
order_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
7068
order_mock.return_value = SoftLayer_Product_Order.rsi_placeOrder
71-
result = self.run_command(['vs', 'capacity', 'create_guest', '--capacity-id=3103', '--primary-disk=25',
69+
result = self.run_command(['vs', 'capacity', 'create-guest', '--capacity-id=3103', '--primary-disk=25',
7270
'-H ABCDEFG', '-D test_list.com', '-o UBUNTU_LATEST_64', '-kTest 1'])
7371
self.assert_no_fail(result)

0 commit comments

Comments
 (0)