Skip to content

Commit

Permalink
two-spacing and refactoring to move esx -> esxi
Browse files Browse the repository at this point in the history
  • Loading branch information
jcran committed Apr 2, 2012
1 parent 60c7268 commit e3027a2
Show file tree
Hide file tree
Showing 26 changed files with 1,845 additions and 1,747 deletions.
11 changes: 11 additions & 0 deletions config/test_lab.yml
@@ -0,0 +1,11 @@
- vmid: backtrack
driver: workstation
location: /opt/vm/backtrack5/Backtrack5x64.vmx
modifiers:
- Test
credentials:
- user: root
pass: toor
os: linux
flavor: ubuntu
arch: 64
21 changes: 21 additions & 0 deletions config/test_targets.yml
@@ -0,0 +1,21 @@
- vmid: metasploitable
driver: workstation
location: /opt/vm/lab/user/Metasploitable/Metasploitable.vmx
tools: false
credentials:
- user: msfadmin
pass: msfadmin
- vmid: windows2000_target
driver: workstation
location: /opt/vm/lab/vuln/msf_Win2000SP4/Windows 2000 AS.vmx
tools: true
credentials:
- vmid: windowsxp_target
driver: remote_workstation
host: vmhost
user: root
location: /opt/vm/lab/vuln/msf_WinXPSP1/Windows XP Professional.vmx
tools: true
credentials:
- user: administrator
pass: administrator
12 changes: 6 additions & 6 deletions lib/lab/controller/dynagen_controller.rb
Expand Up @@ -2,13 +2,13 @@ module Lab
module Controllers
module DynagenController

def self.running_list
raise "Unsupported"
end
def self.running_list
raise "Unsupported"
end

def self.dir_list(basepath=nil)
raise "Unsupported"
end
def self.dir_list(basepath=nil)
raise "Unsupported"
end
end
end
end
102 changes: 51 additions & 51 deletions lib/lab/controller/remote_esx_controller.rb
Expand Up @@ -3,60 +3,60 @@

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

def self.dir_list(basepath=nil)
# Does this method really even make sense for esx?
return "Unsupported :("
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
module RemoteEsxiController
# Note that 3.5 was different (vmware-vim-cmd)
VIM_CMD = 'vim-cmd'.freeze

def self.dir_list(basepath=nil)
# Does this method really even make sense for esx?
return "Unsupported :("
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
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
end
end
62 changes: 62 additions & 0 deletions lib/lab/controller/remote_esxi_controller.rb
@@ -0,0 +1,62 @@
# This controller was built against:
# VMware ESX Host Agent 4.1.0 build-348481

module Lab
module Controllers
module RemoteEsxiController

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

def self.dir_list(basepath=nil)
# Does this method really even make sense for esx?
return "Unsupported :("
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
end
end
24 changes: 12 additions & 12 deletions lib/lab/controller/remote_workstation_controller.rb
Expand Up @@ -2,21 +2,21 @@ module Lab
module Controllers
module RemoteWorkstationController

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

remote_cmd = "ssh #{user}@#{host} \"vmrun list nogui\""
vm_list = `#{remote_cmd}`.split("\n")
vm_list.shift
remote_cmd = "ssh #{user}@#{host} \"vmrun list nogui\""
vm_list = `#{remote_cmd}`.split("\n")
vm_list.shift

return vm_list
end
return vm_list
end

def self.dir_list(basepath=nil)
vm_list = Find.find(basepath).select { |f| f =~ /\.vmx$/ }
return vm_list
end
def self.dir_list(basepath=nil)
vm_list = Find.find(basepath).select { |f| f =~ /\.vmx$/ }
return vm_list
end
end
end
end
32 changes: 16 additions & 16 deletions lib/lab/controller/virtualbox_controller.rb
Expand Up @@ -2,24 +2,24 @@ module Lab
module Controllers
module VirtualBoxController

def self.running_list
vm_names_and_uuids = `VBoxManage list runningvms`
return vm_names_and_uuids.scan(/\"(.*)\" {.*}/).flatten
end
def self.running_list
vm_names_and_uuids = `VBoxManage list runningvms`
return vm_names_and_uuids.scan(/\"(.*)\" {.*}/).flatten
end

def self.config_list
vm_names_and_uuids = `VBoxManage list vms`
return vm_names_and_uuids.scan(/\"(.*)\" {.*}/).flatten
end
def self.config_list
vm_names_and_uuids = `VBoxManage list vms`
return vm_names_and_uuids.scan(/\"(.*)\" {.*}/).flatten
end

def self.config_list_uuid
vm_names_and_uuids = `VBoxManage list vms`
return vm_names_and_uuids.scan(/\".*\" {(.*)}/).flatten
end
def self.dir_list(basepath=nil)
vm_list = Find.find(basepath).select { |f| f =~ /\.xml$/ }
end
def self.config_list_uuid
vm_names_and_uuids = `VBoxManage list vms`
return vm_names_and_uuids.scan(/\".*\" {(.*)}/).flatten
end
def self.dir_list(basepath=nil)
vm_list = Find.find(basepath).select { |f| f =~ /\.xml$/ }
end
end
end
end
18 changes: 9 additions & 9 deletions lib/lab/controller/workstation_controller.rb
Expand Up @@ -2,16 +2,16 @@ module Lab
module Controllers
module WorkstationController

def self.running_list
vm_list = `vmrun list`.split("\n")
vm_list.shift
return vm_list
end
def self.running_list
vm_list = `vmrun list`.split("\n")
vm_list.shift
return vm_list
end

def self.dir_list(basepath=nil)
vm_list = Find.find(basepath).select { |f| f =~ /\.vmx$/ }
return vm_list
end
def self.dir_list(basepath=nil)
vm_list = Find.find(basepath).select { |f| f =~ /\.vmx$/ }
return vm_list
end
end
end
end
18 changes: 9 additions & 9 deletions lib/lab/controller/workstation_vixr_controller.rb
Expand Up @@ -2,18 +2,18 @@ module Lab
module Controllers
module WorkstationVixrController

def self.running_list
vm_list = `vmrun list`.split("\n")
vm_list.shift
def self.running_list
vm_list = `vmrun list`.split("\n")
vm_list.shift

return vm_list
end
return vm_list
end

def self.dir_list(basepath=nil)
vm_list = Find.find(basepath).select { |f| f =~ /\.vmx$/ }
def self.dir_list(basepath=nil)
vm_list = Find.find(basepath).select { |f| f =~ /\.vmx$/ }

return vm_list
end
return vm_list
end
end
end
end
4 changes: 1 addition & 3 deletions lib/lab/controllers.rb
Expand Up @@ -3,8 +3,6 @@
require 'controller/fog_controller'
require 'controller/dynagen_controller'
require 'controller/remote_workstation_controller'
require 'controller/remote_esx_controller'
require 'controller/remote_esxi_controller'
#require 'controller/qemu_controller'
#require 'controller/qemudo_controller'


0 comments on commit e3027a2

Please sign in to comment.