Class: RbVmomi::VIM::EsxcliNamespace

Inherits:
Object
  • Object
show all
Defined in:
lib/rbvmomi/vim/HostSystem.rb

Constant Summary collapse

ESXCLI_PREFIX =
'vim.EsxCLI.'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parent, host) ⇒ EsxcliNamespace

Returns a new instance of EsxcliNamespace



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rbvmomi/vim/HostSystem.rb', line 70

def initialize name, parent, host
  @name = name
  @parent = parent
  @host = host
  @type = nil
  @instance = nil
  @type_info = nil
  @namespaces = Hash.new { |h,k| h[k] = self.class.new k, self, host }
  @commands = {}
  @cached_cli_info = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



115
116
117
118
119
120
121
122
123
124
# File 'lib/rbvmomi/vim/HostSystem.rb', line 115

def method_missing name, *args
  name = name.to_s
  if @namespaces.member? name and args.empty?
    @namespaces[name]
  elsif @commands.member? name
    @commands[name].call *args
  else
    raise NoMethodError
  end
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands



52
53
54
# File 'lib/rbvmomi/vim/HostSystem.rb', line 52

def commands
  @commands
end

#hostObject (readonly)

Returns the value of attribute host



52
53
54
# File 'lib/rbvmomi/vim/HostSystem.rb', line 52

def host
  @host
end

#instanceObject (readonly)

Returns the value of attribute instance



52
53
54
# File 'lib/rbvmomi/vim/HostSystem.rb', line 52

def instance
  @instance
end

#nameObject (readonly)

Returns the value of attribute name



52
53
54
# File 'lib/rbvmomi/vim/HostSystem.rb', line 52

def name
  @name
end

#namespacesObject (readonly)

Returns the value of attribute namespaces



52
53
54
# File 'lib/rbvmomi/vim/HostSystem.rb', line 52

def namespaces
  @namespaces
end

#parentObject (readonly)

Returns the value of attribute parent



52
53
54
# File 'lib/rbvmomi/vim/HostSystem.rb', line 52

def parent
  @parent
end

#typeObject (readonly)

Returns the value of attribute type



52
53
54
# File 'lib/rbvmomi/vim/HostSystem.rb', line 52

def type
  @type
end

#type_infoObject (readonly)

Returns the value of attribute type_info



52
53
54
# File 'lib/rbvmomi/vim/HostSystem.rb', line 52

def type_info
  @type_info
end

Class Method Details

.root(host) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rbvmomi/vim/HostSystem.rb', line 54

def self.root host
  type_hash = host.dti.toRbvmomiTypeHash
  VIM.loader.add_types type_hash
  all_instances = host.dtm.DynamicTypeMgrQueryMoInstances
  instances = Hash[all_instances.select { |x| x.moType.start_with? ESXCLI_PREFIX }.
                                 map { |x| [x.moType,x.id] }]
  type_infos = Hash[host.dti.managedTypeInfo.map { |x| [x.name,x] }]
  new('root', nil, host).tap do |root|
    instances.each do |type,instance|
      path = type.split('.')[2..-1]
      ns = path.inject(root) { |b,v| b.namespaces[v] }
      ns.realize type, instance, type_infos[type]
    end
  end
end

Instance Method Details

#cli_infoObject



100
101
102
103
104
105
106
107
108
# File 'lib/rbvmomi/vim/HostSystem.rb', line 100

def cli_info
  @cached_cli_info ||=
    if @host.direct?
      @host.cli_info_fetcher.VimCLIInfoFetchCLIInfo(:typeName => type_name)
    else
      @host.mme.execute(@host.cli_info_fetcher._ref,
                        "vim.CLIInfo.FetchCLIInfo", :typeName => type_name)
    end
end

#objObject



110
111
112
113
# File 'lib/rbvmomi/vim/HostSystem.rb', line 110

def obj
  conn = @host._connection
  conn.type(@type_info.wsdlName).new(conn, @instance)
end

#pretty_print(q) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/rbvmomi/vim/HostSystem.rb', line 126

def pretty_print q
  q.text @name
  q.text ' '
  q.group 2 do
    q.text '{'
    q.breakable
    items = (@namespaces.values+@commands.values).sort_by(&:name)
    q.seplist items, nil, :each do |v|
      if v.is_a? VIM::EsxcliNamespace
        q.pp v
      else
        q.text v.name
      end
    end
  end
  q.breakable
  q.text '}'
end

#realize(type, instance, type_info) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/rbvmomi/vim/HostSystem.rb', line 82

def realize type, instance, type_info
  fail if @type or @instance
  @type = type
  @instance = instance
  @type_info = type_info
  @type_info.method.each do |method_type_info|
    name = method_type_info.name
    @commands[name] = VIM::EsxcliCommand.new self, method_type_info
  end
end

#type_nameObject



93
94
95
96
97
98
# File 'lib/rbvmomi/vim/HostSystem.rb', line 93

def type_name
  if @type then @type
  elsif @parent then "#{@parent.type_name}.#{@name}"
  else 'vim.EsxCLI'
  end
end