Class: RbVmomi::VIM::EsxcliNamespace
- Inherits:
-
Object
- Object
- RbVmomi::VIM::EsxcliNamespace
- Defined in:
- lib/rbvmomi/vim/HostSystem.rb
Constant Summary collapse
- ESXCLI_PREFIX =
'vim.EsxCLI.'
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#type_info ⇒ Object
readonly
Returns the value of attribute type_info.
Class Method Summary collapse
Instance Method Summary collapse
- #cli_info ⇒ Object
-
#initialize(name, parent, host) ⇒ EsxcliNamespace
constructor
A new instance of EsxcliNamespace.
- #method_missing(name, *args) ⇒ Object
- #obj ⇒ Object
- #pretty_print(q) ⇒ Object
- #realize(type, instance, type_info) ⇒ Object
- #type_name ⇒ Object
Constructor Details
#initialize(name, parent, host) ⇒ EsxcliNamespace
Returns a new instance of EsxcliNamespace.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 75 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
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 121 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
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
57 58 59 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 57 def commands @commands end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
57 58 59 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 57 def host @host end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
57 58 59 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 57 def instance @instance end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
57 58 59 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 57 def name @name end |
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
57 58 59 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 57 def namespaces @namespaces end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
57 58 59 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 57 def parent @parent end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
57 58 59 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 57 def type @type end |
#type_info ⇒ Object (readonly)
Returns the value of attribute type_info.
57 58 59 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 57 def type_info @type_info end |
Class Method Details
.root(host) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 59 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_info ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 106 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 |
#obj ⇒ Object
116 117 118 119 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 116 def obj conn = @host._connection conn.type(@type_info.wsdlName).new(conn, @instance) end |
#pretty_print(q) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 132 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
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 87 def realize type, instance, type_info raise 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_name ⇒ Object
99 100 101 102 103 104 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 99 def type_name if @type then @type elsif @parent then "#{@parent.type_name}.#{@name}" else 'vim.EsxCLI' end end |