mirror of
https://github.com/puppetlabs/vmpooler-provider-vsphere.git
synced 2026-01-25 19:08:41 -05:00
Initial commit migrating from VMPooler proper
This copies in all needed files from the main VMPooler repo. Version 1.3.0 of VMPooler was used as the basis for this code.
This commit is contained in:
commit
a08cba099f
19 changed files with 11422 additions and 0 deletions
8
.github/dependabot.yml
vendored
Normal file
8
.github/dependabot.yml
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: bundler
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
time: "13:00"
|
||||
open-pull-requests-limit: 10
|
||||
47
.github/workflows/testing.yml
vendored
Normal file
47
.github/workflows/testing.yml
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# This workflow uses actions that are not certified by GitHub.
|
||||
# They are provided by a third-party and are governed by
|
||||
# separate terms of service, privacy policy, and support
|
||||
# documentation.
|
||||
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
||||
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
||||
|
||||
name: Testing
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
rubocop:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
ruby-version:
|
||||
- '2.5.8'
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Ruby
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: ${{ matrix.ruby-version }}
|
||||
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
||||
- name: Run Rubocop
|
||||
run: bundle exec rake rubocop
|
||||
|
||||
spec_tests:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
ruby-version:
|
||||
- '2.5.8'
|
||||
- 'jruby-9.2.12.0'
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Ruby
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: ${{ matrix.ruby-version }}
|
||||
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
||||
- name: Run spec tests
|
||||
run: bundle exec rake test
|
||||
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
.bundle/
|
||||
.vagrant/
|
||||
coverage/
|
||||
vendor/
|
||||
.dccache
|
||||
.ruby-version
|
||||
Gemfile.local
|
||||
results.xml
|
||||
/vmpooler.yaml
|
||||
|
||||
10
CODEOWNERS
Normal file
10
CODEOWNERS
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
# This will cause DIO to be assigned review of any opened PRs against
|
||||
# the branches containing this file.
|
||||
# See https://help.github.com/en/articles/about-code-owners for info on how to
|
||||
# take ownership of parts of the code base that should be reviewed by another
|
||||
# team.
|
||||
|
||||
# DIO will be the default owners for everything in the repo.
|
||||
* @puppetlabs/dio
|
||||
|
||||
13
Gemfile
Normal file
13
Gemfile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
source ENV['GEM_SOURCE'] || 'https://rubygems.org'
|
||||
|
||||
gemspec
|
||||
|
||||
# Evaluate Gemfile.local if it exists
|
||||
if File.exists? "#{__FILE__}.local"
|
||||
instance_eval(File.read("#{__FILE__}.local"))
|
||||
end
|
||||
|
||||
# Evaluate ~/.gemfile if it exists
|
||||
if File.exists?(File.join(Dir.home, '.gemfile'))
|
||||
instance_eval(File.read(File.join(Dir.home, '.gemfile')))
|
||||
end
|
||||
191
Gemfile.lock
Normal file
191
Gemfile.lock
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
vmpooler-vsphere-provider (1.3.0)
|
||||
rbvmomi (>= 2.1, < 4.0)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
ast (2.4.2)
|
||||
bindata (2.4.10)
|
||||
builder (3.2.4)
|
||||
climate_control (1.0.1)
|
||||
coderay (1.1.3)
|
||||
concurrent-ruby (1.1.9)
|
||||
connection_pool (2.2.5)
|
||||
diff-lcs (1.4.4)
|
||||
docile (1.4.0)
|
||||
faraday (1.8.0)
|
||||
faraday-em_http (~> 1.0)
|
||||
faraday-em_synchrony (~> 1.0)
|
||||
faraday-excon (~> 1.1)
|
||||
faraday-httpclient (~> 1.0.1)
|
||||
faraday-net_http (~> 1.0)
|
||||
faraday-net_http_persistent (~> 1.1)
|
||||
faraday-patron (~> 1.0)
|
||||
faraday-rack (~> 1.0)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
ruby2_keywords (>= 0.0.4)
|
||||
faraday-em_http (1.0.0)
|
||||
faraday-em_synchrony (1.0.0)
|
||||
faraday-excon (1.1.0)
|
||||
faraday-httpclient (1.0.1)
|
||||
faraday-net_http (1.0.1)
|
||||
faraday-net_http_persistent (1.2.0)
|
||||
faraday-patron (1.0.0)
|
||||
faraday-rack (1.0.0)
|
||||
google-cloud-env (1.5.0)
|
||||
faraday (>= 0.17.3, < 2.0)
|
||||
json (2.6.1)
|
||||
method_source (1.0.0)
|
||||
mock_redis (0.29.0)
|
||||
ruby2_keywords
|
||||
multipart-post (2.1.1)
|
||||
mustermann (1.1.1)
|
||||
ruby2_keywords (~> 0.0.1)
|
||||
net-ldap (0.17.0)
|
||||
nio4r (2.5.8)
|
||||
nokogiri (1.12.5-x86_64-linux)
|
||||
racc (~> 1.4)
|
||||
opentelemetry-api (0.17.0)
|
||||
opentelemetry-common (0.17.0)
|
||||
opentelemetry-api (~> 0.17.0)
|
||||
opentelemetry-exporter-jaeger (0.17.0)
|
||||
opentelemetry-api (~> 0.17.0)
|
||||
opentelemetry-common (~> 0.17.0)
|
||||
opentelemetry-sdk (~> 0.17.0)
|
||||
thrift
|
||||
opentelemetry-instrumentation-base (0.17.0)
|
||||
opentelemetry-api (~> 0.17.0)
|
||||
opentelemetry-instrumentation-concurrent_ruby (0.17.0)
|
||||
opentelemetry-api (~> 0.17.0)
|
||||
opentelemetry-instrumentation-base (~> 0.17.0)
|
||||
opentelemetry-instrumentation-redis (0.17.0)
|
||||
opentelemetry-api (~> 0.17.0)
|
||||
opentelemetry-common (~> 0.17.0)
|
||||
opentelemetry-instrumentation-base (~> 0.17.0)
|
||||
opentelemetry-instrumentation-sinatra (0.17.0)
|
||||
opentelemetry-api (~> 0.17.0)
|
||||
opentelemetry-instrumentation-base (~> 0.17.0)
|
||||
opentelemetry-resource_detectors (0.17.0)
|
||||
google-cloud-env
|
||||
opentelemetry-sdk
|
||||
opentelemetry-sdk (0.17.0)
|
||||
opentelemetry-api (~> 0.17.0)
|
||||
opentelemetry-common (~> 0.17.0)
|
||||
opentelemetry-instrumentation-base (~> 0.17.0)
|
||||
optimist (3.0.1)
|
||||
parallel (1.21.0)
|
||||
parser (3.0.3.1)
|
||||
ast (~> 2.4.1)
|
||||
pickup (0.0.11)
|
||||
prometheus-client (2.1.0)
|
||||
pry (0.14.1)
|
||||
coderay (~> 1.1)
|
||||
method_source (~> 1.0)
|
||||
puma (5.5.2)
|
||||
nio4r (~> 2.0)
|
||||
racc (1.6.0)
|
||||
rack (2.2.3)
|
||||
rack-protection (2.1.0)
|
||||
rack
|
||||
rack-test (1.1.0)
|
||||
rack (>= 1.0, < 3)
|
||||
rainbow (3.0.0)
|
||||
rake (13.0.6)
|
||||
rbvmomi (3.0.0)
|
||||
builder (~> 3.2)
|
||||
json (~> 2.3)
|
||||
nokogiri (~> 1.10)
|
||||
optimist (~> 3.0)
|
||||
redis (4.5.1)
|
||||
regexp_parser (2.1.1)
|
||||
rexml (3.2.5)
|
||||
rspec (3.10.0)
|
||||
rspec-core (~> 3.10.0)
|
||||
rspec-expectations (~> 3.10.0)
|
||||
rspec-mocks (~> 3.10.0)
|
||||
rspec-core (3.10.1)
|
||||
rspec-support (~> 3.10.0)
|
||||
rspec-expectations (3.10.1)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.10.0)
|
||||
rspec-mocks (3.10.2)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.10.0)
|
||||
rspec-support (3.10.3)
|
||||
rubocop (1.1.0)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 2.7.1.5)
|
||||
rainbow (>= 2.2.2, < 4.0)
|
||||
regexp_parser (>= 1.8)
|
||||
rexml
|
||||
rubocop-ast (>= 1.0.1)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (>= 1.4.0, < 2.0)
|
||||
rubocop-ast (1.13.0)
|
||||
parser (>= 3.0.1.1)
|
||||
ruby-progressbar (1.11.0)
|
||||
ruby2_keywords (0.0.5)
|
||||
simplecov (0.21.2)
|
||||
docile (~> 1.1)
|
||||
simplecov-html (~> 0.11)
|
||||
simplecov_json_formatter (~> 0.1)
|
||||
simplecov-html (0.12.3)
|
||||
simplecov_json_formatter (0.1.3)
|
||||
sinatra (2.1.0)
|
||||
mustermann (~> 1.0)
|
||||
rack (~> 2.2)
|
||||
rack-protection (= 2.1.0)
|
||||
tilt (~> 2.0)
|
||||
spicy-proton (2.1.13)
|
||||
bindata (~> 2.3)
|
||||
statsd-ruby (1.5.0)
|
||||
thor (1.1.0)
|
||||
thrift (0.15.0)
|
||||
tilt (2.0.10)
|
||||
unicode-display_width (1.8.0)
|
||||
vmpooler (1.3.0)
|
||||
concurrent-ruby (~> 1.1)
|
||||
connection_pool (~> 2.2)
|
||||
net-ldap (~> 0.16)
|
||||
nokogiri (~> 1.10)
|
||||
opentelemetry-exporter-jaeger (= 0.17.0)
|
||||
opentelemetry-instrumentation-concurrent_ruby (= 0.17.0)
|
||||
opentelemetry-instrumentation-redis (= 0.17.0)
|
||||
opentelemetry-instrumentation-sinatra (= 0.17.0)
|
||||
opentelemetry-resource_detectors (= 0.17.0)
|
||||
opentelemetry-sdk (= 0.17.0)
|
||||
pickup (~> 0.0.11)
|
||||
prometheus-client (~> 2.0)
|
||||
puma (~> 5.0, >= 5.0.4)
|
||||
rack (~> 2.2)
|
||||
rake (~> 13.0)
|
||||
rbvmomi (>= 2.1, < 4.0)
|
||||
redis (~> 4.1)
|
||||
sinatra (~> 2.0)
|
||||
spicy-proton (~> 2.1)
|
||||
statsd-ruby (~> 1.4)
|
||||
yarjuf (2.0.0)
|
||||
builder
|
||||
rspec (~> 3)
|
||||
|
||||
PLATFORMS
|
||||
x86_64-linux
|
||||
|
||||
DEPENDENCIES
|
||||
climate_control (>= 0.2.0)
|
||||
mock_redis (>= 0.17.0)
|
||||
pry
|
||||
rack-test (>= 0.6)
|
||||
rspec (>= 3.2)
|
||||
rubocop (~> 1.1.0)
|
||||
simplecov (>= 0.11.2)
|
||||
thor (~> 1.0, >= 1.0.1)
|
||||
vmpooler (~> 1.3, >= 1.3.0)
|
||||
vmpooler-vsphere-provider!
|
||||
yarjuf (>= 2.0)
|
||||
|
||||
BUNDLED WITH
|
||||
2.2.22
|
||||
3
README.md
Normal file
3
README.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# vmpooler-vsphere-provider
|
||||
|
||||
This is a WIP - do not use yet. The goal is to extract the vSphere provider from the main VMPooler codebase. Force pushes to this repo may happen while initial development is happening.
|
||||
25
Rakefile
Normal file
25
Rakefile
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
require 'rspec/core/rake_task'
|
||||
|
||||
rubocop_available = Gem::Specification::find_all_by_name('rubocop').any?
|
||||
require 'rubocop/rake_task' if rubocop_available
|
||||
|
||||
desc 'Run rspec tests with coloring.'
|
||||
RSpec::Core::RakeTask.new(:test) do |t|
|
||||
t.rspec_opts = %w[--color --format documentation]
|
||||
t.pattern = 'spec/'
|
||||
end
|
||||
|
||||
desc 'Run rspec tests and save JUnit output to results.xml.'
|
||||
RSpec::Core::RakeTask.new(:junit) do |t|
|
||||
t.rspec_opts = %w[-r yarjuf -f JUnit -o results.xml]
|
||||
t.pattern = 'spec/'
|
||||
end
|
||||
|
||||
if rubocop_available
|
||||
desc 'Run RuboCop'
|
||||
RuboCop::RakeTask.new(:rubocop) do |task|
|
||||
task.options << '--display-cop-names'
|
||||
end
|
||||
end
|
||||
|
||||
task :default => [:test]
|
||||
5
lib/vmpooler-vsphere-provider/version.rb
Normal file
5
lib/vmpooler-vsphere-provider/version.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module VmpoolerVsphereProvider
|
||||
VERSION = '1.3.0'
|
||||
end
|
||||
1173
lib/vmpooler/providers/vsphere.rb
Normal file
1173
lib/vmpooler/providers/vsphere.rb
Normal file
File diff suppressed because it is too large
Load diff
98
scripts/create_template_deltas.rb
Executable file
98
scripts/create_template_deltas.rb
Executable file
|
|
@ -0,0 +1,98 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
require 'rubygems'
|
||||
require 'rbvmomi'
|
||||
require 'yaml'
|
||||
|
||||
def load_configuration( file_array )
|
||||
file_array.each do |file|
|
||||
file = File.expand_path( file )
|
||||
|
||||
if File.exists?( file )
|
||||
return YAML.load_file( file )
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
def create_template_deltas( folder )
|
||||
config = load_configuration( [ 'vmpooler.yaml', '~/.vmpooler' ] ) || nil
|
||||
|
||||
abort 'No config file (./vmpooler.yaml or ~/.vmpooler) found!' unless config
|
||||
|
||||
vim = RbVmomi::VIM.connect(
|
||||
:host => config[ :providers ][ :vsphere ][ "server" ],
|
||||
:user => config[ :providers ][ :vsphere ][ "username" ],
|
||||
:password => config[ :providers ][ :vsphere ][ "password" ],
|
||||
:ssl => true,
|
||||
:insecure => true,
|
||||
) or abort "Unable to connect to #{config[ :vsphere ][ "server" ]}!"
|
||||
|
||||
containerView = vim.serviceContent.viewManager.CreateContainerView( {
|
||||
:container => vim.serviceContent.rootFolder,
|
||||
:recursive => true,
|
||||
:type => [ 'VirtualMachine' ]
|
||||
} )
|
||||
|
||||
datacenter = vim.serviceInstance.find_datacenter
|
||||
base = datacenter.vmFolder
|
||||
|
||||
case base
|
||||
when RbVmomi::VIM::Folder
|
||||
base = base.childEntity.find { |f| f.name == folder }
|
||||
else
|
||||
abort "Unexpected object type encountered (#{base.class}) while finding folder!"
|
||||
end
|
||||
|
||||
unless base
|
||||
abort "Folder #{ARGV[0]} not found!"
|
||||
end
|
||||
|
||||
base.childEntity.each do |vm|
|
||||
print vm.name
|
||||
|
||||
begin
|
||||
disks = vm.config.hardware.device.grep( RbVmomi::VIM::VirtualDisk )
|
||||
rescue
|
||||
puts ' !'
|
||||
next
|
||||
end
|
||||
|
||||
begin
|
||||
disks.select { |d| d.backing.parent == nil }.each do |disk|
|
||||
linkSpec = {
|
||||
:deviceChange => [
|
||||
{
|
||||
:operation => :remove,
|
||||
:device => disk
|
||||
},
|
||||
{
|
||||
:operation => :add,
|
||||
:fileOperation => :create,
|
||||
:device => disk.dup.tap { |x|
|
||||
x.backing = x.backing.dup
|
||||
x.backing.fileName = "[#{disk.backing.datastore.name}]"
|
||||
x.backing.parent = disk.backing
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
vm.ReconfigVM_Task( :spec => linkSpec ).wait_for_completion
|
||||
end
|
||||
|
||||
puts " \u2713"
|
||||
rescue
|
||||
puts ' !'
|
||||
end
|
||||
end
|
||||
|
||||
vim.close
|
||||
end
|
||||
|
||||
if ARGV[0]
|
||||
create_template_deltas( ARGV[0] )
|
||||
else
|
||||
puts "Usage: #{$0} <folder>"
|
||||
end
|
||||
43
spec/fixtures/vmpooler.yaml
vendored
Normal file
43
spec/fixtures/vmpooler.yaml
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
---
|
||||
:providers:
|
||||
:dummy:
|
||||
|
||||
:redis:
|
||||
server: 'localhost'
|
||||
|
||||
:auth:
|
||||
provider: dummy
|
||||
|
||||
:tagfilter:
|
||||
url: '(.*)\/'
|
||||
|
||||
:config:
|
||||
site_name: 'vmpooler'
|
||||
# Need to change this on Windows
|
||||
logfile: '/var/log/vmpooler.log'
|
||||
task_limit: 10
|
||||
timeout: 15
|
||||
vm_checktime: 1
|
||||
vm_lifetime: 12
|
||||
vm_lifetime_auth: 24
|
||||
allowed_tags:
|
||||
- 'created_by'
|
||||
- 'project'
|
||||
domain: 'example.com'
|
||||
prefix: 'poolvm-'
|
||||
|
||||
# Uncomment the lines below to suppress metrics to STDOUT
|
||||
# :statsd:
|
||||
# server: 'localhost'
|
||||
# prefix: 'vmpooler'
|
||||
# port: 8125
|
||||
|
||||
:pools:
|
||||
- name: 'pool01'
|
||||
size: 5
|
||||
provider: dummy
|
||||
ready_ttl: 5
|
||||
- name: 'pool02'
|
||||
size: 5
|
||||
provider: dummy
|
||||
ready_ttl: 5
|
||||
43
spec/fixtures/vmpooler2.yaml
vendored
Normal file
43
spec/fixtures/vmpooler2.yaml
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
---
|
||||
:providers:
|
||||
:dummy:
|
||||
|
||||
:redis:
|
||||
server: 'localhost'
|
||||
|
||||
:auth:
|
||||
provider: dummy
|
||||
|
||||
:tagfilter:
|
||||
url: '(.*)\/'
|
||||
|
||||
:config:
|
||||
site_name: 'vmpooler'
|
||||
# Need to change this on Windows
|
||||
logfile: '/var/log/vmpooler.log'
|
||||
task_limit: 10
|
||||
timeout: 15
|
||||
vm_checktime: 1
|
||||
vm_lifetime: 12
|
||||
vm_lifetime_auth: 24
|
||||
allowed_tags:
|
||||
- 'created_by'
|
||||
- 'project'
|
||||
domain: 'example.com'
|
||||
prefix: 'poolvm-'
|
||||
|
||||
# Uncomment the lines below to suppress metrics to STDOUT
|
||||
# :statsd:
|
||||
# server: 'localhost'
|
||||
# prefix: 'vmpooler'
|
||||
# port: 8125
|
||||
|
||||
:pools:
|
||||
- name: 'pool03'
|
||||
size: 5
|
||||
provider: dummy
|
||||
ready_ttl: 5
|
||||
- name: 'pool04'
|
||||
size: 5
|
||||
provider: dummy
|
||||
ready_ttl: 5
|
||||
154
spec/helpers.rb
Normal file
154
spec/helpers.rb
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
require 'mock_redis'
|
||||
|
||||
def redis
|
||||
unless @redis
|
||||
@redis = MockRedis.new
|
||||
end
|
||||
@redis
|
||||
end
|
||||
|
||||
# Mock an object which represents a Logger. This stops the proliferation
|
||||
# of allow(logger).to .... expectations in tests.
|
||||
class MockLogger
|
||||
def log(_level, string)
|
||||
end
|
||||
end
|
||||
|
||||
def expect_json(ok = true, http = 200)
|
||||
expect(last_response.header['Content-Type']).to eq('application/json')
|
||||
|
||||
if (ok == true) then
|
||||
expect(JSON.parse(last_response.body)['ok']).to eq(true)
|
||||
else
|
||||
expect(JSON.parse(last_response.body)['ok']).to eq(false)
|
||||
end
|
||||
|
||||
expect(last_response.status).to eq(http)
|
||||
end
|
||||
|
||||
def create_token(token, user, timestamp)
|
||||
redis.hset("vmpooler__token__#{token}", 'user', user)
|
||||
redis.hset("vmpooler__token__#{token}", 'created', timestamp)
|
||||
end
|
||||
|
||||
def get_token_data(token)
|
||||
redis.hgetall("vmpooler__token__#{token}")
|
||||
end
|
||||
|
||||
def token_exists?(token)
|
||||
result = get_token_data
|
||||
result && !result.empty?
|
||||
end
|
||||
|
||||
def create_ready_vm(template, name, redis, token = nil)
|
||||
create_vm(name, redis, token)
|
||||
redis.sadd("vmpooler__ready__#{template}", name)
|
||||
redis.hset("vmpooler__vm__#{name}", "template", template)
|
||||
end
|
||||
|
||||
def create_running_vm(template, name, redis, token = nil, user = nil)
|
||||
create_vm(name, redis, token, user)
|
||||
redis.sadd("vmpooler__running__#{template}", name)
|
||||
redis.hset("vmpooler__vm__#{name}", 'template', template)
|
||||
redis.hset("vmpooler__vm__#{name}", 'checkout', Time.now)
|
||||
redis.hset("vmpooler__vm__#{name}", 'host', 'host1')
|
||||
end
|
||||
|
||||
def create_pending_vm(template, name, redis, token = nil)
|
||||
create_vm(name, redis, token)
|
||||
redis.sadd("vmpooler__pending__#{template}", name)
|
||||
redis.hset("vmpooler__vm__#{name}", "template", template)
|
||||
end
|
||||
|
||||
def create_vm(name, redis, token = nil, user = nil)
|
||||
redis.hset("vmpooler__vm__#{name}", 'checkout', Time.now)
|
||||
redis.hset("vmpooler__vm__#{name}", 'clone', Time.now)
|
||||
redis.hset("vmpooler__vm__#{name}", 'token:token', token) if token
|
||||
redis.hset("vmpooler__vm__#{name}", 'token:user', user) if user
|
||||
end
|
||||
|
||||
def create_completed_vm(name, pool, redis, active = false)
|
||||
redis.sadd("vmpooler__completed__#{pool}", name)
|
||||
redis.hset("vmpooler__vm__#{name}", 'checkout', Time.now)
|
||||
redis.hset("vmpooler__active__#{pool}", name, Time.now) if active
|
||||
end
|
||||
|
||||
def create_discovered_vm(name, pool, redis)
|
||||
redis.sadd("vmpooler__discovered__#{pool}", name)
|
||||
end
|
||||
|
||||
def create_migrating_vm(name, pool, redis)
|
||||
redis.hset("vmpooler__vm__#{name}", 'checkout', Time.now)
|
||||
redis.sadd("vmpooler__migrating__#{pool}", name)
|
||||
end
|
||||
|
||||
def create_tag(vm, tag_name, tag_value, redis)
|
||||
redis.hset("vmpooler__vm__#{vm}", "tag:#{tag_name}", tag_value)
|
||||
end
|
||||
|
||||
def add_vm_to_migration_set(name, redis)
|
||||
redis.sadd('vmpooler__migration', name)
|
||||
end
|
||||
|
||||
def fetch_vm(vm)
|
||||
redis.hgetall("vmpooler__vm__#{vm}")
|
||||
end
|
||||
|
||||
def set_vm_data(vm, key, value, redis)
|
||||
redis.hset("vmpooler__vm__#{vm}", key, value)
|
||||
end
|
||||
|
||||
def snapshot_revert_vm(vm, snapshot = '12345678901234567890123456789012', redis)
|
||||
redis.sadd('vmpooler__tasks__snapshot-revert', "#{vm}:#{snapshot}")
|
||||
redis.hset("vmpooler__vm__#{vm}", "snapshot:#{snapshot}", "1")
|
||||
end
|
||||
|
||||
def snapshot_vm(vm, snapshot = '12345678901234567890123456789012', redis)
|
||||
redis.sadd('vmpooler__tasks__snapshot', "#{vm}:#{snapshot}")
|
||||
redis.hset("vmpooler__vm__#{vm}", "snapshot:#{snapshot}", "1")
|
||||
end
|
||||
|
||||
def disk_task_vm(vm, disk_size = '10', redis)
|
||||
redis.sadd('vmpooler__tasks__disk', "#{vm}:#{disk_size}")
|
||||
end
|
||||
|
||||
def has_vm_snapshot?(vm, redis)
|
||||
redis.smembers('vmpooler__tasks__snapshot').any? do |snapshot|
|
||||
instance, _sha = snapshot.split(':')
|
||||
vm == instance
|
||||
end
|
||||
end
|
||||
|
||||
def vm_reverted_to_snapshot?(vm, redis, snapshot = nil)
|
||||
redis.smembers('vmpooler__tasks__snapshot-revert').any? do |action|
|
||||
instance, sha = action.split(':')
|
||||
instance == vm and (snapshot ? (sha == snapshot) : true)
|
||||
end
|
||||
end
|
||||
|
||||
def pool_has_ready_vm?(pool, vm, redis)
|
||||
!!redis.sismember('vmpooler__ready__' + pool, vm)
|
||||
end
|
||||
|
||||
def create_ondemand_request_for_test(request_id, score, platforms_string, redis, user = nil, token = nil)
|
||||
redis.zadd('vmpooler__provisioning__request', score, request_id)
|
||||
redis.hset("vmpooler__odrequest__#{request_id}", 'requested', platforms_string)
|
||||
redis.hset("vmpooler__odrequest__#{request_id}", 'token:token', token) if token
|
||||
redis.hset("vmpooler__odrequest__#{request_id}", 'token:user', user) if user
|
||||
end
|
||||
|
||||
def set_ondemand_request_status(request_id, status, redis)
|
||||
redis.hset("vmpooler__odrequest__#{request_id}", 'status', status)
|
||||
end
|
||||
|
||||
def create_ondemand_vm(vmname, request_id, pool, pool_alias, redis)
|
||||
redis.sadd("vmpooler__#{request_id}__#{pool_alias}__#{pool}", vmname)
|
||||
end
|
||||
|
||||
def create_ondemand_creationtask(request_string, score, redis)
|
||||
redis.zadd('vmpooler__odcreate__task', score, request_string)
|
||||
end
|
||||
|
||||
def create_ondemand_processing(request_id, score, redis)
|
||||
redis.zadd('vmpooler__provisioning__processing', score, request_id)
|
||||
end
|
||||
922
spec/rbvmomi_helper.rb
Normal file
922
spec/rbvmomi_helper.rb
Normal file
|
|
@ -0,0 +1,922 @@
|
|||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Managed Objects (https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/index-mo_types.html)
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
MockClusterComputeResource = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.ClusterComputeResource.html
|
||||
# From MockClusterComputeResource
|
||||
:actionHistory, :configuration, :drsFault, :drsRecommendation, :migrationHistory, :recommendation,
|
||||
# From ComputeResource
|
||||
:resourcePool,
|
||||
# From ManagedEntity
|
||||
:name
|
||||
)
|
||||
|
||||
MockComputeResource = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.ComputeResource.html
|
||||
# From ComputeResource
|
||||
:configurationEx, :datastore, :host, :network, :resourcePool, :summary,
|
||||
# From ManagedEntity
|
||||
:name
|
||||
)
|
||||
|
||||
MockContainerView = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.view.ContainerView.html
|
||||
# From ContainerView
|
||||
:container, :recursive, :type
|
||||
) do
|
||||
def _search_tree(layer)
|
||||
results = []
|
||||
|
||||
layer.children.each do |child|
|
||||
if type.any? { |t| child.is_a?(RbVmomi::VIM.const_get(t)) }
|
||||
results << child
|
||||
end
|
||||
|
||||
if recursive && child.respond_to?(:children)
|
||||
results += _search_tree(child)
|
||||
end
|
||||
end
|
||||
results
|
||||
end
|
||||
|
||||
def view
|
||||
_search_tree(container)
|
||||
end
|
||||
|
||||
def DestroyView
|
||||
end
|
||||
end
|
||||
|
||||
MockDatacenter = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.Datacenter.html
|
||||
# From Datacenter
|
||||
:datastore, :datastoreFolder, :hostFolder, :network, :networkFolder, :vmFolder,
|
||||
# From ManagedEntity
|
||||
:name
|
||||
) do
|
||||
# From RBVMOMI::VIM::Datacenter https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim/Datacenter.rb
|
||||
|
||||
# Find the Datastore with the given +name+.
|
||||
def find_datastore name
|
||||
datastore.find { |x| x.name == name }
|
||||
end
|
||||
end
|
||||
|
||||
MockNetwork = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.Network.html
|
||||
# From Network
|
||||
:host, :name, :summary, :vm
|
||||
)
|
||||
|
||||
MockVirtualVmxnet3 = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.device.VirtualVmxnet.html
|
||||
# From VirtualEthenetCard
|
||||
:addressType,
|
||||
# From VirtualDevice
|
||||
:key, :deviceInfo, :backing, :connectable
|
||||
)
|
||||
|
||||
MockDatastore = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.Datastore.html
|
||||
# From Datastore
|
||||
:browser, :capability, :host, :info, :iormConfiguration, :summary, :vm,
|
||||
# From ManagedEntity
|
||||
:name
|
||||
)
|
||||
|
||||
MockFolder = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.Folder.html
|
||||
# From Folder
|
||||
:childEntity, :childType,
|
||||
# From ManagedEntity
|
||||
:name
|
||||
) do
|
||||
# From RBVMOMI::VIM::Folder https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim/Folder.rb#L107-L110
|
||||
def children
|
||||
childEntity
|
||||
end
|
||||
|
||||
# https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim/Folder.rb#L9-L12
|
||||
def find(name, type=Object)
|
||||
# Fake the searchIndex
|
||||
childEntity.each do |child|
|
||||
if child.name == name
|
||||
if child.kind_of?(type)
|
||||
return child
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
MockHostSystem = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.HostSystem.html
|
||||
# From HostSystem
|
||||
:capability, :config, :configManager, :datastore, :datastoreBrowser, :hardware, :network, :runtime, :summary, :systemResources, :vm,
|
||||
# From ManagedEntity
|
||||
:overallStatus, :name, :parent,
|
||||
# From ManagedObject
|
||||
:configIssue
|
||||
)
|
||||
|
||||
MockPropertyCollector = Struct.new(
|
||||
# https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvmodl.query.PropertyCollector.html
|
||||
# PropertyCollector
|
||||
:filter
|
||||
)
|
||||
|
||||
MockResourcePool = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.ResourcePool.html
|
||||
# From ResourcePool
|
||||
:childConfiguration, :config, :owner, :resourcePool, :runtime, :summary, :vm,
|
||||
# From ManagedEntity
|
||||
:name
|
||||
)
|
||||
|
||||
MockSearchIndex = Object
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.SearchIndex.html
|
||||
|
||||
MockServiceInstance = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.ServiceInstance.html
|
||||
# From ServiceInstance
|
||||
:capability, :content, :serverClock
|
||||
) do
|
||||
# From ServiceInstance
|
||||
# Mock the CurrentTime method so that it appears the ServiceInstance is valid.
|
||||
def CurrentTime
|
||||
Time.now
|
||||
end
|
||||
|
||||
# From RBVMOMI::VIM::ServiceInstance https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim/ServiceInstance.rb
|
||||
def find_datacenter(path=nil)
|
||||
# In our mocked instance, DataCenters are always in the root Folder.
|
||||
# If path is nil the first DC is returned otherwise match by name
|
||||
content.rootFolder.childEntity.each do |child|
|
||||
if child.is_a?(RbVmomi::VIM::Datacenter)
|
||||
return child if path.nil? || child.name == path
|
||||
end
|
||||
end
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
MockTask = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.Task.html
|
||||
# From Task
|
||||
:info,
|
||||
) do
|
||||
# From RBVMOMI https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim/Task.rb
|
||||
# Mock the with 'Not Implemented'
|
||||
def wait_for_completion
|
||||
raise(RuntimeError,'Not Implemented')
|
||||
end
|
||||
end
|
||||
|
||||
MockViewManager = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.view.ViewManager.html
|
||||
# From ViewManager
|
||||
:viewList,
|
||||
) do
|
||||
# From ViewManager
|
||||
def CreateContainerView(options)
|
||||
mock_RbVmomi_VIM_ContainerView({
|
||||
:container => options[:container],
|
||||
:recursive => options[:recursive],
|
||||
:type => options[:type],
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
MockVirtualDiskManager = Object
|
||||
# https://pubs.vmware.com/vsphere-55/index.jsp#com.vmware.wssdk.apiref.doc/vim.VirtualDiskManager.html
|
||||
|
||||
MockVirtualMachine = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.VirtualMachine.html
|
||||
# From VirtualMachine
|
||||
:config, :runtime, :snapshot, :summary,
|
||||
# From ManagedEntity
|
||||
:name,
|
||||
# From RbVmomi::VIM::ManagedEntity
|
||||
# https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim/ManagedEntity.rb
|
||||
:path
|
||||
)
|
||||
|
||||
MockVirtualMachineSnapshot = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.Snapshot.html
|
||||
# From VirtualMachineSnapshot
|
||||
:config
|
||||
)
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------
|
||||
# Data Objects (https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/index-do_types.html)
|
||||
# -------------------------------------------------------------------------------------------------------------
|
||||
|
||||
MockDescription = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.Description.html
|
||||
# From Description
|
||||
:label, :summary
|
||||
)
|
||||
|
||||
MockVirtualEthernetCardNetworkBackingInfo = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.device.VirtualEthernetCard.NetworkBackingInfo.html
|
||||
# From VirtualEthernetCardNetworkBackingInfo
|
||||
:network,
|
||||
|
||||
# From VirtualDeviceBackingInfo
|
||||
:deviceName, :useAutoDetect
|
||||
)
|
||||
|
||||
MockVirtualDeviceConnectInfo = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.device.VirtualDevice.ConnectInfo.html
|
||||
# From VirtualDeviceConnectInfo
|
||||
:allowGuestControl, :connected, :startConnected
|
||||
)
|
||||
|
||||
MockVirtualMachineConfigSpec = Struct.new(
|
||||
# https://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigSpec.html
|
||||
# From VirtualMachineConfigSpec
|
||||
:deviceChange, :annotation, :extraConfig
|
||||
)
|
||||
|
||||
MockVirtualMachineRelocateSpec = Struct.new(
|
||||
# https://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.RelocateSpec.html
|
||||
# From VirtualMachineRelocateSpec
|
||||
:datastore, :diskMoveType, :pool
|
||||
)
|
||||
|
||||
MockDynamicProperty = Struct.new(
|
||||
# https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvmodl.DynamicProperty.html
|
||||
# From DynamicProperty
|
||||
:name, :val
|
||||
)
|
||||
|
||||
MockHostCpuPackage = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.host.CpuPackage.html
|
||||
# From HostCpuPackage
|
||||
:busHz, :cpuFeature, :description, :hz, :index, :threadId, :vendor
|
||||
)
|
||||
|
||||
MockHostHardwareSummary = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.host.Summary.HardwareSummary.html
|
||||
# From HostHardwareSummary
|
||||
:cpuMhz, :numCpuCores, :numCpuPkgs, :memorySize
|
||||
)
|
||||
|
||||
MockHostListSummary = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.host.Summary.html
|
||||
# From HostListSummary
|
||||
:quickStats, :hardware
|
||||
)
|
||||
|
||||
MockHostListSummaryQuickStats = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.host.Summary.QuickStats.html
|
||||
# From HostListSummaryQuickStats
|
||||
:overallCpuUsage, :overallMemoryUsage
|
||||
)
|
||||
|
||||
MockHostRuntimeInfo = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.host.RuntimeInfo.html
|
||||
# From HostRuntimeInfo
|
||||
:bootTime, :connectionState, :healthSystemRuntime, :inMaintenanceMode, :powerState, :tpmPcrValues
|
||||
)
|
||||
|
||||
MockHostSystemHostHardwareInfo = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.host.HardwareInfo.html
|
||||
# From HostHardwareInfo
|
||||
:biosInfo, :cpuFeature, :cpuInfo, :cpuPkg, :cpuPowerManagementInfo, :memorySize, :numaInfo, :pciDevice, :systemInfo
|
||||
)
|
||||
|
||||
MockObjectContent = Struct.new(
|
||||
# https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvmodl.query.PropertyCollector.ObjectContent.html
|
||||
# From ObjectContent
|
||||
:missingSet, :obj, :propSet
|
||||
)
|
||||
|
||||
MockRetrieveResult = Struct.new(
|
||||
# https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvmodl.query.PropertyCollector.RetrieveResult.html
|
||||
# From RetrieveResult
|
||||
:objects, :token
|
||||
)
|
||||
|
||||
MockServiceContent = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.ServiceInstanceContent.html#field_detail
|
||||
# From ServiceContent
|
||||
:propertyCollector, :rootFolder, :searchIndex, :viewManager, :virtualDiskManager
|
||||
)
|
||||
|
||||
MockVirtualDevice = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.device.VirtualDevice.html
|
||||
# From VirtualDevice
|
||||
:deviceInfo, :controllerKey, :key, :backing, :connectable, :unitNumber
|
||||
)
|
||||
|
||||
MockVirtualDisk = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.device.VirtualDisk.html
|
||||
# From VirtualDisk
|
||||
:capacityInKB, :shares,
|
||||
# From VirtualDevice
|
||||
:deviceInfo, :controllerKey, :key, :backing, :connectable, :unitNumber
|
||||
)
|
||||
|
||||
MockVirtualHardware = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.VirtualHardware.html
|
||||
# From VirtualHardware
|
||||
:device
|
||||
)
|
||||
|
||||
MockVirtualMachineConfigInfo = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.ConfigInfo.html
|
||||
# From VirtualMachineConfigInfo
|
||||
:hardware
|
||||
)
|
||||
|
||||
MockVirtualMachineFileLayoutExFileInfo = Struct.new(
|
||||
# https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.vm.FileLayoutEx.FileInfo.html
|
||||
# From VirtualMachineFileLayoutExFileInfo
|
||||
:key, :name, :size, :type, :uniqueSize
|
||||
)
|
||||
|
||||
MockVirtualMachineGuestSummary = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.Summary.GuestSummary.html
|
||||
# From VirtualMachineGuestSummary
|
||||
:hostName
|
||||
)
|
||||
|
||||
MockVirtualMachineRuntimeInfo = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.RuntimeInfo.html
|
||||
# From VirtualMachineRuntimeInfo
|
||||
:bootTime, :cleanPowerOff, :connectionState, :faultToleranceState, :host, :maxCpuUsage, :maxMemoryUsage, :memoryOverhead,
|
||||
:needSecondaryReason, :numMksConnections, :powerState, :question, :recordReplayState, :suspendInterval, :suspendTime, :toolsInstallerMounted
|
||||
)
|
||||
|
||||
MockVirtualMachineSnapshotInfo = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.SnapshotInfo.html
|
||||
# From MockVirtualMachineSnapshotInfo
|
||||
:currentSnapshot, :rootSnapshotList
|
||||
)
|
||||
|
||||
MockVirtualMachineSnapshotTree = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.SnapshotTree.html
|
||||
# From VirtualMachineSnapshotTree
|
||||
:backupManifest, :childSnapshotList, :createTime, :description, :id, :name, :quiesced, :replaySupported,
|
||||
:snapshot, :state, :vm
|
||||
)
|
||||
|
||||
MockVirtualMachineSummary = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.Summary.html
|
||||
# From VirtualMachineSummary
|
||||
:config, :customValue, :guest, :quickStats, :runtime, :storage, :vm
|
||||
)
|
||||
|
||||
MockVirtualSCSIController = Struct.new(
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.device.VirtualSCSIController.html
|
||||
# From VirtualSCSIController
|
||||
:hotAddRemove, :scsiCtlrUnitNumber, :sharedBus,
|
||||
# From VirtualDevice
|
||||
:deviceInfo, :controllerKey, :key, :backing, :connectable, :unitNumber
|
||||
)
|
||||
|
||||
# --------------------
|
||||
# RBVMOMI only Objects
|
||||
# --------------------
|
||||
MockRbVmomiVIMConnection = Struct.new(
|
||||
# https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim.rb
|
||||
:serviceInstance, :serviceContent, :rootFolder, :root
|
||||
) do
|
||||
# From https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim.rb
|
||||
# Alias to serviceContent.searchIndex
|
||||
def searchIndex
|
||||
serviceContent.searchIndex
|
||||
end
|
||||
# Alias to serviceContent.propertyCollector
|
||||
def propertyCollector
|
||||
serviceContent.propertyCollector
|
||||
end
|
||||
end
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------
|
||||
# Mocking Methods
|
||||
# -------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.ClusterComputeResource.html
|
||||
def mock_RbVmomi_VIM_ClusterComputeResource(options = {})
|
||||
options[:name] = 'Cluster' + rand(65536).to_s if options[:name].nil?
|
||||
|
||||
mock = MockClusterComputeResource.new()
|
||||
|
||||
mock.name = options[:name]
|
||||
# All cluster compute resources have a root Resource Pool
|
||||
mock.resourcePool = mock_RbVmomi_VIM_ResourcePool({:name => options[:name]})
|
||||
|
||||
allow(mock).to receive(:is_a?) do |expected_type|
|
||||
expected_type == RbVmomi::VIM::ClusterComputeResource
|
||||
end
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.view.ContainerView.html
|
||||
def mock_RbVmomi_VIM_ContainerView(options = {})
|
||||
mock = MockContainerView.new()
|
||||
mock.container = options[:container]
|
||||
mock.recursive = options[:recursive]
|
||||
mock.type = options[:type]
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.ComputeResource.html
|
||||
def mock_RbVmomi_VIM_ComputeResource(options = {})
|
||||
options[:name] = 'Compute' + rand(65536).to_s if options[:name].nil?
|
||||
options[:hosts] = [{}] if options[:hosts].nil?
|
||||
|
||||
mock = MockComputeResource.new()
|
||||
|
||||
mock.name = options[:name]
|
||||
mock.host = []
|
||||
|
||||
# A compute resource must have at least one host.
|
||||
options[:hosts].each do |host_options|
|
||||
mock_host = mock_RbVmomi_VIM_HostSystem(host_options)
|
||||
mock_host.parent = mock
|
||||
mock.host << mock_host
|
||||
end
|
||||
|
||||
allow(mock).to receive(:is_a?) do |expected_type|
|
||||
expected_type == RbVmomi::VIM::ComputeResource
|
||||
end
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim.rb
|
||||
def mock_RbVmomi_VIM_Connection(options = {})
|
||||
options[:serviceInstance] = {} if options[:serviceInstance].nil?
|
||||
options[:serviceContent] = {} if options[:serviceContent].nil?
|
||||
|
||||
mock = MockRbVmomiVIMConnection.new()
|
||||
mock.serviceContent = mock_RbVmomi_VIM_ServiceContent(options[:serviceContent])
|
||||
options[:serviceInstance][:servicecontent] = mock.serviceContent if options[:serviceInstance][:servicecontent].nil?
|
||||
mock.serviceInstance = mock_RbVmomi_VIM_ServiceInstance(options[:serviceInstance])
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.Datastore.html
|
||||
def mock_RbVmomi_VIM_Datacenter(options = {})
|
||||
options[:hostfolder_tree] = {} if options[:hostfolder_tree].nil?
|
||||
options[:vmfolder_tree] = {} if options[:vmfolder_tree].nil?
|
||||
# Currently don't support mocking datastore tree
|
||||
options[:datastores] = [] if options[:datastores].nil?
|
||||
options[:name] = 'Datacenter' + rand(65536).to_s if options[:name].nil?
|
||||
options[:networks] = [] if options[:networks].nil?
|
||||
|
||||
mock = MockDatacenter.new()
|
||||
|
||||
mock.name = options[:name]
|
||||
mock.hostFolder = mock_RbVmomi_VIM_Folder({ :name => 'hostFolderRoot'})
|
||||
mock.vmFolder = mock_RbVmomi_VIM_Folder({ :name => 'vmFolderRoot'})
|
||||
mock.datastore = []
|
||||
mock.network = []
|
||||
|
||||
# Create vmFolder hierarchy
|
||||
recurse_folder_tree(options[:vmfolder_tree],mock.vmFolder.childEntity)
|
||||
|
||||
# Create hostFolder hierarchy
|
||||
recurse_folder_tree(options[:hostfolder_tree],mock.hostFolder.childEntity)
|
||||
|
||||
# Create mock Datastores
|
||||
options[:datastores].each do |datastorename|
|
||||
mock_ds = mock_RbVmomi_VIM_Datastore({ :name => datastorename })
|
||||
mock.datastore << mock_ds
|
||||
end
|
||||
|
||||
# Create mock Networks
|
||||
options[:networks].each do |networkname|
|
||||
mock_nw = mock_RbVmomi_VIM_Network({ :name => networkname })
|
||||
mock.network << mock_nw
|
||||
end
|
||||
|
||||
allow(mock).to receive(:is_a?) do |expected_type|
|
||||
expected_type == RbVmomi::VIM::Datacenter
|
||||
end
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
def recurse_folder_tree(tree, root_object)
|
||||
tree.keys.each do |foldername|
|
||||
folder_options = tree[foldername].nil? ? {} : tree[foldername]
|
||||
folder_options[:name] = foldername if folder_options[:name].nil?
|
||||
|
||||
case folder_options[:object_type]
|
||||
when 'vm'
|
||||
child_object = mock_RbVmomi_VIM_VirtualMachine({ :name => folder_options[:name]})
|
||||
when 'compute_resource'
|
||||
child_object = mock_RbVmomi_VIM_ComputeResource({ :name => folder_options[:name]})
|
||||
when 'cluster_compute_resource'
|
||||
child_object = mock_RbVmomi_VIM_ClusterComputeResource({ :name => folder_options[:name]})
|
||||
when 'resource_pool'
|
||||
child_object = mock_RbVmomi_VIM_ResourcePool({ :name => folder_options[:name]})
|
||||
else
|
||||
child_object = mock_RbVmomi_VIM_Folder({:name => foldername})
|
||||
end
|
||||
|
||||
# Recursively create children - Default is the child_object is a Folder
|
||||
case folder_options[:object_type]
|
||||
when 'cluster_compute_resource'
|
||||
# Append children into the root Resource Pool for a cluster, instead of directly into the cluster itself.
|
||||
recurse_folder_tree(folder_options[:children],child_object.resourcePool.resourcePool) unless folder_options[:children].nil?
|
||||
when 'resource_pool'
|
||||
recurse_folder_tree(folder_options[:children],child_object.resourcePool) unless folder_options[:children].nil?
|
||||
else
|
||||
recurse_folder_tree(folder_options[:children],child_object.childEntity) unless folder_options[:children].nil?
|
||||
end
|
||||
|
||||
root_object << child_object
|
||||
end
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.Datastore.html
|
||||
def mock_RbVmomi_VIM_Datastore(options = {})
|
||||
options[:name] = 'Datastore' + rand(65536).to_s if options[:name].nil?
|
||||
|
||||
mock = MockDatastore.new()
|
||||
|
||||
mock.name = options[:name]
|
||||
|
||||
allow(mock).to receive(:is_a?) do |expected_type|
|
||||
expected_type == RbVmomi::VIM::Datastore
|
||||
end
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.Network.html
|
||||
def mock_RbVmomi_VIM_Network(options = {})
|
||||
options[:name] = 'Network' + rand(65536).to_s if options[:name].nil?
|
||||
|
||||
mock = MockNetwork.new()
|
||||
|
||||
mock.name = options[:name]
|
||||
|
||||
allow(mock).to receive(:is_a?) do |expected_type|
|
||||
expected_type == RbVmomi::VIM::Network
|
||||
end
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.device.VirtualVmxnet3.html
|
||||
def mock_RbVmomi_VIM_VirtualVmxnet3(options = {})
|
||||
options[:key] = rand(65536) if options[:key].nil?
|
||||
options[:deviceInfo] = MockDescription.new()
|
||||
options[:backing] = MockVirtualEthernetCardNetworkBackingInfo.new()
|
||||
options[:addressType] = 'assigned'
|
||||
options[:connectable] = MockVirtualDeviceConnectInfo.new()
|
||||
|
||||
mock = MockVirtualVmxnet3.new()
|
||||
|
||||
mock.key = options[:key]
|
||||
mock.deviceInfo = options[:deviceInfo]
|
||||
mock.backing = options[:backing]
|
||||
mock.addressType = options[:addressType]
|
||||
mock.connectable = options[:connectable]
|
||||
|
||||
allow(mock).to receive(:instance_of?) do |expected_type|
|
||||
expected_type == RbVmomi::VIM::VirtualVmxnet3
|
||||
end
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.RelocateSpec.html
|
||||
def mock_RbVmomi_VIM_VirtualMachineRelocateSpec(options = {})
|
||||
options[:datastore] = 'Datastore' + rand(65536).to_s if options[:datastore].nil?
|
||||
options[:diskMoveType] = :moveChildMostDiskBacking
|
||||
options[:pool] = 'Pool' + rand(65536).to_s if options[:pool].nil?
|
||||
|
||||
mock = MockVirtualMachineRelocateSpec.new
|
||||
|
||||
mock.datastore = mock_RbVmomi_VIM_Datastore({ :name => options[:datastore]})
|
||||
mock.diskMoveType = options[:diskMoveType]
|
||||
mock.pool = mock_RbVmomi_VIM_ResourcePool({:name => options[:pool]})
|
||||
allow(mock).to receive(:is_a?).and_return(RbVmomi::VIM::VirtualMachineRelocateSpec)
|
||||
mock
|
||||
end
|
||||
|
||||
# https://pubs.vmware.com/vi3/sdk/ReferenceGuide/vim.vm.ConfigSpec.html
|
||||
def mock_RbVmomi_VIM_VirtualMachineConfigSpec(options = {})
|
||||
options[:device] = mock_RbVmomi_VIM_VirtualVmxnet3()
|
||||
|
||||
|
||||
mock = MockVirtualMachineConfigSpec.new
|
||||
|
||||
mock.deviceChange = []
|
||||
mock.deviceChange << { operation: :edit, device: options[:device]}
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.Datastore.html
|
||||
def mock_RbVmomi_VIM_Folder(options = {})
|
||||
options[:name] = 'Folder' + rand(65536).to_s if options[:name].nil?
|
||||
|
||||
mock = MockFolder.new()
|
||||
|
||||
mock.name = options[:name]
|
||||
mock.childEntity = []
|
||||
allow(mock).to receive(:is_a?) do |expected_type|
|
||||
expected_type == RbVmomi::VIM::Folder
|
||||
end
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.HostSystem.html
|
||||
def mock_RbVmomi_VIM_HostSystem(options = {})
|
||||
options[:memory_size] = 4294967296 if options[:memory_size].nil? # 4GB RAM
|
||||
options[:num_cpu] = 1 if options[:num_cpu].nil?
|
||||
options[:num_cores_per_cpu] = 1 if options[:num_cores_per_cpu].nil?
|
||||
options[:cpu_speed] = 2048 if options[:cpu_speed].nil? # 2.0 GHz
|
||||
options[:cpu_model] = 'Intel(R) Xeon(R) CPU E5-2697 v4 @ 2.0GHz' if options[:cpu_model].nil?
|
||||
options[:maintenance_mode] = false if options[:maintenance_mode].nil?
|
||||
options[:overall_status] = 'green' if options[:overall_status].nil?
|
||||
options[:overall_cpu_usage] = 1 if options[:overall_cpu_usage].nil?
|
||||
options[:overall_memory_usage] = 1 if options[:overall_memory_usage].nil?
|
||||
options[:name] = 'HOST' + rand(65536).to_s if options[:name].nil?
|
||||
options[:config_issue] = [] if options[:config_issue].nil?
|
||||
|
||||
mock = MockHostSystem.new()
|
||||
mock.name = options[:name]
|
||||
mock.summary = MockHostListSummary.new()
|
||||
mock.summary.quickStats = MockHostListSummaryQuickStats.new()
|
||||
mock.summary.hardware = MockHostHardwareSummary.new()
|
||||
mock.hardware = MockHostSystemHostHardwareInfo.new()
|
||||
mock.runtime = MockHostRuntimeInfo.new()
|
||||
|
||||
mock.hardware.cpuPkg = []
|
||||
(1..options[:num_cpu]).each do |cpuid|
|
||||
mockcpu = MockHostCpuPackage.new()
|
||||
mockcpu.hz = options[:cpu_speed] * 1024 * 1024
|
||||
mockcpu.description = options[:cpu_model]
|
||||
mockcpu.index = 0
|
||||
mock.hardware.cpuPkg << mockcpu
|
||||
end
|
||||
|
||||
mock.runtime.inMaintenanceMode = options[:maintenance_mode]
|
||||
mock.overallStatus = options[:overall_status]
|
||||
mock.configIssue = options[:config_issue]
|
||||
|
||||
mock.summary.hardware.memorySize = options[:memory_size]
|
||||
mock.hardware.memorySize = options[:memory_size]
|
||||
|
||||
mock.summary.hardware.cpuMhz = options[:cpu_speed]
|
||||
mock.summary.hardware.numCpuCores = options[:num_cpu] * options[:num_cores_per_cpu]
|
||||
mock.summary.hardware.numCpuPkgs = options[:num_cpu]
|
||||
mock.summary.quickStats.overallCpuUsage = options[:overall_cpu_usage]
|
||||
mock.summary.quickStats.overallMemoryUsage = options[:overall_memory_usage]
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvmodl.query.PropertyCollector.RetrieveResult.html
|
||||
def mock_RbVmomi_VIM_RetrieveResult(options = {})
|
||||
options[:response] = [] if options[:response].nil?
|
||||
mock = MockRetrieveResult.new()
|
||||
|
||||
mock.objects = []
|
||||
|
||||
options[:response].each do |response|
|
||||
mock_objectdata = MockObjectContent.new()
|
||||
|
||||
mock_objectdata.propSet = []
|
||||
|
||||
mock_objectdata.obj = response[:object]
|
||||
|
||||
# Mock the object properties
|
||||
response.each do |key,value|
|
||||
unless key == :object
|
||||
mock_property = MockDynamicProperty.new()
|
||||
mock_property.name = key
|
||||
mock_property.val = value
|
||||
mock_objectdata.propSet << mock_property
|
||||
end
|
||||
end
|
||||
mock.objects << mock_objectdata
|
||||
end
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvmodl.query.PropertyCollector.html
|
||||
def mock_RbVmomi_VIM_PropertyCollector(options = {})
|
||||
mock = MockPropertyCollector.new()
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.ServiceInstanceContent.html#field_detail
|
||||
def mock_RbVmomi_VIM_ServiceContent(options = {})
|
||||
options[:propertyCollector] = {} if options[:propertyCollector].nil?
|
||||
options[:datacenters] = [] if options[:datacenters].nil?
|
||||
|
||||
mock = MockServiceContent.new()
|
||||
|
||||
mock.searchIndex = MockSearchIndex.new()
|
||||
mock.viewManager = MockViewManager.new()
|
||||
mock.virtualDiskManager = MockVirtualDiskManager.new()
|
||||
mock.rootFolder = mock_RbVmomi_VIM_Folder({ :name => 'RootFolder' })
|
||||
|
||||
mock.propertyCollector = mock_RbVmomi_VIM_PropertyCollector(options[:propertyCollector])
|
||||
|
||||
# Create the DCs in this ServiceContent
|
||||
options[:datacenters].each do |dc_options|
|
||||
mock_dc = mock_RbVmomi_VIM_Datacenter(dc_options)
|
||||
mock.rootFolder.childEntity << mock_dc
|
||||
end
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.ServiceInstance.html
|
||||
def mock_RbVmomi_VIM_ServiceInstance(options = {})
|
||||
mock = MockServiceInstance.new()
|
||||
|
||||
mock.content = options[:servicecontent]
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.Task.html
|
||||
def mock_RbVmomi_VIM_Task(options = {})
|
||||
mock = MockTask.new()
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.ResourcePool.html
|
||||
def mock_RbVmomi_VIM_ResourcePool(options = {})
|
||||
options[:name] = 'ResourcePool' + rand(65536).to_s if options[:name].nil?
|
||||
|
||||
mock = MockResourcePool.new()
|
||||
|
||||
mock.name = options[:name]
|
||||
mock.resourcePool = []
|
||||
allow(mock).to receive(:is_a?) do |expected_type|
|
||||
expected_type == RbVmomi::VIM::ResourcePool
|
||||
end
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.device.VirtualDisk.html
|
||||
def mock_RbVmomi_VIM_VirtualDisk(options = {})
|
||||
options[:controllerKey] = rand(65536) if options[:controllerKey].nil?
|
||||
options[:key] = rand(65536) if options[:key].nil?
|
||||
options[:label] = 'SCSI' + rand(65536).to_s if options[:label].nil?
|
||||
options[:unitNumber] = rand(65536) if options[:unitNumber].nil?
|
||||
|
||||
mock = MockVirtualDisk.new()
|
||||
mock.deviceInfo = MockDescription.new()
|
||||
|
||||
mock.deviceInfo.label = options[:label]
|
||||
mock.controllerKey = options[:controllerKey]
|
||||
mock.key = options[:key]
|
||||
mock.unitNumber = options[:unitNumber]
|
||||
|
||||
allow(mock).to receive(:is_a?) do |expected_type|
|
||||
expected_type == RbVmomi::VIM::VirtualDisk
|
||||
end
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.VirtualMachine.html
|
||||
def mock_RbVmomi_VIM_VirtualMachine(options = {})
|
||||
options[:snapshot_tree] = nil if options[:snapshot_tree].nil?
|
||||
options[:name] = 'VM' + rand(65536).to_s if options[:name].nil?
|
||||
options[:path] = [] if options[:path].nil?
|
||||
|
||||
mock = MockVirtualMachine.new()
|
||||
mock.config = MockVirtualMachineConfigInfo.new()
|
||||
mock.config.hardware = MockVirtualHardware.new([])
|
||||
mock.summary = MockVirtualMachineSummary.new()
|
||||
mock.summary.runtime = MockVirtualMachineRuntimeInfo.new()
|
||||
mock.summary.guest = MockVirtualMachineGuestSummary.new()
|
||||
mock.runtime = mock.summary.runtime
|
||||
|
||||
mock.name = options[:name]
|
||||
mock.summary.guest.hostName = options[:hostname]
|
||||
mock.runtime.bootTime = options[:boottime]
|
||||
mock.runtime.powerState = options[:powerstate]
|
||||
|
||||
unless options[:snapshot_tree].nil?
|
||||
mock.snapshot = MockVirtualMachineSnapshotInfo.new()
|
||||
mock.snapshot.rootSnapshotList = []
|
||||
index = 0
|
||||
|
||||
# Create a recursive snapshot tree
|
||||
recurse_snapshot_tree(options[:snapshot_tree],mock.snapshot.rootSnapshotList,index)
|
||||
end
|
||||
|
||||
# Create an array of items that describe the path of the VM from the root folder
|
||||
# all the way to the VM itself
|
||||
mock.path = []
|
||||
options[:path].each do |path_item|
|
||||
mock_item = nil
|
||||
case path_item[:type]
|
||||
when 'folder'
|
||||
mock_item = mock_RbVmomi_VIM_Folder({ :name => path_item[:name] })
|
||||
when 'datacenter'
|
||||
mock_item = mock_RbVmomi_VIM_Datacenter({ :name => path_item[:name] })
|
||||
else
|
||||
raise("Unknown mock type #{path_item[:type]} for mock_RbVmomi_VIM_VirtualMachine")
|
||||
end
|
||||
mock.path << [mock_item,path_item[:name]]
|
||||
end
|
||||
mock.path << [mock,options[:name]]
|
||||
|
||||
allow(mock).to receive(:is_a?) do |expected_type|
|
||||
expected_type == RbVmomi::VIM::VirtualMachine
|
||||
end
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
def recurse_snapshot_tree(tree, root_object, index)
|
||||
tree.keys.each do |snapshotname|
|
||||
snap_options = tree[snapshotname].nil? ? {} : tree[snapshotname]
|
||||
snap = MockVirtualMachineSnapshotTree.new()
|
||||
snap.id = index
|
||||
snap.name = snapshotname
|
||||
snap.childSnapshotList = []
|
||||
snap.description = "Snapshot #{snapshotname}"
|
||||
snap.snapshot = snap_options[:ref] unless snap_options[:ref].nil?
|
||||
|
||||
# Recursively create chilren
|
||||
recurse_snapshot_tree(snap_options[:children],snap.childSnapshotList,index) unless snap_options[:children].nil?
|
||||
|
||||
root_object << snap
|
||||
index += 1
|
||||
end
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.device.VirtualDevice.html
|
||||
def mock_RbVmomi_VIM_VirtualMachineDevice(options = {})
|
||||
mock = MockVirtualDevice.new()
|
||||
mock.deviceInfo = MockDescription.new()
|
||||
|
||||
mock.deviceInfo.label = options[:label]
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.vm.FileLayoutEx.FileInfo.html
|
||||
def mock_RbVmomi_VIM_VirtualMachineFileLayoutExFileInfo(options = {})
|
||||
options[:key] = rand(65536).to_s if options[:key].nil?
|
||||
|
||||
mock = MockVirtualMachineFileLayoutExFileInfo.new()
|
||||
|
||||
mock.key = options[:key]
|
||||
mock.name = options[:name]
|
||||
mock.size = options[:size]
|
||||
mock.type = options[:type]
|
||||
mock.uniqueSize = options[:uniqueSize]
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.Snapshot.html
|
||||
def mock_RbVmomi_VIM_VirtualMachineSnapshot(options = {})
|
||||
mock = MockVirtualMachineSnapshot.new()
|
||||
|
||||
mock
|
||||
end
|
||||
|
||||
# https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.vm.device.VirtualSCSIController.html
|
||||
def mock_RbVmomi_VIM_VirtualSCSIController(options = {})
|
||||
options[:controllerKey] = rand(65536) if options[:controllerKey].nil?
|
||||
options[:key] = rand(65536) if options[:key].nil?
|
||||
options[:label] = 'SCSI' + rand(65536).to_s if options[:label].nil?
|
||||
options[:scsiCtlrUnitNumber] = 7 if options[:scsiCtlrUnitNumber].nil?
|
||||
|
||||
mock = MockVirtualSCSIController.new()
|
||||
mock.deviceInfo = MockDescription.new()
|
||||
|
||||
mock.deviceInfo.label = options[:label]
|
||||
mock.controllerKey = options[:controllerKey]
|
||||
mock.key = options[:key]
|
||||
mock.scsiCtlrUnitNumber = options[:scsiCtlrUnitNumber]
|
||||
|
||||
allow(mock).to receive(:is_a?) do |expected_type|
|
||||
expected_type == RbVmomi::VIM::VirtualSCSIController
|
||||
end
|
||||
|
||||
mock
|
||||
end
|
||||
19
spec/spec_helper.rb
Normal file
19
spec/spec_helper.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
require 'simplecov'
|
||||
SimpleCov.start do
|
||||
add_filter '/spec/'
|
||||
end
|
||||
require 'helpers'
|
||||
require 'rbvmomi_helper'
|
||||
require 'rbvmomi'
|
||||
require 'rspec'
|
||||
require 'vmpooler'
|
||||
require 'redis'
|
||||
require 'vmpooler/metrics'
|
||||
|
||||
def project_root_dir
|
||||
File.dirname(File.dirname(__FILE__))
|
||||
end
|
||||
|
||||
def fixtures_dir
|
||||
File.join(project_root_dir, 'spec', 'fixtures')
|
||||
end
|
||||
5027
spec/unit/pool_manager_spec.rb
Normal file
5027
spec/unit/pool_manager_spec.rb
Normal file
File diff suppressed because it is too large
Load diff
3599
spec/unit/providers/vsphere_spec.rb
Normal file
3599
spec/unit/providers/vsphere_spec.rb
Normal file
File diff suppressed because it is too large
Load diff
32
vmpooler-vsphere-provider.gemspec
Normal file
32
vmpooler-vsphere-provider.gemspec
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
lib = File.expand_path('../lib', __FILE__)
|
||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
||||
require 'vmpooler-vsphere-provider/version'
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = 'vmpooler-vsphere-provider'
|
||||
s.version = VmpoolerVsphereProvider::VERSION
|
||||
s.authors = ['Puppet']
|
||||
s.email = ['support@puppet.com']
|
||||
|
||||
s.summary = 'VMware provider for VMPooler'
|
||||
s.homepage = 'https://github.com/puppetlabs/vmpooler-provider-vsphere'
|
||||
s.license = 'Apache-2.0'
|
||||
s.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
||||
|
||||
s.files = Dir[ "lib/**/*" ]
|
||||
s.require_paths = ["lib"]
|
||||
s.add_dependency 'rbvmomi', '>= 2.1', '< 4.0'
|
||||
|
||||
s.add_development_dependency 'vmpooler', '~> 1.3', '>= 1.3.0'
|
||||
|
||||
# Testing dependencies
|
||||
s.add_development_dependency 'climate_control', '>= 0.2.0'
|
||||
s.add_development_dependency 'mock_redis', '>= 0.17.0'
|
||||
s.add_development_dependency 'pry'
|
||||
s.add_development_dependency 'rack-test', '>= 0.6'
|
||||
s.add_development_dependency 'rspec', '>= 3.2'
|
||||
s.add_development_dependency 'rubocop', '~> 1.1.0'
|
||||
s.add_development_dependency 'simplecov', '>= 0.11.2'
|
||||
s.add_development_dependency 'thor', '~> 1.0', '>= 1.0.1'
|
||||
s.add_development_dependency 'yarjuf', '>= 2.0'
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue