Class: Fog::DNS::Dynect::Real
- Inherits:
-
Object
- Object
- Fog::DNS::Dynect::Real
- Defined in:
- lib/fog/dns/dynect.rb,
lib/fog/dns/requests/dynect/get_zone.rb,
lib/fog/dns/requests/dynect/put_zone.rb,
lib/fog/dns/requests/dynect/post_zone.rb,
lib/fog/dns/requests/dynect/get_record.rb,
lib/fog/dns/requests/dynect/delete_zone.rb,
lib/fog/dns/requests/dynect/post_record.rb,
lib/fog/dns/requests/dynect/post_session.rb,
lib/fog/dns/requests/dynect/delete_record.rb,
lib/fog/dns/requests/dynect/get_node_list.rb
Instance Method Summary collapse
- #auth_token ⇒ Object
-
#delete_record(type, zone, fqdn, record_id) ⇒ Object
Delete a record.
-
#delete_zone(zone) ⇒ Object
Delete a zone.
-
#get_node_list(zone, options = {}) ⇒ Object
Get one or more node lists.
-
#get_record(type, zone, fqdn, options = {}) ⇒ Object
List records of a given type.
-
#get_zone(options = {}) ⇒ Object
Get one or more zones.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#post_record(type, zone, fqdn, rdata, options = {}) ⇒ Object
Create a record.
- #post_session ⇒ Object
-
#post_zone(rname, ttl, zone, options = {}) ⇒ Object
Create a zone.
-
#put_zone(zone, options = {}) ⇒ Object
Update a zone.
- #request(params) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fog/dns/dynect.rb', line 37 def initialize(={}) require 'multi_json' @dynect_customer = [:dynect_customer] @dynect_username = [:dynect_username] @dynect_password = [:dynect_password] @host = "api2.dynect.net" @port = [:port] || 443 @path = [:path] || '/REST' @scheme = [:scheme] || 'https' @version = [:version] || '2.3.1' @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", [:persistent] || true) end |
Instance Method Details
#auth_token ⇒ Object
52 53 54 |
# File 'lib/fog/dns/dynect.rb', line 52 def auth_token @auth_token ||= post_session.body['data']['token'] end |
#delete_record(type, zone, fqdn, record_id) ⇒ Object
Delete 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
-
fqdn<~String> - fqdn of record
-
record_id<~String> - id of record
14 15 16 17 18 19 20 |
# File 'lib/fog/dns/requests/dynect/delete_record.rb', line 14 def delete_record(type, zone, fqdn, record_id) request( :expects => 200, :method => :delete, :path => ["#{type.to_s.upcase}Record", zone, fqdn, record_id].join('/') ) end |
#delete_zone(zone) ⇒ Object
Delete a zone
Parameters
-
zone<~String> - zone to host
11 12 13 14 15 16 17 |
# File 'lib/fog/dns/requests/dynect/delete_zone.rb', line 11 def delete_zone(zone) request( :expects => 200, :method => :delete, :path => "Zone/#{zone}" ) end |
#get_node_list(zone, options = {}) ⇒ Object
Get one or more node lists
Parameters
-
zone<~String> - zone to lookup node lists for
-
options<~Hash>
-
fqdn<~String> - fully qualified domain name of node to lookup
-
13 14 15 16 17 18 19 |
# File 'lib/fog/dns/requests/dynect/get_node_list.rb', line 13 def get_node_list(zone, = {}) request( :expects => 200, :method => :get, :path => ['NodeList', zone, ['fqdn']].compact.join('/') ) end |
#get_record(type, zone, fqdn, options = {}) ⇒ Object
List records of a given type
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> - name of zone to lookup
-
fqdn<~String> - name of fqdn to lookup
-
options<~Hash>:
-
record_id<~String> - id of record
-
15 16 17 18 19 20 21 |
# File 'lib/fog/dns/requests/dynect/get_record.rb', line 15 def get_record(type, zone, fqdn, = {}) request( :expects => 200, :method => :get, :path => ["#{type.to_s.upcase}Record", zone, fqdn, ['record_id']].compact.join('/') ) end |
#get_zone(options = {}) ⇒ Object
Get one or more zones
Parameters
-
options<~Hash>:
-
zone<~String> - name of zone to lookup, or omit to return list of zones
-
12 13 14 15 16 17 18 |
# File 'lib/fog/dns/requests/dynect/get_zone.rb', line 12 def get_zone( = {}) request( :expects => 200, :method => :get, :path => ['Zone', ['zone']].compact.join('/') ) end |
#post_record(type, zone, fqdn, rdata, options = {}) ⇒ Object
Create 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
-
15 16 17 18 19 20 21 22 23 |
# File 'lib/fog/dns/requests/dynect/post_record.rb', line 15 def post_record(type, zone, fqdn, rdata, = {}) .merge!('rdata' => rdata) request( :body => MultiJson.encode(), :expects => 200, :method => :post, :path => ["#{type.to_s.upcase}Record", zone, fqdn].join('/') ) end |
#post_session ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fog/dns/requests/dynect/post_session.rb', line 6 def post_session request( :expects => 200, :method => :post, :path => "Session", :body => MultiJson.encode({ :customer_name => @dynect_customer, :user_name => @dynect_username, :password => @dynect_password }) ) end |
#post_zone(rname, ttl, zone, options = {}) ⇒ Object
Create a zone
Parameters
-
rname<~String> - administrative contact
-
ttl<~Integer> - time to live (in seconds) for records in this zone
-
zone<~String> - name of zone to host
-
options<~Hash>:
-
serial_style<~String> - style of serial number, in [‘day’, ‘epoch’, ‘increment’, ‘minute’]. Defaults to increment
-
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog/dns/requests/dynect/post_zone.rb', line 15 def post_zone(rname, ttl, zone, = {}) body = MultiJson.encode({ :rname => rname, :token => auth_token, :ttl => ttl }.merge!()) request( :body => body, :expects => 200, :method => :post, :path => 'Zone/' << zone ) end |
#put_zone(zone, options = {}) ⇒ Object
Update a zone
Parameters
-
zone<~String> - name or id of zone
-
options<~Hash>:
-
freeze<~Boolean> - causes zone to become frozen
-
publish<~Boolean> - causes all pending changes to be pushed to nameservers
-
thaw<~Boolean> - causes zone to cease being frozen
-
15 16 17 18 19 20 21 22 |
# File 'lib/fog/dns/requests/dynect/put_zone.rb', line 15 def put_zone(zone, = {}) request( :body => MultiJson.encode(), :expects => 200, :method => :put, :path => 'Zone/' << zone ) end |
#request(params) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fog/dns/dynect.rb', line 56 def request(params) begin params[:headers] ||= {} params[:headers]['Content-Type'] = 'application/json' params[:headers]['API-Version'] = @version params[:headers]['Auth-Token'] = auth_token unless params[:path] == "Session" params[:path] = "#{@path}/#{params[:path]}" response = @connection.request(params.merge!({:host => @host})) unless response.body.empty? response.body = MultiJson.decode(response.body) end response rescue Excon::Errors::HTTPStatusError => error raise error end response end |