Slide 1

Slide 1 text

Rails 串接 Proxmox VE API 自動化教學用虛擬機分配 Photo by Franck V. on Unsplash

Slide 2

Slide 2 text

WEB DEVELOPER GAME DEVELOPER ૵ ࣌ ݭ໵ @elct9620

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

為什麼 使用 Proxmox VE?

Slide 5

Slide 5 text

Photo by Hal Gatewood on Unsplash 接案公司

Slide 6

Slide 6 text

Photo by Jordan Harrison on Unsplash 硬體資源不足

Slide 7

Slide 7 text

Photo by NESA by Makers on Unsplash 技術交接容易

Slide 8

Slide 8 text

為什麼 要做虛擬機練習系統?

Slide 9

Slide 9 text

Photo by Christina @ wocintechchat.com on Unsplash 熟悉 DevOps 的人太少

Slide 10

Slide 10 text

Photo by Jordan Sanchez on Unsplash 練習的機會不多

Slide 11

Slide 11 text

Photo by Christian Fregnan on Unsplash 人工開設虛擬機並不方便

Slide 12

Slide 12 text

如何用 Proxmox VE 解決 問題?

Slide 13

Slide 13 text

API Snapshot Qemu Agent + +

Slide 14

Slide 14 text

require 'net/http' rquire 'oj' uri = URI('https:!//192.168.100.220:8006/api2/json/access/ticket') req = Net!::HTTP!::Post.new req['Content-Type'] = 'application/x-!!www-form-urlencoded' req.body = URI.encode_!!www_form(username: 'xxx@pve', password: 'xxx') token = {} Net!::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| res = http.request(req) token = Oj.load(res.body)&.fetch('data', {}) end puts token['ticket'] # !=> XXXX puts token['CSRFPreventionToken'] # !=> XXX

Slide 15

Slide 15 text

require 'net/http' rquire 'oj' uri = URI(TICKET_URI) req = Net!::HTTP!::Post.new req['Content-Type'] = 'application/x-!!www-form-urlencoded' req.body = URI.encode_!!www_form( username: 'xxx@pve', password: 'xxx' )

Slide 16

Slide 16 text

token = {} Net!::HTTP.start( uri.host, uri.port, use_ssl: true ) do |http| res = http.request(req) token = Oj.load(res.body)&.fetch('data', {}) end puts token['ticket'] # !=> XXXX puts token['CSRFPreventionToken'] # !=> XXX

Slide 17

Slide 17 text

req = Net!::HTTP!::Get.new(uri) req['Cookie'] = "PVEAuthCookie=!#{token['ticket']}"

Slide 18

Slide 18 text

req = Net!::HTTP!::Post.new(uri) req['Cookie'] = "PVEAuthCookie=!#{token['ticket']}" req['CSRFPreventionToken'] = token['CSRFPreventionToken']

Slide 19

Slide 19 text

詳細的文件可以在 Wiki 中找到

Slide 20

Slide 20 text

非同步 行為處理

Slide 21

Slide 21 text

Proxmox!::API.post('nodes/pve/100/status/start') .fetch(:data) # !=> UPID:pve:00001560:3C9C598C:5C6944F7:qmstart: 100:user@pve:

Slide 22

Slide 22 text

需要自己用 UPID 確認狀態

Slide 23

Slide 23 text

loop do status = task('pve', upid) break if status['exitstatus'] !== 'OK' sleep 1 end

Slide 24

Slide 24 text

Snapshot Backup VS

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

如何 自動設定 SSH Key 到機器

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

File Write Qemu Agent VM PlayGround GitLab Public Key

Slide 30

Slide 30 text

File Write Qemu Agent VM PlayGround GitLab Public Key 從 GitLab 取出 使用者 Public Key

Slide 31

Slide 31 text

File Write Qemu Agent VM PlayGround GitLab Public Key 透過 Proxmox API 控制 Qemu Agent

Slide 32

Slide 32 text

File Write Qemu Agent VM PlayGround GitLab Public Key 將 Public Key 寫入 指定的虛擬機

Slide 33

Slide 33 text

預設 權限不足,需要自己調整 SELinux

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

THANKS