Pi

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

from hostedpi import Pi
class hostedpi.pi.Pi(name: str | None, *, info: PiInfoBasic, auth: MythicAuth | None = None, status_url: str | None = None)[source]

The Pi class represents a single Raspberry Pi service in the Mythic Beasts Pi cloud. Initialising a Pi object does not provision a new Pi, rather initialisation is for internal construction only.

There are two ways to get access to a Pi object: retrieval from the pis dictionary; and the return value of create_pi() method.

With a Pi object, you can access data about that particular Pi service, add SSH keys, reboot it, cancel it and more.

Note

The Pi class should not be initialised by the user, only internally within the module

property session: Session

The authenticated requests session used to communicate with the API

property info: PiInfo

The full Pi information as a PiInfo object. Always fetches the latest information from the API when this is called (with a cache timeout of 10 seconds).

Raises:
property name: str

The name of the Pi

property model: int

The Pi’s model (3 or 4)

property model_full: str | None

The Pi’s model name (3B, 3B+ or 4B)

property memory_mb: int | None

The Pi’s RAM size in MB

property memory_gb: int | None

The Pi’s RAM size in GB

property cpu_speed: int | None

The Pi’s CPU speed in MHz

property disk_size: int | None

The Pi’s disk size in GB

property nic_speed: int | None

The Pi’s NIC speed in Mbps

property status: str

A string representing the Pi’s current status (provisioning, booting, live, powered on or powered off).

property boot_progress: str

A string representing the Pi’s boot progress. Can be booted, powered off or a particular stage of the boot process if currently booting.

property initialised_keys: bool

A boolean representing whether or not the Pi has been initialised with SSH keys

property ipv4_ssh_port: int

The SSH port to use when connecting via the IPv4 proxy

property ipv6_address: IPv6Address

The Pi’s IPv6 address as an IPv6Address object

property ipv6_network: IPv6Network

The Pi’s IPv6 network as an IPv6Network object

property is_booting: bool

A boolean representing whether or not the Pi is currently booting

property location: str

The Pi’s physical location (data centre)

property power: bool

A boolean representing whether or not the Pi is currently powered on

property provision_status: str

A string representing the provision status of the Pi. Can be “provisioning”, “initialising” or “live”.

property hostname: str

The hostname of the Pi

property ipv4_ssh_hostname: str

The hostname to use when connecting to the Pi over SSH using IPv4

property ipv6_ssh_hostname: str

The hostname to use when connecting to the Pi using SSH over IPv6

property ipv4_ssh_command: str

The default SSH command required to connect to the Pi using SSH over IPv4

property ipv6_ssh_command: str

The default SSH command required to connect to the Pi using SSH over IPv6

property ipv4_ssh_config: str

A string containing the default IPv4 SSH config for the Pi. The contents could be added to an SSH config file for easy access to the Pi.

property ipv6_ssh_config: str

A string containing the default IPv6 SSH config for the Pi. The contents could be added to an SSH config file for easy access to the Pi.

property url: str

The http version of the hostedpi.com URL of the Pi.

Note

Note that a web server must be installed on the Pi for the URL to be resolvable.

property url_ssl: str

The https version of the hostedpi.com URL of the Pi.

Note

Note that a web server must be installed on the Pi for the URL to be resolvable, and an SSL certificate must be created.

See https://letsencrypt.org/

property ssh_keys: set[str]

Retrieve the SSH keys on the Pi, or use assignment to update them. Property value is a set of strings. Assigned value should also be a set of strings, or None to unset.

Raises:
on(*, wait: bool = False) bool | None[source]

Power the Pi on. If wait is False (the default), return immediately. If wait is True, wait until the power on request is completed, and return True on success, and False on failure.

Raises:
off()[source]

Power the Pi off and return immediately

Raises:
reboot(*, wait: bool = False)[source]

Reboot the Pi. If wait is False (the default), return None immediately. If wait is True, wait until the reboot request is completed, and return True on success, and False on failure.

Note

Note that if wait is False, you can poll for the boot status while rebooting by inspecting the properties is_booting and boot_progress.

Raises:
cancel()[source]

Unprovision the Pi server immediately

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

Construct an SSH command required to connect to the Pi using SSH over IPv4

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

Construct an SSH command required to connect to the Pi using SSH over IPv6

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

Construct a string containing the IPv4 SSH config for the Pi. The contents could be added to an SSH config file for easy access to the Pi.

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

Construct a string containing the SSH config for the Pi. The contents could be added to an SSH config file for easy access to the Pi.

add_ssh_keys(ssh_keys: SSHKeySources) set[str][source]

Add SSH keys to the Pi from the specified sources.

Parameters:

ssh_keys (SSHKeySources) – The sources to find keys to add to the Pi

Raises:
unimport_ssh_keys(*, github_usernames: set[str] | None = None, launchpad_usernames: set[str] | None = None) set[str][source]

Remove SSH keys that were imported from GitHub or Launchpad, and return the remaining set of keys.

Parameters:
  • github_usernames (set[str] or None) – A set of GitHub usernames to remove SSH keys for (keyword-only argument)

  • launchpad_usernames (set[str] or None) – A set of Launchpad usernames to remove SSH keys for (keyword-only argument)

Raises:
remove_ssh_keys(label: str | None = None) set[str][source]

Remove an SSH key from the Pi that has a specific label (e.g. user@hostname) and return the remaining set of keys. If label is None, all keys will be removed.

Parameters:

label (str or None) – The label of the SSH key to remove

Raises:
wait_until_provisioned()[source]

Wait for the new Pi to be provisioned

Raises:
get_provision_status() PiInfo | ProvisioningServer | None[source]

Send a request to the server creation status endpoint and return the status as either a PiInfo or ProvisioningServer or None if the status is not yet available.

Raises: