Skip to content
This repository
Browse code

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...
commit 017e1643369ddd5fef26fe806f2df6fa353fa20d 1 parent b6bae30
Lisa Hagemann authored
13  cookbooks/dynect/providers/rr.rb
@@ -33,6 +33,18 @@ def load_current_resource
33 33
 
34 34
   begin
35 35
     @rr = DynectRest::Resource.new(@dyn, @new_resource.record_type, @new_resource.zone).get(@new_resource.fqdn)
  36
+
  37
+# let's find the ONE RR we were asked for
  38
+	if @rr && @rr.kind_of?(Array)
  39
+		@target = nil
  40
+		@rr.each do |rr|
  41
+			@new_resource.rdata.each do |key, value|
  42
+				@target =  rr if rr[key.to_s] == value
  43
+			end
  44
+		end
  45
+		@rr = @target
  46
+	end
  47
+
36 48
     @current_resource.fqdn(@rr.fqdn)
37 49
     @current_resource.ttl(@rr.ttl)
38 50
     @current_resource.zone(@rr.zone)
@@ -93,6 +105,7 @@ def action_replace
93 105
 def action_delete
94 106
   if @rr
95 107
     @rr.delete
  108
+	@dyn.publish
96 109
     Chef::Log.info("Deleted #{@new_resource} from dynect")
97 110
     @updated = true
98 111
   end
34  cookbooks/dynect/recipes/add_a_record.rb
... ...
@@ -0,0 +1,34 @@
  1
+#
  2
+# Cookbook Name:: dynect
  3
+# Recipe:: add_a_record
  4
+#
  5
+# Copyright:: 2010, Opscode, Inc <legal@opscode.com>
  6
+#
  7
+# Licensed under the Apache License, Version 2.0 (the "License");
  8
+# you may not use this file except in compliance with the License.
  9
+# You may obtain a copy of the License at
  10
+#
  11
+#     http://www.apache.org/licenses/LICENSE-2.0
  12
+#
  13
+# Unless required by applicable law or agreed to in writing, software
  14
+# distributed under the License is distributed on an "AS IS" BASIS,
  15
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16
+# See the License for the specific language governing permissions and
  17
+# limitations under the License.
  18
+#
  19
+
  20
+include_recipe 'dynect'
  21
+
  22
+dynect_rr node[:hostname] do
  23
+  customer node[:dynect][:customer]
  24
+  username node[:dynect][:username]
  25
+  password node[:dynect][:password]
  26
+  zone     node[:dynect][:zone]
  27
+
  28
+  record_type "A"
  29
+  #rdata({ "address" => node[:ipaddress] })
  30
+  rdata({ "address" => "10.10.2.2"}) # address of the EC2 instance brought up (elastic ips)
  31
+  fqdn "#{node[:dynect][:fqdn]}" # reserve.dyntini.com
  32
+
  33
+  action :create
  34
+end
34  cookbooks/dynect/recipes/del_a_record.rb
... ...
@@ -0,0 +1,34 @@
  1
+#
  2
+# Cookbook Name:: dynect
  3
+# Recipe:: del_a_record
  4
+#
  5
+# Copyright:: 2010, Opscode, Inc <legal@opscode.com>
  6
+#
  7
+# Licensed under the Apache License, Version 2.0 (the "License");
  8
+# you may not use this file except in compliance with the License.
  9
+# You may obtain a copy of the License at
  10
+#
  11
+#     http://www.apache.org/licenses/LICENSE-2.0
  12
+#
  13
+# Unless required by applicable law or agreed to in writing, software
  14
+# distributed under the License is distributed on an "AS IS" BASIS,
  15
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16
+# See the License for the specific language governing permissions and
  17
+# limitations under the License.
  18
+#
  19
+
  20
+include_recipe 'dynect'
  21
+
  22
+dynect_rr node[:hostname] do
  23
+  customer node[:dynect][:customer]
  24
+  username node[:dynect][:username]
  25
+  password node[:dynect][:password]
  26
+  zone     node[:dynect][:zone]
  27
+
  28
+  record_type "A"
  29
+  #rdata({ "address" => node[:ipaddress] })
  30
+  rdata({ "address" => "10.10.1.1" }) # EC2 address that faile (elastic ips)
  31
+  fqdn "#{node[:dynect][:fqdn]}" # reserve.dyntini.com
  32
+
  33
+  action :delete
  34
+end

0 notes on commit 017e164

Please sign in to comment.
Something went wrong with that request. Please try again.