SoftLayer.ordering

Ordering Manager

license

MIT, see LICENSE for more details.

class SoftLayer.managers.ordering.OrderingManager(client)[source]

Manager to help ordering via the SoftLayer API.

Parameters

client (SoftLayer.API.BaseClient) – the client instance

static filter_outlet_packages(packages)[source]

Remove packages designated as OUTLET.

Those type of packages must be handled in a different way, and they are not supported at the moment.

Parameters

packages – Dictionary of packages. Name and description keys must be present in each of them.

generate_order(package_keyname, location, item_keynames, complex_type=None, hourly=True, preset_keyname=None, extras=None, quantity=1)[source]

Generates an order with the given package and prices.

This function takes in parameters needed for an order and generates an order dictionary. This dictionary can then be used in either verify or placeOrder().

Parameters
  • package_keyname (str) – The keyname for the package being ordered

  • location (str) – The datacenter location string for ordering (Ex: DALLAS13)

  • item_keynames (list) – The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or slcli order item-list)

  • complex_type (str) – The complex type to send with the order. Typically begins with SoftLayer_Container_Product_Order_.

  • hourly (bool) – If true, uses hourly billing, otherwise uses monthly billing

  • preset_keyname (string) – If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or slcli order preset-list)

  • extras (dict) – The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: {‘virtualGuests’: [{‘hostname’: ‘test’, ‘domain’: ‘softlayer.com’}]}

  • quantity (int) – The number of resources to order

generate_order_template(quote_id, extra, quantity=1)[source]

Generate a complete order template.

Parameters
  • quote_id (int) – ID of target quote

  • extra (dictionary) – Overrides for the defaults of SoftLayer_Container_Product_Order

  • quantity (int) – Number of items to order.

get_item_capacity(items, item_keynames)[source]

Get item capacity.

static get_item_price_id(core, prices, term=0)[source]

get item price id

core: None or a number to match against capacityRestrictionType prices: list of SoftLayer_Product_Item_Price term: int to match against SoftLayer_Product_Item_Price.termLength

get_item_prices(package_id)[source]

Get item prices.

Retrieve a SoftLayer_Product_Package item prices record.

Parameters

package_id (int) – package identifier.

Returns

A list of price IDs associated with the given package.

get_item_prices_by_location(location, package_keyname)[source]

Returns the item prices by location.

Parameters
  • package_keyname (string) – The package for which to get the items.

  • location (string) – location name or keyname to get the item prices.

get_location_id(location)[source]

Finds the location ID of a given datacenter

This is mostly used so either a dc name, or regions keyname can be used when ordering :param str location: Region Keyname (DALLAS13) or datacenter name (dal13) :returns: integer id of the datacenter

static get_only_active_packages(packages)[source]

Return only active packages.

If a package is active, it is eligible for ordering This will inspect the ‘isActive’ property on the provided packages

Parameters

packages – Dictionary of packages, isActive key must be present

get_order_container(quote_id)[source]

Generate an order container from a quote object.

Parameters

quote_id – ID number of target quote

get_order_detail(order_id, mask=None)[source]

Get order details.

Parameters
  • order_id (int) – to specify the order that we want to retrieve.

  • mask (string) – Mask to specify the properties we want to retrieve.

get_package_by_key(package_keyname, mask=None)[source]

Get a single package with a given key.

If no packages are found, returns None

Parameters
  • package_keyname – string representing the package key name we are interested in.

  • mask (string) – Mask to specify the properties we want to retrieve

get_package_by_type(package_type, mask=None)[source]

Get a single package of a given type.

Syntactic sugar to retrieve a single package of a given type. If multiple packages share the given type, this will return the first one returned by the API. If no packages are found, returns None

Parameters

package_type (string) – representing the package type key name we are interested in

get_package_id_by_type(package_type)[source]

Return the package ID of a Product Package with a given type.

Parameters

package_type (string) – representing the package type key name we are interested in

Raises

ValueError – when no package of the given type is found

get_packages_of_type(package_types, mask=None)[source]

Get packages that match a certain type.

Each ordering package has a type, so return all packages that match the types we are looking for

Parameters
  • package_types (list) – List of strings representing the package type keynames we are interested in.

  • mask (string) – Mask to specify the properties we want to retrieve

get_preset_by_key(package_keyname, preset_keyname, mask=None)[source]

Gets a single preset with the given key.

get_preset_prices(preset)[source]

Get preset item prices.

Retrieve a SoftLayer_Product_Package_Preset record.

Parameters

preset (int) – preset identifier.

Returns

A list of price IDs associated with the given preset_id.

get_price_id_list(package_keyname, item_keynames, core=None)[source]

Converts a list of item keynames to a list of price IDs.

This function is used to convert a list of item keynames into a list of price IDs that are used in the Product_Order verifyOrder() and placeOrder() functions.

Parameters
  • package_keyname (str) – The package associated with the prices

  • item_keynames (list) – A list of item keyname strings

  • core (str) – preset guest core capacity.

Returns

A list of price IDs associated with the given item keynames in the given package

get_quote_details(quote_id)[source]

Retrieve quote details.

Parameters

quote_id – ID number of target quote

