$30 off During Our Annual Pro Sale. View Details »

Manage your own Pi Cloud with hostedpi

Manage your own Pi Cloud with hostedpi

Talk given at Raspberry Pint

Ben Nuttall

March 30, 2021
Tweet

More Decks by Ben Nuttall

Other Decks in Technology

Transcript

  1. @ben_nuttall
    Manage your own Pi Cloud with hostedpi

    View Slide

  2. @ben_nuttall
    Ben Nuttall

    Software Engineer at BBC News
    Labs

    Former Community Manager at
    Raspberry Pi

    Creator of gpiozero & piwheels

    twitter.com/ben_nuttall

    github.com/bennuttall

    View Slide

  3. @ben_nuttall
    GPIO Zero v1.6

    Python library

    Simple interface to GPIO devices

    New v1.6 release featuring
    rotary encoder thanks to the talk
    from Tony Smith last month!

    gpiozero.readthedocs.io

    View Slide

  4. @ben_nuttall
    Mythic Beasts

    Competent & trustworthy UK based
    hosting provider
    – Raspberry Pi OS downloads
    – Raspberry Pi apt archive

    UK based, data centres in UK, EU & US

    Range of support options

    View Slide

  5. @ben_nuttall
    Mythic Beasts Pi Cloud

    Raspberry Pi 3/4 hosting service

    Netbooted (no SD cards) with
    network storage

    IPv6-only connectivity

    IPv4 proxy

    IPv4 SSH access

    Billed monthly or on-demand

    Reinstall at any time

    View Slide

  6. @ben_nuttall
    Mythic Beasts Pi Cloud

    View Slide

  7. @ben_nuttall
    Mythic Beasts Pi Cloud

    View Slide

  8. @ben_nuttall
    piwheels

    Automated compilation of Python
    packages for Raspberry Pi hardware

    Makes "pip install" fast

    Raspberry Pi OS pre-configured to
    use piwheels.org

    First announced at Raspberry Pint in
    2017

    www.piwheels.org

    github.com/piwheels/piwheels

    View Slide

  9. @ben_nuttall
    piwheels setup

    1 x Pi 4 (previously Pi 3) with 2TB
    storage - controller software and web
    server

    5 x Pi 3 (building packages for
    Stretch)

    3 x Pi 4 (building packages for
    Buster)

    1 x VM (previously Pi 3) running
    postgres database

    View Slide

  10. @ben_nuttall
    piwheels stats

    39 million downloads total

    1 day:
    – 130k downloads
    – 140GB bandwidth
    – 850k searches

    View Slide

  11. @ben_nuttall
    Mythic Beasts API

    View Slide

  12. @ben_nuttall
    curl
    $ curl -s -H "Authorization: Bearer $TOKEN" $API_URL/$PI | jq

    View Slide

  13. @ben_nuttall
    Python
    >>> url = API_URL + '/' + name
    >>> r = requests.get(url, headers=headers)
    >>> r.json()

    View Slide

  14. @ben_nuttall
    hostedpi

    Python library

    CLI
    ● pip install hostedpi

    View Slide

  15. @ben_nuttall
    Getting started
    1. Create a Mythic Beasts account
    2. Create an API key
    3. Install hostedpi
    4. Configure API keys as
    environment variables
    5. Test your API connection

    View Slide

  16. @ben_nuttall
    CLI - commands

    hostedpi add-key

    hostedpi cancel

    hostedpi copy-keys

    hostedpi count-keys

    hostedpi create

    hostedpi images

    hostedpi keys

    hostedpi list

    hostedpi off

    hostedpi on

    hostedpi power

    hostedpi reboot

    hostedpi remove-keys

    hostedpi show

    hostedpi ssh-command

    hostedpi ssh-config

    hostedpi ssh-import-id

    hostedpi status

    hostedpi test

    View Slide

  17. @ben_nuttall
    CLI - account commands

    hostedpi test

    hostedpi images

    hostedpi create

    hostedpi list

    View Slide

  18. @ben_nuttall
    Test the API
    $ hostedpi test
    Connected to the Mythic Beasts API

    View Slide

  19. @ben_nuttall
    Provision a new Pi
    $ hostedpi create mypi
    Pi mypi provisioned successfully
    Name: mypi
    Provision status: provisioning
    Model: Raspberry Pi 3
    Disk size: 10GB
    IPv6 address: 2a00:1098:8:5b::1
    IPv6 network: 2a00:1098:8:5b00::/56
    SSH port: 5091
    Location: MER
    URLs:
    http://www.mypi.hostedpi.com
    https://www.mypi.hostedpi.com
    SSH commands:
    ssh -p 5091 [email protected] # IPv4
    ssh root@[2a00:1098:8:5b::1] # IPv6

    View Slide

  20. @ben_nuttall
    Pi 3 images
    $ hostedpi images 3
    Ubuntu 16.04 (Xenial) : ubuntu-16.04
    Ubuntu 18.04 (Bionic) : ubuntu-18.04
    Raspbian Jessie : raspbian-jessie
    Raspbian Stretch : stretch
    Raspbian Buster : raspbian-buster

    View Slide

  21. @ben_nuttall
    Pi 4 images
    $ hostedpi images 4
    Ubuntu 20.04 64 bit : ubuntu20.04.arm64
    Raspbian Buster : raspbian-buster4
    Raspberry Pi OS 64 bit : pios64b
    Ubuntu 18.04 (Bionic) : ubuntu-18.04-rpi4

    View Slide

  22. @ben_nuttall
    Provision a new Pi - with options
    $ hostedpi create mypi4 --model 4 --disk 60 --image ubuntu20.04.arm64 --ssh-key-
    path ~/.ssh/id_rsa.pub
    Pi mypi4 provisioned successfully
    Name: mypi4
    Provision status: provisioning
    Model: Raspberry Pi 4
    Disk size: 60GB
    IPv6 address: 2a00:1098:8:5b::1
    IPv6 network: 2a00:1098:8:5b00::/56
    SSH port: 5091
    Location: MER
    URLs:
    http://www.mypi4.hostedpi.com
    https://www.mypi4.hostedpi.com
    SSH commands:
    ssh -p 5091 [email protected] # IPv4
    ssh root@[2a00:1098:8:5b::1] # IPv6

    View Slide

  23. @ben_nuttall
    List Pis
    $ hostedpi list
    mypi
    mypi2
    mypi3
    mypi4

    View Slide

  24. @ben_nuttall
    CLI - Pi management commands

    hostedpi cancel

    hostedpi off

    hostedpi on

    hostedpi power

    hostedpi reboot

    hostedpi show

    hostedpi status

    View Slide

  25. @ben_nuttall
    CLI - Pi management commands
    $ hostedpi on mypi
    mypi powered on
    $ hostedpi off mypi2
    mypi2 powered off
    $ hostedpi reboot mypi3
    mypi3 rebooted
    $ hostedpi power mypi4
    mypi4: powered on
    $ hostedpi status mypi
    mypi: live
    $ hostedpi cancel mypi5
    mypi5 cancelled

    View Slide

  26. @ben_nuttall
    CLI - Pi management commands
    $ hostedpi reboot mypi mypi2 mypi3
    mypi rebooted
    mypi2 rebooted
    mypi3 rebooted
    $ hostedpi off mypi{4,5,6}
    mypi4 powered off
    mypi5 powered off
    mypi6 powered off

    View Slide

  27. @ben_nuttall
    CLI - show Pi information
    $ hostedpi show mypi
    Name: mypi
    Provision status: live
    Model: Raspberry Pi 3B
    Disk size: 10GB
    Power: off
    IPv6 address: 2a00:1098:8:5b::1
    IPv6 network: 2a00:1098:8:5b00::/56
    Initialised keys: yes
    SSH keys: 0
    IPv4 SSH port: 5091
    Location: MER
    URLs:
    http://www.mypi.hostedpi.com
    https://www.mypi.hostedpi.com
    SSH commands:
    ssh -p 5091 [email protected] # IPv4
    ssh root@[2a00:1098:8:5b::1] # IPv6

    View Slide

  28. @ben_nuttall
    CLI - Pi SSH key management commands

    hostedpi add-key

    hostedpi copy-keys

    hostedpi count-keys

    hostedpi keys

    hostedpi remove-keys

    hostedpi ssh-import-id

    View Slide

  29. @ben_nuttall
    CLI - Pi SSH key management commands
    $ hostedpi add-key ~/.ssh/id_rsa.pub mypi
    1 key added to mypi
    $ hostedpi count-keys mypi
    mypi: 4 keys
    $ hostedpi copy-keys mypi mypi2
    1 key added to mypi2
    $ hostedpi ssh-import-id mypi --gh bennuttall
    4 keys retrieved from GitHub
    4 keys added to mypi
    $ hostedpi keys mypi
    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDSkT3A1j89RT...
    $ hostedpi remove-keys mypi
    1 key removed from mypi

    View Slide

  30. @ben_nuttall
    SSH
    $ hostedpi ssh-command mypi
    ssh -p 5091 [email protected]
    $ ssh -p 5091 [email protected]
    root@raspberrypi:~#

    View Slide

  31. @ben_nuttall
    SSH
    $ `hostedpi ssh-command mypi`
    root@raspberrypi:~#

    View Slide

  32. @ben_nuttall
    Python API reference

    View Slide

  33. @ben_nuttall
    Python recipe - gpiozero button
    from hostedpi import PiCloud
    from gpiozero import Button, LED
    cloud = PiCloud()
    btn = Button(2)
    led = LED(3)
    def make_pi():
    name = "helloworld"
    cloud.create_pi(name)
    led.on()
    btn.when_pressed = make_pi

    View Slide

  34. @ben_nuttall
    Python recipe - access a web page
    from hostedpi import PiCloud
    import requests
    cloud = PiCloud()
    pi = cloud.pis['somepi']
    r = requests.get(pi.url)
    with open('pi.html', 'w') as f:
    f.write(r.text)

    View Slide

  35. @ben_nuttall
    Project status / what next?

    Continual feedback loop with Mythic Beasts

    This is a beta - API/CLI subject to change until v1.0
    release

    Test suite in progress

    Integrate into piwheels - auto scale builders
    up/down and auto re-image

    View Slide

  36. @ben_nuttall
    Try it out! Give feedback!

    Docs:
    – hostedpi.readthedocs.io

    GitHub:
    – github.com/piwheels/hostedpi

    PyPI:
    – pypi.org/project/hostedpi

    View Slide

  37. @ben_nuttall
    Manage your own Pi Cloud with hostedpi

    View Slide