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



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
# File 'lib/fog/azurerm/models/dns/record_set.rb', line 19

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['records'] = []
  if type == 'A'
    record_entries = recordset['properties']['ARecords']
    record_entries.each do |record|
      hash['records'] << record['ipv4Address']
    end
  end
  if type == 'CNAME'
    record_entries = recordset['properties']['CNAMERecord']['cname']
    hash['records'] << record_entries
  end
  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

Instance Method Details

#add_a_type_record(record) ⇒ Object



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

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

#destroyObject



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

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



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

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



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

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

#saveObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/fog/azurerm/models/dns/record_set.rb', line 46

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

#update_ttl(ttl) ⇒ Object



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

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