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.
- created_at¶
The creation date of the lease.
- Type:
datetime
- add_device_reservation(amount: int | None = None, machine_type: str | None = None, device_model: str | None = None, device_name: str | 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.
- 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_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.
- 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_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)[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.
- 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:
- 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
countor 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_nameis provided, butcountis 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.
- 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:
- 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.datetimeobject, or if the string'now', starts in about a minute.length – length of time as a
datetime.timedeltaobject 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_propertiesvalue 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 theresource_propertiespayload 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
daysandhours, 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)
- chi.lease.list_leases() List[Lease][source]¶
Return a list of user leases.
- Returns:
A list of Lease objects representing user leases.
- 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.