Module: PuppetX::EnterpriseModules::Oracle::Settings

Includes:
Information
Included in:
OracleFeature, Access, Command, OraTab, OrapwdCommand, RmanCommand, SqlplusCommand
Defined in:
lib/puppet_x/enterprisemodules/oracle/settings.rb

Overview

rubocop:disable Style/Documentation

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Information

#cached_sid_value, #cluster?, #cluster_instances, #containerdb?, #database_properties, #database_version, #db_create_file_dest, #db_domain, #db_for, #diagnostic_dest, #local_sid_for_db, #open_pdbs, #oracle_major_version, #oracle_managed_files_enabled?, #pdb?, #primary?, #rootdb?, #seeddb?, #sid_for, #value_for_init_param

Class Method Details

.included(parent) ⇒ Object



29
30
31
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 29

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

Instance Method Details

#asm_sid?(sid) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 59

def asm_sid?(sid)
  sid =~ ASM_REGXP
end

#asm_sidsObject



63
64
65
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 63

def asm_sids
  registered_sids.select { |sid| asm_sid?(sid) }
end

#configurationObject



43
44
45
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 43

def configuration
  @configuration = read_from_yaml
end

#configuration_for(key) ⇒ Object



33
34
35
36
37
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 33

def configuration_for(key)
  fail "No configuration found for #{key}." if configuration.nil? || configuration.key?(key).nil? || !configuration.key?(key)

  configuration[key]
end

#configuration_value_for(sid, value, default_value = '') ⇒ Object



39
40
41
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 39

def configuration_value_for(sid, value, default_value = '')
  configuration_for(sid).fetch(value) { default_value }
end

#container_db?(sid) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 129

def container_db?(sid)
  configuration_value_for(sid, 'cdb')
end

#database_sid?(sid) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 75

def database_sid?(sid)
  sid =~ NON_ASM_REGXP
end

#database_sidsObject



79
80
81
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 79

def database_sids
  registered_sids.select { |sid| database_sid?(sid) }
end

#default_asm_sidObject



209
210
211
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 209

def default_asm_sid
  asm_sids.find { |sid| default_sids.include? sid }
end

#default_database_sidObject



205
206
207
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 205

def default_database_sid
  database_sids.find { |sid| default_sids.include? sid }
end

#default_sidsObject



193
194
195
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 193

def default_sids
  configuration.select { |_sid, hash| hash['default'] == true }.to_h.keys
end

#local_pdb?(sid) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
118
119
120
121
122
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 115

def local_pdb?(sid)
  pdb = configuration_value_for(sid, 'pluggable')
  return false unless pdb

  container = configuration_value_for(sid, 'contained_by')
  connect_string = configuration_value_for(sid, 'connect_string')
  connect_string.empty? && running_pdb?(sid) ? true : connect_string.include?(Facter.value('hostname')) && running_db?(container) && running_pdb?(sid)
end

#mgmt_sid?(sid) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 67

def mgmt_sid?(sid)
  sid =~ MGMT_REGXP
end

#mgmt_sidsObject



71
72
73
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 71

def mgmt_sids
  registered_sids.select { |sid| mgmt_sid?(sid) }
end

#normal_db?(sid) ⇒ Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 133

def normal_db?(sid)
  !configuration_value_for(sid, 'pluggable')
end

#num_default_asm_sidsObject



201
202
203
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 201

def num_default_asm_sids
  database_sids.count { |sid| default_sids.include? sid }
end

#num_default_database_sidsObject



197
198
199
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 197

def num_default_database_sids
  database_sids.count { |sid| default_sids.include? sid }
end

#read_from_yamlObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 47

def read_from_yaml
  if File.exist?(settings_file)
    # rubocop:disable Security/Open
    # rubocop:disable Security/YAMLLoad
    open(settings_file) { |f| YAML.load(f) }
    # rubocop:enable Security/Open
    # rubocop:enable Security/YAMLLoad
  else
    {}
  end
