|
9 | 9 |
|
10 | 10 |
|
11 | 11 | @click.command(short_help="Get options to use for creating virtual servers.") |
| 12 | +@click.argument('location', required=False) |
12 | 13 | @click.option('--vsi-type', required=False, show_default=True, default='PUBLIC_CLOUD_SERVER', |
13 | | - type=click.Choice(['TRANSIENT_CLOUD_SERVER', 'SUSPEND_CLOUD_SERVER', 'PUBLIC_CLOUD_SERVER']), |
| 14 | + type=click.Choice(['PUBLIC_CLOUD_SERVER', 'TRANSIENT_CLOUD_SERVER', 'SUSPEND_CLOUD_SERVER', |
| 15 | + 'CLOUD_SERVER']), |
14 | 16 | help="Display options for a specific virtual server packages, for default is PUBLIC_CLOUD_SERVER, " |
15 | | - "choose between TRANSIENT_CLOUD_SERVER, SUSPEND_CLOUD_SERVER, PUBLIC_CLOUD_SERVER") |
| 17 | + "choose between TRANSIENT_CLOUD_SERVER, SUSPEND_CLOUD_SERVER, CLOUD_SERVER") |
| 18 | +@click.option('--prices', '-p', is_flag=True, |
| 19 | + help='Use --prices to list the server item prices, and to list the Item Prices by location,' |
| 20 | + 'add it to the --prices option using location short name, e.g. --prices dal13') |
16 | 21 | @environment.pass_env |
17 | | -def cli(env, vsi_type): |
| 22 | +def cli(env, vsi_type, prices, location=None): |
18 | 23 | """Virtual server order options.""" |
19 | 24 |
|
20 | 25 | vsi = SoftLayer.VSManager(env.client) |
21 | | - options = vsi.get_create_options(vsi_type) |
| 26 | + options = vsi.get_create_options(vsi_type, location) |
22 | 27 |
|
23 | 28 | tables = [] |
24 | 29 |
|
25 | 30 | # Datacenters |
26 | 31 | dc_table = formatting.Table(['datacenter', 'Value'], title="Datacenters") |
27 | 32 | dc_table.sortby = 'Value' |
28 | 33 | dc_table.align = 'l' |
29 | | - |
30 | | - for location in options['locations']: |
31 | | - dc_table.add_row([location['name'], location['key']]) |
| 34 | + for location_info in options['locations']: |
| 35 | + dc_table.add_row([location_info['name'], location_info['key']]) |
32 | 36 | tables.append(dc_table) |
33 | 37 |
|
34 | | - # Operation system |
35 | | - os_table = formatting.Table(['OS', 'Key', 'Reference Code'], title="Operating Systems") |
36 | | - os_table.sortby = 'Key' |
37 | | - os_table.align = 'l' |
| 38 | + if prices: |
| 39 | + preset_prices_table(options['sizes'], tables) |
| 40 | + os_prices_table(options['operating_systems'], tables) |
| 41 | + port_speed_prices_table(options['port_speed'], tables) |
| 42 | + ram_prices_table(options['ram'], tables) |
| 43 | + database_prices_table(options['database'], tables) |
| 44 | + guest_core_prices_table(options['guest_core'], tables) |
| 45 | + guest_disk_prices_table(options['guest_disk'], tables) |
| 46 | + extras_prices_table(options['extras'], tables) |
| 47 | + else: |
| 48 | + # Operation system |
| 49 | + os_table = formatting.Table(['OS', 'Key', 'Reference Code'], title="Operating Systems") |
| 50 | + os_table.sortby = 'Key' |
| 51 | + os_table.align = 'l' |
38 | 52 |
|
39 | | - for operating_system in options['operating_systems']: |
40 | | - os_table.add_row([operating_system['name'], operating_system['key'], operating_system['referenceCode']]) |
41 | | - tables.append(os_table) |
| 53 | + for operating_system in options['operating_systems']: |
| 54 | + os_table.add_row([operating_system['name'], operating_system['key'], operating_system['referenceCode']]) |
| 55 | + tables.append(os_table) |
| 56 | + |
| 57 | + # Sizes |
| 58 | + preset_table = formatting.Table(['Size', 'Value'], title="Sizes") |
| 59 | + preset_table.sortby = 'Value' |
| 60 | + preset_table.align = 'l' |
| 61 | + |
| 62 | + for size in options['sizes']: |
| 63 | + preset_table.add_row([size['name'], size['key']]) |
| 64 | + tables.append(preset_table) |
| 65 | + |
| 66 | + # RAM |
| 67 | + ram_table = formatting.Table(['memory', 'Value'], title="RAM") |
| 68 | + ram_table.sortby = 'Value' |
| 69 | + ram_table.align = 'l' |
| 70 | + |
| 71 | + for ram in options['ram']: |
| 72 | + ram_table.add_row([ram['name'], ram['key']]) |
| 73 | + tables.append(ram_table) |
| 74 | + |
| 75 | + # Data base |
| 76 | + database_table = formatting.Table(['database', 'Value'], title="Databases") |
| 77 | + database_table.sortby = 'Value' |
| 78 | + database_table.align = 'l' |
| 79 | + |
| 80 | + for database in options['database']: |
| 81 | + database_table.add_row([database['name'], database['key']]) |
| 82 | + tables.append(database_table) |
| 83 | + |
| 84 | + # Guest_core |
| 85 | + guest_core_table = formatting.Table(['cpu', 'Value', 'Capacity'], title="Guest_core") |
| 86 | + guest_core_table.sortby = 'Value' |
| 87 | + guest_core_table.align = 'l' |
| 88 | + |
| 89 | + for guest_core in options['guest_core']: |
| 90 | + guest_core_table.add_row([guest_core['name'], guest_core['key'], guest_core['capacity']]) |
| 91 | + tables.append(guest_core_table) |
| 92 | + |
| 93 | + # Guest_core |
| 94 | + guest_disk_table = formatting.Table(['guest_disk', 'Value', 'Capacity', 'Disk'], title="Guest_disks") |
| 95 | + guest_disk_table.sortby = 'Value' |
| 96 | + guest_disk_table.align = 'l' |
| 97 | + |
| 98 | + for guest_disk in options['guest_disk']: |
| 99 | + guest_disk_table.add_row( |
| 100 | + [guest_disk['name'], guest_disk['key'], guest_disk['capacity'], guest_disk['disk']]) |
| 101 | + tables.append(guest_disk_table) |
42 | 102 |
|
43 | | - # Sizes |
44 | | - preset_table = formatting.Table(['Size', 'Value'], title="Sizes") |
| 103 | + # Port speed |
| 104 | + port_speed_table = formatting.Table(['network', 'Key'], title="Network Options") |
| 105 | + port_speed_table.sortby = 'Key' |
| 106 | + port_speed_table.align = 'l' |
| 107 | + |
| 108 | + for speed in options['port_speed']: |
| 109 | + port_speed_table.add_row([speed['name'], speed['key']]) |
| 110 | + tables.append(port_speed_table) |
| 111 | + |
| 112 | + env.fout(formatting.listing(tables, separator='\n')) |
| 113 | + |
| 114 | + |
| 115 | +def preset_prices_table(sizes, tables): |
| 116 | + """Shows Server Preset options prices. |
| 117 | +
|
| 118 | + :param [] sizes: List of Hardware Server sizes. |
| 119 | + :param tables: Table formatting. |
| 120 | + """ |
| 121 | + preset_table = formatting.Table(['Size', 'Value', 'Hourly', 'Monthly'], title="Sizes Prices") |
45 | 122 | preset_table.sortby = 'Value' |
46 | 123 | preset_table.align = 'l' |
47 | | - |
48 | | - for size in options['sizes']: |
49 | | - preset_table.add_row([size['name'], size['key']]) |
| 124 | + for size in sizes: |
| 125 | + preset_table.add_row([size['name'], size['key'], "%.4f" % size['hourlyRecurringFee'], |
| 126 | + "%.4f" % size['recurringFee']]) |
50 | 127 | tables.append(preset_table) |
51 | 128 |
|
52 | | - # RAM |
53 | | - ram_table = formatting.Table(['memory', 'Value'], title="RAM") |
54 | | - ram_table.sortby = 'Value' |
55 | | - ram_table.align = 'l' |
56 | 129 |
|
57 | | - for ram in options['ram']: |
58 | | - ram_table.add_row([ram['name'], ram['key']]) |
| 130 | +def os_prices_table(operating_systems, tables): |
| 131 | + """Shows Server Operating Systems prices cost and capacity restriction. |
| 132 | +
|
| 133 | + :param [] operating_systems: List of Hardware Server operating systems. |
| 134 | + :param tables: Table formatting. |
| 135 | + """ |
| 136 | + os_table = formatting.Table(['OS Key', 'Hourly', 'Monthly', 'Restriction'], |
| 137 | + title="Operating Systems Prices") |
| 138 | + os_table.sortby = 'OS Key' |
| 139 | + os_table.align = 'l' |
| 140 | + for operating_system in operating_systems: |
| 141 | + for price in operating_system['prices']: |
| 142 | + cr_max = _get_price_data(price, 'capacityRestrictionMaximum') |
| 143 | + cr_min = _get_price_data(price, 'capacityRestrictionMinimum') |
| 144 | + cr_type = _get_price_data(price, 'capacityRestrictionType') |
| 145 | + os_table.add_row( |
| 146 | + [operating_system['key'], |
| 147 | + _get_price_data(price, 'hourlyRecurringFee'), |
| 148 | + _get_price_data(price, 'recurringFee'), |
| 149 | + "%s - %s %s" % (cr_min, cr_max, cr_type)]) |
| 150 | + tables.append(os_table) |
| 151 | + |
| 152 | + |
| 153 | +def port_speed_prices_table(port_speeds, tables): |
| 154 | + """Shows Server Port Speeds prices cost and capacity restriction. |
| 155 | +
|
| 156 | + :param [] port_speeds: List of Hardware Server Port Speeds. |
| 157 | + :param tables: Table formatting. |
| 158 | + """ |
| 159 | + port_speed_table = formatting.Table(['Key', 'Speed', 'Hourly', 'Monthly', 'Restriction'], |
| 160 | + title="Network Options Prices") |
| 161 | + port_speed_table.sortby = 'Speed' |
| 162 | + port_speed_table.align = 'l' |
| 163 | + for speed in port_speeds: |
| 164 | + for price in speed['prices']: |
| 165 | + cr_max = _get_price_data(price, 'capacityRestrictionMaximum') |
| 166 | + cr_min = _get_price_data(price, 'capacityRestrictionMinimum') |
| 167 | + cr_type = _get_price_data(price, 'capacityRestrictionType') |
| 168 | + port_speed_table.add_row( |
| 169 | + [speed['key'], speed['speed'], |
| 170 | + _get_price_data(price, 'hourlyRecurringFee'), |
| 171 | + _get_price_data(price, 'recurringFee'), |
| 172 | + "%s - %s %s" % (cr_min, cr_max, cr_type)]) |
| 173 | + tables.append(port_speed_table) |
| 174 | + |
| 175 | + |
| 176 | +def extras_prices_table(extras, tables): |
| 177 | + """Shows Server extras prices cost and capacity restriction. |
| 178 | +
|
| 179 | + :param [] extras: List of Hardware Server Extras. |
| 180 | + :param tables: Table formatting. |
| 181 | + """ |
| 182 | + extras_table = formatting.Table(['Extra Option Key', 'Hourly', 'Monthly', 'Restriction'], |
| 183 | + title="Extras Prices") |
| 184 | + extras_table.align = 'l' |
| 185 | + for extra in extras: |
| 186 | + for price in extra['prices']: |
| 187 | + cr_max = _get_price_data(price, 'capacityRestrictionMaximum') |
| 188 | + cr_min = _get_price_data(price, 'capacityRestrictionMinimum') |
| 189 | + cr_type = _get_price_data(price, 'capacityRestrictionType') |
| 190 | + extras_table.add_row( |
| 191 | + [extra['key'], |
| 192 | + _get_price_data(price, 'hourlyRecurringFee'), |
| 193 | + _get_price_data(price, 'recurringFee'), |
| 194 | + "%s - %s %s" % (cr_min, cr_max, cr_type)]) |
| 195 | + tables.append(extras_table) |
| 196 | + |
| 197 | + |
| 198 | +def _location_item_prices(location_prices, tables): |
| 199 | + """Get a specific data from HS price. |
| 200 | +
|
| 201 | + :param price: Hardware Server price. |
| 202 | + :param string item: Hardware Server price data. |
| 203 | + """ |
| 204 | + location_prices_table = formatting.Table(['keyName', 'priceId', 'Hourly', 'Monthly', 'Restriction']) |
| 205 | + location_prices_table.sortby = 'keyName' |
| 206 | + location_prices_table.align = 'l' |
| 207 | + for price in location_prices: |
| 208 | + cr_max = _get_price_data(price, 'capacityRestrictionMaximum') |
| 209 | + cr_min = _get_price_data(price, 'capacityRestrictionMinimum') |
| 210 | + cr_type = _get_price_data(price, 'capacityRestrictionType') |
| 211 | + location_prices_table.add_row( |
| 212 | + [price['item']['keyName'], price['id'], |
| 213 | + _get_price_data(price, 'hourlyRecurringFee'), |
| 214 | + _get_price_data(price, 'recurringFee'), |
| 215 | + "%s - %s %s" % (cr_min, cr_max, cr_type)]) |
| 216 | + tables.append(location_prices_table) |
| 217 | + |
| 218 | + |
| 219 | +def ram_prices_table(ram_list, tables): |
| 220 | + """Shows Server Port Speeds prices cost and capacity restriction. |
| 221 | +
|
| 222 | + :param [] ram_list: List of Virtual Server Ram. |
| 223 | + :param tables: Table formatting. |
| 224 | + """ |
| 225 | + ram_table = formatting.Table(['Key', 'Hourly', 'Monthly', 'Restriction'], |
| 226 | + title="Ram Prices") |
| 227 | + ram_table.sortby = 'Key' |
| 228 | + ram_table.align = 'l' |
| 229 | + for ram in ram_list: |
| 230 | + for price in ram['prices']: |
| 231 | + cr_max = _get_price_data(price, 'capacityRestrictionMaximum') |
| 232 | + cr_min = _get_price_data(price, 'capacityRestrictionMinimum') |
| 233 | + cr_type = _get_price_data(price, 'capacityRestrictionType') |
| 234 | + ram_table.add_row( |
| 235 | + [ram['key'], |
| 236 | + _get_price_data(price, 'hourlyRecurringFee'), |
| 237 | + _get_price_data(price, 'recurringFee'), |
| 238 | + "%s - %s %s" % (cr_min, cr_max, cr_type)]) |
59 | 239 | tables.append(ram_table) |
60 | 240 |
|
61 | | - # Data base |
62 | | - database_table = formatting.Table(['database', 'Value'], title="Databases") |
63 | | - database_table.sortby = 'Value' |
64 | | - database_table.align = 'l' |
65 | 241 |
|
66 | | - for database in options['database']: |
67 | | - database_table.add_row([database['name'], database['key']]) |
| 242 | +def database_prices_table(database_list, tables): |
| 243 | + """Shows Server Port Speeds prices cost and capacity restriction. |
| 244 | +
|
| 245 | + :param [] database_list: List of Virtual Server database. |
| 246 | + :param tables: Table formatting. |
| 247 | + """ |
| 248 | + database_table = formatting.Table(['Key', 'Hourly', 'Monthly', 'Restriction'], |
| 249 | + title="Data Base Prices") |
| 250 | + database_table.sortby = 'Key' |
| 251 | + database_table.align = 'l' |
| 252 | + for database in database_list: |
| 253 | + for price in database['prices']: |
| 254 | + cr_max = _get_price_data(price, 'capacityRestrictionMaximum') |
| 255 | + cr_min = _get_price_data(price, 'capacityRestrictionMinimum') |
| 256 | + cr_type = _get_price_data(price, 'capacityRestrictionType') |
| 257 | + database_table.add_row( |
| 258 | + [database['key'], |
| 259 | + _get_price_data(price, 'hourlyRecurringFee'), |
| 260 | + _get_price_data(price, 'recurringFee'), |
| 261 | + "%s - %s %s" % (cr_min, cr_max, cr_type)]) |
68 | 262 | tables.append(database_table) |
69 | 263 |
|
70 | | - # Guest_core |
71 | | - guest_core_table = formatting.Table(['cpu', 'Value', 'Capacity'], title="Guest_core") |
72 | | - guest_core_table.sortby = 'Value' |
73 | | - guest_core_table.align = 'l' |
74 | 264 |
|
75 | | - for guest_core in options['guest_core']: |
76 | | - guest_core_table.add_row([guest_core['name'], guest_core['key'], guest_core['capacity']]) |
| 265 | +def guest_core_prices_table(guest_core_list, tables): |
| 266 | + """Shows Server Port Speeds prices cost and capacity restriction. |
| 267 | +
|
| 268 | + :param [] guest_core_list: List of Virtual Server guest_core. |
| 269 | + :param tables: Table formatting. |
| 270 | + """ |
| 271 | + guest_core_table = formatting.Table(['Key', 'Hourly', 'Monthly', 'Restriction'], |
| 272 | + title="Guest Core Prices") |
| 273 | + guest_core_table.sortby = 'Key' |
| 274 | + guest_core_table.align = 'l' |
| 275 | + for guest_core in guest_core_list: |
| 276 | + for price in guest_core['prices']: |
| 277 | + cr_max = _get_price_data(price, 'capacityRestrictionMaximum') |
| 278 | + cr_min = _get_price_data(price, 'capacityRestrictionMinimum') |
| 279 | + cr_type = _get_price_data(price, 'capacityRestrictionType') |
| 280 | + guest_core_table.add_row( |
| 281 | + [guest_core['key'], |
| 282 | + _get_price_data(price, 'hourlyRecurringFee'), |
| 283 | + _get_price_data(price, 'recurringFee'), |
| 284 | + "%s - %s %s" % (cr_min, cr_max, cr_type)]) |
77 | 285 | tables.append(guest_core_table) |
78 | 286 |
|
79 | | - # Guest_core |
80 | | - guest_disk_table = formatting.Table(['guest_disk', 'Value', 'Capacity', 'Disk'], title="Guest_disks") |
81 | | - guest_disk_table.sortby = 'Value' |
82 | | - guest_disk_table.align = 'l' |
83 | 287 |
|
84 | | - for guest_disk in options['guest_disk']: |
85 | | - guest_disk_table.add_row([guest_disk['name'], guest_disk['key'], guest_disk['capacity'], guest_disk['disk']]) |
| 288 | +def guest_disk_prices_table(guest_disk_list, tables): |
| 289 | + """Shows Server Port Speeds prices cost and capacity restriction. |
| 290 | +
|
| 291 | + :param [] guest_disk_list: List of Virtual Server guest_disk. |
| 292 | + :param tables: Table formatting. |
| 293 | + """ |
| 294 | + guest_disk_table = formatting.Table(['Key', 'Hourly', 'Monthly', 'Restriction'], |
| 295 | + title="Guest Disk Prices") |
| 296 | + guest_disk_table.sortby = 'Key' |
| 297 | + guest_disk_table.align = 'l' |
| 298 | + for guest_disk in guest_disk_list: |
| 299 | + for price in guest_disk['prices']: |
| 300 | + cr_max = _get_price_data(price, 'capacityRestrictionMaximum') |
| 301 | + cr_min = _get_price_data(price, 'capacityRestrictionMinimum') |
| 302 | + cr_type = _get_price_data(price, 'capacityRestrictionType') |
| 303 | + guest_disk_table.add_row( |
| 304 | + [guest_disk['key'], |
| 305 | + _get_price_data(price, 'hourlyRecurringFee'), |
| 306 | + _get_price_data(price, 'recurringFee'), |
| 307 | + "%s - %s %s" % (cr_min, cr_max, cr_type)]) |
86 | 308 | tables.append(guest_disk_table) |
87 | 309 |
|
88 | | - # Port speed |
89 | | - port_speed_table = formatting.Table(['network', 'Key'], title="Network Options") |
90 | | - port_speed_table.sortby = 'Key' |
91 | | - port_speed_table.align = 'l' |
92 | 310 |
|
93 | | - for speed in options['port_speed']: |
94 | | - port_speed_table.add_row([speed['name'], speed['key']]) |
95 | | - tables.append(port_speed_table) |
| 311 | +def _get_price_data(price, item): |
| 312 | + """Get a specific data from HS price. |
96 | 313 |
|
97 | | - env.fout(formatting.listing(tables, separator='\n')) |
| 314 | + :param price: Hardware Server price. |
| 315 | + :param string item: Hardware Server price data. |
| 316 | + """ |
| 317 | + result = '-' |
| 318 | + if item in price: |
| 319 | + result = price[item] |
| 320 | + return result |
0 commit comments