Class: Puter::Provider::Vm
- Inherits:
-
Object
- Object
- Puter::Provider::Vm
- Defined in:
- lib/puter/providers/vm.rb
Instance Method Summary collapse
- #build(build_path, image_path, template_name, opts, &block) ⇒ Object
- #create(image_path, instance_path, opts) ⇒ Object
- #host(name, &block) ⇒ Object
- #images(path, sub = "") ⇒ Object
- #init(path) ⇒ Object
- #kill(instance_name) ⇒ Object
- #ps(instances_path, all, sub = "") ⇒ Object
- #rm(path) ⇒ Object
- #rmi(path) ⇒ Object
- #start(instance_name, &block) ⇒ Object
- #stop(instance_name) ⇒ Object
- #vmonkey ⇒ Object
Instance Method Details
#build(build_path, image_path, template_name, opts, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/puter/providers/vm.rb', line 22 def build(build_path, image_path, template_name, opts, &block) vmonkey.folder('/').mk_parent_folder build_path template = vmonkey.vm! template_name if opts[:force] build = template.clone_to! build_path else build = template.clone_to build_path end build.start build.wait_for_port 22 block.call(build.guest_ip) if block build.stop build.MarkAsTemplate() vmonkey.folder('/').mk_parent_folder image_path if opts[:force] build.move_to! image_path else build.move_to image_path end end |
#create(image_path, instance_path, opts) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/puter/providers/vm.rb', line 51 def create(image_path, instance_path, opts) vmonkey.folder('/').mk_parent_folder instance_path if opts[:force] vmonkey.vm!(image_path).clone_to! instance_path else vmonkey.vm!(image_path).clone_to instance_path end end |
#host(name, &block) ⇒ Object
17 18 19 20 |
# File 'lib/puter/providers/vm.rb', line 17 def host(name, &block) target = vmonkey.vm! name block.call(target.guest_ip) end |
#images(path, sub = "") ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/puter/providers/vm.rb', line 8 def images(path, sub="") folder = vmonkey.folder!(path) imgs = folder.templates.collect { |t| "#{sub}#{t.name}" } folder.folders.each do |sub_folder| imgs += images("#{path}/#{sub_folder.name}", "#{sub}#{sub_folder.name}/") end imgs end |
#init(path) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/puter/providers/vm.rb', line 94 def init(path) root = vmonkey.folder '/' root.mk_folder "#{path}/Build" root.mk_folder "#{path}/Images" root.mk_folder "#{path}/Instances" end |
#kill(instance_name) ⇒ Object
73 74 75 76 |
# File 'lib/puter/providers/vm.rb', line 73 def kill(instance_name) instance = vmonkey.vm! instance_name instance.kill end |
#ps(instances_path, all, sub = "") ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/puter/providers/vm.rb', line 78 def ps(instances_path, all, sub="") folder = vmonkey.folder! instances_path instances = folder.vms instances.select! { |vm| vm.runtime.powerState == 'poweredOn' } unless all ret = instances.collect { |i| "#{sub}#{i.name}" } folder.folders.each do |sub_folder| ret += ps("#{instances_path}/#{sub_folder.name}", all, "#{sub}#{sub_folder.name}/") end ret end |
#rm(path) ⇒ Object
90 91 92 |
# File 'lib/puter/providers/vm.rb', line 90 def rm(path) vmonkey.vm!(path).destroy end |
#rmi(path) ⇒ Object
47 48 49 |
# File 'lib/puter/providers/vm.rb', line 47 def rmi(path) vmonkey.template!(path).destroy end |
#start(instance_name, &block) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/puter/providers/vm.rb', line 61 def start(instance_name, &block) instance = vmonkey.vm! instance_name instance.start instance.wait_for_port 22 block.call(instance.guest_ip) if block end |
#stop(instance_name) ⇒ Object
68 69 70 71 |
# File 'lib/puter/providers/vm.rb', line 68 def stop(instance_name) instance = vmonkey.vm! instance_name instance.stop end |
#vmonkey ⇒ Object
101 102 103 |
# File 'lib/puter/providers/vm.rb', line 101 def vmonkey @vmonkey ||= VMonkey.connect end |