get_quotes()[source]

Retrieve a list of active quotes.

Returns

a list of SoftLayer_Billing_Order_Quote

list_categories(package_keyname, **kwargs)[source]

List the categories for the given package.

Parameters

package_keyname (str) – The package for which to get the categories.

Returns

List of categories associated with the package

list_items(package_keyname, **kwargs)[source]

List the items for the given package.

Parameters

package_keyname (str) – The package for which to get the items.

Returns

List of items in the package

list_packages(**kwargs)[source]

List active packages.

Returns

List of active packages.

list_presets(package_keyname, **kwargs)[source]

Gets active presets for the given package.

Parameters

package_keyname (str) – The package for which to get presets

Returns

A list of package presets that can be used for ordering

order_quote(quote_id, extra)[source]

Places an order using a quote

extras = {
    'hardware': {'hostname': 'test', 'domain': 'testing.com'},
    'quantity': 2
}
manager = ordering.OrderingManager(env.client)
result = manager.order_quote(12345, extras)
Parameters
  • quote_id (int) – ID for the target quote

  • extra (dictionary) – Overrides for the defaults of SoftLayer_Container_Product_Order

  • quantity (int) – Quantity to override default

package_locations(package_keyname)[source]

List datacenter locations for a package keyname

Parameters

package_keyname (str) – The package for which to get the items.

Returns

List of locations a package is orderable in

place_order(package_keyname, location, item_keynames, complex_type=None, hourly=True, preset_keyname=None, extras=None, quantity=1)[source]

Places an order with the given package and prices.

This function takes in parameters needed for an order and places the order.

Parameters
  • package_keyname (str) – The keyname for the package being ordered

  • location (str) – The datacenter location string for ordering (Ex: DALLAS13)

  • item_keynames (list) – The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or slcli order item-list)

  • complex_type (str) – The complex type to send with the order. Typically begins with SoftLayer_Container_Product_Order_.

  • hourly (bool) – If true, uses hourly billing, otherwise uses monthly billing

  • preset_keyname (string) – If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or slcli order preset-list)

  • extras (dict) – The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: {‘virtualGuests’: [{‘hostname’: ‘test’, domain’: ‘softlayer.com’}]}

  • quantity (int) – The number of resources to order

place_quote(package_keyname, location, item_keynames, complex_type=None, preset_keyname=None, extras=None, quantity=1, quote_name=None, send_email=False)[source]

Place a quote with the given package and prices.

This function takes in parameters needed for an order and places the quote.

Parameters
  • package_keyname (str) – The keyname for the package being ordered

  • location (str) – The datacenter location string for ordering (Ex: DALLAS13)

  • item_keynames (list) – The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or slcli order item-list)

  • complex_type (str) – The complex type to send with the order. Typically begins with SoftLayer_Container_Product_Order_.

  • preset_keyname (string) – If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or slcli order preset-list)

  • extras (dict) – The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: {‘virtualGuests’: [{‘hostname’: ‘test’, domain’: ‘softlayer.com’}]}

  • quantity (int) – The number of resources to order

  • quote_name (string) – A custom name to be assigned to the quote (optional).

  • send_email (bool) – This flag indicates that the quote should be sent to the email address associated with the account or order.

resolve_location_name(location_key)[source]

Resolves a location name using a string location key.

Parameters

location_key (string) – A string location used to resolve the location name.

Returns

An location name.

save_quote(quote_id)[source]

Save a quote.

Parameters

quote_id – ID number of target quote

verify_order(package_keyname, location, item_keynames, complex_type=None, hourly=True, preset_keyname=None, extras=None, quantity=1)[source]

Verifies an order with the given package and prices.

This function takes in parameters needed for an order and verifies the order to ensure the given items are compatible with the given package.

Parameters
  • package_keyname (str) – The keyname for the package being ordered

  • location (str) – The datacenter location string for ordering (Ex: DALLAS13)

  • item_keynames (list) – The list of item keyname strings to order. To see list of possible keynames for a package, use list_items() (or slcli order item-list)

  • complex_type (str) – The complex type to send with the order. Typically begins with SoftLayer_Container_Product_Order_.

  • hourly (bool) – If true, uses hourly billing, otherwise uses monthly billing

  • preset_keyname (string) – If needed, specifies a preset to use for that package. To see a list of possible keynames for a package, use list_preset() (or slcli order preset-list)

  • extras (dict) – The extra data for the order in dictionary format. Example: A VSI order requires hostname and domain to be set, so extras will look like the following: ‘virtualGuests’: [{‘hostname’: ‘test’, ‘domain’: ‘softlayer.com’}]}

  • quantity (int) – The number of resources to order

verify_quote(quote_id, extra)[source]

Verifies that a quote order is valid.

extras = {
    'hardware': {'hostname': 'test', 'domain': 'testing.com'},
    'quantity': 2
}
manager = ordering.OrderingManager(env.client)
result = manager.verify_quote(12345, extras)
Parameters
  • quote_id (int) – ID for the target quote

  • extra (dictionary) – Overrides for the defaults of SoftLayer_Container_Product_Order

  • quantity (int) – Quantity to override default