Class: Puppet::Provider::Asadmin

Inherits:
Puppet::Provider
  • Object
show all
Defined in:
lib/puppet/provider/asadmin.rb

Instance Method Summary collapse

Instance Method Details

#asadmin_exec(passed_args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/puppet/provider/asadmin.rb', line 3

def asadmin_exec(passed_args)
  
  # Use dashost if present
  if @resource.parameters.include?(:dashost)
    host = @resource[:dashost]
  end
  
  # Use dasport first, and then fallback to portbase
  if @resource.parameters.include?(:dasport)
    port = @resource[:dasport]
  else
    port = @resource[:portbase].to_i + 48
  end

  # Compile an array of command args
  args = Array.new
  args << '--host' << host if host && !host.nil?
  args << '--port' << port.to_s
  args << '--user' << @resource[:asadminuser]
  # Only add passwordfile if specified
  args << '--passwordfile' << @resource[:passwordfile] if @resource[:passwordfile] and
    not @resource[:passwordfile].empty?
      
  # Need to add the passed_args to args array.  
  passed_args.each { |arg| args << arg }
  
  # Transform args array into a exec args string.  
  exec_args = args.join " "
  command = "asadmin #{exec_args}"
  Puppet.debug("asadmin command = #{command}")
  
  # Compile the actual command as the specified user. 
  command = "su - #{@resource[:user]} -c \"#{command}\"" if @resource[:user] and
    not command.match(/create-service/)
  # Debug output of command if required. 
  Puppet.debug("exec command = #{command}")
  
  # Execute the command. 
  output = `#{command}`
  # Check return code and fail if required
  self.fail output unless $? == 0
  
  # Split into array, for later processing...
  result = output.split(/\n/)
  Puppet.debug("result = \n#{result.inspect}")

  # Return the result
  result
end

#escape(value) ⇒ Object



53
54
55
56
# File 'lib/puppet/provider/asadmin.rb', line 53

def escape(value)
  # Add three backslashes to escape the colon
  return value.gsub(/:/) { '\\:' }
end