Class: Sambot::DNS::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/sambot/dns/repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(url = '[email protected]:ads-devops/as-terraform-dns-config.git', name = 'as-terraform-dns-config') ⇒ Repository

Returns a new instance of Repository.



9
10
11
12
# File 'lib/sambot/dns/repository.rb', line 9

def initialize(url = '[email protected]:ads-devops/as-terraform-dns-config.git', name = 'as-terraform-dns-config')
  @url = url
  @name = name
end

Instance Method Details

#cloneObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/sambot/dns/repository.rb', line 36

def clone
  tmp = Dir.mktmpdir
  Dir.chdir(tmp) do
    `git clone #{@url} #{@name}`
    repo = File.join(tmp, @name, 'rackspace')
    puts repo
    Dir.chdir(repo) do
      `git checkout master`
      yield(repo)
    end
  end
end

#list_recordsObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sambot/dns/repository.rb', line 18

def list_records
  records = []
  clone do |directory|
    records << ['Module', 'Hostname', 'Enable Internal IP', 'Enable External IP', 'External IP', 'Internal IP']
    Dir['*'].each do |folder|
      filename = File.join(directory, "#{folder}/dyn_dns.tf")
      contents = Rhcl.parse(File.read(filename))
      modules = contents['module']
      modules.each do |section|
        record = section[1]
        next unless record['int-type'] == 'A' || record['ext-type'] == 'A'
        records << [folder, record['name'], record['enable-int'], record['enable-ext'], record['ext-value'], record['int-value']]
      end
    end
  end
  records
end

#recordsObject



14
15
16
# File 'lib/sambot/dns/repository.rb', line 14

def records
  Records.new(self)
end