2019 - PVE 社群 - Rails 串接 Proxmox VE API 自動化教學用虛擬機分配

888339de9e7a88688b6acb30d33e66cd?s=47 蒼時弦や
December 07, 2019

2019 - PVE 社群 - Rails 串接 Proxmox VE API 自動化教學用虛擬機分配

再接案公司用 Proxmox VE 建制簡易的練習 VM 環境,讓同事可以在需要的時候申請機器來練習使用。

888339de9e7a88688b6acb30d33e66cd?s=128

蒼時弦や

December 07, 2019
Tweet

Transcript

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

    on Unsplash
  2. WEB DEVELOPER GAME DEVELOPER ૵ ࣌ ݭ໵ @elct9620

  3. None
  4. 為什麼 使用 Proxmox VE?

  5. Photo by Hal Gatewood on Unsplash 接案公司

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

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

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

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

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

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

  12. 如何用 Proxmox VE 解決 問題?

  13. API Snapshot Qemu Agent + +

  14. 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
  15. 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' )
  16. 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
  17. req = Net!::HTTP!::Get.new(uri) req['Cookie'] = "PVEAuthCookie=!#{token['ticket']}"

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

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

  20. 非同步 行為處理

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

  22. 需要自己用 UPID 確認狀態

  23. loop do status = task('pve', upid) break if status['exitstatus'] !==

    'OK' sleep 1 end
  24. Snapshot Backup VS

  25. None
  26. 如何 自動設定 SSH Key 到機器

  27. None
  28. None
  29. File Write Qemu Agent VM PlayGround GitLab Public Key

  30. File Write Qemu Agent VM PlayGround GitLab Public Key 從

    GitLab 取出 使用者 Public Key
  31. File Write Qemu Agent VM PlayGround GitLab Public Key 透過

    Proxmox API 控制 Qemu Agent
  32. File Write Qemu Agent VM PlayGround GitLab Public Key 將

    Public Key 寫入 指定的虛擬機
  33. 預設 權限不足,需要自己調整 SELinux

  34. None
  35. THANKS