Permalink
Browse files

The dynect RR provider was expecting 0 or 1 records at a node. :create

would fail in the case where we wanted to add a record at node with an
existing record. Change the current_resource to account for the
possibility of a set of RRs returned.

a record delete action needs a publish to commit the changes to the zone
file.

Example add and delete recipes
  • Loading branch information...
1 parent b6bae30 commit 017e1643369ddd5fef26fe806f2df6fa353fa20d @lhagemann lhagemann committed Jul 16, 2010
View
13 cookbooks/dynect/providers/rr.rb
@@ -33,6 +33,18 @@ def load_current_resource
begin
@rr = DynectRest::Resource.new(@dyn, @new_resource.record_type, @new_resource.zone).get(@new_resource.fqdn)
+
+# let's find the ONE RR we were asked for
+ if @rr && @rr.kind_of?(Array)
+ @target = nil
+ @rr.each do |rr|
+ @new_resource.rdata.each do |key, value|
+ @target = rr if rr[key.to_s] == value
+ end
+ end
+ @rr = @target
+ end
+
@current_resource.fqdn(@rr.fqdn)
@current_resource.ttl(@rr.ttl)
@current_resource.zone(@rr.zone)
@@ -93,6 +105,7 @@ def action_replace
def action_delete
if @rr
@rr.delete
+ @dyn.publish
Chef::Log.info("Deleted #{@new_resource} from dynect")
@updated = true
end
View
34 cookbooks/dynect/recipes/add_a_record.rb
@@ -0,0 +1,34 @@
+#
+# Cookbook Name:: dynect
+# Recipe:: add_a_record
+#
+# Copyright:: 2010, Opscode, Inc <legal@opscode.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include_recipe 'dynect'
+
+dynect_rr node[:hostname] do
+ customer node[:dynect][:customer]
+ username node[:dynect][:username]
+ password node[:dynect][:password]
+ zone node[:dynect][:zone]
+
+ record_type "A"
+ #rdata({ "address" => node[:ipaddress] })
+ rdata({ "address" => "10.10.2.2"}) # address of the EC2 instance brought up (elastic ips)
+ fqdn "#{node[:dynect][:fqdn]}" # reserve.dyntini.com
+
+ action :create
+end
View
34 cookbooks/dynect/recipes/del_a_record.rb
@@ -0,0 +1,34 @@
+#
+# Cookbook Name:: dynect
+# Recipe:: del_a_record
+#
+# Copyright:: 2010, Opscode, Inc <legal@opscode.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include_recipe 'dynect'
+
+dynect_rr node[:hostname] do
+ customer node[:dynect][:customer]
+ username node[:dynect][:username]
+ password node[:dynect][:password]
+ zone node[:dynect][:zone]
+
+ record_type "A"
+ #rdata({ "address" => node[:ipaddress] })
+ rdata({ "address" => "10.10.1.1" }) # EC2 address that faile (elastic ips)
+ fqdn "#{node[:dynect][:fqdn]}" # reserve.dyntini.com
+
+ action :delete
+end

0 comments on commit 017e164

Please sign in to comment.