Parent

Class/Module Index [+]

Quicksearch

Fog::DNS::Dynect::Real

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/dynect/dns.rb, line 62
def initialize(options={})
  @dynect_customer = options[:dynect_customer]
  @dynect_username = options[:dynect_username]
  @dynect_password = options[:dynect_password]

  @connection_options = options[:connection_options] || {}
  @host       = 'api-v4.dynect.net'
  @port       = options[:port]        || 443
  @path       = options[:path]        || '/REST'
  @persistent = options[:persistent]  || false
  @scheme     = options[:scheme]      || 'https'
  @version    = options[:version]     || '2.3.1'
  @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Public Instance Methods

auth_token() click to toggle source
# File lib/fog/dynect/dns.rb, line 77
def auth_token
  @auth_token ||= post_session.body['data']['token']
end
delete_record(type, zone, fqdn, record_id) click to toggle source

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

# File lib/fog/dynect/requests/dns/delete_record.rb, line 14
def delete_record(type, zone, fqdn, record_id)
  request(
    :expects  => 200,
    :idempotent => true,
    :method   => :delete,
    :path     => ["#{type.to_s.upcase}Record", zone, fqdn, record_id].join('/')
  )
end
delete_zone(zone) click to toggle source

Delete a zone

Parameters

  • zone<~String> - zone to host

# File lib/fog/dynect/requests/dns/delete_zone.rb, line 11
def delete_zone(zone)
  request(
    :expects  => 200,
    :method   => :delete,
    :path     => "Zone/#{zone}"
  )
end
get_node_list(zone, options = {}) click to toggle source

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

# File lib/fog/dynect/requests/dns/get_node_list.rb, line 13
def get_node_list(zone, options = {})
  requested_fqdn = options['fqdn'] || options[:fqdn]
  request(
    :expects  => 200,
    :idempotent => true,
    :method   => :get,
    :path     => ['NodeList', zone, requested_fqdn].compact.join('/')
  )
end
get_record(type, zone, fqdn, options = {}) click to toggle source

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

# File lib/fog/dynect/requests/dns/get_record.rb, line 15
def get_record(type, zone, fqdn, options = {})
  request(
    :expects  => 200,
    :idempotent => true,
    :method   => :get,
    :path     => ["#{type.to_s.upcase}Record", zone, fqdn, options['record_id']].compact.join('/')
  )
end
get_zone(options = {}) click to toggle source

Get one or more zones

Parameters

  • options<~Hash>:

    • zone<~String> - name of zone to lookup, or omit to return list of zones

# File lib/fog/dynect/requests/dns/get_zone.rb, line 12
def get_zone(options = {})
  request(
    :expects  => 200,
    :idempotent => true,
    :method   => :get,
    :path     => ['Zone', options['zone']].compact.join('/')
  )
end
poll_job(response, original_expects, time_to_wait = 10) click to toggle source
# File lib/fog/dynect/dns.rb, line 121
def poll_job(response, original_expects, time_to_wait = 10)
  job_location = response.headers['Location']

  Fog.wait_for(time_to_wait) do
    response = request(:expects => original_expects, :method => :get, :path => job_location)
    response.body['status'] != 'incomplete'
  end

  if response.body['status'] == 'incomplete'
    raise JobIncomplete.new("Job #{response.body['job_id']} is still incomplete")
  end

  response
end
post_record(type, zone, fqdn, rdata, options = {}) click to toggle source

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

# File lib/fog/dynect/requests/dns/post_record.rb, line 15
def post_record(type, zone, fqdn, rdata, options = {})
  options.merge!('rdata' => rdata)
  request(
    :body     => Fog::JSON.encode(options),
    :expects  => 200,
    :method   => :post,
    :path     => ["#{type.to_s.upcase}Record", zone, fqdn].join('/')
  )
end
post_session() click to toggle source
# File lib/fog/dynect/requests/dns/post_session.rb, line 6
def post_session
  request(
    :expects  => 200,
    :idempotent => true,
    :method   => :post,
    :path     => "Session",
    :body     => Fog::JSON.encode({
      :customer_name  => @dynect_customer,
      :user_name      => @dynect_username,
      :password       => @dynect_password
    })
  )
end
post_zone(rname, ttl, zone, options = {}) click to toggle source

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

# File lib/fog/dynect/requests/dns/post_zone.rb, line 15
def post_zone(rname, ttl, zone, options = {})
  body = Fog::JSON.encode({
    :rname  => rname,
    :token  => auth_token,
    :ttl    => ttl
  }.merge!(options))

  request(
    :body     => body,
    :expects  => 200,
    :method   => :post,
    :path     => 'Zone/' << zone
  )
end
put_zone(zone, options = {}) click to toggle source

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

# File lib/fog/dynect/requests/dns/put_zone.rb, line 15
def put_zone(zone, options = {})
  request(
    :body     => Fog::JSON.encode(options),
    :expects  => 200,
    :method   => :put,
    :path     => 'Zone/' << zone
  )
end
request(params) click to toggle source
# File lib/fog/dynect/dns.rb, line 81
def request(params)
  begin
    # any request could redirect to a job
    params[:expects] = Array(params[:expects]) | [307]

    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]}" unless params[:path] =~ %{^#{Regexp.escape(@path)}/}

    response = @connection.request(params.merge!({:host => @host}))

    if response.body.empty?
      response.body = {}
    elsif response.headers['Content-Type'] == 'application/json'
      response.body = Fog::JSON.decode(response.body)
    end

    if response.body['status'] == 'failure'
      raise Error, response.body['msgs'].first['INFO']
    end

    if response.status == 307 && params[:path] !~ %{^/REST/Job/}
      response = poll_job(response, params[:expects])
    end

    response
  rescue Excon::Errors::HTTPStatusError => error
    if @auth_token && error.message =~ /login: (Bad or expired credentials|inactivity logout)/
      @auth_token = nil
      retry
    else
      raise error
    end
  end

  response
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.