chi.lease

The chi.lease module can be used for interacting with resource leases.

class chi.lease.Lease(name: str | None = None, start_date: datetime | None = None, end_date: datetime | None = None, duration: timedelta | None = None, lease_json: dict | None = None)[source]

Represents a lease in the CHI system.

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

  • start_date (datetime, optional) – The start date of the lease. Defaults to None.

  • end_date (datetime, optional) – The end date of the lease. Defaults to None.

  • duration (timedelta, optional) – The duration of the lease. Defaults to None.

  • lease_json (dict, optional) – JSON representation of the lease. Defaults to None.

name

The name of the lease.

Type:

str

start_date

The start date of the lease in the format specified by BLAZAR_TIME_FORMAT.

Type:

str

end_date

The end date of the lease in the format specified by BLAZAR_TIME_FORMAT.

Type:

str

id

The ID of the lease.

Type:

str

status

The status of the lease.

Type:

str

user_id

The ID of the user associated with the lease.

Type:

str

project_id

The ID of the project associated with the lease.

Type:

str

created_at

The creation date of the lease.

Type:

datetime

device_reservations

List of device reservations associated with the lease.

Type:

list

node_reservations

List of node reservations associated with the lease.

Type:

list

fip_reservations

List of floating IP reservations associated with the lease.

Type:

list

network_reservations

List of network reservations associated with the lease.

Type:

list

flavor_reservations

List of flavor reservations associated with the lease.

Type:

list

events

List of events associated with the lease.

Type:

list

add_device_reservation(amount: int | None = None, machine_type: str | None = None, device_model: str | None = None, device_name: str | None = None, devices: List[Device] | None = None)[source]

Add a IoT device reservation to the list of device reservations.

Parameters:
  • amount (int, optional) – The number of devices to reserve. Defaults to None.

  • machine_type (str, optional) – The type of machine to reserve. Defaults to None.

  • device_model (str, optional) – The model of the device to reserve. Defaults to None.

  • device_name (str, optional) – The name of the device to reserve. Defaults to None.

  • devices (List[Device]) – A list of Device objects to reserve.

Raises:

CHIValueError – If devices are specified, no other arguments should be included.

add_fip_reservation(amount: int)[source]

Add a reservation for a floating IP address to the list of FIP reservations.

Parameters:

amount (int) – The number of reservations to add.

Returns:

None

add_flavor_reservation(id=None, name=None, amount=1)[source]

Add a reservation for a KVM flavor to the list of reservations by name or ID.

Parameters:
  • id (str) – The ID of the flavor to reserve

  • name (str) – The name of the flavor to reserve

  • amount (int) – The number of instances of this flavor to reserve

add_network_reservation(network_name: str, usage_type: str | None = None, stitch_provider: str | None = None)[source]

Add a network reservation to the list of network reservations.

Parameters:
  • network_name (str) – The name of the network to be reserved.

  • usage_type (str, optional) – The type of usage for the network reservation. Defaults to None.

  • stitch_provider (str, optional) – The stitch provider for the network reservation. Defaults to None.

add_node_reservation(amount: int | None = None, node_type: str | None = None, node_name: str | None = None, nodes: List[Node] | None = None)[source]

Add a node reservation to the lease.

Parameters: - amount (int): The number of nodes to reserve. - node_type (str): The type of nodes to reserve. - node_name (str): The name of the node to reserve. - nodes (List[Node]): A list of Node objects to reserve.

Raises: - CHIValueError: If nodes are specified, no other arguments should be included.

get_reserved_flavors()[source]

Get flavors from flavor reservations in this lease. There will be one flavor per flavor reservation.

Returns:

List[chi.server.Flavor] of flavor

get_reserved_floating_ips()[source]

Get reserved floating ips from this lease

Returns:

List[str] of fip addresses

submit(wait_for_active: bool = True, wait_timeout: int = 300, show: str | None = None, idempotent: bool = False, retry_on_error: bool = False)[source]

