Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions SoftLayer/CLI/order/category_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@
def cli(env, package_keyname, required):
"""List the categories of a package.

Package keynames can be retrieved from `slcli order package-list`
::

\b
Example:
# List the categories of Bare Metal servers
slcli order category-list BARE_METAL_SERVER

When using the --required flag, it will list out only the categories
that are required for ordering that package (see `slcli order item-list`)

\b
Example:
# List the required categories for Bare Metal servers
slcli order category-list BARE_METAL_SERVER --required

Expand Down
19 changes: 4 additions & 15 deletions SoftLayer/CLI/order/item_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,18 @@
def cli(env, package_keyname, keyword, category):
"""List package items used for ordering.

The items listed can be used with `slcli order place` to specify
The item keyNames listed can be used with `slcli order place` to specify
the items that are being ordered in the package.

Package keynames can be retrieved using `slcli order package-list`

\b
Note:
.. Note::
Items with a numbered category, like disk0 or gpu0, can be included
multiple times in an order to match how many of the item you want to order.

\b
Example:
::

# List all items in the VSI package
slcli order item-list CLOUD_SERVER

The --keyword option is used to filter items by name.

The --category option is used to filter items by category.

Both --keyword and --category can be used together.

\b
Example:
# List Ubuntu OSes from the os category of the Bare Metal package
slcli order item-list BARE_METAL_SERVER --category os --keyword ubuntu

Expand Down
15 changes: 4 additions & 11 deletions SoftLayer/CLI/order/package_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,16 @@
def cli(env, keyword, package_type):
"""List packages that can be ordered via the placeOrder API.

\b
Example:
# List out all packages for ordering
slcli order package-list

::

Keywords can also be used for some simple filtering functionality
to help find a package easier.
# List out all packages for ordering
slcli order package-list

\b
Example:
# List out all packages with "server" in the name
slcli order package-list --keyword server

Package types can be used to remove unwanted packages
\b
Example:
# Select only specifict package types
slcli order package-list --package_type BARE_METAL_CPU
"""
manager = ordering.OrderingManager(env.client)
Expand Down
9 changes: 5 additions & 4 deletions SoftLayer/CLI/order/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
default='hourly',
show_default=True,
help="Billing rate")
@click.option('--complex-type', help=("The complex type of the order. This typically begins"
" with 'SoftLayer_Container_Product_Order_'."))
@click.option('--complex-type',
help=("The complex type of the order. Starts with 'SoftLayer_Container_Product_Order'."))
@click.option('--extras',
help="JSON string denoting extra data that needs to be sent with the order")
@click.argument('order_items', nargs=-1)
Expand All @@ -55,8 +55,9 @@ def cli(env, package_keyname, location, preset, verify, billing, complex_type,
items for the order, use `slcli order category-list`, and then provide the
--category option for each category code in `slcli order item-list`.

\b
Example:

Example::

# Order an hourly VSI with 4 CPU, 16 GB RAM, 100 GB SAN disk,
# Ubuntu 16.04, and 1 Gbps public & private uplink in dal13
slcli order place --billing hourly CLOUD_SERVER DALLAS13 \\
Expand Down
13 changes: 7 additions & 6 deletions SoftLayer/CLI/order/place_quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
help="A custom name to be assigned to the quote (optional)")
@click.option('--send-email',
is_flag=True,
help="The quote will be sent to the email address associated.")
@click.option('--complex-type', help=("The complex type of the order. This typically begins"
" with 'SoftLayer_Container_Product_Order_'."))
help="The quote will be sent to the email address associated with your user.")
@click.option('--complex-type',
help="The complex type of the order. Starts with 'SoftLayer_Container_Product_Order'.")
@click.option('--extras',
help="JSON string denoting extra data that needs to be sent with the order")
@click.argument('order_items', nargs=-1)
Expand All @@ -31,7 +31,7 @@ def cli(env, package_keyname, location, preset, name, send_email, complex_type,
extras, order_items):
"""Place a quote.

This CLI command is used for placing a quote of the specified package in
This CLI command is used for creating a quote of the specified package in
the given location (denoted by a datacenter's long name). Orders made via the CLI
can then be converted to be made programmatically by calling
SoftLayer.OrderingManager.place_quote() with the same keynames.
Expand All @@ -44,8 +44,9 @@ def cli(env, package_keyname, location, preset, name, send_email, complex_type,
items for the order, use `slcli order category-list`, and then provide the
--category option for each category code in `slcli order item-list`.

\b
Example:

Example::

# Place quote a VSI with 4 CPU, 16 GB RAM, 100 GB SAN disk,
# Ubuntu 16.04, and 1 Gbps public & private uplink in dal13
slcli order place-quote --name "foobar" --send-email CLOUD_SERVER DALLAS13 \\
Expand Down
14 changes: 5 additions & 9 deletions SoftLayer/CLI/order/preset_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,15 @@
def cli(env, package_keyname, keyword):
"""List package presets.