end

#registered_sidsObject



95
96
97
98
99
100
101
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 95

def registered_sids
  if configuration.is_a?(Hash)
    configuration.keys
  else
    []
  end
end

#remote_sid?(sid) ⇒ Boolean

Is the SID a local running sid

Returns:

  • (Boolean)


104
105
106
107
108
109
110
111
112
113
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 104

def remote_sid?(sid)
  connect_string = configuration_value_for(sid, 'connect_string')
  #
  # Connect string is both used when accessing a remote database and when accessing
  # a container database. When we access a container database, the connect string
  # contains the local node name. So this is the way to distinquesh between a
  # pluggable database and a real remote database.
  #
  connect_string != '' && !connect_string.include?(Facter.value('hostname'))
end

#running_asm_sidsObject



181
182
183
184
185
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 181

def running_asm_sids
  asm_sids.select do |sid|
    process?(asm_process_regexp(sid)) || remote_sid?(sid)
  end
end

#running_database_sidsObject



149
150
151
152
153
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 149

def running_database_sids
  database_sids.select do |sid|
    process?(db_process_regexp(sid)) || remote_sid?(sid) || local_pdb?(sid)
  end
end

#running_db?(sid) ⇒ Boolean

Returns:

  • (Boolean)


137
138
139
140
141
142
143
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 137

def running_db?(sid)
  if Facter.value(:kernel) == 'windows'
    `tasklist /svc | findstr "oracle.exe.*OracleService#{sid}"` != ''
  else
    `ps -ef | egrep "(ora|xe)_pmon_#{sid}$"` != ''
  end
end

#running_mgmt_sidsObject



187
188
189
190
191
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 187

def running_mgmt_sids
  mgmt_sids.select do |sid|
    process?(mgmt_process_regexp(sid)) || remote_sid?(sid)
  end
end

#running_mt_database_sidsObject

Array of multitenant database that are running Might not be needed after all, we’ll see



175
176
177
178
179
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 175

def running_mt_database_sids
  running_database_sids.select do |sid|
    container_db?(sid) || local_pdb?(sid)
  end
end

#running_nopdb_database_sidsObject



155
156
157
158
159
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 155

def running_nopdb_database_sids
  database_sids.select do |sid|
    process?(db_process_regexp(sid)) || remote_sid?(sid)
  end
end

#running_normal_database_sidsObject

Array of normal database that are running Might not be needed after all, we’ll see



167
168
169
170
171
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 167

def running_normal_database_sids
  running_database_sids.select do |sid|
    process?(db_process_regexp(sid)) && normal_db?(sid)
  end
end

#running_pdb?(sid) ⇒ Boolean

Returns:

  • (Boolean)


124
125
126
127
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 124

def running_pdb?(sid)
  container = configuration_value_for(sid, 'contained_by')
  open_pdbs(container).include?(sid)
end

#running_primary_database_sidsObject



161
162
163
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 161

def running_primary_database_sids
  running_database_sids.select { |sid| primary?(sid) }
end

#running_sidsObject



145
146
147
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 145

def running_sids
  running_database_sids + running_asm_sids + running_mgmt_sids
end

#settings_fileObject



20
21
22
23
24
25
26
27
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 20

def settings_file
  path = if Puppet::Util::Platform.windows?
           'c:\\Windows\\System32\\Drivers\\etc\ora_setting.yaml'
         else
           '/etc/ora_setting.yaml'
         end
  Pathname.new(path).expand_path
end

#valid_asm_sid?(sid) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 87

def valid_asm_sid?(sid)
  asm_sids.include?(sid)
end

#valid_database_sid(sid) ⇒ Object



91
92
93
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 91

def valid_database_sid(sid)
  database_sids.include?(sid)
end

#valid_sid?(sid) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/puppet_x/enterprisemodules/oracle/settings.rb', line 83

def valid_sid?(sid)
  registered_sids.include?(sid)
end