Skip to content
This repository was archived by the owner on Jul 1, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions devel/migrate-vmodl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env ruby
# Migrate vmodl.db from marchal db to yaml format
require 'yaml'

input_vmodl_filename = ARGV[0] or abort 'input vmodl filename required'
output_vmodl_filename = ARGV[1] or abort 'output vmodl filename required'

input_vmodl = case File.extname(input_vmodl_filename)
when '.yml', '.yaml'
File.open(input_vmodl_filename, 'r') { |io| YAML.load_file io }
when '.db'
File.open(input_vmodl_filename, 'r') { |io| Marshal.load io }
end

case File.extname(output_vmodl_filename)
when '.yml', '.yaml'
File.open(output_vmodl_filename, 'w') { |io| YAML.dump(input_vmodl, io) }
when '.db'
File.open(output_vmodl_filename, 'w') { |io| Marshal.dump(input_vmodl, io) }
end
4 changes: 4 additions & 0 deletions lib/rbvmomi/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ def self.method_missing sym, *a
end
end

def self.vmodl_filename
ENV['VMODL'] || Dir[File.join(File.dirname(__FILE__), "../../vmodl.*")].first
end

def self.load_vmodl fn
@loader = RbVmomi::TypeLoader.new fn, extension_dirs, self
nil
Expand Down
2 changes: 1 addition & 1 deletion lib/rbvmomi/pbm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def pretty_print pp
end

add_extension_dir File.join(File.dirname(__FILE__), "pbm")
load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), "../../vmodl.db"))
load_vmodl(vmodl_filename)
end

end
2 changes: 1 addition & 1 deletion lib/rbvmomi/sms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def pretty_print pp
end

add_extension_dir File.join(File.dirname(__FILE__), "sms")
load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), "../../vmodl.db"))
load_vmodl(vmodl_filename)
end

end
Expand Down
8 changes: 7 additions & 1 deletion lib/rbvmomi/type_loader.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2010 VMware, Inc. All Rights Reserved.
require 'set'
require 'monitor'
require 'yaml'

module RbVmomi

Expand All @@ -13,7 +14,12 @@ def initialize fn, extension_dirs, namespace
@id2wsdl = {}
@loaded = {}
add_types Hash[BasicTypes::BUILTIN.map { |k| [k,nil] }]
vmodl_database = File.open(fn, 'r') { |io| Marshal.load io }
vmodl_database = case File.extname(fn)
when '.yml', '.yaml'
File.open(fn, 'r') { |io| YAML.load io }
else
File.open(fn, 'r') { |io| Marshal.load io }
end
vmodl_database.reject! { |k,v| k =~ /^_/ }
add_types vmodl_database
preload
Expand Down
2 changes: 1 addition & 1 deletion lib/rbvmomi/vim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def get_log_keys host=nil
add_extension_dir File.join(File.dirname(__FILE__), "vim")
(ENV['RBVMOMI_VIM_EXTENSION_PATH']||'').split(':').each { |dir| add_extension_dir dir }

load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), "../../vmodl.db"))
load_vmodl(vmodl_filename)
end

end