class Chef::Provider::AwsCloudsearchDomain
Public Instance Methods
create_aws_object()
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 6 def create_aws_object domain = nil # define here to ensure it is available outside of the coverge_by scope converge_by "create CloudSearch domain #{new_resource.name}" do domain = create_domain end update_aws_object(domain) # TODO: since we don't support updating index fields yet, # it will not be handled by update_aws_object, so we need to # create the index fields here. create_index_fields end
destroy_aws_object(_domain)
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 20 def destroy_aws_object(_domain) converge_by "delete CloudSearch domain #{new_resource.name}" do cs_client.delete_domain(domain_name: new_resource.name) end # CloudSearch can take over 30 minutes to delete so im not adding a waiter # for now end
update_aws_object(domain)
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 28 def update_aws_object(domain) if update_availability_options?(domain) converge_by "update availability options for CloudSearch domain #{new_resource}" do update_availability_options end end if update_scaling_params?(domain) converge_by "update scaling parameters for CloudSearch domain #{new_resource.name}" do update_scaling_parameters end end if update_policy?(domain) converge_by "update access policy for CloudSearch domain #{new_resource.name}" do update_service_access_policy end end if update_index_fields?(domain) Chef::Log.warn("Updating existing index_fields not currently supported") end end
Private Instance Methods
access_policies()
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 161 def access_policies get_option(:service_access_policies, :access_policies) end
availability_options()
click to toggle source
API Query Functions
The CloudSearch API doesn't provide all of the data about the domain's settings via the descrbe domain API. We have to call additional endpoints to determine the current values of: availability_options
, scalability_parameters, index_fields
, and access_policies
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 151 def availability_options get_option(:availability_options) end
create_domain()
click to toggle source
API Update Functions
The following functions all make changes to our domain. Unlike other AWS
APIs we don't have a single modify function for this domain. Rather, updates our split up over a number of different API requestsion.
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 111 def create_domain cs_client.create_domain(domain_name: new_resource.name)[:domain_status] end
create_index_field(field)
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 130 def create_index_field(field) cs_client.define_index_field(domain_name: new_resource.name, index_field: field) end
create_index_fields()
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 134 def create_index_fields unless new_resource.index_fields.nil? new_resource.index_fields.each do |field| create_index_field(field) end end end
cs_client()
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 175 def cs_client @cs_client ||= new_resource.driver.cloudsearch end
desired_scaling_parameters()
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 95 def desired_scaling_parameters ret = {} ret[:desired_partition_count] = new_resource.partition_count if new_resource.partition_count ret[:desired_replication_count] = new_resource.replication_count if new_resource.replication_count ret[:desired_instance_type] = new_resource.instance_type if new_resource.instance_type ret end
get_option(option_name, key = nil)
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 169 def get_option(option_name, key = nil) opt = cs_client.send("describe_#{option_name}".to_sym, domain_name: new_resource.name)[key || option_name] opt[:options] unless opt[:status][:pending_deletion] end
index_fields()
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 165 def index_fields cs_client.describe_index_fields(domain_name: new_resource.name).index_fields end
scaling_parameters(object)
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 155 def scaling_parameters(object) scaling_parameters = get_option(:scaling_parameters) scaling_parameters.desired_instance_type = object[:search_instance_type] scaling_parameters end
update_availability_options()
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 115 def update_availability_options cs_client.update_availability_options(domain_name: new_resource.name, multi_az: new_resource.multi_az) end
update_availability_options?(_domain)
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 54 def update_availability_options?(_domain) # new_resource.multi_az defaults to false so we don't need an existence check new_resource.multi_az != availability_options end
update_index_fields?(_domain)
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 82 def update_index_fields?(_domain) if !new_resource.index_fields.nil? index_fields.each do |index_field| unless new_resource.index_fields.include?(index_field.to_h[:options]) return true end end false else false end end
update_policy?(_domain)
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 74 def update_policy?(_domain) if !new_resource.access_policies.nil? new_resource.access_policies != access_policies else false end end
update_scaling_parameters()
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 120 def update_scaling_parameters cs_client.update_scaling_parameters(domain_name: new_resource.name, scaling_parameters: desired_scaling_parameters) end
update_scaling_params?(domain)
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 59 def update_scaling_params?(domain) if new_resource.partition_count || new_resource.replication_count || new_resource.instance_type # We don't want to change scaling parameters that the user # didn't specify. Thus, we compare on a key-by-key basis. Only # user-specified keys show up in desired_scaling_parameters actual_scaling_parameters = scaling_parameters(domain) desired_scaling_parameters.each do |key, value| return true if value != actual_scaling_parameters[key] end false else false end end
update_service_access_policy()
click to toggle source
# File lib/chef/provider/aws_cloudsearch_domain.rb, line 125 def update_service_access_policy cs_client.update_service_access_policies(domain_name: new_resource.name, access_policies: new_resource.access_policies) end