chi.lease

The chi.lease module exposes both a functional interface and an object-oriented interface for interacting with resource leases.

Functional interface

chi.lease.add_device_reservation(reservation_list, count=1, machine_name=None, device_model=None, device_name=None)[source]

Add an IoT/edge device reservation to a reservation list.

Parameters:
  • reservation_list (list[dict]) – The list of reservations to add to.

  • count (int) – The number of devices to request.

  • machine_name (str) – The device machine name to reserve. This should match a “machine_name” property of the devices registered in Blazar. This is the easiest way to reserve a particular device type, e.g. “raspberrypi4-64”.

  • device_model (str) – The model of device to reserve. This should match a “model” property of the devices registered in Blazar.

  • device_name (str) – The name of a specific device to reserve. If this is provided in conjunction with count or other constraints, an error will be raised, as there is only 1 possible device that can match this criteria, because devices have unique names.

Raises:

ValueError – If device_name is provided, but count is greater than 1, or some other constraint is present.

chi.lease.add_fip_reservation(reservation_list, count=1)[source]

Add a floating IP reservation to a reservation list.

Parameters:
  • reservation_list (list[dict]) – The list of reservations to add to. The list will be extended in-place.

  • count (int) – The number of floating IPs to reserve.

chi.lease.add_network_reservation(reservation_list, network_name, of_controller_ip=None, of_controller_port=None, vswitch_name=None, resource_properties=None, physical_network='physnet1')[source]

Add a network reservation to a reservation list.

Parameters:
  • reservation_list (list[dict]) – The list of reservations to add to. The list will be extended in-place.

  • network_name (str) – The name of the network to create when the reservation starts.

  • of_controller_ip (str) – The OpenFlow controller IP, if the network should be controlled by an external controller.

  • of_controller_port (int) – The OpenFlow controller port.

  • vswitch_name (str) – The name of the virtual switch associated with this network. See the virtual forwarding context documentation for more details.

  • resource_properties (list) – A list of resource property constraints. These take the form [<operation>, <search_key>, <search_value>]

  • physical_network (str) – The physical provider network to reserve from. This only needs to be changed if you are reserving a stitchable network. (Default “physnet1”).

chi.lease.add_node_reservation(reservation_list, count=1, resource_properties=None, node_type=None, architecture=None)[source]

Add a node reservation to a reservation list.

Parameters:
  • reservation_list (list[dict]) – The list of reservations to add to. The list will be extended in-place.

  • count (int) – The number of nodes of the given type to request. (Default 1).

  • resource_properties (list) –

    A list of resource property constraints. These take the form [<operation>, <search_key>, <search_value>], e.g.:

    ["==", "$node_type", "some-node-type"]: filter the reservation to only
      nodes with a `node_type` matching "some-node-type".
    [">", "$architecture.smt_size", 40]: filter to nodes having more than 40
      (hyperthread) cores.
    

  • node_type (str) – The node type to request. If None, the reservation will not target any particular node type. If resource_properties is defined, the node type constraint is added to the existing property constraints.

  • architecture (str) – The node architecture to request. If resource_properties is defined, the architecture constraint is added to the existing property constraints.

chi.lease.create_lease(lease_name, reservations=[], start_date=None, end_date=None)[source]

Create a new lease with some requested reservations.

Parameters:
  • lease_name (str) – The name to give the new lease.

  • reservations (list[dict]) – The reservations to request with the lease.

  • start_date (datetime) – The start date of the lease. (Defaults to now.)

  • end_date (datetime) – The end date of the lease. (Defaults to 1 day from the lease start date.)

Returns:

The created lease representation.

chi.lease.delete_lease(ref)[source]

Delete the lease.

Parameters:

ref (str) – The name or ID of the lease.

chi.lease.get_device_reservation(lease_ref, count=None, machine_name=None, device_model=None, device_name=None)[source]

Retrieve a reservation ID for a device reservation.

The reservation ID is useful to have when requesting containers.

