Skip to content

Commit

Permalink
Merge pull request crowbar#82 from tboerger/feature/add-records
Browse files Browse the repository at this point in the history
Added functionality to add A records with the UI to the main zone file
  • Loading branch information
vuntz committed Jan 23, 2014
2 parents d17ca4d + 83e0356 commit d2ade50
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 3 deletions.
1 change: 1 addition & 0 deletions chef/cookbooks/bind9/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def make_zone(zone)
end
end

cluster_zone[:records] = node[:dns][:records] || {}
zones[node[:dns][:domain]]=cluster_zone

case node[:platform]
Expand Down
7 changes: 7 additions & 0 deletions chef/cookbooks/bind9/templates/default/db.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ $TTL <%= @zone[:ttl] %>
@ MX <%= prio -%> <%= host %>
<% end if @zone[:mail_exchangers]-%>

; Manual records
<% @zone[:records].each do |host, values| -%>
<% values[:ips].each do |ip| -%>
<%= host %> IN A <%= ip %>
<% end -%>
<% end if @zone[:records] -%>

; Per-host records
<% @zone[:hosts].keys.sort.each do |host|
record=@zone[:hosts][host]
Expand Down
6 changes: 3 additions & 3 deletions chef/data_bags/crowbar/bc-template-dns.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
"domain": "pod.your.cloud.org",
"forwarders": [ ],
"allow_transfer": [ ],
"nameservers": [ ]
"nameservers": [ ],
"records": { }
}
},
"deployment": {
"dns": {
"crowbar-revision": 0,
"schema-revision": 1,
"schema-revision": 2,
"element_states": {
"dns-server": [ "readying", "ready", "applying" ],
"dns-client": [ "all" ]
Expand All @@ -33,4 +34,3 @@
}
}
}

17 changes: 17 additions & 0 deletions chef/data_bags/crowbar/bc-template-dns.schema
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@
"type": "seq",
"required": false,
"sequence": [ { "type": "str" } ]
},
"records": {
"type": "map",
"required": false,
"mapping": {
= : {
"type" : "map",
"required" : false,
"mapping" : {
"ips": {
"type" : "seq",
"required" : true,
"sequence": [ { "type": "str", "name": "IpAddress" } ]
}
}
}
}
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions chef/data_bags/crowbar/migrate/dns/002_add_records.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def upgrade ta, td, a, d
a["records"] = {}
return a, d
end

def downgrade ta, td, a, d
a.delete "records"
return a, d
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,43 @@
= array_string_field :allow_transfer
%span.help-block
= t('.ip_list_hint')

%fieldset
%legend
= t(".records")

%table.table.table-middle{ "data-dynamic" => "#record-entries", "data-namespace" => "records", "data-optional" => "", "data-invalid" => t(".record_invalid"), "data-duplicate" => t(".record_duplicate") }
%thead
%tr
%th.col-sm-3
= t(".record_name")
%th.col-sm-8
= t(".record_ips")
%th.col-sm-1

%tbody

%tfoot
%tr
%td
= text_field_tag "record[name]", "", :placeholder => t(".record_name"), :class => "form-control", "data-name" => "name", "data-type" => "string"
%td
= text_field_tag "record[ips]", "", :placeholder => t(".record_ips"), :class => "form-control", "data-name" => "ips", "data-type" => "array-string"
%td
= link_to t(".record_add"), "#", :class => "btn btn-default btn-block", "data-add" => true

%script#record-entries{ :type => "text/x-handlebars-template" }
{{#each entries}}
%tr.edit
%td
= text_field_tag "record[name]", "{{name}}", :placeholder => t(".record_name"), :class => "form-control", :disabled => "disabled"
%td
= text_field_tag "record[ips]", "{{ips}}", :placeholder => t(".record_ips"), :class => "form-control", "data-update" => "records/{{name}}/ips", "data-name" => "ips", "data-type" => "array-string"
%td
= link_to t(".record_remove"), "#", :class => "btn btn-default btn-block", "data-remove" => "{{name}}"
{{else}}
%tr
%td{ :colspan => 3 }
.empty.alert.alert-info.text-center
= t(".no_records")
{{/each}}
9 changes: 9 additions & 0 deletions crowbar_framework/config/locales/dns.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ en:
forwarders: Forwarders
allow_transfer: Allow Transfer
ip_list_hint: A comma-separated list of IP Addresses

records: Manual A Records
record_name: Name
record_ips: IP Addresses
record_add: Add
record_remove: Remove
record_invalid: Name and IP Addresses must not be empty!
record_duplicate: There is already a record for this name defined!
no_records: Currently there are no records defined

0 comments on commit d2ade50

Please sign in to comment.