Sha256: 29ca096141076ec6d03649b83671f4a0aaa42871448d5728b53ee2da0b909789

Contents?: true

Size: 1.87 KB

Versions: 1

Compression:

Stored size: 1.87 KB

Contents

module Fog
  module DNS
    class AzureRM
      # This class is giving implementation of create/save and
      # delete/destroy for RecordSet.
      class RecordSet < Fog::Model
        attribute :id
        identity :name
        attribute :resource_group
        attribute :location
        attribute :zone_name
        attribute :records
        attribute :type
        attribute :ttl
        attribute :fqdn
        attribute :cname_record
        attribute :a_record

        def self.parse(recordset)
        hash = {}
        hash['id'] = recordset['id']
        hash['name'] = recordset['name']
        hash['resource_group'] = recordset['id'].split('/')[4]
        hash['location'] = recordset['location']
        hash['zone_name'] = recordset['id'].split('/')[8]
        hash['type'] = recordset['type']
        type = recordset['type'].split('/')[2]
        hash['a_record'] = recordset['properties']['ARecords'] if type == 'A'
        hash['cname_record'] = recordset['properties']['CNAMERecord'] if type == 'CNAME'
        hash['ttl'] = recordset['properties']['TTL']
        hash['fqdn'] = recordset['properties']['fqdn']
        hash
        end

        def save
          requires :name
          requires :resource_group
          requires :zone_name
          requires :records
          requires :type
          requires :ttl
          record_set = service.create_record_set(resource_group, name, zone_name, records, type, ttl)
          merge_attributes(Fog::DNS::AzureRM::RecordSet.parse(record_set))
        end

        def destroy
          service.delete_record_set(resource_group, name, zone_name, type.split('/').last)
        end

        def get_records(resource_group, name, zone_name, record_type)
          service.get_records_from_record_set(resource_group, name, zone_name, record_type)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fog-azure-rm-0.0.2 lib/fog/azurerm/models/dns/record_set.rb