Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Initial commit.

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

0 comments on commit 5999d63

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