Slide 1

Slide 1 text

@ben_nuttall Manage your own Pi Cloud with hostedpi

Slide 2

Slide 2 text

@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

Slide 3

Slide 3 text

@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

Slide 4

Slide 4 text

@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

Slide 5

Slide 5 text

@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

Slide 6

Slide 6 text

@ben_nuttall Mythic Beasts Pi Cloud

Slide 7

Slide 7 text

@ben_nuttall Mythic Beasts Pi Cloud

Slide 8

Slide 8 text

@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

Slide 9

Slide 9 text

@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

Slide 10

Slide 10 text

@ben_nuttall piwheels stats ● 39 million downloads total ● 1 day: – 130k downloads – 140GB bandwidth – 850k searches

Slide 11

Slide 11 text

@ben_nuttall Mythic Beasts API

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

@ben_nuttall hostedpi ● Python library ● CLI ● pip install hostedpi

Slide 15

Slide 15 text

@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

Slide 16

Slide 16 text

@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

Slide 17

Slide 17 text

@ben_nuttall CLI - account commands ● hostedpi test ● hostedpi images ● hostedpi create ● hostedpi list

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

@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

Slide 20

Slide 20 text

@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

Slide 21

Slide 21 text

@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

Slide 22

Slide 22 text

@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

Slide 23

Slide 23 text

@ben_nuttall List Pis $ hostedpi list mypi mypi2 mypi3 mypi4

Slide 24

Slide 24 text

@ben_nuttall CLI - Pi management commands ● hostedpi cancel ● hostedpi off ● hostedpi on ● hostedpi power ● hostedpi reboot ● hostedpi show ● hostedpi status

Slide 25

Slide 25 text

@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

Slide 26

Slide 26 text

@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

Slide 27

Slide 27 text

@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

Slide 28

Slide 28 text

@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

Slide 29

Slide 29 text

@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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

@ben_nuttall Python API reference

Slide 33

Slide 33 text

@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

Slide 34

Slide 34 text

@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)

Slide 35

Slide 35 text

@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

Slide 36

Slide 36 text

@ben_nuttall Try it out! Give feedback! ● Docs: – hostedpi.readthedocs.io ● GitHub: – github.com/piwheels/hostedpi ● PyPI: – pypi.org/project/hostedpi

Slide 37

Slide 37 text

@ben_nuttall Manage your own Pi Cloud with hostedpi