Class: PuppetX::VMware::Mapper::Map
- Inherits:
-
Object
- Object
- PuppetX::VMware::Mapper::Map
- Defined in:
- lib/puppet_x/vmware/mapper.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#leaf_list ⇒ Object
readonly
Returns the value of attribute leaf_list.
-
#node_list ⇒ Object
readonly
Returns the value of attribute node_list.
Instance Method Summary collapse
- #annotate_is_now(is_now) ⇒ Object
-
#initialize ⇒ Map
constructor
abstract class - concrete classes contain initialization data - this class contains methods.
- #objectify(should) ⇒ Object
Constructor Details
#initialize ⇒ Map
abstract class
-
concrete classes contain initialization data
-
this class contains methods
148 149 150 151 152 153 154 155 |
# File 'lib/puppet_x/vmware/mapper.rb', line 148 def initialize # @initTree is defined in subclasses... @leaf_list = [] @node_list = [] # walk down the initTree and find the leaves walk_down @initTree, [], @leaf_list, @node_list end |
Instance Attribute Details
#leaf_list ⇒ Object (readonly)
Returns the value of attribute leaf_list.
157 158 159 |
# File 'lib/puppet_x/vmware/mapper.rb', line 157 def leaf_list @leaf_list end |
#node_list ⇒ Object (readonly)
Returns the value of attribute node_list.
157 158 159 |
# File 'lib/puppet_x/vmware/mapper.rb', line 157 def node_list @node_list end |
Instance Method Details
#annotate_is_now(is_now) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/puppet_x/vmware/mapper.rb', line 227 def annotate_is_now is_now # for each Node representing an abstract type, annotate # the is_now tree to include the current :vsphereType @node_list.each do |node| if (node.node_type == :ABSTRACT) and o = PuppetX::VMware::Util::nested_value(is_now, node.path_is_now) o[node.node_type_key] = o.class.to_s.split('::').last.to_sym end end is_now end |
#objectify(should) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/puppet_x/vmware/mapper.rb', line 159 def objectify should obj_tree = Marshal.load(Marshal.dump(should)) # Step through the node list, which is in bottom-up sequence. # If data for a vSphere object are found in 'should', # create the object and replace the data with the object. @node_list.each do |node| node = node.dup Puppet.debug "node #{node.path_should.join('.')}: checking #{node.inspect}" data = PuppetX::VMware::Util::nested_value(obj_tree, node.path_should) if data Puppet.debug "node #{node.path_should.join('.')}: found #{data.inspect}" # If this node is a concrete type, the type is in the node. # If it's an abstract type, the type must be in a subkey. node_type = node.node_type node_type = data.delete(node.node_type_key) if node_type == :ABSTRACT if data.empty? # data was originally empty, or contained only type information parent = PuppetX::VMware::Util::nested_value(obj_tree, node.path_should[0..-2]) parent.delete(node.path_should[-1]) Puppet.debug "node #{node.path_should.join('.')}: key and value deleted" else unless node_type if (node.node_type == :ABSTRACT) && node.node_type_key msg = "Input error. vSphere API object type required: " + "[#{node.path_should.join('.')}.#{node.node_type_key}]" else # neither node_type nor node_type_key found in initTree msg = "Internal error. Type unknown for vSphere API object " + "at [#{node.path_should.join('.')}] type unknown." end fail msg end begin vso = RbVmomi::VIM.const_get(node_type).new data Puppet.debug "node #{node.path_should.join('.')}: created #{vso.inspect}" rescue RuntimeError => e # Check for invalid properties that can occur with abstract types. # See for example ClusterDasAdmissionControlPolicy at # http://pubs.vmware.com/vsphere-51/topic/ # com.vmware.wssdk.apiref.doc/ # vim.cluster.DasAdmissionControlPolicy.html r = e..match(/unexpected property name (.*)/) if r && r[1] name = r[1] msg = "Property [#{node.path_should.join('.')}.#{name}] " + "incompatible with type '#{node_type}'" fail msg else fail e. end end # store the object in the tree in place of the data hash if node.path_should.empty? obj_tree = vso else PuppetX::VMware::Util::nested_value_set(obj_tree, node.path_should, vso) end end end end obj_tree end |