From 93356bb8d9ed18c1195116fe243364bc75f68b4f Mon Sep 17 00:00:00 2001 From: caberos Date: Tue, 1 Sep 2020 15:58:36 -0400 Subject: [PATCH 1/4] refactor vsi create-option --- SoftLayer/CLI/virt/create_options.py | 275 +++++------------- SoftLayer/fixtures/SoftLayer_Virtual_Guest.py | 109 ++++++- SoftLayer/managers/vs.py | 91 +++++- tests/CLI/modules/vs/vs_tests.py | 14 +- tests/managers/vs/vs_tests.py | 7 +- 5 files changed, 269 insertions(+), 227 deletions(-) diff --git a/SoftLayer/CLI/virt/create_options.py b/SoftLayer/CLI/virt/create_options.py index 693de74a2..64a2c71a3 100644 --- a/SoftLayer/CLI/virt/create_options.py +++ b/SoftLayer/CLI/virt/create_options.py @@ -6,213 +6,92 @@ import SoftLayer from SoftLayer.CLI import environment from SoftLayer.CLI import formatting -from SoftLayer import utils @click.command(short_help="Get options to use for creating virtual servers.") +@click.option('--vsi-type', required=False, type=click.Choice(['TRANSIENT', 'SUSPEND']), + help="Billing rate") @environment.pass_env -def cli(env): +def cli(env, vsi_type): """Virtual server order options.""" + if vsi_type is None: + vsi_type = 'PUBLIC' + vsi_type = vsi_type + '_CLOUD_SERVER' vsi = SoftLayer.VSManager(env.client) - options = vsi.get_create_options() - - tables = [ - _get_datacenter_table(options), - _get_flavors_table(options), - _get_cpu_table(options), - _get_memory_table(options), - _get_os_table(options), - _get_disk_table(options), - _get_network_table(options), - ] - - env.fout(formatting.listing(tables, separator='\n')) + options = vsi.get_create_options(vsi_type) + tables = [] -def _get_datacenter_table(create_options): - datacenters = [dc['template']['datacenter']['name'] - for dc in create_options['datacenters']] + # Datacenters + dc_table = formatting.Table(['datacenter', 'Value'], title="Datacenters") + dc_table.sortby = 'Value' + dc_table.align = 'l' - datacenters = sorted(datacenters) + for location in options['locations']: + dc_table.add_row([location['name'], location['key']]) + tables.append(dc_table) - dc_table = formatting.Table(['datacenter'], title='Datacenters') - dc_table.sortby = 'datacenter' - dc_table.align = 'l' - for datacenter in datacenters: - dc_table.add_row([datacenter]) - return dc_table - - -def _get_flavors_table(create_options): - flavor_table = formatting.Table(['flavor', 'value'], title='Flavors') - flavor_table.sortby = 'flavor' - flavor_table.align = 'l' - grouping = { - 'balanced': {'key_starts_with': 'B1', 'flavors': []}, - 'balanced local - hdd': {'key_starts_with': 'BL1', 'flavors': []}, - 'balanced local - ssd': {'key_starts_with': 'BL2', 'flavors': []}, - 'compute': {'key_starts_with': 'C1', 'flavors': []}, - 'memory': {'key_starts_with': 'M1', 'flavors': []}, - 'GPU': {'key_starts_with': 'AC', 'flavors': []}, - 'transient': {'transient': True, 'flavors': []}, - } - - if create_options.get('flavors', None) is None: - return flavor_table - - for flavor_option in create_options['flavors']: - flavor_key_name = utils.lookup(flavor_option, 'flavor', 'keyName') - - for name, group in grouping.items(): - if utils.lookup(flavor_option, 'template', 'transientGuestFlag') is True: - if utils.lookup(group, 'transient') is True: - group['flavors'].append(flavor_key_name) - break - - elif utils.lookup(group, 'key_starts_with') is not None \ - and flavor_key_name.startswith(group['key_starts_with']): - group['flavors'].append(flavor_key_name) - break - - for name, group in grouping.items(): - if len(group['flavors']) > 0: - flavor_table.add_row(['{}'.format(name), - formatting.listing(group['flavors'], - separator='\n')]) - return flavor_table - - -def _get_cpu_table(create_options): - cpu_table = formatting.Table(['cpu', 'value'], title='CPUs') - cpu_table.sortby = 'cpu' - cpu_table.align = 'l' - standard_cpus = [int(x['template']['startCpus']) for x in create_options['processors'] - if not x['template'].get('dedicatedAccountHostOnlyFlag', - False) - and not x['template'].get('dedicatedHost', None)] - ded_cpus = [int(x['template']['startCpus']) for x in create_options['processors'] - if x['template'].get('dedicatedAccountHostOnlyFlag', False)] - ded_host_cpus = [int(x['template']['startCpus']) for x in create_options['processors'] - if x['template'].get('dedicatedHost', None)] - - standard_cpus = sorted(standard_cpus) - cpu_table.add_row(['standard', formatting.listing(standard_cpus, separator=',')]) - ded_cpus = sorted(ded_cpus) - cpu_table.add_row(['dedicated', formatting.listing(ded_cpus, separator=',')]) - ded_host_cpus = sorted(ded_host_cpus) - cpu_table.add_row(['dedicated host', formatting.listing(ded_host_cpus, separator=',')]) - return cpu_table - - -def _get_memory_table(create_options): - memory_table = formatting.Table(['memory', 'value'], title='Memories') - memory_table.sortby = 'memory' - memory_table.align = 'l' - memory = [int(m['template']['maxMemory']) for m in create_options['memory'] - if not m['itemPrice'].get('dedicatedHostInstanceFlag', False)] - ded_host_memory = [int(m['template']['maxMemory']) for m in create_options['memory'] - if m['itemPrice'].get('dedicatedHostInstanceFlag', False)] - - memory = sorted(memory) - memory_table.add_row(['standard', - formatting.listing(memory, separator=',')]) - - ded_host_memory = sorted(ded_host_memory) - memory_table.add_row(['dedicated host', - formatting.listing(ded_host_memory, separator=',')]) - return memory_table - - -def _get_os_table(create_options): - os_table = formatting.Table(['KeyName', 'Description'], title='Operating Systems') - os_table.sortby = 'KeyName' + # Operation system + os_table = formatting.Table(['OS', 'Key', 'Reference Code'], title="Operating Systems") + os_table.sortby = 'Key' os_table.align = 'l' - op_sys = [] - for operating_system in create_options['operatingSystems']: - os_option = { - 'referenceCode': operating_system['template']['operatingSystemReferenceCode'], - 'description': operating_system['itemPrice']['item']['description'] - } - op_sys.append(os_option) - - for operating_system in op_sys: - os_table.add_row([ - operating_system['referenceCode'], - operating_system['description'] - ]) - return os_table - - -def _get_disk_table(create_options): - disk_table = formatting.Table(['disk', 'value'], title='Disks') - disk_table.sortby = 'disk' - disk_table.align = 'l' - local_disks = [x for x in create_options['blockDevices'] - if x['template'].get('localDiskFlag', False) - and not x['itemPrice'].get('dedicatedHostInstanceFlag', - False)] - - ded_host_local_disks = [x for x in create_options['blockDevices'] - if x['template'].get('localDiskFlag', False) - and x['itemPrice'].get('dedicatedHostInstanceFlag', - False)] - - san_disks = [x for x in create_options['blockDevices'] - if not x['template'].get('localDiskFlag', False)] - - def add_block_rows(disks, name): - """Add block rows to the table.""" - simple = {} - for disk in disks: - block = disk['template']['blockDevices'][0] - bid = block['device'] - - if bid not in simple: - simple[bid] = [] - - simple[bid].append(str(block['diskImage']['capacity'])) - - for label in sorted(simple): - disk_table.add_row(['%s disk(%s)' % (name, label), - formatting.listing(simple[label], - separator=',')]) - - add_block_rows(san_disks, 'san') - add_block_rows(local_disks, 'local') - add_block_rows(ded_host_local_disks, 'local (dedicated host)') - return disk_table - - -def _get_network_table(create_options): - network_table = formatting.Table(['network', 'value'], title='Network') - network_table.sortby = 'network' - network_table.align = 'l' - speeds = [] - ded_host_speeds = [] - for option in create_options['networkComponents']: - template = option.get('template', None) - price = option.get('itemPrice', None) - - if not template or not price \ - or not template.get('networkComponents', None): - continue - - if not template['networkComponents'][0] \ - or not template['networkComponents'][0].get('maxSpeed', None): - continue - - max_speed = str(template['networkComponents'][0]['maxSpeed']) - if price.get('dedicatedHostInstanceFlag', False) \ - and max_speed not in ded_host_speeds: - ded_host_speeds.append(max_speed) - elif max_speed not in speeds: - speeds.append(max_speed) - - speeds = sorted(speeds) - network_table.add_row(['nic', formatting.listing(speeds, separator=',')]) - - ded_host_speeds = sorted(ded_host_speeds) - network_table.add_row(['nic (dedicated host)', - formatting.listing(ded_host_speeds, separator=',')]) - return network_table + + for operating_system in options['operating_systems']: + os_table.add_row([operating_system['name'], operating_system['key'], operating_system['referenceCode']]) + tables.append(os_table) + + flavors_table = formatting.Table(['flavor', 'Name'], title="Flavors") + flavors_table.sortby = 'Name' + flavors_table.align = 'l' + + for flavor in options['flavors']: + flavors_table.add_row([flavor['flavor']['keyName'], flavor['flavor']['name']]) + tables.append(flavors_table) + + # RAM + ram_table = formatting.Table(['memory', 'Value'], title="RAM") + ram_table.sortby = 'Value' + ram_table.align = 'l' + + for ram in options['ram']: + ram_table.add_row([ram['name'], ram['key']]) + tables.append(ram_table) + + # Data base + database_table = formatting.Table(['database', 'Value'], title="Databases") + database_table.sortby = 'Value' + database_table.align = 'l' + + for database in options['database']: + database_table.add_row([database['name'], database['key']]) + tables.append(database_table) + + # Guest_core + guest_core_table = formatting.Table(['cpu', 'Value', 'Capacity'], title="Guest_core") + guest_core_table.sortby = 'Value' + guest_core_table.align = 'l' + + for guest_core in options['guest_core']: + guest_core_table.add_row([guest_core['name'], guest_core['key'], guest_core['capacity']]) + tables.append(guest_core_table) + + # Guest_core + guest_disk_table = formatting.Table(['guest_disk', 'Value', 'Capacity', 'Disk'], title="Guest_disks") + guest_disk_table.sortby = 'Value' + guest_disk_table.align = 'l' + + for guest_disk in options['guest_disk']: + guest_disk_table.add_row([guest_disk['name'], guest_disk['key'], guest_disk['capacity'], guest_disk['disk']]) + tables.append(guest_disk_table) + + # Port speed + port_speed_table = formatting.Table(['network', 'Key'], title="Network Options") + port_speed_table.sortby = 'Key' + port_speed_table.align = 'l' + + for speed in options['port_speed']: + port_speed_table.add_row([speed['name'], speed['key']]) + tables.append(port_speed_table) + + env.fout(formatting.listing(tables, separator='\n')) diff --git a/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py b/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py index 3b9a24302..987fd12d7 100644 --- a/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py +++ b/SoftLayer/fixtures/SoftLayer_Virtual_Guest.py @@ -68,12 +68,12 @@ }], 'tagReferences': [{'tag': {'name': 'production'}}], } - getCreateObjectOptions = { 'flavors': [ { 'flavor': { - 'keyName': 'B1_1X2X25' + 'keyName': 'B1_1X2X25', + 'name': 'B1-1X2X25' }, 'template': { 'supplementalCreateObjectOptions': { @@ -83,7 +83,8 @@ }, { 'flavor': { - 'keyName': 'B1_1X2X25_TRANSIENT' + 'keyName': 'B1_1X2X25_TRANSIENT', + 'name': 'B1-1X2X25_TRANSIENT' }, 'template': { 'supplementalCreateObjectOptions': { @@ -94,7 +95,8 @@ }, { 'flavor': { - 'keyName': 'B1_1X2X100' + 'keyName': 'B1_1X2X100', + 'name': 'B1-1X2X100' }, 'template': { 'supplementalCreateObjectOptions': { @@ -104,7 +106,8 @@ }, { 'flavor': { - 'keyName': 'BL1_1X2X100' + 'keyName': 'BL1_1X2X100', + 'name': 'BL1_1X2X100' }, 'template': { 'supplementalCreateObjectOptions': { @@ -114,7 +117,8 @@ }, { 'flavor': { - 'keyName': 'BL2_1X2X100' + 'keyName': 'BL2_1X2X100', + 'name': 'BL2-1X2X100' }, 'template': { 'supplementalCreateObjectOptions': { @@ -124,7 +128,8 @@ }, { 'flavor': { - 'keyName': 'C1_1X2X25' + 'keyName': 'C1_1X2X25', + 'name': 'C1-1X2X25' }, 'template': { 'supplementalCreateObjectOptions': { @@ -134,7 +139,8 @@ }, { 'flavor': { - 'keyName': 'M1_1X2X100' + 'keyName': 'M1_1X2X100', + 'name': 'M1_1X2X100' }, 'template': { 'supplementalCreateObjectOptions': { @@ -144,7 +150,8 @@ }, { 'flavor': { - 'keyName': 'AC1_1X2X100' + 'keyName': 'AC1_1X2X100', + 'name': 'AC1_1X2X100' }, 'template': { 'supplementalCreateObjectOptions': { @@ -154,7 +161,8 @@ }, { 'flavor': { - 'keyName': 'ACL1_1X2X100' + 'keyName': 'ACL1_1X2X100', + 'name': 'ACL1_1X2X100' }, 'template': { 'supplementalCreateObjectOptions': { @@ -245,6 +253,12 @@ ], 'memory': [ { + "description": "1 GB ", + "attributes": [], + "itemCategory": { + "categoryCode": "ram", + "id": 4 + }, 'itemPrice': { 'item': {'description': '1 GB'}, 'hourlyRecurringFee': '.03', @@ -253,14 +267,27 @@ 'template': {'maxMemory': 1024} }, { - 'itemPrice': { - 'item': {'description': '2 GB'}, - 'hourlyRecurringFee': '.06', - 'recurringFee': '42' + "description": "2 GB ", + "attributes": [], + "itemCategory": { + "categoryCode": "ram", + "id": 5 }, + 'itemPrice': + { + 'item': {'description': '2 GB'}, + 'hourlyRecurringFee': '.06', + 'recurringFee': '42' + }, 'template': {'maxMemory': 2048} }, { + "description": "3 GB", + "attributes": [], + "itemCategory": { + "categoryCode": "ram", + "id": 65 + }, 'itemPrice': { 'item': {'description': '3 GB'}, 'hourlyRecurringFee': '.085', @@ -268,6 +295,12 @@ 'template': {'maxMemory': 3072} }, { + "description": "4 GB", + "attributes": [], + "itemCategory": { + "categoryCode": "ram", + "id": 35 + }, 'itemPrice': { 'item': {'description': '4 GB'}, 'hourlyRecurringFee': '.11', @@ -276,6 +309,12 @@ 'template': {'maxMemory': 4096} }, { + "description": "64 GB (Dedicated Host)", + "attributes": [], + "itemCategory": { + "categoryCode": "ram", + "id": 3 + }, 'itemPrice': { 'hourlyRecurringFee': '0', 'recurringFee': '0', @@ -289,6 +328,12 @@ } }, { + "description": "8 GB (Dedicated Host)", + "attributes": [], + "itemCategory": { + "categoryCode": "ram", + "id": 36 + }, 'itemPrice': { 'hourlyRecurringFee': '0', 'recurringFee': '0', @@ -423,6 +468,42 @@ {'template': {'datacenter': {'name': 'ams01'}}}, {'template': {'datacenter': {'name': 'dal05'}}}, ], + 'guest_disk': [{ + "description": "25 GB (SAN)", + "attributes": [ + { + "id": 197, + "attributeTypeKeyName": "SAN_DISK" + } + ], + "itemCategory": { + "categoryCode": "guest_disk0", + "id": 81 + }}, { + "description": "250 GB (SAN)", + "attributes": [ + { + "id": 198, + "attributeTypeKeyName": "SAN_DISK" + }], + "itemCategory": { + "categoryCode": "guest_disk0", + "id": 89 + }}], + 'guest_core': [{ + "description": "4 x 2.0 GHz or higher Cores (Dedicated)", + "attributes": [], + "itemCategory": { + "categoryCode": "guest_core", + "id": 80 + }}, + { + "description": "8 x 2.0 GHz or higher Cores", + "attributes": [], + "itemCategory": { + "categoryCode": "guest_core", + "id": 90 + }}] } getReverseDomainRecords = [{ diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py index 2a58d9b62..6c6fec747 100644 --- a/SoftLayer/managers/vs.py +++ b/SoftLayer/managers/vs.py @@ -249,7 +249,7 @@ def get_instance(self, instance_id, **kwargs): return self.guest.getObject(id=instance_id, **kwargs) @retry(logger=LOGGER) - def get_create_options(self): + def get_create_options(self, vsi_type): """Retrieves the available options for creating a VS. :returns: A dictionary of creation options. @@ -260,7 +260,94 @@ def get_create_options(self): options = mgr.get_create_options() print(options) """ - return self.guest.getCreateObjectOptions() + + # TRANSIENT_CLOUD_SERVER + # SUSPEND_CLOUD_SERVER + package = self._get_package(vsi_type) + + # Locations + locations = [] + for region in package['regions']: + locations.append({ + 'name': region['location']['location']['longName'], + 'key': region['location']['location']['name'], + }) + + operating_systems = [] + database = [] + port_speeds = [] + guest_core = [] + local_disk = [] + ram = [] + for item in package['items']: + category = item['itemCategory']['categoryCode'] + # Operating systems + if category == 'os': + operating_systems.append({ + 'name': item['softwareDescription']['longDescription'], + 'key': item['keyName'], + 'referenceCode': item['softwareDescription']['referenceCode'] + }) + # database + elif category == 'database': + database.append({ + 'name': item['description'], + 'key': item['keyName'] + }) + + elif category == 'port_speed': + port_speeds.append({ + 'name': item['description'], + 'key': item['keyName'] + }) + + elif category == 'guest_core': + guest_core.append({ + 'name': item['description'], + 'capacity': item['capacity'], + 'key': item['keyName'] + }) + + elif category == 'ram': + ram.append({ + 'name': item['description'], + 'capacity': item['capacity'], + 'key': item['keyName'] + }) + + elif category.__contains__('guest_disk'): + local_disk.append({ + 'name': item['description'], + 'capacity': item['capacity'], + 'key': item['keyName'], + 'disk': category + }) + # Extras + + return { + 'locations': locations, + 'ram': ram, + 'database': database, + 'operating_systems': operating_systems, + 'guest_core': guest_core, + 'port_speed': port_speeds, + 'guest_disk': local_disk, + 'flavors': self.guest.getCreateObjectOptions()['flavors'] + } + + @retry(logger=LOGGER) + def _get_package(self, package_keyname): + """Get the package related to simple hardware ordering.""" + mask = ''' + items[ + description, keyName, capacity, + attributes[id,attributeTypeKeyName], + itemCategory[ id, categoryCode], + softwareDescription[id,referenceCode,longDescription],prices], + regions[location[location[priceGroups]]] + ''' + package = self.ordering_manager.get_package_by_key(package_keyname, mask=mask) + return package def cancel_instance(self, instance_id): """Cancel an instance immediately, deleting all its data. diff --git a/tests/CLI/modules/vs/vs_tests.py b/tests/CLI/modules/vs/vs_tests.py index c9b6c9c0b..fd562f69d 100644 --- a/tests/CLI/modules/vs/vs_tests.py +++ b/tests/CLI/modules/vs/vs_tests.py @@ -314,14 +314,10 @@ def test_detail_vs_ptr_error(self): self.assertEqual(output.get('ptr', None), None) def test_create_options(self): - result = self.run_command(['vs', 'create-options']) + result = self.run_command(['vs', 'create-options', '--vsi-type', 'TRANSIENT']) self.assert_no_fail(result) - self.assertIn('datacenter', result.output) - self.assertIn('flavor', result.output) - self.assertIn('memory', result.output) - self.assertIn('cpu', result.output) - self.assertIn('OS', result.output) - self.assertIn('network', result.output) + self.assert_called_with('SoftLayer_Product_Package', 'getAllObjects') + self.assert_called_with('SoftLayer_Virtual_Guest', 'getCreateObjectOptions') @mock.patch('SoftLayer.CLI.formatting.confirm') def test_dns_sync_both(self, confirm_mock): @@ -887,6 +883,6 @@ def test_credentail(self): result = self.run_command(['vs', 'credentials', '100']) self.assert_no_fail(result) self.assertEqual(json.loads(result.output), [{ - "username": "user", - "password": "pass" + "username": "user", + "password": "pass" }]) diff --git a/tests/managers/vs/vs_tests.py b/tests/managers/vs/vs_tests.py index a9f256c80..c00941433 100644 --- a/tests/managers/vs/vs_tests.py +++ b/tests/managers/vs/vs_tests.py @@ -116,10 +116,9 @@ def test_get_instance(self): identifier=100) def test_get_create_options(self): - results = self.vs.get_create_options() - - self.assertEqual( - fixtures.SoftLayer_Virtual_Guest.getCreateObjectOptions, results) + self.vs.get_create_options('PUBLIC_CLOUD_SERVER') + self.assert_called_with('SoftLayer_Product_Package', 'getAllObjects') + self.assert_called_with('SoftLayer_Virtual_Guest', 'getCreateObjectOptions') def test_cancel_instance(self): result = self.vs.cancel_instance(1) From 7669134285cee0c55cb3809cd8bb3f2e6f1aaea5 Mon Sep 17 00:00:00 2001 From: caberos Date: Thu, 10 Sep 2020 19:16:32 -0400 Subject: [PATCH 2/4] fix the Christopher code review --- SoftLayer/CLI/virt/create_options.py | 22 ++++++++++----------- SoftLayer/managers/vs.py | 29 ++++++++++++++++++---------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/SoftLayer/CLI/virt/create_options.py b/SoftLayer/CLI/virt/create_options.py index 64a2c71a3..4e73d55be 100644 --- a/SoftLayer/CLI/virt/create_options.py +++ b/SoftLayer/CLI/virt/create_options.py @@ -9,15 +9,14 @@ @click.command(short_help="Get options to use for creating virtual servers.") -@click.option('--vsi-type', required=False, type=click.Choice(['TRANSIENT', 'SUSPEND']), - help="Billing rate") +@click.option('--vsi-type', required=False, show_default=True, default='PUBLIC_CLOUD_SERVER', + type=click.Choice(['TRANSIENT_CLOUD_SERVER', 'SUSPEND_CLOUD_SERVER', 'PUBLIC_CLOUD_SERVER']), + help="Display options for a specific virtual server packages, for default is PUBLIC_CLOUD_SERVER, " + "choose between TRANSIENT_CLOUD_SERVER, SUSPEND_CLOUD_SERVER, PUBLIC_CLOUD_SERVER") @environment.pass_env def cli(env, vsi_type): """Virtual server order options.""" - if vsi_type is None: - vsi_type = 'PUBLIC' - vsi_type = vsi_type + '_CLOUD_SERVER' vsi = SoftLayer.VSManager(env.client) options = vsi.get_create_options(vsi_type) @@ -41,13 +40,14 @@ def cli(env, vsi_type): os_table.add_row([operating_system['name'], operating_system['key'], operating_system['referenceCode']]) tables.append(os_table) - flavors_table = formatting.Table(['flavor', 'Name'], title="Flavors") - flavors_table.sortby = 'Name' - flavors_table.align = 'l' + # Sizes + preset_table = formatting.Table(['Size', 'Value'], title="Sizes") + preset_table.sortby = 'Value' + preset_table.align = 'l' - for flavor in options['flavors']: - flavors_table.add_row([flavor['flavor']['keyName'], flavor['flavor']['name']]) - tables.append(flavors_table) + for size in options['sizes']: + preset_table.add_row([size['name'], size['key']]) + tables.append(preset_table) # RAM ram_table = formatting.Table(['memory', 'Value'], title="RAM") diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py index 6c6fec747..1ddbdc3e1 100644 --- a/SoftLayer/managers/vs.py +++ b/SoftLayer/managers/vs.py @@ -249,7 +249,7 @@ def get_instance(self, instance_id, **kwargs): return self.guest.getObject(id=instance_id, **kwargs) @retry(logger=LOGGER) - def get_create_options(self, vsi_type): + def get_create_options(self, vsi_type="PUBLIC_CLOUD_SERVER"): """Retrieves the available options for creating a VS. :returns: A dictionary of creation options. @@ -279,6 +279,14 @@ def get_create_options(self, vsi_type): guest_core = [] local_disk = [] ram = [] + + sizes = [] + for preset in package['activePresets'] + package['accountRestrictedActivePresets']: + sizes.append({ + 'name': preset['description'], + 'key': preset['keyName'] + }) + for item in package['items']: category = item['itemCategory']['categoryCode'] # Operating systems @@ -332,21 +340,22 @@ def get_create_options(self, vsi_type): 'guest_core': guest_core, 'port_speed': port_speeds, 'guest_disk': local_disk, - 'flavors': self.guest.getCreateObjectOptions()['flavors'] + 'sizes': sizes } @retry(logger=LOGGER) def _get_package(self, package_keyname): """Get the package related to simple hardware ordering.""" mask = ''' - items[ - description, keyName, capacity, - attributes[id,attributeTypeKeyName], - itemCategory[ id, categoryCode], - softwareDescription[id,referenceCode,longDescription],prices], - regions[location[location[priceGroups]]] - ''' - package = self.ordering_manager.get_package_by_key(package_keyname, mask=mask) + activePresets, accountRestrictedActivePresets, + items[description, keyName, capacity, + attributes[id, attributeTypeKeyName], + itemCategory[id, categoryCode], + softwareDescription[id, referenceCode, longDescription], prices], + regions[location[location[priceGroups]]]''' + + package_id = self.ordering_manager.get_package_by_key(package_keyname, mask="mask[id]")['id'] + package = self.client.call('Product_Package', 'getObject', id=package_id, mask=mask) return package def cancel_instance(self, instance_id): From f4af694d7a784e68e6bdd0acc6654d77202f4c8b Mon Sep 17 00:00:00 2001 From: caberos Date: Tue, 15 Sep 2020 15:11:07 -0400 Subject: [PATCH 3/4] fix tox tool and fix unit test --- .../fixtures/SoftLayer_Product_Package.py | 105 ++++++++++++++++++ techbabble.xyz.crt | 2 + techbabble.xyz.csr | 3 + techbabble.xyz.icc | 0 techbabble.xyz.key | 3 + tests/CLI/modules/vs/vs_tests.py | 4 +- tests/managers/vs/vs_tests.py | 6 +- 7 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 techbabble.xyz.crt create mode 100644 techbabble.xyz.csr create mode 100644 techbabble.xyz.icc create mode 100644 techbabble.xyz.key diff --git a/SoftLayer/fixtures/SoftLayer_Product_Package.py b/SoftLayer/fixtures/SoftLayer_Product_Package.py index 07aefab69..2549847d4 100644 --- a/SoftLayer/fixtures/SoftLayer_Product_Package.py +++ b/SoftLayer/fixtures/SoftLayer_Product_Package.py @@ -1779,3 +1779,108 @@ ] } ] + +getObject = { + 'id': 200, + 'regions': [{'description': 'WDC01 - Washington, DC - East Coast U.S.', + 'keyname': 'WASHINGTON_DC', + 'location': {'location': {'id': 37473, + 'longName': 'Washington 1', + 'name': 'wdc01'}}, + 'sortOrder': 10}], + 'accountRestrictedActivePresets': [], + 'activePresets': [ + { + 'description': 'AC2.8x60x25', + 'id': 861, + 'isActive': '1', + 'keyName': 'AC2_8X60X25', + 'name': 'AC2.8x60x25', + 'packageId': 835 + }, + { + 'description': 'AC2.8x60x100', + 'id': 863, + 'isActive': '1', + 'keyName': 'AC2_8X60X100', + 'name': 'AC2.8x60x100', + 'packageId': 835 + }], + "items": [{ + "capacity": "56", + "description": "56 Cores x 360 RAM x 1.2 TB x 2 GPU P100 [encryption enabled]", + "bundleItems": [ + { + "capacity": "1200", + "keyName": "1.2 TB Local Storage (Dedicated Host Capacity)", + "categories": [{ + "categoryCode": "dedicated_host_disk" + }] + }, + { + "capacity": "242", + "keyName": "2_GPU_P100_DEDICATED", + "hardwareGenericComponentModel": { + "capacity": "16", + "id": 849, + "hardwareComponentType": { + "id": 20, + "keyName": "GPU" + } + }, + "categories": [{ + "categoryCode": "dedicated_host_ram" + }, { + "capacity": "2", + "description": "2 x 2.0 GHz or higher Cores", + "keyName": "GUEST_CORES_2", + "attributes": [ + { + "id": 8261, + "attributeTypeKeyName": "ORDER_SAVES_USAGE_FEES" + } + ], + "itemCategory": { + "categoryCode": "guest_core", + "id": 80 + }}] + } + ], + "prices": [ + { + "itemId": 10195, + "setupFee": "0", + "recurringFee": "2099", + "tierMinimumThreshold": "", + "hourlyRecurringFee": "3.164", + "oneTimeFee": "0", + "currentPriceFlag": "", + "id": 200269, + "sort": 0, + "onSaleFlag": "", + "laborFee": "0", + "locationGroupId": "", + "quantity": "" + }, + { + "itemId": 10195, + "setupFee": "0", + "recurringFee": "2161.97", + "tierMinimumThreshold": "", + "hourlyRecurringFee": "3.258", + "oneTimeFee": "0", + "currentPriceFlag": "", + "id": 200271, + "sort": 0, + "onSaleFlag": "", + "laborFee": "0", + "locationGroupId": 503, + "quantity": "" + } + ], + "keyName": "56_CORES_X_484_RAM_X_1_5_TB_X_2_GPU_P100", + "id": 10195, + "itemCategory": { + "categoryCode": "dedicated_virtual_hosts" + } + }]} diff --git a/techbabble.xyz.crt b/techbabble.xyz.crt new file mode 100644 index 000000000..01d72d87f --- /dev/null +++ b/techbabble.xyz.crt @@ -0,0 +1,2 @@ +-----BEGIN CERTIFICATE----- +MIIEJTCCAw2gAwIBAgIDCbQ0MA0GCSqGSIb3DQEBCwUAMEcxCzAJBgNVBAYTAlVT -----END CERTIFICATE----- \ No newline at end of file diff --git a/techbabble.xyz.csr b/techbabble.xyz.csr new file mode 100644 index 000000000..78d978dca --- /dev/null +++ b/techbabble.xyz.csr @@ -0,0 +1,3 @@ +-----BEGIN CERTIFICATE REQUEST----- +MIIC1jCCAb4CAQAwgZAxCzAJBgNVBAYTAlVTMQ4wDAYDVQQIDAVUZXhh123456QMA4G +-----END CERTIFICATE REQUEST----- \ No newline at end of file diff --git a/techbabble.xyz.icc b/techbabble.xyz.icc new file mode 100644 index 000000000..e69de29bb diff --git a/techbabble.xyz.key b/techbabble.xyz.key new file mode 100644 index 000000000..1d906abc7 --- /dev/null +++ b/techbabble.xyz.key @@ -0,0 +1,3 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEA3SwTZ7sh7we5zIbmtSbxGJxff07eutrK12345678WXtwQSdE +-----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/tests/CLI/modules/vs/vs_tests.py b/tests/CLI/modules/vs/vs_tests.py index fd562f69d..a680e3c72 100644 --- a/tests/CLI/modules/vs/vs_tests.py +++ b/tests/CLI/modules/vs/vs_tests.py @@ -314,10 +314,8 @@ def test_detail_vs_ptr_error(self): self.assertEqual(output.get('ptr', None), None) def test_create_options(self): - result = self.run_command(['vs', 'create-options', '--vsi-type', 'TRANSIENT']) + result = self.run_command(['vs', 'create-options', '--vsi-type', 'TRANSIENT_CLOUD_SERVER']) self.assert_no_fail(result) - self.assert_called_with('SoftLayer_Product_Package', 'getAllObjects') - self.assert_called_with('SoftLayer_Virtual_Guest', 'getCreateObjectOptions') @mock.patch('SoftLayer.CLI.formatting.confirm') def test_dns_sync_both(self, confirm_mock): diff --git a/tests/managers/vs/vs_tests.py b/tests/managers/vs/vs_tests.py index c00941433..cf701d21f 100644 --- a/tests/managers/vs/vs_tests.py +++ b/tests/managers/vs/vs_tests.py @@ -116,9 +116,9 @@ def test_get_instance(self): identifier=100) def test_get_create_options(self): - self.vs.get_create_options('PUBLIC_CLOUD_SERVER') - self.assert_called_with('SoftLayer_Product_Package', 'getAllObjects') - self.assert_called_with('SoftLayer_Virtual_Guest', 'getCreateObjectOptions') + self.vs.get_create_options() + self.assert_called_with('SoftLayer_Product_Package', 'getObject', + identifier=200) def test_cancel_instance(self): result = self.vs.cancel_instance(1) From 9599d22bbd8041f3004cc9b0a1625b715efb5742 Mon Sep 17 00:00:00 2001 From: caberos Date: Tue, 15 Sep 2020 15:12:08 -0400 Subject: [PATCH 4/4] fix tox tool and fix unit test --- techbabble.xyz.crt | 2 -- techbabble.xyz.csr | 3 --- techbabble.xyz.icc | 0 techbabble.xyz.key | 3 --- 4 files changed, 8 deletions(-) delete mode 100644 techbabble.xyz.crt delete mode 100644 techbabble.xyz.csr delete mode 100644 techbabble.xyz.icc delete mode 100644 techbabble.xyz.key diff --git a/techbabble.xyz.crt b/techbabble.xyz.crt deleted file mode 100644 index 01d72d87f..000000000 --- a/techbabble.xyz.crt +++ /dev/null @@ -1,2 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIEJTCCAw2gAwIBAgIDCbQ0MA0GCSqGSIb3DQEBCwUAMEcxCzAJBgNVBAYTAlVT -----END CERTIFICATE----- \ No newline at end of file diff --git a/techbabble.xyz.csr b/techbabble.xyz.csr deleted file mode 100644 index 78d978dca..000000000 --- a/techbabble.xyz.csr +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN CERTIFICATE REQUEST----- -MIIC1jCCAb4CAQAwgZAxCzAJBgNVBAYTAlVTMQ4wDAYDVQQIDAVUZXhh123456QMA4G ------END CERTIFICATE REQUEST----- \ No newline at end of file diff --git a/techbabble.xyz.icc b/techbabble.xyz.icc deleted file mode 100644 index e69de29bb..000000000 diff --git a/techbabble.xyz.key b/techbabble.xyz.key deleted file mode 100644 index 1d906abc7..000000000 --- a/techbabble.xyz.key +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEA3SwTZ7sh7we5zIbmtSbxGJxff07eutrK12345678WXtwQSdE ------END RSA PRIVATE KEY----- \ No newline at end of file