Class: VagrantPlugins::Dustcloud::Action::DustcloudAPI
- Inherits:
-
Object
- Object
- VagrantPlugins::Dustcloud::Action::DustcloudAPI
- Defined in:
- lib/vagrant-dustcloud/action/connect_dustcloud.rb
Instance Method Summary collapse
- #create_vm(image, flavor) ⇒ Object
- #destroy_vm(uuid) ⇒ Object
- #get_vm(uuid) ⇒ Object
-
#initialize(api_token) ⇒ DustcloudAPI
constructor
A new instance of DustcloudAPI.
- #start_vm(uuid) ⇒ Object
- #stop_vm(uuid) ⇒ Object
Constructor Details
#initialize(api_token) ⇒ DustcloudAPI
Returns a new instance of DustcloudAPI.
30 31 32 33 34 35 |
# File 'lib/vagrant-dustcloud/action/connect_dustcloud.rb', line 30 def initialize(api_token) net = Net::HTTP.new("dust.ludd.ltu.se", 443) net.use_ssl = true @api_token = api_token @net = net end |
Instance Method Details
#create_vm(image, flavor) ⇒ Object
42 43 44 45 |
# File 'lib/vagrant-dustcloud/action/connect_dustcloud.rb', line 42 def create_vm(image, flavor) res = @net.post("/cloud/new", "image=#{image}&flavor=#{flavor}", "x-dustcloud-token" => @api_token ) JSON.parse(res.body) end |
#destroy_vm(uuid) ⇒ Object
58 59 60 61 |
# File 'lib/vagrant-dustcloud/action/connect_dustcloud.rb', line 58 def destroy_vm(uuid) res = @net.post("/cloud/vm/#{uuid}/delete", "", "x-dustcloud-token" => @api_token) JSON.parse(res.body) end |
#get_vm(uuid) ⇒ Object
37 38 39 40 |
# File 'lib/vagrant-dustcloud/action/connect_dustcloud.rb', line 37 def get_vm(uuid) res = @net.get("/cloud/vm/#{uuid}", "X-Dustcloud-Token" => @api_token ) JSON.parse(res.body) end |
#start_vm(uuid) ⇒ Object
48 49 50 51 |
# File 'lib/vagrant-dustcloud/action/connect_dustcloud.rb', line 48 def start_vm(uuid) res = @net.post("/cloud/vm/#{uuid}/start", "", "x-dustcloud-token" => @api_token) JSON.parse(res.body) end |
#stop_vm(uuid) ⇒ Object
53 54 55 56 |
# File 'lib/vagrant-dustcloud/action/connect_dustcloud.rb', line 53 def stop_vm(uuid) res = @net.post("/cloud/vm/#{uuid}/stop", "", "x-dustcloud-token" => @api_token) JSON.parse(res.body) end |