Class: Fog::DNS::AzureRM::RecordSet

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/azurerm/models/dns/record_set.rb

Overview

This class is giving implementation of create/save and delete/destroy for RecordSet.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(recordset) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/azurerm/models/dns/record_set.rb', line 17

def self.parse(recordset)
  hash = get_hash_from_object(recordset)
  hash['resource_group'] = get_resource_group_from_id(recordset.id)
  hash['zone_name'] = get_record_set_from_id(recordset.id)
  type = get_type_from_recordset_type(recordset.type)

  hash['records'] = []
  if type == 'A'
    record_entries = recordset.arecords
    record_entries.each do |record|
      hash['records'] << record.ipv4address
    end
  end
  if type == 'CNAME'
    record_entries = recordset.cname_record
    hash['records'] << record_entries.cname
  end

  unless recordset.arecords.nil?
    a_records = []
    recordset.arecords.each do |record|
      a_record = Fog::DNS::AzureRM::ARecord.new
      a_record.merge_attributes(Fog::DNS::AzureRM::ARecord.parse(record))
      a_records.push(a_record)
    end
    hash['a_records'] = a_records
  end

  unless recordset.cname_record.nil?
    cname_record = Fog::DNS::AzureRM::CnameRecord.new
    cname_record.merge_attributes(Fog::DNS::AzureRM::CnameRecord.parse(recordset.cname_record))
    hash['cname_record'] = cname_record
  end

  hash
end

Instance Method Details

#add_a_type_record(record) ⇒ Object



75
76
77
78
79
# File 'lib/fog/azurerm/models/dns/record_set.rb', line 75

def add_a_type_record(record)
  records << record
  record_set = service.create_or_update_record_set(record_set_params, get_record_type(type))
  merge_attributes(Fog::DNS::AzureRM::RecordSet.parse(record_set))
end

#destroyObject



60
61
62
# File 'lib/fog/azurerm/models/dns/record_set.rb', line 60

def destroy
  service.delete_record_set(resource_group, name, zone_name, get_record_type(type))
end

#get_records(resource_group, name, zone_name, record_type) ⇒ Object



64
65
66
# File 'lib/fog/azurerm/models/dns/record_set.rb', line 64

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

#remove_a_type_record(record) ⇒ Object



81
82
83
84
85
# File 'lib/fog/azurerm/models/dns/record_set.rb', line 81

def remove_a_type_record(record)
  records.delete(record)
  record_set = service.create_or_update_record_set(record_set_params, get_record_type(type))
  merge_attributes(Fog::DNS::AzureRM::RecordSet.parse(record_set))
end

#saveObject



54
55
56
57
58
# File 'lib/fog/azurerm/models/dns/record_set.rb', line 54

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

#update_ttl(ttl) ⇒ Object



68
69
70
71
72
73
# File 'lib/fog/azurerm/models/dns/record_set.rb', line 68

def update_ttl(ttl)
  params = record_set_params
  params[:ttl] = ttl
  record_set = service.create_or_update_record_set(params, get_record_type(type))
  merge_attributes(Fog::DNS::AzureRM::RecordSet.parse(record_set))
end