Class: SimpleStack::Guest

Inherits:
Entity
  • Object
show all
Defined in:
lib/simple_stack/guest.rb

Instance Attribute Summary

Attributes inherited from Entity

#hypervisor, #parent, #url

Instance Method Summary collapse

Methods inherited from Entity

#connection, #delete, #info, #initialize, #inspect, #update

Methods included from Cacheable

#cacheable?, #cached_attributes, #reload

Constructor Details

This class inherits a constructor from SimpleStack::Entity

Instance Method Details

#add_tag(tag) ⇒ Object



11
12
13
14
15
# File 'lib/simple_stack/guest.rb', line 11

def add_tag(tag)
  cached_attributes[:tags] ||= []
  hypervisor.post "#{url}/tags", :name => tag
  cached_attributes[:tags] << tag if cached_attributes[:tags]
end

#eject_mediaObject



47
48
49
# File 'lib/simple_stack/guest.rb', line 47

def eject_media
  hypervisor.put("#{url}/media_device", :name => nil)
end

#export(opts = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/simple_stack/guest.rb', line 27

def export(opts={})
  opts = {:to => "/tmp/export_file"}.merge(opts)
  file = File.open(opts[:to], "wb")

  hypervisor.get_stream("#{url}/export", file)

  options[:to]
ensure
  file.close rescue nil
end

#insert_media(media_name, opts = {}) ⇒ Object



42
43
44
45
# File 'lib/simple_stack/guest.rb', line 42

def insert_media(media_name, opts={})
  media_options = opts.merge(:name => media_name)
  hypervisor.put("#{url}/media_device", media_options)
end

#inserted_mediaObject



51
52
53
# File 'lib/simple_stack/guest.rb', line 51

def inserted_media
  hypervisor.get("#{url}/media_device").parsed_response["name"]
end

#power_state=(state) ⇒ Object



55
56
57
# File 'lib/simple_stack/guest.rb', line 55

def power_state=(state)
  hypervisor.put "#{url}/power", :state => state
end

#reboot(opts = {:force => false}) ⇒ Object



23
24
25
# File 'lib/simple_stack/guest.rb', line 23

def reboot(opts={:force => false})
  hypervisor.put "#{url}/reboot", :force => opts[:force]
end

#remove_tag(tag) ⇒ Object



17
18
19
20
21
# File 'lib/simple_stack/guest.rb', line 17

def remove_tag(tag)
  cached_attributes[:tags] ||= []
  hypervisor.delete "#{url}/tags/#{tag}"
  cached_attributes[:tags].delete tag if cached_attributes[:tags]
end

#revert_to(snapshot) ⇒ Object



38
39
40
# File 'lib/simple_stack/guest.rb', line 38

def revert_to(snapshot)
  snapshot.revert
end

#snapshotsObject



3
4
5
# File 'lib/simple_stack/guest.rb', line 3

def snapshots
  cached_attributes[:snapshots] ||= SimpleStack::Collection.new hypervisor, self, "#{url}/snapshots", SimpleStack::Snapshot
end

#tagsObject



7
8
9
# File 'lib/simple_stack/guest.rb', line 7

def tags
  cached_attributes[:tags] ||= hypervisor.get("#{url}/tags").parsed_response
end