Submits the lease for creation.

Parameters:
  • wait_for_active (bool, optional) – Whether to wait for the lease to become active. Defaults to True.

  • wait_timeout (int, optional) – The maximum time to wait for the lease to become active, in seconds. Defaults to 300.

  • show (Optional[str], optional) – The types of lease information to display. Defaults to None, options are “widget”, “text”.

  • idempotent (bool, optional) – Whether to create the lease only if it doesn’t already exist. Defaults to False.

  • retry_on_error (bool, optional) – Whether to retry the server creation if creation fails. Defaults to False.

Raises:

ResourceError – If unable to create the lease.

Returns:

None

wait(status='active', show: str = 'widget', timeout: int = 500)[source]

Waits for the lease’s status to reach the specified status.

Parameters:
  • status (str) – The status to wait for. Defaults to “ACTIVE”.

  • show (str, optional) – The type of server information to display after creation. Defaults to “widget”.

  • timeout (int) – How long to wait for lease to start

Raises:

ServiceError – If the server does not reach the specified status within the timeout period.

Returns:

None

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

Deprecated since version 1.0.

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]

Deprecated since version 1.0.

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, usage_type=None, of_controller_ip=None, of_controller_port=None, vswitch_name=None, stitch_provider=None, resource_properties=None, physical_network='physnet1')[source]

Deprecated since version 1.0.

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.

  • stich_provider (str) – specify a stitching provider such as fabric. ‘

  • 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, node_name=None, architecture=None)[source]

Deprecated since version 1.0.

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_name (str) – The specific node name to request. If None, the reservation will

  • node_type. (target any node of the)

  • 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]

Deprecated since version 1.0.

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]

Deprecated since version 1.0.

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]

Deprecated since version 1.0.

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: str) Lease | None[source]

Get a lease by its ID or name.

Parameters:

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

Returns:

A Lease object matching the ID or name, or None if not found.

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]

Deprecated since version 1.0.

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]

Deprecated since version 1.0.

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_create_args(neutronclient, name=None, start='now', end=None, length=None, nodes=1, node_resource_properties=None, fips=0, networks=0, network_resource_properties=['==', '$physical_network', 'physnet1'])[source]

Deprecated since version 1.0.

Generates the nested object that needs to be sent to the Blazar client to create the lease. Provides useful defaults for Chameleon.

Parameters:
  • name (str) – name of lease. If None, generates a random name.

  • start (str/datetime) – when to start lease as a datetime.datetime object, or if the string 'now', starts in about a minute.

  • length – length of time as a datetime.timedelta object or number of seconds as a number. Defaults to 1 day.

  • end (datetime.datetime) – when to end the lease. Provide only this or length, not both.

  • nodes (int) – number of nodes to reserve.

  • resource_properties – object that is JSON-encoded and sent as the resource_properties value to Blazar. Commonly used to specify node types.

chi.lease.lease_create_nodetype(*args, **kwargs)[source]

Deprecated since version 1.0.

Wrapper for lease_create_args() that adds the resource_properties payload to specify node type.

Parameters:

node_type (str) – Node type to filter by, compute_skylake, et al.

Raises:

ValueError – if there is no node_type named argument.

chi.lease.lease_duration(days=1, hours=0, td=None)[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.list_leases() List[Lease][source]

Return a list of user leases.

Returns:

A list of Lease objects representing user leases.

chi.lease.show_leases() DataGrid[source]

Displays a table of the user’s leases in an interactive, sortable format.

Uses an ipydatagrid to present key lease attributes such as ID, name, status, duration, and reservation counts. The grid supports sorting, filtering, and scrolling for easy exploration of lease state.

Returns:

An ipydatagrid widget displaying the leases.

Return type:

DataGrid

chi.lease.wait_for_active(ref)[source]

Deprecated since version 1.0.

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.