Parameters:
  • lease_ref (str) – The ID or name of the lease.

  • count (int) – An optional count of devices the desired reservation was made for. Use this if you have multiple reservations under a lease.

  • machine_name (str) – An optional device machine name the desired reservation was made for. Use this if you have multiple reservations under a lease.

  • device_model (str) – An optional device model the desired reservation was made for. Use this if you have multiple reservations under a lease.

  • device_name (str) – An optional device name the desired reservation was made for. Use this if you have multiple reservations under a lease.

Returns:

The ID of the reservation, if found.

Raises:

ValueError – If no reservation was found, or multiple were found.

chi.lease.get_lease(ref) dict[source]

Get a lease by its ID or name.

Parameters:

ref (str) – The ID or name of the lease.

Returns:

The lease matching the ID or name.

chi.lease.get_lease_id(lease_name) str[source]

Look up a lease’s ID from its name.

Parameters:

name (str) – The name of the lease.

Returns:

The ID of the found lease.

Raises:

ValueError – If the lease could not be found, or if multiple leases were found with the same name.

chi.lease.get_node_reservation(lease_ref, count=None, resource_properties=None, node_type=None, architecture=None)[source]

Retrieve a reservation ID for a node reservation.

The reservation ID is useful to have when launching bare metal instances.

Parameters:
  • lease_ref (str) – The ID or name of the lease.

  • count (int) – An optional count of nodes the desired reservation was made for. Use this if you have multiple reservations under a lease.

  • resource_properties (list) – An optional set of resource property constraints the desired reservation was made under. Use this if you have multiple reservations under a lease.

  • node_type (str) – An optional node type the desired reservation was made for. Use this if you have multiple reservations under a lease.

  • architecture (str) – An optional node architecture the desired reservation was made for. Use this if you have multiple reservations under a lease.

Returns:

The ID of the reservation, if found.

Raises:

ValueError – If no reservation was found, or multiple were found.

chi.lease.get_reserved_floating_ips(lease_ref) list[str][source]

Get a list of Floating IP addresses reserved in a lease.

Parameters:

lease_ref (str) – The ID or name of the lease.

Returns:

A list of all reserved Floating IP addresses, if any were reserved.

chi.lease.lease_duration(days=1, hours=0)[source]

Compute the start and end dates for a lease given its desired duration.

When providing both days and hours, the duration is summed. So, the following would be a lease for one and a half days:

start_date, end_date = lease_duration(days=1, hours=12)
Parameters:
  • days (int) – The number of days the lease should be for.

  • hours (int) – The number of hours the lease should be for.

chi.lease.wait_for_active(ref)[source]

Wait for the lease to become active.

This function will wait for 2.5 minutes, which is a somewhat arbitrary amount of time.

Parameters:

ref (str) – The name or ID of the lease.

Returns:

The lease in ACTIVE state.

Raises:

TimeoutError – If the lease fails to become active within the timeout.

Object-oriented interface

class chi.lease.Lease(**kwargs)[source]

Creates and manages a lease, optionally with a context manager (with).

with Lease(session, node_type='compute_skylake') as lease:
    instance = lease.create_server()
    ...

When using the context manager, on entering it will wait for the lease to launch, then on exiting it will delete the lease, which in-turn also deletes the instances launched with it.

Parameters:
  • keystone_session – session object

  • sequester (bool) – If the context manager catches that an instance failed to start, it will not delete the lease, but rather extend it and rename it with the ID of the instance that failed.

  • _no_clean (bool) – Don’t delete the lease at the end of a context manager

  • kwargs – Parameters passed through to lease_create_nodetype() and in turn lease_create_args()

create_server(*server_args, **server_kwargs)[source]

Generates instances using the resource of the lease. Arguments are passed to ccmanage.server.Server and returns same object.

delete()[source]

Deletes the lease

classmethod from_existing(id)[source]

Attach to an existing lease by ID. When using in conjunction with the context manager, it will not delete the lease at the end.

property ready

Returns True if the lease has started.

refresh()[source]

Updates the lease data

property status

Refreshes and returns the status of the lease.

wait()[source]

Blocks for up to 150 seconds, waiting for the lease to be ready. Raises a RuntimeError if it times out.