Module: PuppetX::EnterpriseModules::OraInstall::Tasks

Defined in:
lib/puppet_x/enterprisemodules/ora_install/tasks.rb

Overview

Docs

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(parent) ⇒ Object



10
11
12
# File 'lib/puppet_x/enterprisemodules/ora_install/tasks.rb', line 10

def self.extended(parent)
  parent.extend GetHomes
end

Instance Method Details

#copy(files_array, current_path, new_path) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/puppet_x/enterprisemodules/ora_install/tasks.rb', line 111

def copy(files_array, current_path, new_path)
  files_array.each do | file |
    current_file = "#{current_path}/#{file}"
    new_file     = "#{new_path}/#{file}"
    if File.exist?(current_file)
      uid = File.stat(current_file).uid
      owner = Etc.getpwuid(uid).name
      gid = File.stat(current_file).gid
      group = Etc.getgrgid(gid).name
      mode = File.stat(current_file).mode
      FileUtils.cp(current_file , new_file)
      FileUtils.chown(owner, group, new_file)
      FileUtils.chmod(mode, new_file)
      log_msg "File #{current_file} copied to #{new_file}, with owner #{owner}:#{group} and mode #{mode.to_s(8)[2..5]}."
    else
      log_msg "File #{current_file} not found. Skipping it."
    end
  end
end

#database_action(action, sid, options) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/puppet_x/enterprisemodules/ora_install/tasks.rb', line 64

def database_action(action, sid, options)
  Puppet::Util::Log.level = @verbose
  home    = oracle_home_for(sid)
  os_user = user_for_file(home)
  opts = {
    :name                    => 'startup',
    :instance_name           => sid,
    :os_user                 => os_user,
    :oracle_product_home_dir => home
  }

  provider = Puppet::Type.type(:db_control).new(opts).provider
  if provider.status == action
    return "Instance #{sid} already #{action}'ed."
  else
    provider.instance_control(action, options)
  end
end

#error_output(exitcode, message, kind) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/puppet_x/enterprisemodules/ora_install/tasks.rb', line 36

def error_output(exitcode, message, kind)
  rc = exitcode.to_s.split.last
  endtime = Time.now.iso8601
  json = {
    :message => message,
    :ok      => false,
    :_error  => {
      :msg        => "Task exited : #{rc}\n#{message}",
      :kind       => kind,
      :details    => {
        :exitcode   => rc,
        :start_time => @starttime,
        :end_time   => endtime,
      },
    },
  }
  puts JSON.pretty_generate(json)
  exit rc.to_i
end

#listener_action(action, sid, listener_name) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/puppet_x/enterprisemodules/ora_install/tasks.rb', line 91

def listener_action(action, sid, listener_name)
  Puppet::Util::Log.level = @verbose
  home    = oracle_home_for(sid)
  os_user = user_for_file(home)
  opts    = {
    :name            => 'start',
    :os_user         => os_user,
    :oracle_home_dir => home,
    :listener_name   => listener_name
  }

  provider = Puppet::Type.type(:db_listener).new(opts).provider
  if provider.status == action
    return "Listener \"#{listener_name}\" already #{action}'ed."
  else
    provider.listener_control(action)
  end

end

#log_msg(msg) ⇒ Object



14
15
16
# File 'lib/puppet_x/enterprisemodules/ora_install/tasks.rb', line 14

def log_msg(msg)
  @message << msg
end

#output(returncode, message) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/puppet_x/enterprisemodules/ora_install/tasks.rb', line 18

def output(returncode, message)
  endtime = Time.now.iso8601
  json = {
    :return     => returncode,
    :ok         => true,
    :message    => message,
    :start_time => @starttime,
    :end_time   => endtime,
  }
  # TODO Make it pretty for task too, this will only make it pretty for plans
  if @format == 'pretty'
    puts JSON.pretty_generate(json)
  else
    puts message
  end
  exit returncode.to_i
end

#shutdown(sid = nil, options = nil) ⇒ Object



60
61
62
# File 'lib/puppet_x/enterprisemodules/ora_install/tasks.rb', line 60

def shutdown(sid = nil, options = nil)
  database_action(:stop, sid, options)
end

#start_listener(sid = nil, listener_name) ⇒ Object



83
84
85
# File 'lib/puppet_x/enterprisemodules/ora_install/tasks.rb', line 83

def start_listener(sid = nil, listener_name)
  listener_action(:start, sid, listener_name)
end

#startup(sid = nil, options = nil) ⇒ Object



56
57
58
# File 'lib/puppet_x/enterprisemodules/ora_install/tasks.rb', line 56

def startup(sid = nil, options = nil)
  database_action(:start, sid, options)
end

#stop_listener(sid = nil, listener_name) ⇒ Object



87
88
89
# File 'lib/puppet_x/enterprisemodules/ora_install/tasks.rb', line 87

def stop_listener(sid = nil, listener_name)
  listener_action(:stop, sid, listener_name)
end