lib/rvc/modules/vim.rb in rvc-1.6.0 vs lib/rvc/modules/vim.rb in rvc-1.7.0

- old
+ new

@@ -17,63 +17,30 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. require 'rvc/known_hosts' +require 'rvc/vim' -URI_REGEX = %r{ - ^ - (?: - ([^@:]+) - (?:: - ([^@]*) - )? - @ - )? - ([^@:]+) - (?::(\d{1,5}))? - (?::([0-9a-z]{64}))? - $ -}x +RVC::SCHEMES['vim'] = lambda { |uri| connect uri, {} } -class RbVmomi::VIM - include RVC::InventoryObject - - def children - rootFolder.children - end - - def self.folder? - true - end - - def display_info - puts serviceContent.about.fullName - end - - def _connection - self - end -end - opts :connect do summary 'Open a connection to ESX/VC' arg :uri, "Host to connect to" opt :rev, "Override protocol revision", :type => :string end rvc_alias :connect def connect uri, opts - match = URI_REGEX.match uri - Trollop.die "invalid hostname" unless match + uri = RVC::URIParser.parse uri unless uri.is_a? URI - username = match[1] || ENV['RBVMOMI_USER'] - password = match[2] || ENV['RBVMOMI_PASSWORD'] - host = match[3] - port = match[4] || 443 - certdigest = match[5] || opts[:certdigest] + username = uri.user || ENV['RBVMOMI_USER'] + password = uri.password || ENV['RBVMOMI_PASSWORD'] + host = uri.host + port = uri.port || 443 + certdigest = opts[:certdigest] # TODO put in URI bad_cert = false vim = nil loop do begin @@ -112,11 +79,11 @@ rev = vim.serviceContent.about.apiVersion env_rev = ENV['RVC_VIMREV'] if env_rev && env_rev.to_f == 0 vim.rev = env_rev else - vim.rev = [rev, env_rev || '5.0'].min + vim.rev = [rev, env_rev || '5.1'].min end end isVC = vim.serviceContent.about.apiType == "VirtualCenter" @@ -168,18 +135,14 @@ # Stash the address we used to connect so VMRC can use it. vim.define_singleton_method(:_host) { host } conn_name = host.dup - conn_name = "#{conn_name}:1" if $shell.connections.member? conn_name - conn_name.succ! while $shell.connections.member? conn_name + conn_name = "#{conn_name}:1" if shell.connections.member? conn_name + conn_name.succ! while shell.connections.member? conn_name - $shell.connections[conn_name] = vim - $shell.session.set_connection conn_name, - 'host' => host, - 'username' => username, - 'rev' => opts[:rev] + shell.connections[conn_name] = vim end def prompt_password ask("password: ") { |q| q.echo = false } end @@ -240,11 +203,11 @@ opts :tasks do summary "Watch tasks in progress" end def tasks - conn = single_connection [$shell.fs.cur] + conn = single_connection [shell.fs.cur] begin view = conn.serviceContent.viewManager.CreateListView collector = conn.serviceContent.taskManager.CreateCollectorForTasks(:filter => { @@ -317,10 +280,13 @@ include_default = servers.member? vim puts "#{Time.now}: Generating log bundles..." bundles = begin - diagMgr.GenerateLogBundles_Task(:includeDefault => include_default, :host => hosts).wait_for_completion + diagMgr.GenerateLogBundles_Task( + :includeDefault => include_default, + :host => hosts + ).wait_for_completion rescue VIM::TaskInProgress $!.task.wait_for_completion end dest_path = nil