Skip to content

Commit

Permalink
back to sanity. added a console and updated the test lab
Browse files Browse the repository at this point in the history
  • Loading branch information
jcran committed Apr 3, 2012
1 parent 470d76e commit 37821c9
Show file tree
Hide file tree
Showing 39 changed files with 90 additions and 2,280 deletions.
61 changes: 61 additions & 0 deletions config/test_lab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,67 @@
credentials:
- user: root
pass: toor
admin: true
os: linux
flavor: ubuntu
arch: 64
- vmid: backtrack_remote
driver: remote_workstation
user: root
host: vmhost
modifiers:
- Test
credentials:
- user: root
pass: toor
admin: true
os: linux
flavor: ubuntu
arch: 64
###
# Windows XP SP3 - Browser Autopwn Target
###
- vmid: 222
hostname: xp
description: Windows XP SP3 - Browser Autopwn Target
driver: remote_esxi
user: root
host: vmhost1
type: target
arch: 32
os: linux
credentials:
- user: msfadmin
pass: msfadmin
admin: true
tags:
- ie6
- ie7
- ie8
- firefox
- java
- flash
- quicktime
###
# Windows 7 SP1
###
- vmid: 1111
hostname: win7
description: Windows 7 SP1 - Browser Autopwn Target
driver: remote_esxi
user: root
host: vmhost1
pass: whatever
type: target
arch: 32
os: linux
credentials:
- user: msfadmin
pass: msfadmin
admin: true
tags:
- ie8
- firefox
- java
- flash
- quicktime
48 changes: 2 additions & 46 deletions lib/lab/controller/vsphere_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,14 @@

module Lab
module Controllers
module RemoteEsxiController

# Note that 3.5 was different (vmware-vim-cmd)
VIM_CMD = 'vim-cmd'.freeze
module VsphereController

def self.dir_list(basepath=nil)
# Does this method really even make sense for esxi?
return "Unsupported :("
return "Unimplemented"
end

def self.running_list(user, host)
user.gsub!(/(\W)*/, '')
host.gsub!(/(\W)*/, '')

# first get all registered vms
registered_vms = self.get_vms(user, host) || []
running_vms = []

# now let's see which ones are running
# TODO: this is ghetto, would be better not to connect repeatedly
registered_vms.each do |vm|
remote_cmd = "ssh #{user}@#{host} \"#{VIM_CMD} vmsvc/power.getstate #{vm[:id]}\""
raw = `#{remote_cmd}`
running_vms << vm if raw =~ /Powered on/
end

return running_vms
end

private

def self.get_vms(user, host)
user.gsub!(/(\W)*/, '')
host.gsub!(/(\W)*/, '')

vms = [] # array of VM hashes
remote_cmd = "ssh #{user}@#{host} \"#{VIM_CMD} vmsvc/getallvms | grep ^[0-9] | sed 's/[[:blank:]]\\{3,\\}/ /g'\""
raw = `#{remote_cmd}`.split("\n")

raw.each do |line|
# So effing ghetto
id_and_name = line.split('[datastore').first
id = id_and_name.split(' ').first

# TODO - there's surely a better way to do this.
name_array = id_and_name.split(' ')
name_array.shift
name = name_array.join(' ')
vms << {:id => id, :name => name}
end

return vms
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/lab/driver/vsphere_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class VsphereDriver < VmDriver
def initialize(config)
unless config['user'] then raise ArgumentError, "Must provide a username" end
unless config['host'] then raise ArgumentError, "Must provide a hostname" end
unless config[''] then raise ArgumentError, "Must provide a password" end
unless config['pass'] then raise ArgumentError, "Must provide a password" end
super(config)

@user = filter_command(config['user'])
Expand All @@ -28,7 +28,7 @@ def initialize(config)
raise "WARNING: Library rbvmomi not found. Could not create driver!"
end

vim = RbVmomi::VIM.connect host: @host, user: @user, password: @pass
vim = RbVmomi::VIM.connect host: @host, user: @user, password: @pass, insecure: true
dc = vim.serviceInstance.find_datacenter("datacenter1") or fail "datacenter not found"
@vm = dc.find_vm("test") or fail "VM not found"
end
Expand Down
19 changes: 15 additions & 4 deletions lib/lab/vm_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class VmController
include Lab::Controllers::FogController
include Lab::Controllers::DynagenController
include Lab::Controllers::RemoteEsxiController
include Lab::Controllers::VsphereDriver
include Lab::Controllers::VsphereController
#include Lab::Controllers::QemuController
#include Lab::Controllers::QemudoController
def initialize (labdef=nil)
Expand All @@ -62,15 +62,19 @@ def [](x)

def find_by_vmid(search)
@vms.each do |vm|
return vm if vm.hostname.to_s.downcase == search.to_s.downcase
return vm if vm.hostname == search
end
return nil
nil
end

def find_by_hostname(search)
self.find_by_vmid search
end

def find_by_tag(search)
@vms.each do |vm|
vm.tags.each do |tag|
return vm if tag.downcase == search.to_s.downcase
return vm if tag == search
end
end
return nil
Expand Down Expand Up @@ -121,6 +125,13 @@ def includes_vmid?(vmid)
false
end

def includes_hostname?(hostname)
@vms.each do |vm|
return true if (vm.hostname == hostname)
end
false
end

#
# Build a vm lab from a directory of files. Really only useful for file-based
# vm hosts. (vmware workstation)
Expand Down
4 changes: 0 additions & 4 deletions src/Gemfile

This file was deleted.

1 change: 0 additions & 1 deletion src/Rakefile

This file was deleted.

15 changes: 0 additions & 15 deletions src/TODO

This file was deleted.

11 changes: 0 additions & 11 deletions src/config/test_lab.yml

This file was deleted.

21 changes: 0 additions & 21 deletions src/config/test_targets.yml

This file was deleted.

35 changes: 0 additions & 35 deletions src/lab.gemspec

This file was deleted.

2 changes: 0 additions & 2 deletions src/lib/lab.rb

This file was deleted.

14 changes: 0 additions & 14 deletions src/lib/lab/controller/dynagen_controller.rb

This file was deleted.

6 changes: 0 additions & 6 deletions src/lib/lab/controller/fog_controller.rb

This file was deleted.

62 changes: 0 additions & 62 deletions src/lib/lab/controller/remote_esxi_controller.rb

This file was deleted.

22 changes: 0 additions & 22 deletions src/lib/lab/controller/remote_workstation_controller.rb

This file was deleted.

Loading

0 comments on commit 37821c9

Please sign in to comment.