Package keynames can be retrieved from `slcli order package-list`.
Some packages do not have presets.
.. Note::
Presets are set CPU / RAM / Disk allotments. You still need to specify required items.
Some packages do not have presets.

::

\b
Example:
# List the presets for Bare Metal servers
slcli order preset-list BARE_METAL_SERVER

The --keyword option can also be used for additional filtering on
the returned presets.

\b
Example:
# List the Bare Metal server presets that include a GPU
slcli order preset-list BARE_METAL_SERVER --keyword gpu

Expand Down
130 changes: 130 additions & 0 deletions SoftLayer/CLI/order/quote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
"""View and Order a quote"""
# :license: MIT, see LICENSE for more details.
import click

from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.CLI import helpers
from SoftLayer.managers import ImageManager as ImageManager
from SoftLayer.managers import ordering
from SoftLayer.managers import SshKeyManager as SshKeyManager


def _parse_create_args(client, args):
"""Converts CLI arguments to args for VSManager.create_instance.

:param dict args: CLI arguments
"""
data = {}

if args.get('quantity'):
data['quantity'] = int(args.get('quantity'))
if args.get('postinstall'):
data['provisionScripts'] = [args.get('postinstall')]
if args.get('complex_type'):
data['complexType'] = args.get('complex_type')

if args.get('fqdn'):
servers = []
for name in args.get('fqdn'):
fqdn = name.split(".", 1)
servers.append({'hostname': fqdn[0], 'domain': fqdn[1]})
data['hardware'] = servers

if args.get('image'):
if args.get('image').isdigit():
image_mgr = ImageManager(client)
image_details = image_mgr.get_image(args.get('image'), mask="id,globalIdentifier")
data['imageTemplateGlobalIdentifier'] = image_details['globalIdentifier']
else:
data['imageTemplateGlobalIdentifier'] = args['image']

userdata = None
if args.get('userdata'):
userdata = args['userdata']
elif args.get('userfile'):
with open(args['userfile'], 'r') as userfile:
userdata = userfile.read()
if userdata:
for hardware in data['hardware']:
hardware['userData'] = [{'value': userdata}]

# Get the SSH keys
if args.get('key'):
keys = []
for key in args.get('key'):
resolver = SshKeyManager(client).resolve_ids
key_id = helpers.resolve_id(resolver, key, 'SshKey')
keys.append(key_id)
data['sshKeys'] = keys

return data


