Class: PoolParty::Remote::Libvirt
- Inherits:
-
RemoterBase
- Object
- RemoterBase
- PoolParty::Remote::Libvirt
- Includes:
- Dslify
- Defined in:
- lib/poolparty/net/remoter_bases/libvirt/libvirt.rb
Class Method Summary collapse
- .describe_instance(o = {}) ⇒ Object
-
.describe_instances(o = {}) ⇒ Object
Returns an array of instance name => state For example: [=>“shut off”, =>“shut off”, =>“running”].
- .launch_new_instance!(o = {}) ⇒ Object
-
.terminate_instance!(o = {}) ⇒ Object
Terminate an instance by id.
- .virsh ⇒ Object
Instance Method Summary collapse
-
#after_launched(force = false) ⇒ Object
After launch callback This is called after a new instance is launched.
-
#before_shutdown ⇒ Object
Before shutdown callback This is called before the cloud is contracted.
- #describe_instance(o = {}) ⇒ Object
- #describe_instances(o = {}) ⇒ Object
-
#initialize(opts = {}, &block) ⇒ Libvirt
constructor
A new instance of Libvirt.
- #launch_new_instance!(o = {}) ⇒ Object
- #terminate_instance!(o = {}) ⇒ Object
Methods inherited from RemoterBase
#after_launch_instance, available_bases, #cloud, inherited, #key_name, #keypair, #launch_instance!, launch_instance!, #remoter_base_options, symbol, #terminate_youngest_instance!, #to_hash, #to_s
Methods included from Pinger
Methods included from PoolParty::Remote
#are_any_nodes_exceeding_minimum_runtime?, #are_too_few_instances_running?, #are_too_many_instances_running?, available, #commands, #execute!, #list_of_instances, #list_of_nodes_exceeding_minimum_runtime, #netssh, #nodes, #remote_rsync_command, #remote_ssh_array, #remote_ssh_string, #rsync, #rsync_command, #rsync_storage_files_to, #rsync_storage_files_to_command, #rsync_to, #rsync_to_command, #run_command_on, #run_command_on_command, #run_command_on_instance_number, #run_local, #run_remote, #scp_array, #scp_to_command, #simplest_run_remote, #ssh_array, #ssh_command, #ssh_into, #ssh_into_instance_number, #ssh_options, #ssh_string, #target_host
Constructor Details
#initialize(opts = {}, &block) ⇒ Libvirt
Returns a new instance of Libvirt.
13 14 15 16 |
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt.rb', line 13 def initialize(opts={}, &block) opts super end |
Class Method Details
.describe_instance(o = {}) ⇒ Object
33 34 35 |
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt.rb', line 33 def self.describe_instance(o={}) new(o).describe_instance end |
.describe_instances(o = {}) ⇒ Object
Returns an array of instance name => state For example:
[{"i-3687065A" =>"shut off"},
{"jaunty19" =>"shut off"},
{"jauntykvm" =>"running"}]
45 46 47 |
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt.rb', line 45 def self.describe_instances(o={}) new(o).describe_instances end |
.launch_new_instance!(o = {}) ⇒ Object
18 19 20 |
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt.rb', line 18 def self.launch_new_instance!(o={}) new(o).launch_new_instance! end |
.terminate_instance!(o = {}) ⇒ Object
Terminate an instance by id
26 27 28 |
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt.rb', line 26 def self.terminate_instance!(o={}) new(o).terminate_instance! end |
.virsh ⇒ Object
67 68 69 |
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt.rb', line 67 def self.virsh new({}).path_to_binary end |
Instance Method Details
#after_launched(force = false) ⇒ Object
After launch callback This is called after a new instance is launched
59 60 61 |
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt.rb', line 59 def after_launched(force=false) puts "new instance was launched" end |
#before_shutdown ⇒ Object
Before shutdown callback This is called before the cloud is contracted
65 66 |
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt.rb', line 65 def before_shutdown end |
#describe_instance(o = {}) ⇒ Object
36 37 38 |
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt.rb', line 36 def describe_instance(o={}) LibvirtInstance.new(o).description end |
#describe_instances(o = {}) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt.rb', line 48 def describe_instances(o={}) output = `virsh list`.split("\n") return [] if output.empty? || output.size < 3 output[2..-1].collect do |i| d=i.split(' ') LibvirtInstance.new(:name => d[1], :status => d[2..-1].join(' ')) end end |
#launch_new_instance!(o = {}) ⇒ Object
21 22 23 24 |
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt.rb', line 21 def launch_new_instance!(o={}) `virsh start #{image_id}` describe_instance :image_id=>image_id end |
#terminate_instance!(o = {}) ⇒ Object
29 30 31 |
# File 'lib/poolparty/net/remoter_bases/libvirt/libvirt.rb', line 29 def terminate_instance!(o={}) `virsh shutdown #{image_id}` end |