再接案公司用 Proxmox VE 建制簡易的練習 VM 環境,讓同事可以在需要的時候申請機器來練習使用。
Rails 串接 Proxmox VEAPI 自動化教學用虛擬機分配Photo by Franck V. on Unsplash
View Slide
WEB DEVELOPERGAME DEVELOPER࣌ݭ@elct9620
為什麼 使用 Proxmox VE?
Photo by Hal Gatewood on Unsplash接案公司
Photo by Jordan Harrison on Unsplash硬體資源不足
Photo by NESA by Makers on Unsplash技術交接容易
為什麼 要做虛擬機練習系統?
Photo by Christina @ wocintechchat.com on Unsplash熟悉 DevOps 的人太少
Photo by Jordan Sanchez on Unsplash練習的機會不多
Photo by Christian Fregnan on Unsplash人工開設虛擬機並不方便
如何用 Proxmox VE 解決 問題?
API Snapshot Qemu Agent+ +
require 'net/http'rquire 'oj'uri = URI('https:!//192.168.100.220:8006/api2/json/access/ticket')req = Net!::HTTP!::Post.newreq['Content-Type'] = 'application/x-!!www-form-urlencoded'req.body = URI.encode_!!www_form(username: '[email protected]', 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', {})endputs token['ticket'] # !=> XXXXputs token['CSRFPreventionToken'] # !=> XXX
require 'net/http'rquire 'oj'uri = URI(TICKET_URI)req = Net!::HTTP!::Post.newreq['Content-Type'] = 'application/x-!!www-form-urlencoded'req.body = URI.encode_!!www_form(username: '[email protected]',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', {})endputs token['ticket'] # !=> XXXXputs token['CSRFPreventionToken'] # !=> XXX
req = Net!::HTTP!::Get.new(uri)req['Cookie'] = "PVEAuthCookie=!#{token['ticket']}"
req = Net!::HTTP!::Post.new(uri)req['Cookie'] = "PVEAuthCookie=!#{token['ticket']}"req['CSRFPreventionToken'] = token['CSRFPreventionToken']
詳細的文件可以在 Wiki 中找到
非同步 行為處理
Proxmox!::API.post('nodes/pve/100/status/start').fetch(:data)# !=> UPID:pve:00001560:3C9C598C:5C6944F7:qmstart:100:[email protected]:
需要自己用 UPID 確認狀態
loop dostatus = task('pve', upid)break if status['exitstatus'] !== 'OK'sleep 1end
Snapshot BackupVS
如何 自動設定 SSH Key 到機器
File WriteQemu AgentVMPlayGroundGitLabPublic Key
File WriteQemu AgentVMPlayGroundGitLabPublic Key從 GitLab 取出使用者 Public Key
File WriteQemu AgentVMPlayGroundGitLabPublic Key透過 Proxmox API控制 Qemu Agent
File WriteQemu AgentVMPlayGroundGitLabPublic Key將 Public Key 寫入指定的虛擬機
預設 權限不足,需要自己調整 SELinux
THANKS