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

2019 - PVE 社群 - Rails 串接 Proxmox VE API 自動化教學用虛...

蒼時弦や
December 07, 2019

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

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

蒼時弦や

December 07, 2019
Tweet

More Decks by 蒼時弦や

Other Decks in Programming

Transcript

  1. 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
  2. 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' )
  3. 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
  4. File Write Qemu Agent VM PlayGround GitLab Public Key 將

    Public Key 寫入 指定的虛擬機