Module: Puppet_X::EnterpriseModules::WebLogic::Access

Includes:
EasyType::Encryption, Settings
Included in:
Functions, WlstProvider
Defined in:
lib/puppet_x/enterprisemodules/weblogic/access.rb

Overview

Access module

Constant Summary collapse

DEFAULT_FILE =
'/etc/wls_setting.yaml'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Settings

#configuration, #read_from_yaml, #setting_for, #settings

Class Method Details

.included(parent) ⇒ Object



21
22
23
# File 'lib/puppet_x/enterprisemodules/weblogic/access.rb', line 21

def self.included(parent)
  parent.extend(Access)
end

Instance Method Details

#child_of(type, variable = nil, &proc) ⇒ Object

Based on the value of ensure, do an autorequire or an autobefore



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/puppet_x/enterprisemodules/weblogic/access.rb', line 35

def child_of(type, variable = nil, &proc)
  autorequire(type) do
    next if instance_eval('self[:disable_autorequire]', __FILE__, __LINE__)

    begin
      present = instance_eval('self[:ensure]', __FILE__, __LINE__).to_s == 'present'
    rescue Puppet::Error
      present = true
    end
    if variable.nil? # Always
      instance_eval(&proc) if present
    elsif present
      self[variable].nil? || self[variable].to_s == 'absent' ? nil : instance_eval(&proc)
    end
  end
  if puppet_version_higher_or_equal_then('4.0.0')
    #
    # Older puppet versions don't support autobefore.
    # Because we want to be compatible with puppet 3, we will Skip
    # this functionality on older versions.
    #
    autobefore(type) do
      next if instance_eval('self[:disable_autorequire]', __FILE__, __LINE__)

      begin
        absent = instance_eval('self[:ensure]', __FILE__, __LINE__).to_s == 'absent'
      rescue Puppet::Error
        absent = false
      end
      if absent
        if variable.nil? # Always
          instance_eval(&proc)
        elsif provider
          #
          # Check the value of the provider is set
          #
          provider.send(variable).to_s == 'absent' ? nil : full_resource(provider).instance_eval(&proc)
        end
      end
    end
  else
    Puppet.debug "Skipping setting autobefore on #{type}"
  end
end

#puppet_version_higher_or_equal_then(version) ⇒ Object



25
26
27
28
29
# File 'lib/puppet_x/enterprisemodules/weblogic/access.rb', line 25

def puppet_version_higher_or_equal_then(version)
  current_version = Gem::Version.new(Puppet.version)
  requested_version = Gem::Version.new(version)
  current_version >= requested_version
end

#wlst(content, parameters = {}) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/puppet_x/enterprisemodules/weblogic/access.rb', line 80

def wlst(content, parameters = {})
  script = 'wlstScript'
  action = ''
  if parameters.nil?
    Puppet.debug "Executing: #{script} for a create,modify or destroy"
  else
    action = parameters['action']
    Puppet.debug "Executing: #{script} with action #{action}"
  end

  tmp_file = Tempfile.new([script, '.py'])
  tmp_file.write(content)
  tmp_file.close
  FileUtils.chmod(0o555, tmp_file.path)

  csv_string = ''
  domains = configuration

  case action
  when 'index'
    # if index do all domains
    i = 1
    domains.each do |key, values|
      Puppet.debug "domain found #{key}"
      csv_domain_string = execute_wlst(script, tmp_file, parameters, key, values, :return_output => true)
      if i > 1
        # with multi domain, remove first line if it is a header
        csv_domain_string = csv_domain_string.lines.to_a[1..-1].join
      end
      csv_string += csv_domain_string
      i += 1
    end
    convert_csv_data_to_hash(csv_string, [], :col_sep => ';')
  when 'execute'
    domains.each do |key, values|
      # check content if we do this for the right domain
      if content.include? "real_domain='#{key}"
        csv_string = execute_wlst(script, tmp_file, parameters, key, values, :return_output => true)
      else
        Puppet.debug "Skip WLST for domain #{key}"
      end
    end
    convert_csv_data_to_hash(csv_string, [], :col_sep => ';')
  else
    #  Puppet.info "domain found #{domain}"
    domains.each do |key, values|
      # check content if we do this for the right domain
      if content.include? "real_domain='#{key}"
        Puppet.debug "Got the right domain #{key} script, now execute WLST"
        execute_wlst(script, tmp_file, parameters, key, values, :return_output => false)
      else
        Puppet.debug "Skip WLST for domain #{key}"
      end
    end
  end
end