Sha256: e54dfd2e4be87030bc047af1e17c9cb6d5c055d2403eb3c4fec19f4da6568b59

Contents?: true

Size: 1.73 KB

Versions: 11

Compression:

Stored size: 1.73 KB

Contents

require 'fog/core/collection'
require 'fog/dynect/models/dns/record'

module Fog
  module DNS
    class Dynect
      class Records < Fog::Collection
        attribute :zone

        model Fog::DNS::Dynect::Record

        def all(options = {})
          requires :zone
          data = []
          service.get_all_records(zone.domain, options).body['data'].each do |url|
            (_, _, t, _, fqdn, id) = url.split('/')
            type = t.gsub(/Record$/, '')

            # leave out the default, read only records
            # by putting this here we don't make the secondary request for these records
            next if ['NS', 'SOA'].include?(type)

            record = service.get_record(type, zone.domain, fqdn, 'record_id' => id).body['data']

            data << {
              :identity => record['record_id'],
              :fqdn => record['fqdn'],
              :type => record['record_type'],
              :rdata => record['rdata']
            }
          end

          load(data)
        end

        def get(record_id)
          requires :zone

          list = service.get_all_records(zone.domain, {}).body['data']
          url = list.find { |e| e =~ /\/#{record_id}$/ }
          return unless url
          (_, _, t, _, fqdn, id) = url.split('/')
          type = t.gsub(/Record$/, '')
          record = service.get_record(type, zone.domain, fqdn, 'record_id' => id).body['data']

          new({
            :identity => record['record_id'],
            :fqdn => record['fqdn'],
            :type => record['record_type'],
            :rdata => record['rdata']
          })
        end

        def new(attributes = {})
          requires :zone
          super({:zone => zone}.merge!(attributes))
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/lib/fog/dynect/models/dns/records.rb
ns-fog-1.22.11 lib/fog/dynect/models/dns/records.rb
ns-fog-1.22.10 lib/fog/dynect/models/dns/records.rb
ns-fog-1.22.9 lib/fog/dynect/models/dns/records.rb
ns-fog-1.22.8 lib/fog/dynect/models/dns/records.rb
ns-fog-1.22.7 lib/fog/dynect/models/dns/records.rb
ns-fog-1.22.6 lib/fog/dynect/models/dns/records.rb
ns-fog-1.22.4 lib/fog/dynect/models/dns/records.rb
ns-fog-1.22.3 lib/fog/dynect/models/dns/records.rb
ns-fog-1.22.2 lib/fog/dynect/models/dns/records.rb
fog-1.22.1 lib/fog/dynect/models/dns/records.rb