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, #method_missing, #update

Methods included from Cacheable

#cacheable?, #cached_attributes, #reload

Constructor Details

This class inherits a constructor from SimpleStack::Entity

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.headers["location"].sub(/^\//, "").sub(/\/$/, "")
  entity_url = "#{connection.url}/#{entity_path}"
  new_item = SimpleStack::Guest.new hypervisor, self, entity_url
end

#disksObject



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

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

#eject_mediaObject



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

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



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

#inserted_mediaObject



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_interfacesObject



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

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

#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

#snapshotsObject



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

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

#tagsObject



15
16
17
# File 'lib/simple_stack/guest.rb', line 15

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