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.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 73 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
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 118 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.
55 56 57 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 55 def commands @commands end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
55 56 57 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 55 def host @host end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
55 56 57 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 55 def instance @instance end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
55 56 57 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 55 def name @name end |
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces.
55 56 57 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 55 def namespaces @namespaces end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
55 56 57 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 55 def parent @parent end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
55 56 57 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 55 def type @type end |
#type_info ⇒ Object (readonly)
Returns the value of attribute type_info.
55 56 57 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 55 def type_info @type_info end |
Class Method Details
.root(host) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 57 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
103 104 105 106 107 108 109 110 111 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 103 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
113 114 115 116 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 113 def obj conn = @host._connection conn.type(@type_info.wsdlName).new(conn, @instance) end |
#pretty_print(q) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 129 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
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 85 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_name ⇒ Object
96 97 98 99 100 101 |
# File 'lib/rbvmomi/vim/HostSystem.rb', line 96 def type_name if @type then @type elsif @parent then "#{@parent.type_name}.#{@name}" else 'vim.EsxCLI' end end |