mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2174 from jblancett/master
added put_record for dynect
This commit is contained in:
commit
ed6886d2da
3 changed files with 98 additions and 0 deletions
|
@ -25,6 +25,7 @@ module Fog
|
||||||
request :post_session
|
request :post_session
|
||||||
request :post_zone
|
request :post_zone
|
||||||
request :put_zone
|
request :put_zone
|
||||||
|
request :put_record
|
||||||
|
|
||||||
class JobIncomplete < Error; end
|
class JobIncomplete < Error; end
|
||||||
|
|
||||||
|
|
76
lib/fog/dynect/requests/dns/put_record.rb
Normal file
76
lib/fog/dynect/requests/dns/put_record.rb
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
module Fog
|
||||||
|
module DNS
|
||||||
|
class Dynect
|
||||||
|
class Real
|
||||||
|
|
||||||
|
# Update or replace a record
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# * type<~String> - type of record in ['AAAA', 'ANY', 'A', 'CNAME', 'DHCID', 'DNAME', 'DNSKEY', 'DS', 'KEY', 'LOC', 'MX', 'NSA', 'NS', 'PTR', 'PX', 'RP', 'SOA', 'SPF', 'SRV', 'SSHFP', 'TXT']
|
||||||
|
# * zone<~String> - zone of record
|
||||||
|
# * rdata<~Hash> - rdata for record
|
||||||
|
# * options<~Hash>: (options vary by type, listing below includes common parameters)
|
||||||
|
# * ttl<~Integer> - ttl for the record, defaults to zone ttl
|
||||||
|
|
||||||
|
def put_record(type, zone, fqdn, rdata, options = {})
|
||||||
|
options.merge!('rdata' => rdata)
|
||||||
|
type.to_s.upcase!
|
||||||
|
options = {"#{type}Records" => [options]} unless options['record_id']
|
||||||
|
path = ["#{type}Record", zone, fqdn].join('/')
|
||||||
|
path += "/#{options.delete('record_id')}" if options['record_id']
|
||||||
|
request(
|
||||||
|
:body => Fog::JSON.encode(options),
|
||||||
|
:expects => 200,
|
||||||
|
:method => :put,
|
||||||
|
:path => path
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
def put_record(type, zone, fqdn, rdata, options = {})
|
||||||
|
raise Fog::DNS::Dynect::NotFound unless zone = self.data[:zones][zone]
|
||||||
|
|
||||||
|
records = zone[:records]
|
||||||
|
record_id = zone[:next_record_id]
|
||||||
|
zone[:next_record_id] += 1
|
||||||
|
|
||||||
|
record = {
|
||||||
|
:type => type,
|
||||||
|
:zone => zone,
|
||||||
|
:fqdn => fqdn,
|
||||||
|
:rdata => rdata,
|
||||||
|
:ttl => options[:ttl] || zone[:ttl],
|
||||||
|
:record_id => record_id
|
||||||
|
}
|
||||||
|
|
||||||
|
records[type] << record
|
||||||
|
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
|
||||||
|
response.body = {
|
||||||
|
"status" => "success",
|
||||||
|
"data" => {
|
||||||
|
"zone" => record[:zone][:zone],
|
||||||
|
"ttl" => record[:ttl],
|
||||||
|
"fqdn" => record[:fqdn],
|
||||||
|
"record_type" => record[:type],
|
||||||
|
"rdata" => record[:rdata],
|
||||||
|
"record_id" => record[:record_id]
|
||||||
|
},
|
||||||
|
"job_id" => Fog::Dynect::Mock.job_id,
|
||||||
|
"msgs" => [{
|
||||||
|
"INFO"=>"add: Record added",
|
||||||
|
"SOURCE"=>"BLL",
|
||||||
|
"ERR_CD"=>nil,
|
||||||
|
"LVL"=>"INFO"
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
|
response
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -79,6 +79,27 @@ Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do
|
||||||
@dns.post_record('A', @domain, @fqdn, {'address' => '1.2.3.4'}).body
|
@dns.post_record('A', @domain, @fqdn, {'address' => '1.2.3.4'}).body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
put_record_format = shared_format.merge({
|
||||||
|
'data' => {
|
||||||
|
'fqdn' => String,
|
||||||
|
'ARecords' => [
|
||||||
|
{
|
||||||
|
'rdata' => {
|
||||||
|
'address' => String
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'record_id' => Integer,
|
||||||
|
'record_type' => String,
|
||||||
|
'ttl' => Integer,
|
||||||
|
'zone' => String
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
tests("put_record('A', '#{@domain}', '#{@fqdn}', 'address' => '1.2.3.4')").formats(post_record_format) do
|
||||||
|
@dns.put_record('A', @domain, @fqdn, {'address' => '1.2.3.4'}).body
|
||||||
|
end
|
||||||
|
|
||||||
publish_zone_format = shared_format.merge({
|
publish_zone_format = shared_format.merge({
|
||||||
'data' => {
|
'data' => {
|
||||||
'serial' => Integer,
|
'serial' => Integer,
|
||||||
|
|
Loading…
Reference in a new issue