Class: PuppetX::EnterpriseModules::Oracle::OraTab

Inherits:
Object
  • Object
show all
Includes:
Settings
Defined in:
lib/puppet_x/enterprisemodules/oracle/ora_tab.rb

Overview

Docs

Instance Method Summary collapse

Methods included from Settings

#asm_sid?, #asm_sids, #configuration, #configuration_for, #configuration_value_for, #container_db?, #database_sid?, #database_sids, #default_asm_sid, #default_database_sid, #default_sids, included, #local_pdb?, #mgmt_sid?, #mgmt_sids, #normal_db?, #num_default_asm_sids, #num_default_database_sids, #read_from_yaml, #registered_sids, #remote_sid?, #running_asm_sids, #running_database_sids, #running_db?, #running_mgmt_sids, #running_mt_database_sids, #running_nopdb_database_sids, #running_normal_database_sids, #running_pdb?, #running_primary_database_sids, #running_sids, #settings_file, #valid_asm_sid?, #valid_database_sid, #valid_sid?

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, included, #local_sid_for_db, #open_pdbs, #oracle_major_version, #oracle_managed_files_enabled?, #pdb?, #primary?, #rootdb?, #seeddb?, #sid_for, #value_for_init_param

Constructor Details

#initialize(file = default_file) ⇒ OraTab

Returns a new instance of OraTab.



36
37
38
39
40
# File 'lib/puppet_x/enterprisemodules/oracle/ora_tab.rb', line 36

def initialize(file = default_file)
  fail "oratab #{file} not found. Probably Oracle not installed" unless File.exist?(file)

  @oratab = file
end

Instance Method Details

#add_new_entry(sid, home, start) ⇒ Object



42
43
44
# File 'lib/puppet_x/enterprisemodules/oracle/ora_tab.rb', line 42

def add_new_entry(sid, home, start)
  write(append_new_entry(sid, home, start))
end

#append_new_entry(sid, home, start) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/puppet_x/enterprisemodules/oracle/ora_tab.rb', line 54

def append_new_entry(sid, home, start)
  if oratab_content[-1] == "\n"
    "#{oratab_content}#{sid}:#{home}:#{start}\n"
  else
    "#{oratab_content}\n#{sid}:#{home}:#{start}\n"
  end
end

#delete(content) ⇒ Object



70
71
72
73
74
# File 'lib/puppet_x/enterprisemodules/oracle/ora_tab.rb', line 70

def delete(content)
  input = File.readlines(default_file)
  File.open(default_file, 'w') { |f| input.each { |line| f.write(line) unless line.include? content } }
  nil
end

#ensure_entry(sid, home, start) ⇒ Object



46
47
48
# File 'lib/puppet_x/enterprisemodules/oracle/ora_tab.rb', line 46

def ensure_entry(sid, home, start)
  add_new_entry(sid, home, start) unless entry_exists?(sid)
end

#entriesObject



94
95
96
97
98
99
100
101
102
103
# File 'lib/puppet_x/enterprisemodules/oracle/ora_tab.rb', line 94

def entries
  values = []
  File.open(@oratab) do |oratab|
    oratab.each_line do |line|
      content = [:sid, :home, :start].zip(line.split(':'))
      values << content.to_h unless comment?(line)
    end
  end
  values
end

#entry(sid, home, start) ⇒ Object



62
63
64
# File 'lib/puppet_x/enterprisemodules/oracle/ora_tab.rb', line 62

def entry(sid, home, start)
  "#{sid}:#{home}:#{start}\n"
end

#entry_autostart?(sid) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/puppet_x/enterprisemodules/oracle/ora_tab.rb', line 80

def entry_autostart?(sid)
  entry_for(sid)[:start].chomp
end

#entry_exists?(sid) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/puppet_x/enterprisemodules/oracle/ora_tab.rb', line 76

def entry_exists?(sid)
  entries.find { |x| x[:sid] == sid }
end

#entry_for(sid) ⇒ Object



84
85
86
# File 'lib/puppet_x/enterprisemodules/oracle/ora_tab.rb', line 84

def entry_for(sid)
  entries.find { |x| x[:sid] == sid }
end

#oratab_contentObject



88
89
90
91
92
# File 'lib/puppet_x/enterprisemodules/oracle/ora_tab.rb', line 88

def oratab_content
  File.read(default_file)
rescue Errno::ENOENT
  DEFAULT_CONTENT
end

#remove_entry(sid, home, start) ⇒ Object



50
51
52
# File 'lib/puppet_x/enterprisemodules/oracle/ora_tab.rb', line 50

def remove_entry(sid, home, start)
  delete(entry(sid, home, start))
end

#write(content) ⇒ Object



66
67
68
# File 'lib/puppet_x/enterprisemodules/oracle/ora_tab.rb', line 66

def write(content)
  File.write(default_file, content)
end