Class: SimpleStack::Guest
Instance Attribute Summary
Attributes inherited from Entity
#hypervisor, #parent, #url
Instance Method Summary
collapse
Methods inherited from Entity
#connection, #delete, #info, #initialize, #inspect, #method_missing, #update
Methods included from Cacheable
#cacheable?, #cached_attributes, #reload
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class SimpleStack::Entity
Instance Method Details
#add_tag(tag) ⇒ Object
19
20
21
22
23
|
# File 'lib/simple_stack/guest.rb', line 19
def add_tag(tag)
hypervisor.post "#{url}/tags", :name => tag
reload if cacheable?
tag
end
|
#clone(opts = {}) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/simple_stack/guest.rb', line 50
def clone(opts={})
response = hypervisor.post("#{url}/clone", opts)
entity_path = response.["location"].sub(/^\//, "").sub(/\/$/, "")
entity_url = "#{connection.url}/#{entity_path}"
new_item = SimpleStack::Guest.new hypervisor, self, entity_url
end
|
63
64
65
66
|
# File 'lib/simple_stack/guest.rb', line 63
def eject_media
hypervisor.put("#{url}/media_device", :name => nil)
reload if cacheable?
end
|
#export(opts = {}) ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/simple_stack/guest.rb', line 35
def export(opts={})
opts = {:to => "/tmp/export_file"}.merge(opts)
file = File.open(opts[:to], "wb")
hypervisor.get_stream("#{url}/export", file)
opts[:to]
ensure
file.close rescue nil
end
|
57
58
59
60
61
|
# File 'lib/simple_stack/guest.rb', line 57
def insert_media(media_name, opts={})
media_options = opts.merge(:name => media_name)
hypervisor.put("#{url}/media_device", media_options)
reload if cacheable?
end
|
68
69
70
71
72
73
74
|
# File 'lib/simple_stack/guest.rb', line 68
def inserted_media
if cached_attributes.key? :inserted_media
cached_attributes[:inserted_media]
else
cached_attributes[:inserted_media] = hypervisor.get("#{url}/media_device").parsed_response["name"]
end
end
|
#network_interfaces ⇒ Object
#power_state=(state) ⇒ Object
76
77
78
|
# File 'lib/simple_stack/guest.rb', line 76
def power_state=(state)
hypervisor.put "#{url}/power", :state => state
end
|
#reboot(opts = {:force => false}) ⇒ Object
31
32
33
|
# File 'lib/simple_stack/guest.rb', line 31
def reboot(opts={:force => false})
hypervisor.put "#{url}/reboot", :force => opts[:force]
end
|
#remove_tag(tag) ⇒ Object
25
26
27
28
29
|
# File 'lib/simple_stack/guest.rb', line 25
def remove_tag(tag)
hypervisor.delete "#{url}/tags/#{tag}"
reload if cacheable?
tag
end
|
#revert_to(snapshot) ⇒ Object
46
47
48
|
# File 'lib/simple_stack/guest.rb', line 46
def revert_to(snapshot)
snapshot.revert
end
|
15
16
17
|
# File 'lib/simple_stack/guest.rb', line 15
def tags
cached_attributes[:tags] ||= hypervisor.get("#{url}/tags").parsed_response
end
|