Sha256: fa2dcd88db6d5ad2d621a069fe3c4f95a1e25f6ac667df8c5ec266d2cfe69b2b

Contents?: true

Size: 1.84 KB

Versions: 19

Compression:

Stored size: 1.84 KB

Contents

#
# Author:: Celso Fernandes (<fernandes@zertico.com>)
# © Copyright IBM Corporation 2014.
#
# LICENSE: MIT (http://opensource.org/licenses/MIT)
#

module Fog
  module DNS
    class Softlayer
      class Record < Fog::Model
        identity  :id
        attribute :domain_id,     :aliases => "domainId"
        attribute :name,          :aliases => "host"
        attribute :value,         :aliases => "data"
        attribute :ttl
        attribute :priority,      :aliases => "mxPriority"
        attribute :type
        attribute :expire
        attribute :minimum
        attribute :refresh
        attribute :retry
         
        def initialize(attributes={})
          self.domain_id = attributes[:domain_id]
          super(attributes)
        end

        def destroy
          response = service.delete_record(identity)
          response.body
        end

        def save
          requires :name, :type, :value, :domain_id
          opts = generate_template

          # to save or to update, thats the question
          if id.nil?
            data = service.create_record(opts)
            merge_attributes(data.body)
          else
            data = service.update_record(self.id, opts)
          end
          true
        end

        private
        def generate_template
          template = {}
          template[:host] = self.name
          template[:data] = self.value
          template[:type] = self.type
          template[:domainId] = self.domain_id

          template[:ttl] = self.ttl if self.ttl
          template[:mxPriority] = self.priority if self.priority
          template[:expire] = self.expire if self.expire
          template[:minimum] = self.minimum if self.minimum
          template[:refresh] = self.refresh if self.refresh
          template[:retry] = self.retry if self.retry
          template
        end
      end
    end
  end
end

Version data entries

19 entries across 17 versions & 3 rubygems

Version Path
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-softlayer-1.1.4/lib/fog/softlayer/models/dns/record.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-softlayer-1.1.4/lib/fog/softlayer/models/dns/record.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-softlayer-1.1.4/lib/fog/softlayer/models/dns/record.rb
fog-softlayer-1.1.4 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-1.1.3 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-1.1.2 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-1.1.1 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-1.1.0 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-1.0.3 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-1.0.2 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-1.0.1 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-1.0.0 lib/fog/softlayer/models/dns/record.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-softlayer-0.4.7/lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.4.7 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.4.6 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.4.5 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.4.4 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.4.3 lib/fog/softlayer/models/dns/record.rb
fog-softlayer-0.4.2 lib/fog/softlayer/models/dns/record.rb