88from SoftLayer .CLI import formatting
99from SoftLayer .managers import ordering
1010
11- COLUMNS = ['name' ,
12- 'keyName' ,
13- 'description' , ]
11+ COLUMNS = ['Name' , 'Key Name' , 'Description' ]
1412
1513
1614@click .command (cls = SLCommand )
1715@click .argument ('package_keyname' )
18- @click .option ('--keyword' ,
19- help = "A word (or string) used to filter preset names." )
20- @click .option ('--prices' , '-p' , is_flag = True , help = 'Use --prices to list the server item prices, e.g. --prices' )
16+ @click .option ('--keyword' , help = "A word (or string) used to filter preset names." )
17+ @click .option ('--prices' , '-p' , is_flag = True , help = 'Use --prices to list the server item prices.' )
2118@environment .pass_env
2219def cli (env , package_keyname , keyword , prices ):
2320 """List package presets.
2421
2522 .. Note::
2623 Presets are set CPU / RAM / Disk allotments. You still need to specify required items.
2724 Some packages do not have presets.
25+ Cost includes all items in a preset, and may include optional items.
2826
2927 ::
3028
@@ -34,7 +32,37 @@ def cli(env, package_keyname, keyword, prices):
3432 # List the Bare Metal server presets that include a GPU
3533 slcli order preset-list BARE_METAL_SERVER --keyword gpu
3634
35+ # Get a specific flavor for Virtual Server
36+ slcli order preset-list PUBLIC_CLOUD_SERVER --prices --keyword BL2.56x242x
37+
38+ # All packages with active presets
39+ slcli call-api SoftLayer_Product_Package getAllObjects --mask="mask[id,keyName,activePresetCount]" \
40+ --json-filter='{"activePresets":{"operation":"not null"}}'
41+ ┌───────────────────┬──────┬──────────────────────────────────────────────────────────────────┐
42+ │ activePresetCount │ id │ keyName │
43+ ├───────────────────┼──────┼──────────────────────────────────────────────────────────────────┤
44+ │ 1 │ 144 │ 3U_GPU │
45+ │ 6 │ 200 │ BARE_METAL_SERVER │
46+ │ 1 │ 571 │ NETWORK_VLAN │
47+ │ 100 │ 835 │ PUBLIC_CLOUD_SERVER │
48+ │ 6 │ 865 │ NETWORK_VLAN_FOR_SERVICE │
49+ │ 5 │ 885 │ 8U_BI_S2_H4 │
50+ │ 56 │ 991 │ TRANSIENT_CLOUD_SERVER │
51+ │ 56 │ 1035 │ SUSPEND_CLOUD_SERVER │
52+ │ 9 │ 1045 │ 2U_BI_S3_H2000 │
53+ │ 7 │ 1075 │ 2U_IC4V_FIXED_CONFIGURATIONS │
54+ │ 32 │ 1109 │ BI_S4_H2000 │
55+ │ 8 │ 1117 │ BI_S4_H4000 │
56+ │ 7 │ 1119 │ BI_S4_H8000 │
57+ │ 5 │ 2636 │ 2U_BI_S4_H2000_AEP_ENABLED │
58+ │ 5 │ 2676 │ 4U_BI_S4_H4000_AEP_ENABLED │
59+ │ 5 │ 2700 │ 4U_BI_S4_H8000_AEP_ENABLED │
60+ │ 6 │ 2866 │ ORACLE_APPLICATION_CLUSTER_CASCADE_LAKE_SCALABLE_FAMILY_4_DRIVES │
61+ │ 1 │ 2874 │ ORACLE_APPLICATION_CLUSTER_COFFEE_LAKE_E2174G │
62+ └───────────────────┴──────┴──────────────────────────────────────────────────────────────────┘
63+
3764 """
65+ click .secho ("*NOTICE*: Cost includes all items in a preset, and may include optional items." , fg = "yellow" )
3866 manager = ordering .OrderingManager (env .client )
3967
4068 _filter = {}
@@ -43,19 +71,23 @@ def cli(env, package_keyname, keyword, prices):
4371 presets = manager .list_presets (package_keyname , filter = _filter )
4472
4573 if prices :
46- table = formatting .Table (['keyName' , 'priceId' , 'Hourly' , 'Monthly' , 'Restriction' , 'Location' ])
74+ table = formatting .Table (['Id' , 'Key Name' , 'Hourly' , 'Monthly' , 'Location' ])
75+ table .align = {"Id" : "center" , "Key Name" : "left" , "Hourly" : "right" , "Monthly" : "right" , "Location" : "center" }
4776 for price in presets :
48- locations = []
77+ locations_list = []
4978 if price ['locations' ] != []:
5079 for location in price ['locations' ]:
51- locations .append (location ['name' ])
52- cr_max = get_item_price_data (price ['prices' ][0 ], 'capacityRestrictionMaximum' )
53- cr_min = get_item_price_data (price ['prices' ][0 ], 'capacityRestrictionMinimum' )
54- cr_type = get_item_price_data (price ['prices' ][0 ], 'capacityRestrictionType' )
55- table .add_row ([price ['keyName' ], price ['id' ],
56- get_item_price_data (price ['prices' ][0 ], 'hourlyRecurringFee' ),
57- get_item_price_data (price ['prices' ][0 ], 'recurringFee' ),
58- "%s - %s %s" % (cr_min , cr_max , cr_type ), str (locations )])
80+ locations_list .append (location ['name' ])
81+ locations = ', ' .join (locations_list )
82+ else :
83+ locations = "All"
84+ table .add_row ([
85+ price ['id' ],
86+ price ['keyName' ],
87+ get_item_price_data (price ['prices' ], 'hourlyRecurringFee' ),
88+ get_item_price_data (price ['prices' ], 'recurringFee' ),
89+ locations
90+ ])
5991
6092 else :
6193 table = formatting .Table (COLUMNS )
@@ -69,9 +101,10 @@ def cli(env, package_keyname, keyword, prices):
69101 env .fout (table )
70102
71103
72- def get_item_price_data (price , item_attribute ):
104+ def get_item_price_data (prices , item_attribute ):
73105 """Given an SoftLayer_Product_Item_Price, returns its default price data"""
74- result = '-'
75- if item_attribute in price :
76- result = price [item_attribute ]
77- return result
106+ result = 0.0
107+ for this_price in prices :
108+ if item_attribute in this_price :
109+ result = result + float (this_price [item_attribute ])
110+ return round (result , 3 )
0 commit comments