Question

In writing a provider (for a Datastax Opscenter Cluster resource), I required knowledge of any currently existing cluster with the same cluster_id and so have written a load_current_resource method in the provider. My problem is that at run time (as a chef-solo run on a Vagrant instance) I receive an error:

undefined method `exists=' for Chef::Resource::OpscenterCluster

On the @current_resource.exists = false after if response.code != 200 in the method below.

def load_current_resource
   @current_resource = Chef::Resource::OpscenterCluster.new(@new_resource.name)
   log "#{@new_resource} Opscenter Cluster '#{new_resource.name}'"
   @current_resource.name(@new_resource.name)
   uri = URI.parse "http://#{node[:opscenter][:ip]}:8888/cluster-configs/#{@current_resource.cluster_id}"
   response = Net::HTTP.get_response(uri)
   if response.code != 200
      @current_resource.exists = false
   else
      @current_resource.exists = true
   end
end

The cookbook is opscenter and the resource and provider are both in files called cluster.rb, and the attributes that are referenced definitely exist, so the name of the resource class should at least, and the attributes at least should be correct.

Any ideas as to why my @current_resource object doesn't have an exists= method?

Was it helpful?

Solution

You need to define it on your resource...

You can either define an exists=(value) method, or you can use Chef's preferred method of .exsts(false) (note - no =)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top