PiCloud

The PiCloud class is provided at the root of the module and can be imported as follows:

from hostedpi import PiCloud
class hostedpi.picloud.PiCloud(ssh_keys: SSHKeySources | None = None, *, auth: MythicAuth | None = None)[source]

A connection to the Mythic Beasts Pi Cloud API for creating and managing cloud Pi servers.

Parameters:
  • ssh_keys (SSHKeySources or None) – An instance of SSHKeySources containing sources of SSH keys to use when creating new Pis. If not provided, no SSH keys will be used by default.

  • auth (MythicAuth or None) – An instance of MythicAuth to use for authentication with the API. If not provided, a default instance will be created. You almost certainly won’t need to set this yourself.

Note

If any SSH keys are provided on class initialisation, they will be used when creating Pis but are overriden by any passed to the create_pi() method.

property pis: dict[str, Pi]

A dict of all Raspberry Pi servers associated with the account, keyed by their names. Each value is an instance of Pi representing the server.

Raises:
property ipv4_ssh_config: str

A string containing the default IPv4 SSH config for all Pis within the account. The contents could be added to an SSH config file for easy access to the Pis in the account.

property ipv6_ssh_config: str

A string containing the default IPv6 SSH config for all Pis within the account. The contents could be added to an SSH config file for easy access to the Pis in the account.

get_ipv4_ssh_config(user: str | None = 'root') str[source]

Construct a string containing the IPv4 SSH config for all Pis within the account. The contents could be added to an SSH config file for easy access to the Pis in the account.

get_ipv6_ssh_config(user: str | None = 'root', numeric: bool = False) str[source]

Construct a string containing the IPv6 SSH config for all Pis within the account. The contents could be added to an SSH config file for easy access to the Pis in the account.

create_pi(*, name: str | None = None, spec: Pi3ServerSpec | Pi4ServerSpec, ssh_keys: SSHKeySources | None = None, wait: bool = False) Pi[source]

Provision a new cloud Pi with the specified name, model, disk size and SSH keys. Return a new Pi instance.

Parameters:
  • name (str or None) – A unique identifier for the server. This will form part of the hostname for the server, and must consist only of alphanumeric characters and hyphens. If not provided, a server name will be automatically generated.

  • spec (Pi3ServerSpec or Pi4ServerSpec) – The spec of the Raspberry Pi to provision

  • ssh_keys (SSHKeySources or None) – An instance of SSHKeySources containing sources of SSH keys to use when creating a new Pi. If not provided, no SSH keys will be added on creation.

  • wait (bool) – If True, the method will return immediately after the server creation request is accepted, without waiting for the server to be provisioned. The returned Pi instance will not be fully initialised and will not be able to perform actions until the server is ready. If False, the method will wait for the server to be provisioned before returning the Pi instance. Default is False.

Note

If any SSH keys are provided on class initialisation, they will be used here but are overriden by any passed to this method.

Note

When requesting a Pi 3, you will either get a model 3B or 3B+. It is not possible to request a particular model beyond 3 or 4. Some memory and CPU speed options are available when requesting a Pi 4.

Raises:
get_operating_systems(*, model: int) dict[str, str][source]

Return a dict of operating systems supported by the given Pi model (3 or 4). Dict keys are identifiers (e.g. “rpi-bookworm-armhf”) which can be used when provisioning a new Pi with create_pi(); dict values are text labels of the OS/distro names (e.g. “Raspberry Pi OS Bookworm (32 bit)”).

Parameters:

model (int) – The Raspberry Pi model (3 or 4) to get operating systems for (keyword-only argument)

Raises: