Module: PuppetX::VMware::Mapper

Defined in:
lib/puppet_x/vmware/mapper/ip_pool_map.rb,
lib/puppet_x/vmware/mapper.rb,
lib/puppet_x/vmware/mapper/host_virtual_nic_spec_map.rb,
lib/puppet_x/vmware/mapper/cluster_config_spec_ex_map.rb,
lib/puppet_x/vmware/mapper/vmware_dvs_config_spec_map.rb,
lib/puppet_x/vmware/mapper/dvportgroup_config_spec_map.rb,
lib/puppet_x/vmware/mapper/host_internet_scsi_hba_send_target_map.rb

Overview

Copyright © 2013 VMware, Inc.

Defined Under Namespace

Classes: ClusterConfigSpecExMap, DVPortgroupConfigSpecMap, HostInternetScsiHbaSendTargetMap, HostVirtualNicSpecMap, IpPoolMap, Leaf, LeafData, Map, MapComponent, Node, NodeData, VMwareDVSConfigSpecMap

Constant Summary collapse

PROP_NAME_IS_FULL_PATH =

constant for a meaningful unique name that you don’t have to invent

:PROP_NAME_IS_FULL_PATH
InheritablePolicyInherited =

constants for use in Leaf Nodes for InheritablePolicy

:InheritablePolicyInherited
InheritablePolicyExempt =
:InheritablePolicyExempt
InheritablePolicyValue =
:InheritablePolicyValue

Class Method Summary collapse

Class Method Details

.insyncInheritablePolicyValue(is, resource, prop_name) ⇒ Object

This is a version of insync? for InheritablePolicy ‘value’ properties. It looks at the current (is_now) and desired (should) values of ‘inheritable’ (finding it at the same level of nesting) to determine whether the property of interest should be considered to be ‘in sync’. If that can’t be determined, the calling routine should call the normal insync for the property’s class.

Here’s what usage looks like in the type:

newproperty(:foo, ...) do
  :
  def insync?(is)
    v = PuppetX::VMware::Mapper.
        insyncInheritablePolicyValue is, @resource, :foo
    v = super(is) if v.nil?
    v
  end
  :
end

XXX TODO fix this to return a block, to directly call super(is) XXX TODO fix this to return a block, to directly use @resource XXX TODO fix this to hold prop_name in a closure, so the caller

doesn't have to fool around with eval and interpolation
when automatically generating newproperty


493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# File 'lib/puppet_x/vmware/mapper.rb', line 493

def self.insyncInheritablePolicyValue is, resource, prop_name

  provider = resource.provider
  map = provider.map

  # find the leaf for the value to be insync?'d
  leaf_value = map.leaf_list.find do |leaf|
    leaf.prop_name == prop_name
  end

  # for the corresponding 'inherited' value, generate the path
  path_is_now_inherited = leaf_value.path_is_now[0..-2].dup.push(:inherited)

  # for the corresponding 'inherited' value, find leaf, get prop_name
  prop_name_inherited = map.leaf_list.find do |leaf|
                          leaf.path_is_now == path_is_now_inherited
                        end.prop_name

  # get 'is_now' value for 'inherited' from provider
  is_now_inherited = provider.send "#{prop_name_inherited}".to_sym
  # get 'should' value for 'inherited' from resource
  should_inherited = resource[prop_name_inherited]
  # munge
  is_now_inherited = munge_to_tfsyms.call is_now_inherited
  should_inherited = munge_to_tfsyms.call should_inherited

  case [is_now_inherited, should_inherited]
  # 'should' be inherited, so current value is ignored
  when [:true,  :true]  ; then return false
  when [:false, :true]  ; then return false
  # was inherited, but should be no longer - must supply all values
  when [:true, :false]  ; then return false
  # value is and should be uninherited, so normal insync?
  when [:false, :false] ; then return nil
  else
    return nil if is_now_inherited.nil?
    fail "For InheritedPolicy #{leaf_value.full_name}, "\
      "current '.inherited' is '#{is_now_inherited.inspect}', "\
      "requested '.inherited' is '#{should_inherited.inspect}'"
  end
end

.munge_to_iObject

This is a set of tiny utilities for defining validation and munging routines in the input tree for Map. Some are simply static blocks wrapped in Proc, while others allow tailoring the block to specific cases.



422
423
424
# File 'lib/puppet_x/vmware/mapper.rb', line 422

def self.munge_to_i
  Proc.new {|v| v.to_i}
end

.munge_to_symObject



436
437
438
439
440
# File 'lib/puppet_x/vmware/mapper.rb', line 436

def self.munge_to_sym
  Proc.new do |v|
    v.to_sym if String === v
  end
end

.munge_to_tfsymsObject



426
427
428
429
430
431
432
433
434
# File 'lib/puppet_x/vmware/mapper.rb', line 426

def self.munge_to_tfsyms
  Proc.new do |v|
    case v
    when FalseClass then :false
    when TrueClass  then :true
    else v
    end
  end
end

.new_map(mapname) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/puppet_x/vmware/mapper.rb', line 23

def self.new_map mapname
  mapfile = PuppetX::VMware::Util.snakeize mapname
  require 'pathname'
  file_path = Pathname.new(__FILE__)
  Puppet.debug "require \"#{file_path.parent}/#{file_path.basename '.rb'}/#{mapfile}\""
  require "#{file_path.parent}/#{file_path.basename '.rb'}/#{mapfile}"
  PuppetX::VMware::Mapper::const_get(mapname).new
rescue Exception => e
  fail "#{self.name}: Error accessing or creating mapper \"#{mapname}\": #{e.message}"
end

.validate_i_ge(low) ⇒ Object



442
443
444
445
446
447
# File 'lib/puppet_x/vmware/mapper.rb', line 442

def self.validate_i_ge(low)
  Proc.new do |v|
    v = Integer v
    fail "value #{v} not greater than nor equal to #{low}" unless low <= v
  end
end

.validate_i_in(range) ⇒ Object



456
457
458
459
460
461
# File 'lib/puppet_x/vmware/mapper.rb', line 456

def self.validate_i_in(range)
  Proc.new do |v|
    v = Integer v
    fail "value #{v} not in '#{range.inspect}'" unless range.include? v
  end
end

.validate_i_le(high) ⇒ Object



449
450
451
452
453
454
# File 'lib/puppet_x/vmware/mapper.rb', line 449

def self.validate_i_le(high)
  Proc.new do |v|
    v = Integer v
    fail "value #{v} not less than nor equal to #{high}" unless v <= high
  end
end