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
Piclass represents a single Raspberry Pi service in the Mythic Beasts Pi cloud. Initialising aPiobject does not provision a new Pi, rather initialisation is for internal construction only.There are two ways to get access to a
Piobject: retrieval from thepisdictionary; and the return value ofcreate_pi()method.With a
Piobject, you can access data about that particular Pi service, add SSH keys, reboot it, cancel it and more.Note
The
Piclass should not be initialised by the user, only internally within the module- property info: PiInfo
The full Pi information as a
PiInfoobject. Always fetches the latest information from the API when this is called (with a cache timeout of 10 seconds).- Raises:
HostedPiUserError – If the Pi has not been initialised with a name yet, or if the name is
NoneHostedPiNotAuthorizedError – If the user is not authorised to access the server info
HostedPiProvisioningError – If there is an error retrieving the Pi information from the API because the Pi is still provisioning
HostedPiServerError – If there is another error retrieving the Pi information from the API
- 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 offor 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 ipv6_address: IPv6Address
The Pi’s IPv6 address as an
IPv6Addressobject
- property ipv6_network: IPv6Network
The Pi’s IPv6 network as an
IPv6Networkobject
- property provision_status: str
A string representing the provision status of the Pi. Can be “provisioning”, “initialising” or “live”.
- 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.
- 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:
HostedPiNotAuthorizedError – If the user is not authorised to access the server
HostedPiProvisioningError – If the Pi is still provisioning
HostedPiServerError – If there is another error accessing the API
- on(*, wait: bool = False) bool | None[source]
Power the Pi on. If wait is
False(the default), return immediately. If wait isTrue, wait until the power on request is completed, and returnTrueon success, andFalseon failure.- Raises:
HostedPiNotAuthorizedError – If the user is not authorised to access the server
HostedPiProvisioningError – If the server is still provisioning
HostedPiServerError – If there is another error accessing the API
- off()[source]
Power the Pi off and return immediately
- Raises:
HostedPiNotAuthorizedError – If the user is not authorised to access the server
HostedPiProvisioningError – If the server is still provisioning
HostedPiServerError – If there is another error accessing the API
- reboot(*, wait: bool = False)[source]
Reboot the Pi. If wait is
False(the default), returnNoneimmediately. If wait isTrue, wait until the reboot request is completed, and returnTrueon success, andFalseon failure.Note
Note that if wait is
False, you can poll for the boot status while rebooting by inspecting the propertiesis_bootingandboot_progress.- Raises:
HostedPiNotAuthorizedError – If the user is not authorised to access the server
HostedPiServerError – If there is another error accessing the API
- cancel()[source]
Unprovision the Pi server immediately
- Raises:
HostedPiNotAuthorizedError – If the user is not authorised to access the server
HostedPiProvisioningError – If the server is still provisioning
HostedPiServerError – If there is another error accessing the API
- 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:
HostedPiNotAuthorizedError – If the user is not authorised to access the server
HostedPiProvisioningError – If the Pi is still provisioning
HostedPiServerError – If there is another error accessing the API
- 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:
- Raises:
HostedPiNotAuthorizedError – If the user is not authorised to access the server
HostedPiProvisioningError – If the Pi is still provisioning
HostedPiServerError – If there is another error accessing the API
- 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 isNone, all keys will be removed.- Parameters:
label (str or None) – The label of the SSH key to remove
- Raises:
HostedPiNotAuthorizedError – If the user is not authorised to access the server
HostedPiProvisioningError – If the Pi is still provisioning
HostedPiServerError – If there is another error accessing the API
- wait_until_provisioned()[source]
Wait for the new Pi to be provisioned
- Raises:
HostedPiNotAuthorizedError – If the user is not authorised to access the server
HostedPiServerError – If there is another error accessing the API
- get_provision_status() PiInfo | ProvisioningServer | None[source]
Send a request to the server creation status endpoint and return the status as either a
PiInfoorProvisioningServerorNoneif the status is not yet available.- Raises:
HostedPiNotAuthorizedError – If the user is not authorised to access the server
HostedPiServerError – If there is another error accessing the API