Class: Puppet_X::EnterpriseModules::Oci::PuppetTask

Inherits:
Object
  • Object
show all
Includes:
Config, Settings
Defined in:
lib/puppet_x/enterprisemodules/oci/oci_task.rb

Overview

Docs

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Settings

#configuration, included, #read_from_yaml, #setting_for, #settings, #settings_file

Methods included from Config

#client_for, #config_for_settings, #default_tenant, #determine_setting_for, #proxy_config, #retry_config, #settings_for, #tenant_config

Class Method Details

.client(client_class = nil) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/puppet_x/enterprisemodules/oci/oci_task.rb', line 53

def self.client(client_class = nil)
  if client_class.nil?
    @client_class
  else
    @client_class = client_class
  end
end

.oci_info(parameter = nil) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/puppet_x/enterprisemodules/oci/oci_task.rb', line 36

def self.oci_info(parameter = nil)
  if parameter.nil?
    @oci_info
  else
    @oci_info = parameter
  end
end

.parameter(name = nil, default_value = nil) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/puppet_x/enterprisemodules/oci/oci_task.rb', line 44

def self.parameter(name = nil, default_value = nil)
  return @parameters if name.nil?

  @parameters ||= {}
  fail "Parameter #{name} already defined." if @parameters.keys.include?(name)

  @parameters[name] = default_value
end

.runObject



61
62
63
64
# File 'lib/puppet_x/enterprisemodules/oci/oci_task.rb', line 61

def self.run
  instance = new
  instance.run
end

Instance Method Details

#call_ociObject



105
106
107
# File 'lib/puppet_x/enterprisemodules/oci/oci_task.rb', line 105

def call_oci
  fail 'Needs to be implemented by sub class.'
end

#client_classObject



28
29
30
# File 'lib/puppet_x/enterprisemodules/oci/oci_task.rb', line 28

def client_class
  self.class.client
end

#executeObject



109
110
111
112
113
114
115
116
# File 'lib/puppet_x/enterprisemodules/oci/oci_task.rb', line 109

def execute
  @result['data'] = call_oci
rescue OCI::Errors::ServiceError => e
  @result[:_error] = {
    :msg => e.message,
    :kind => 'enterprisemodules-oci_config/oci_error'
  }
end

#fetch_inputObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/puppet_x/enterprisemodules/oci/oci_task.rb', line 78

def fetch_input
  @result = {}
  params = JSON.parse($stdin.read)
  #
  # Fetch defined variables from input
  #
  parameters.each do |parameter, default_value|
    value = params[parameter.to_s] || default_value
    instance_variable_set(:"@#{parameter}", value)
  end
  oci_var = instance_variable_get(:"@#{oci_info}")
  @tenant = if oci_var.nil?
              default_tenant
            else
              text = oci_var.match(/^(.*) \(root\).*$/)
              text[1] if text
            end
  fail 'invalid formatted oci_tenant specified.' if @tenant == ''

  @resolver = Puppet_X::EnterpriseModules::Oci::NameResolver.instance(@tenant)
  @client = client_for(client_class, @tenant) if client_class
end

#oci_infoObject



32
33
34
# File 'lib/puppet_x/enterprisemodules/oci/oci_task.rb', line 32

def oci_info
  self.class.oci_info
end

#parametersObject



24
25
26
# File 'lib/puppet_x/enterprisemodules/oci/oci_task.rb', line 24

def parameters
  self.class.parameter
end

#reportObject



101
102
103
# File 'lib/puppet_x/enterprisemodules/oci/oci_task.rb', line 101

def report
  puts @result.to_json
end

#runObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/puppet_x/enterprisemodules/oci/oci_task.rb', line 66

def run
  fetch_input
  execute
rescue StandardError => e
  @result[:_error] ||= {
    :msg => e.message,
    :kind => 'enterprisemodules-oci_config/generic'
  }
ensure
  report
end