Skip to content

Commit a53a75a

Browse files
Merge branch '1026' of github.com:allmightyspiff/softlayer-python into 1026
2 parents 71931ec + 475b1eb commit a53a75a

File tree

6 files changed

+1072
-0
lines changed

6 files changed

+1072
-0
lines changed

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
('virtual:reload', 'SoftLayer.CLI.virt.reload:cli'),
3131
('virtual:upgrade', 'SoftLayer.CLI.virt.upgrade:cli'),
3232
('virtual:credentials', 'SoftLayer.CLI.virt.credentials:cli'),
33+
('virtual:capacity', 'SoftLayer.CLI.virt.capacity:cli'),
3334

3435
('dedicatedhost', 'SoftLayer.CLI.dedicatedhost'),
3536
('dedicatedhost:list', 'SoftLayer.CLI.dedicatedhost.list:cli'),
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Manages Reserved Capacity."""
2+
# :license: MIT, see LICENSE for more details.
3+
import importlib
4+
import click
5+
import types
6+
import SoftLayer
7+
import os
8+
from SoftLayer.CLI import environment
9+
from SoftLayer.CLI import formatting
10+
11+
from pprint import pprint as pp
12+
class capacityCommands(click.MultiCommand):
13+
"""Loads module for capacity related commands."""
14+
15+
def __init__(self, *path, **attrs):
16+
click.MultiCommand.__init__(self, **attrs)
17+
self.path = os.path.dirname(__file__)
18+
19+
def list_commands(self, ctx):
20+
"""List all sub-commands."""
21+
22+
rv = []
23+
for filename in os.listdir(self.path):
24+
if filename == '__init__.py':
25+
continue
26+
if filename.endswith('.py'):
27+
rv.append(filename[:-3])
28+
rv.sort()
29+
return rv
30+
31+
def get_command(self, ctx, name):
32+
"""Get command for click."""
33+
path = "%s.%s" % (__name__, name)
34+
module = importlib.import_module(path)
35+
return getattr(module, 'cli')
36+
37+
@click.group(cls=capacityCommands,
38+
help="Manages virtual server reserved capacity")
39+
@environment.pass_env
40+
def cli(env):
41+
"""Manages Capacity"""
42+
pass
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""List options for creating Reserved Capacity"""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
from SoftLayer.managers.vs_capacity import CapacityManager as CapacityManager
10+
11+
12+
from pprint import pprint as pp
13+
14+
@click.command()
15+
@environment.pass_env
16+
def cli(env):
17+
"""List options for creating Reserved Capacity"""
18+
manager = CapacityManager(env.client)
19+
items = manager.get_create_options()
20+
items.sort(key=lambda term: int(term['capacity']))
21+
table = formatting.Table(["KeyName", "Description", "Term", "Hourly Price"], title="Reserved Capacity Options")
22+
table.align["Hourly Price"] = "l"
23+
table.align["Description"] = "l"
24+
table.align["KeyName"] = "l"
25+
for item in items:
26+
table.add_row([
27+
item['keyName'], item['description'], item['capacity'], get_price(item)
28+
])
29+
env.fout(table)
30+
31+
regions = manager.get_available_routers()
32+
location_table = formatting.Table(['Location', 'POD', 'BackendRouterId'], 'Orderable Locations')
33+
for region in regions:
34+
for location in region['locations']:
35+
for pod in location['location']['pods']:
36+
location_table.add_row([region['keyname'], pod['backendRouterName'], pod['backendRouterId']])
37+
env.fout(location_table)
38+
39+
40+
def get_price(item):
41+
the_price = "No Default Pricing"
42+
for price in item.get('prices',[]):
43+
if price.get('locationGroupId') == '':
44+
the_price = "%0.4f" % float(price['hourlyRecurringFee'])
45+
return the_price
46+
47+
def get_router_ids():
48+
pass
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""Create a Reserved Capacity instance"""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
from SoftLayer.managers.vs_capacity import CapacityManager as CapacityManager
10+
11+
12+
from pprint import pprint as pp
13+
14+
@click.command(epilog="See 'slcli vs capacity create-options' for valid options")
15+
@click.option('--name', '-n', required=True, prompt=True,
16+
help="Name for your new reserved capacity")
17+
@click.option('--datacenter', '-d', required=True, prompt=True,
18+
help="Datacenter shortname")
19+
@click.option('--backend_router_id', '-b', required=True, prompt=True,
20+
help="backendRouterId, create-options has a list of valid ids to use.")
21+
@click.option('--capacity', '-c', required=True, prompt=True,
22+
help="Capacity keyname (C1_2X2_1_YEAR_TERM for example).")
23+
@click.option('--quantity', '-q', required=True, prompt=True,
24+
help="Number of VSI instances this capacity reservation can support.")
25+
@click.option('--test', is_flag=True,
26+
help="Do not actually create the virtual server")
27+
@environment.pass_env
28+
def cli(env, name, datacenter, backend_router_id, capacity, quantity, test=False):
29+
"""Create a Reserved Capacity instance"""
30+
manager = CapacityManager(env.client)
31+
result = manager.create(
32+
name=name,
33+
datacenter=datacenter,
34+
backend_router_id=backend_router_id,
35+
capacity=capacity,
36+
quantity=quantity,
37+
test=test)
38+
39+
pp(result)
40+
if test:
41+
table = formating.Table(['Name', 'Value'], "Test Order")
42+
container = result['orderContainers'][0]
43+
table.add_row(['Name', container['name']])
44+
table.add_row(['Location'], container['locationObject']['longName'])
45+
for price in container['prices']:
46+
table.add_row([price['item']['keyName'], price['item']['description']])
47+
table.add_row(['Total', result['postTaxRecurring']])
48+
else:
49+
table = formatting.Table(['Name', 'Value'], "Reciept")
50+
table.add_row(['Order Date', result['orderDate']])
51+
table.add_row(['Order ID', result['orderId']])
52+
table.add_row(['status', result['placedOrder']['status']])
53+
for item in result['placedOrder']['items']:
54+
table.add_row([item['categoryCode'], item['description']])
55+
table.add_row(['Total', result['orderDetails']['postTaxRecurring']])
56+
env.fout(table)
57+
58+
59+
"""
60+
Calling: SoftLayer_Product_Order::placeOrder(
61+
id=None,
62+
mask='',
63+
filter='None',
64+
args=(
65+
{'orderContainers': [
66+
{'backendRouterId': 1079095,
67+
'name': 'cgallo-test-capacity',
68+
'quantity': 1,
69+
'packageId': 1059,
70+
'location': 1854895,
71+
'useHourlyPricing': True,
72+
'complexType': 'SoftLayer_Container_Product_Order_Virtual_ReservedCapacity',
73+
'prices': [{'id': 217633}]}]},), limit=None, offset=None))
74+
Resetting dropped connection: r237377.application.qadal0501.softlayer.local
75+
"""
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""List Reserved Capacity"""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
from SoftLayer.managers.vs_capacity import CapacityManager as CapacityManager
10+
11+
12+
from pprint import pprint as pp
13+
14+
@click.command()
15+
@environment.pass_env
16+
def cli(env):
17+
"""List Reserved Capacity"""
18+
manager = CapacityManager(env.client)
19+
result = manager.list()
20+
pp(result)

0 commit comments

Comments
 (0)