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