Module: PuppetX::VMware::MapperNsx

Defined in:
lib/puppet_x/vmware/mapper_nsx.rb,
lib/puppet_x/vmware/mapper_nsx/nsx_edge_lb_vip.rb,
lib/puppet_x/vmware/mapper_nsx/nsx_edge_lb_pool.rb,
lib/puppet_x/vmware/mapper_nsx/nsx_edge_lb_global.rb,
lib/puppet_x/vmware/mapper_nsx/nsx_edge_lb_monitor.rb,
lib/puppet_x/vmware/mapper_nsx/nsx_edge_lb_app_rule.rb,
lib/puppet_x/vmware/mapper_nsx/nsx_edge_lb_app_profile.rb

Defined Under Namespace

Classes: Leaf, LeafData, Map, MapComponent, Node, NodeData, NsxEdgeLbAppProfile, NsxEdgeLbAppRule, NsxEdgeLbGlobal, NsxEdgeLbMonitor, NsxEdgeLbPool, NsxEdgeLbVip

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


600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
# File 'lib/puppet_x/vmware/mapper_nsx.rb', line 600

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
#require 'pry';binding.pry

  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.



529
530
531
# File 'lib/puppet_x/vmware/mapper_nsx.rb', line 529

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

.munge_to_symObject



543
544
545
546
547
# File 'lib/puppet_x/vmware/mapper_nsx.rb', line 543

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

.munge_to_tfsymsObject



533
534
535
536
537
538
539
540
541
# File 'lib/puppet_x/vmware/mapper_nsx.rb', line 533

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_nsx.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}"
  const_get(mapname).new
rescue Exception => e
  fail "#{self.name}: Error accessing or creating mapper \"#{mapname}\": #{e.message}"
end

.validate_i_ge(low) ⇒ Object



549
550
551
552
553
554
# File 'lib/puppet_x/vmware/mapper_nsx.rb', line 549

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



563
564
565
566
567
568
# File 'lib/puppet_x/vmware/mapper_nsx.rb', line 563

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



556
557
558
559
560
561
# File 'lib/puppet_x/vmware/mapper_nsx.rb', line 556

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