File: sms.rb

package info (click to toggle)
ruby-rbvmomi 1.8.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,756 kB
  • sloc: ruby: 5,590; sh: 36; makefile: 7
file content (68 lines) | stat: -rw-r--r-- 2,173 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright (c) 2013 VMware, Inc.  All Rights Reserved.
require 'rbvmomi'
module RbVmomi

# A connection to one vSphere SMS endpoint.
# @see #serviceInstance
class SMS < Connection
  # Connect to a vSphere SMS endpoint
  #
  # @param [VIM] Connection to main vSphere API endpoint
  # @param [Hash] opts The options hash.
  # @option opts [String]  :host Host to connect to.
  # @option opts [Numeric] :port (443) Port to connect to.
  # @option opts [Boolean] :ssl (true) Whether to use SSL.
  # @option opts [Boolean] :insecure (false) If true, ignore SSL certificate errors.
  # @option opts [String]  :path (/sms/sdk) SDK endpoint path.
  # @option opts [Boolean] :debug (false) If true, print SOAP traffic to stderr.
  def self.connect vim, opts = {}
    fail unless opts.is_a? Hash
    opts[:host] = vim.host
    opts[:ssl] = true unless opts.member? :ssl or opts[:"no-ssl"]
    opts[:insecure] ||= true
    opts[:port] ||= (opts[:ssl] ? 443 : 80)
    opts[:path] ||= '/sms/sdk'
    opts[:ns] ||= 'urn:sms'
    rev_given = opts[:rev] != nil
    opts[:rev] = '4.0' unless rev_given
    opts[:debug] = (!ENV['RBVMOMI_DEBUG'].empty? rescue false) unless opts.member? :debug

    new(opts).tap do |sms|
      sms.vcSessionCookie = vim.cookie.split('"')[1]
    end
  end

  def vcSessionCookie= cookie
    @vcSessionCookie = cookie
  end

  def rev= x
    super
    @serviceContent = nil
  end

  # Return the ServiceInstance
  #
  # The ServiceInstance is the root of the vSphere inventory.
  def serviceInstance
    @serviceInstance ||= VIM::SmsServiceInstance self, 'ServiceInstance'
  end

  # @private
  def pretty_print pp
    pp.text "SMS(#{@opts[:host]})"
  end

  add_extension_dir File.join(File.dirname(__FILE__), "sms")

  if File.exist?("/usr/share/ruby-rbvmomi/vmodl.db")
      load_vmodl(ENV['VMODL'] || "/usr/share/ruby-rbvmomi/vmodl.db")
  elsif File.exist?(File.join(File.dirname(__FILE__), "../../../../share/ruby-rbvmomi/vmodl.db"))
      load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), "../../../../share/ruby-rbvmomi/vmodl.db"))
  else
      load_vmodl(ENV['VMODL'] || File.join(File.dirname(__FILE__), "../../vmodl.db"))
  end
end

end