Class: Puppet::Provider::AwsOptionGroup::AwsOptionGroup
- Inherits:
-
Object
- Object
- Puppet::Provider::AwsOptionGroup::AwsOptionGroup
- Defined in:
- lib/puppet/provider/aws_option_group/aws_option_group.rb
Overview
AwsOptionGroup class
Class Method Summary collapse
Instance Method Summary collapse
- #build_hash(resource) ⇒ Object
- #canonicalize(_context, _resources) ⇒ Object
- #create(context, name, should) ⇒ Object
- #delete(should) ⇒ Object
- #destroy ⇒ Object
- #get(context) ⇒ Object
- #instance_to_hash(instance) ⇒ Object
- #name?(hash) ⇒ Boolean
- #namevar ⇒ Object
- #region ⇒ Object
- #set(context, changes, noop: false) ⇒ Object
- #symbolize(obj) ⇒ Object
- #update(context, name, should) ⇒ Object
Class Method Details
.build_key_values ⇒ Object
158 159 160 161 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 158 def self.build_key_values key_values = {} key_values end |
.namevar ⇒ Object
76 77 78 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 76 def self.namevar :option_group_name end |
.region ⇒ Object
109 110 111 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 109 def self.region ENV['AWS_REGION'] || 'us-west-2' end |
Instance Method Details
#build_hash(resource) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 143 def build_hash(resource) option_group = {} option_group['apply_immediately'] = resource[:apply_immediately] unless resource[:apply_immediately].nil? option_group['engine_name'] = resource[:engine_name] unless resource[:engine_name].nil? option_group['filters'] = resource[:filters] unless resource[:filters].nil? option_group['major_engine_version'] = resource[:major_engine_version] unless resource[:major_engine_version].nil? option_group['max_records'] = resource[:max_records] unless resource[:max_records].nil? option_group['option_group_description'] = resource[:option_group_description] unless resource[:option_group_description].nil? option_group['option_group_name'] = resource[:option_group_name] unless resource[:option_group_name].nil? option_group['options_to_include'] = resource[:options_to_include] unless resource[:options_to_include].nil? option_group['options_to_remove'] = resource[:options_to_remove] unless resource[:options_to_remove].nil? option_group['tags'] = resource[:tags] unless resource[:tags].nil? symbolize(option_group) end |
#canonicalize(_context, _resources) ⇒ Object
13 14 15 16 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 13 def canonicalize(_context, _resources) # nout to do here but seems we need to implement it resources end |
#create(context, name, should) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 117 def create(context, name, should) context.creating(name) do new_hash = symbolize(build_hash(should)) client = Aws::RDS::Client.new(region: region) client.create_option_group(new_hash) end rescue StandardError => ex Puppet.alert("Exception during create. The state of the resource is unknown. ex is #{ex} and backtrace is #{ex.backtrace}") raise end |
#delete(should) ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 167 def delete(should) new_hash = symbolize(build_hash(should)) client = Aws::RDS::Client.new(region: region) client.delete_option_group(new_hash) rescue StandardError => ex Puppet.alert("Exception during destroy. ex is #{ex} and backtrace is #{ex.backtrace}") raise end |
#destroy ⇒ Object
163 164 165 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 163 def destroy delete(resource) end |
#get(context) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 17 def get(context) context.debug('Entered get') Puppet.debug("Calling instances for region #{region}") client = Aws::RDS::Client.new(region: region) all_instances = [] client.describe_option_groups.each do |response| response.option_groups_list.each do |i| hash = instance_to_hash(i) all_instances << hash if name?(hash) end end @property_hash = all_instances context.debug("Completed get, returning hash #{all_instances}") all_instances end |
#instance_to_hash(instance) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 35 def instance_to_hash(instance) allows_vpc_and_non_vpc_instance_memberships = instance.respond_to?(:allows_vpc_and_non_vpc_instance_memberships) ? (instance.allows_vpc_and_non_vpc_instance_memberships.respond_to?(:to_hash) ? instance.allows_vpc_and_non_vpc_instance_memberships.to_hash : instance.allows_vpc_and_non_vpc_instance_memberships) : nil apply_immediately = instance.respond_to?(:apply_immediately) ? (instance.apply_immediately.respond_to?(:to_hash) ? instance.apply_immediately.to_hash : instance.apply_immediately) : nil engine_name = instance.respond_to?(:engine_name) ? (instance.engine_name.respond_to?(:to_hash) ? instance.engine_name.to_hash : instance.engine_name) : nil filters = instance.respond_to?(:filters) ? (instance.filters.respond_to?(:to_hash) ? instance.filters.to_hash : instance.filters) : nil major_engine_version = instance.respond_to?(:major_engine_version) ? (instance.major_engine_version.respond_to?(:to_hash) ? instance.major_engine_version.to_hash : instance.major_engine_version) : nil max_records = instance.respond_to?(:max_records) ? (instance.max_records.respond_to?(:to_hash) ? instance.max_records.to_hash : instance.max_records) : nil option_group_arn = instance.respond_to?(:option_group_arn) ? (instance.option_group_arn.respond_to?(:to_hash) ? instance.option_group_arn.to_hash : instance.option_group_arn) : nil option_group_description = instance.respond_to?(:option_group_description) ? (instance.option_group_description.respond_to?(:to_hash) ? instance.option_group_description.to_hash : instance.option_group_description) : nil option_group_name = instance.respond_to?(:option_group_name) ? (instance.option_group_name.respond_to?(:to_hash) ? instance.option_group_name.to_hash : instance.option_group_name) : nil = instance.respond_to?(:options) ? (instance..respond_to?(:to_hash) ? instance..to_hash : instance.) : nil = instance.respond_to?(:options_to_include) ? (instance..respond_to?(:to_hash) ? instance..to_hash : instance.) : nil = instance.respond_to?(:options_to_remove) ? (instance..respond_to?(:to_hash) ? instance..to_hash : instance.) : nil = instance.respond_to?(:tags) ? (instance..respond_to?(:to_hash) ? instance..to_hash : instance.) : nil vpc_id = instance.respond_to?(:vpc_id) ? (instance.vpc_id.respond_to?(:to_hash) ? instance.vpc_id.to_hash : instance.vpc_id) : nil option_group = {} option_group[:ensure] = :present option_group[:object] = instance option_group[:name] = instance.to_hash[self.namevar] option_group[:allows_vpc_and_non_vpc_instance_memberships] = allows_vpc_and_non_vpc_instance_memberships unless allows_vpc_and_non_vpc_instance_memberships.nil? option_group[:apply_immediately] = apply_immediately unless apply_immediately.nil? option_group[:engine_name] = engine_name unless engine_name.nil? option_group[:filters] = filters unless filters.nil? option_group[:major_engine_version] = major_engine_version unless major_engine_version.nil? option_group[:max_records] = max_records unless max_records.nil? option_group[:option_group_arn] = option_group_arn unless option_group_arn.nil? option_group[:option_group_description] = option_group_description unless option_group_description.nil? option_group[:option_group_name] = option_group_name unless option_group_name.nil? option_group[:options] = unless .nil? option_group[:options_to_include] = unless .nil? option_group[:options_to_remove] = unless .nil? option_group[:tags] = unless .nil? option_group[:vpc_id] = vpc_id unless vpc_id.nil? option_group end |
#name?(hash) ⇒ Boolean
80 81 82 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 80 def name?(hash) !hash[self.namevar].nil? && !hash[self.namevar].empty? end |
#namevar ⇒ Object
72 73 74 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 72 def namevar :option_group_name end |
#region ⇒ Object
113 114 115 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 113 def region ENV['AWS_REGION'] || 'us-west-2' end |
#set(context, changes, noop: false) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 84 def set(context, changes, noop: false) context.debug('Entered set') changes.each do |name, change| context.debug("set change with #{name} and #{change}") is = change.key?(:is) ? change[:is] : get(context).find { |key| key[:id] == name } should = change[:should] is = { name: name, ensure: 'absent' } if is.nil? should = { name: name, ensure: 'absent' } if should.nil? if is[:ensure].to_s == 'absent' && should[:ensure].to_s == 'present' create(context, name, should) unless noop elsif is[:ensure].to_s == 'present' && should[:ensure].to_s == 'absent' context.deleting(name) do delete(should) unless noop end elsif is[:ensure].to_s == 'absent' && should[:ensure].to_s == 'absent' context.failed(name, message: 'Unexpected absent to absent change') elsif is[:ensure].to_s == 'present' && should[:ensure].to_s == 'present' # if update method exists call update, else delete and recreate the resourceupdate(context, name, should) end end end |
#symbolize(obj) ⇒ Object
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 176 def symbolize(obj) return obj.reduce({}) do |memo, (k, v)| memo.tap { |m| m[k.to_sym] = symbolize(v) } end if obj.is_a? Hash return obj.reduce([]) do |memo, v| memo << symbolize(v); memo end if obj.is_a? Array obj end |
#update(context, name, should) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/puppet/provider/aws_option_group/aws_option_group.rb', line 130 def update(context, name, should) context.updating(name) do new_hash = symbolize(build_hash(should)) client = Aws::RDS::Client.new(region: region) client.modify_option_group(new_hash) end rescue StandardError => ex Puppet.alert("Exception during flush. ex is #{ex} and backtrace is #{ex.backtrace}") raise end |