Class: PuppetX::EnterpriseModules::Oracle::Command

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

Overview

docs

Instance Attribute Summary collapse

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(command, options, valid_options = COMMAND_VALID_OPTIONS) ⇒ Command

Returns a new instance of Command.



27
28
29
30
31
32
33
34
35
36
# File 'lib/puppet_x/enterprisemodules/oracle/command.rb', line 27

def initialize(command, options, valid_options = COMMAND_VALID_OPTIONS)
  @valid_options = valid_options
  check_options(options)
  @command  = command
  @password = options[:password] # may be empty
  @timeout  = options.fetch(:timeout) { DEFAULT_TIMEOUT }
  @sid      = options.fetch(:sid) { raise ArgumentError, 'you need to specify a sid for oracle access' }
  @os_user  = options.fetch(:os_user) { configuration_value_for(@sid, 'os_user') }
  @username = options.fetch(:username, nil)
end

Instance Attribute Details

#os_userObject (readonly)

Returns the value of attribute os_user.



25
26
27
# File 'lib/puppet_x/enterprisemodules/oracle/command.rb', line 25

def os_user
  @os_user
end

#passwordObject (readonly)

Returns the value of attribute password.



25
26
27
# File 'lib/puppet_x/enterprisemodules/oracle/command.rb', line 25

def password
  @password
end

#sidObject (readonly)

Returns the value of attribute sid.



25
26
27
# File 'lib/puppet_x/enterprisemodules/oracle/command.rb', line 25

def sid
  @sid
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



25
26
27
# File 'lib/puppet_x/enterprisemodules/oracle/command.rb', line 25

def timeout
  @timeout
end

#usernameObject (readonly)

Returns the value of attribute username.



25
26
27
# File 'lib/puppet_x/enterprisemodules/oracle/command.rb', line 25

def username
  @username
end

Instance Method Details

#command_string(arguments = '') ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/puppet_x/enterprisemodules/oracle/command.rb', line 38

def command_string(arguments = '')
  config = @configuration.fetch(@sid) { fail "#{sid} not found in settings" }
  oracle_home = config.fetch('oracle_home') { fail "oracle_home not specified for #{sid}" }
  # TODO: what mechanisme do we need for Windows
  if Puppet::Util::Platform.windows?
    # TODO: Do we need to set ORACLE_HOME?
    "cd #{working_dir} & set ORACLE_SID=#{@host_sid} & #{@command} #{arguments}\""
  else
    "su - #{@os_user} -c \"cd #{working_dir}; export ORACLE_SID=#{@sid}; export ORACLE_HOME=#{oracle_home}; export PATH=$PATH:#{oracle_home}/bin; #{@command} #{arguments}\""
  end
end

#execute(arguments) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/puppet_x/enterprisemodules/oracle/command.rb', line 50

def execute(arguments)
  options = { :failonfail => true, :combine => true }
  value = ''
  within_time(@timeout) do
    Puppet.debug "command.rb: Executing #{@command} command: #{arguments} on #{@sid} as #{os_user}, connected as #{username}"
    value = if Puppet::Util::Platform.windows?
              `command_string(arguments)`
            else
              Puppet::Util::Execution.execute(command_string(arguments), options)
            end
  end
  value
end