Skip to content
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 5999d63b3cafa3d5e17b1d3779302e7878cf72dd @spraints committed Jul 15, 2010
Showing with 54 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +5 −0 Gemfile
  3. +5 −0 README
  4. +13 −0 Rakefile
  5. +1 −0 lib/hyper-v.rb
  6. +4 −0 lib/hyper_v.rb
  7. +14 −0 lib/hyper_v/server.rb
  8. +11 −0 lib/hyper_v/virtual_machine.rb
1 .gitignore
@@ -0,0 +1 @@
+.*.swp
5 Gemfile
@@ -0,0 +1,5 @@
+gem 'ruby-wmi'
+
+group :rake do
+ gem 'jeweler'
+end
5 README
@@ -0,0 +1,5 @@
+A Hyper-V helper.
+
+require 'hyper_v'
+
+HyperV::Server.new('servername').virtual_machines.each { |vm| puts vm.name }
13 Rakefile
@@ -0,0 +1,13 @@
+require 'bundler'
+Bundler.setup :rake
+
+require 'jeweler'
+Jeweler::Tasks.new do |s|
+ s.name = 'hyper-v'
+ s.summary = 'Admin stuff for Microsoft Hyper-V'
+ s.description = 'Admin stuff for Microsoft Hyper-V'
+ s.email = 'spraints@gmail.com'
+ s.homepage = 'http://github.com/spraints/hyper-v'
+ s.files = FileList['[A-Z]*', '{bin,lib,test}/**/*']
+ s.add_dependency 'ruby-wmi'
+end
1 lib/hyper-v.rb
@@ -0,0 +1 @@
+require 'hyper_v'
4 lib/hyper_v.rb
@@ -0,0 +1,4 @@
+module HyperV
+ autoload :Server, 'hyper_v/server'
+ autoload :VirtualMachine, 'hyper_v/virtual_machine'
+end
14 lib/hyper_v/server.rb
@@ -0,0 +1,14 @@
+require 'ruby-wmi'
+
+module HyperV
+ class Server
+ def initialize(host)
+ @host = host
+ end
+
+ def virtual_machines
+ vms = WMI::Msvm_ComputerSystem.find(:all, :host => @host, :class => 'root\\virtualization')
+ vms.collect { |vm| VirtualMachine.new(vm) }
+ end
+ end
+end
11 lib/hyper_v/virtual_machine.rb
@@ -0,0 +1,11 @@
+module HyperV
+ class VirtualMachine
+ def initialize(vm)
+ @vm = vm
+ end
+
+ def name
+ @vm.elementName
+ end
+ end
+end

0 comments on commit 5999d63

Please sign in to comment.
Something went wrong with that request. Please try again.