@click.command()
@click.argument('quote')
@click.option('--verify', is_flag=True, default=False, show_default=True,
help="If specified, will only show what the quote will order, will NOT place an order")
@click.option('--quantity', type=int, default=None,
help="The quantity of the item being ordered if different from quoted value")
@click.option('--complex-type', default='SoftLayer_Container_Product_Order_Hardware_Server', show_default=True,
help=("The complex type of the order. Starts with 'SoftLayer_Container_Product_Order'."))
@click.option('--userdata', '-u', help="User defined metadata string")
@click.option('--userfile', '-F', type=click.Path(exists=True, readable=True, resolve_path=True),
help="Read userdata from file")
@click.option('--postinstall', '-i', help="Post-install script to download")
@helpers.multi_option('--key', '-k', help="SSH keys to add to the root user")
@helpers.multi_option('--fqdn', required=True,
help="<hostname>.<domain.name.tld> formatted name to use. Specify one fqdn per server")
@click.option('--image', help="Image ID. See: 'slcli image list' for reference")
@environment.pass_env
def cli(env, quote, **args):
"""View and Order a quote

\f
:note:
The hostname and domain are split out from the fully qualified domain name.

If you want to order multiple servers, you need to specify each FQDN. Postinstall, userdata, and
sshkeys are applied to all servers in an order.

::

slcli order quote 12345 --fqdn testing.tester.com \\
--complex-type SoftLayer_Container_Product_Order_Virtual_Guest -k sshKeyNameLabel\\
-i https://domain.com/runthis.sh --userdata DataGoesHere

"""
table = formatting.Table([
'Id', 'Name', 'Created', 'Expiration', 'Status'
])
create_args = _parse_create_args(env.client, args)

manager = ordering.OrderingManager(env.client)
quote_details = manager.get_quote_details(quote)

package = quote_details['order']['items'][0]['package']
create_args['packageId'] = package['id']

if args.get('verify'):
result = manager.verify_quote(quote, create_args)
verify_table = formatting.Table(['keyName', 'description', 'cost'])
verify_table.align['keyName'] = 'l'
verify_table.align['description'] = 'l'
for price in result['prices']:
cost_key = 'hourlyRecurringFee' if result['useHourlyPricing'] is True else 'recurringFee'
verify_table.add_row([
price['item']['keyName'],
price['item']['description'],
price[cost_key] if cost_key in price else formatting.blank()
])
env.fout(verify_table)
else:
result = manager.order_quote(quote, create_args)
table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'
table.add_row(['id', result['orderId']])
table.add_row(['created', result['orderDate']])
table.add_row(['status', result['placedOrder']['status']])
env.fout(table)
38 changes: 38 additions & 0 deletions SoftLayer/CLI/order/quote_detail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""View a quote"""
# :license: MIT, see LICENSE for more details.
import click

from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.managers import ordering
from SoftLayer.utils import lookup


@click.command()
@click.argument('quote')
@environment.pass_env
def cli(env, quote):
"""View a quote"""

manager = ordering.OrderingManager(env.client)
result = manager.get_quote_details(quote)

package = result['order']['items'][0]['package']
title = "{} - Package: {}, Id {}".format(result.get('name'), package['keyName'], package['id'])
table = formatting.Table([
'Category', 'Description', 'Quantity', 'Recurring', 'One Time'
], title=title)
table.align['Category'] = 'l'
table.align['Description'] = 'l'

items = lookup(result, 'order', 'items')
for item in items:
table.add_row([
item.get('categoryCode'),
item.get('description'),
item.get('quantity'),
item.get('recurringFee'),
item.get('oneTimeFee')
])

env.fout(table)
36 changes: 36 additions & 0 deletions SoftLayer/CLI/order/quote_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""List active quotes on an account."""
# :license: MIT, see LICENSE for more details.
import click

from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting
from SoftLayer.managers import ordering
from SoftLayer.utils import clean_time


@click.command()
@environment.pass_env
def cli(env):
"""List all active quotes on an account"""
table = formatting.Table([
'Id', 'Name', 'Created', 'Expiration', 'Status', 'Package Name', 'Package Id'
])
table.align['Name'] = 'l'
table.align['Package Name'] = 'r'
table.align['Package Id'] = 'l'

manager = ordering.OrderingManager(env.client)
items = manager.get_quotes()

for item in items:
package = item['order']['items'][0]['package']
table.add_row([
item.get('id'),
item.get('name'),
clean_time(item.get('createDate')),
clean_time(item.get('modifyDate')),
item.get('status'),
package.get('keyName'),
package.get('id')
])
env.fout(table)
Loading