Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Manage your own Pi Cloud with hostedpi

Manage your own Pi Cloud with hostedpi

Talk given at Raspberry Pint

A1995c9abe48450ce2f82d93ca0b863f?s=128

Ben Nuttall

March 30, 2021
Tweet

Transcript

  1. @ben_nuttall Manage your own Pi Cloud with hostedpi

  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
  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
  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
  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
  6. @ben_nuttall Mythic Beasts Pi Cloud

  7. @ben_nuttall Mythic Beasts Pi Cloud

  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
  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
  10. @ben_nuttall piwheels stats • 39 million downloads total • 1

    day: – 130k downloads – 140GB bandwidth – 850k searches
  11. @ben_nuttall Mythic Beasts API

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

    | jq
  13. @ben_nuttall Python >>> url = API_URL + '/' + name

    >>> r = requests.get(url, headers=headers) >>> r.json()
  14. @ben_nuttall hostedpi • Python library • CLI • pip install

    hostedpi
  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
  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
  17. @ben_nuttall CLI - account commands • hostedpi test • hostedpi

    images • hostedpi create • hostedpi list
  18. @ben_nuttall Test the API $ hostedpi test Connected to the

    Mythic Beasts API
  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 root@ssh.mypi.hostedpi.com # IPv4 ssh root@[2a00:1098:8:5b::1] # IPv6
  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
  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
  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 root@ssh.mypi4.hostedpi.com # IPv4 ssh root@[2a00:1098:8:5b::1] # IPv6
  23. @ben_nuttall List Pis $ hostedpi list mypi mypi2 mypi3 mypi4

  24. @ben_nuttall CLI - Pi management commands • hostedpi cancel •

    hostedpi off • hostedpi on • hostedpi power • hostedpi reboot • hostedpi show • hostedpi status
  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
  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
  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 root@ssh.mypi.hostedpi.com # IPv4 ssh root@[2a00:1098:8:5b::1] # IPv6
  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
  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
  30. @ben_nuttall SSH $ hostedpi ssh-command mypi ssh -p 5091 root@ssh.mypi.hostedpi.com

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

  32. @ben_nuttall Python API reference

  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
  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)
  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
  36. @ben_nuttall Try it out! Give feedback! • Docs: – hostedpi.readthedocs.io

    • GitHub: – github.com/piwheels/hostedpi • PyPI: – pypi.org/project/hostedpi
  37. @ben_nuttall Manage your own Pi Cloud with hostedpi