|
| 1 | +"""Place quote""" |
| 2 | +# :license: MIT, see LICENSE for more details. |
| 3 | + |
| 4 | +import json |
| 5 | + |
| 6 | +import click |
| 7 | + |
| 8 | +from SoftLayer.CLI import environment |
| 9 | +from SoftLayer.CLI import formatting |
| 10 | +from SoftLayer.managers import ordering |
| 11 | + |
| 12 | + |
| 13 | +@click.command() |
| 14 | +@click.argument('package_keyname') |
| 15 | +@click.argument('location') |
| 16 | +@click.option('--preset', |
| 17 | + help="The order preset (if required by the package)") |
| 18 | +@click.option('--name', |
| 19 | + help="A custom name to be assigned to the quote (optional)") |
| 20 | +@click.option('--send-email', |
| 21 | + is_flag=True, |
| 22 | + help="The quote will be sent to the email address associated.") |
| 23 | +@click.option('--complex-type', help=("The complex type of the order. This typically begins" |
| 24 | + " with 'SoftLayer_Container_Product_Order_'.")) |
| 25 | +@click.option('--extras', |
| 26 | + help="JSON string denoting extra data that needs to be sent with the order") |
| 27 | +@click.argument('order_items', nargs=-1) |
| 28 | +@environment.pass_env |
| 29 | +def cli(env, package_keyname, location, preset, name, send_email, complex_type, |
| 30 | + extras, order_items): |
| 31 | + """Place a quote. |
| 32 | +
|
| 33 | + This CLI command is used for placing a quote of the specified package in |
| 34 | + the given location (denoted by a datacenter's long name). Orders made via the CLI |
| 35 | + can then be converted to be made programmatically by calling |
| 36 | + SoftLayer.OrderingManager.place_quote() with the same keynames. |
| 37 | +
|
| 38 | + Packages for ordering can be retrieved from `slcli order package-list` |
| 39 | + Presets for ordering can be retrieved from `slcli order preset-list` (not all packages |
| 40 | + have presets) |
| 41 | +
|
| 42 | + Items can be retrieved from `slcli order item-list`. In order to find required |
| 43 | + items for the order, use `slcli order category-list`, and then provide the |
| 44 | + --category option for each category code in `slcli order item-list`. |
| 45 | +
|
| 46 | + \b |
| 47 | + Example: |
| 48 | + # Place quote a VSI with 4 CPU, 16 GB RAM, 100 GB SAN disk, |
| 49 | + # Ubuntu 16.04, and 1 Gbps public & private uplink in dal13 |
| 50 | + slcli order place-quote --name "foobar" --send-email CLOUD_SERVER DALLAS13 \\ |
| 51 | + GUEST_CORES_4 \\ |
| 52 | + RAM_16_GB \\ |
| 53 | + REBOOT_REMOTE_CONSOLE \\ |
| 54 | + 1_GBPS_PUBLIC_PRIVATE_NETWORK_UPLINKS \\ |
| 55 | + BANDWIDTH_0_GB_2 \\ |
| 56 | + 1_IP_ADDRESS \\ |
| 57 | + GUEST_DISK_100_GB_SAN \\ |
| 58 | + OS_UBUNTU_16_04_LTS_XENIAL_XERUS_MINIMAL_64_BIT_FOR_VSI \\ |
| 59 | + MONITORING_HOST_PING \\ |
| 60 | + NOTIFICATION_EMAIL_AND_TICKET \\ |
| 61 | + AUTOMATED_NOTIFICATION \\ |
| 62 | + UNLIMITED_SSL_VPN_USERS_1_PPTP_VPN_USER_PER_ACCOUNT \\ |
| 63 | + NESSUS_VULNERABILITY_ASSESSMENT_REPORTING \\ |
| 64 | + --extras '{"virtualGuests": [{"hostname": "test", "domain": "softlayer.com"}]}' \\ |
| 65 | + --complex-type SoftLayer_Container_Product_Order_Virtual_Guest |
| 66 | +
|
| 67 | + """ |
| 68 | + manager = ordering.OrderingManager(env.client) |
| 69 | + |
| 70 | + if extras: |
| 71 | + extras = json.loads(extras) |
| 72 | + |
| 73 | + args = (package_keyname, location, order_items) |
| 74 | + kwargs = {'preset_keyname': preset, |
| 75 | + 'extras': extras, |
| 76 | + 'quantity': 1, |
| 77 | + 'quote_name': name, |
| 78 | + 'send_email': send_email, |
| 79 | + 'complex_type': complex_type} |
| 80 | + |
| 81 | + order = manager.place_quote(*args, **kwargs) |
| 82 | + |
| 83 | + table = formatting.KeyValueTable(['name', 'value']) |
| 84 | + table.align['name'] = 'r' |
| 85 | + table.align['value'] = 'l' |
| 86 | + table.add_row(['id', order['quote']['id']]) |
| 87 | + table.add_row(['name', order['quote']['name']]) |
| 88 | + table.add_row(['created', order['orderDate']]) |
| 89 | + table.add_row(['expires', order['quote']['expirationDate']]) |
| 90 | + table.add_row(['status', order['quote']['status']]) |
| 91 | + env.fout(table) |
0 commit comments