We didn't have any automation for creation of VMs to server DNS servers
and the process consisted of many manual error-prone steps.
In this commit, we introduce SetupDnsServerVM prog, which makes it
straightforward to create fully-functional DNS servers from scratch
(which could be useful for development environments for now and prod in
the future) as well as adding VMs to existing DNS servers.
While working on this, I noticed that we don't have a config variable
for the project holding the DNS service resources we use in prod, so I
created that. You also need to populate that in the dev env. DnsServer
class itself doesn't hold that value (but DnsZone does) so that addition
could be another beginner-friendly task.
Usage is like this:
```ruby
ds = DnsServer.first || DnsServer.create_with_id(name: "elephant")
dz1 = DnsZone.create_with_id(
project_id: Config.dns_service_project_id,
name: "erentest1.ubicloud.com",
last_purged_at: Time.now
)
dz2 = DnsZone.create_with_id(
project_id: Config.dns_service_project_id,
name: "erentest2.ubicloud.com",
last_purged_at: Time.now
)
Strand.create(prog: "DnsZone::DnsZoneNexus", label: "wait") { _1.id =
dz1.id }
Strand.create(prog: "DnsZone::DnsZoneNexus", label: "wait") { _1.id =
dz2.id }
dz1.add_dns_server DnsServer.first
dz2.add_dns_server DnsServer.first
["hebele", "hubele", "asdasd-asdasd-asd", "123123"].each do |r|
dz1.insert_record(record_name: "#{r}.#{dz1.name}", type: "A", ttl:
10, data: "0.1.1.0")
dz2.insert_record(record_name: "#{r}.#{dz2.name}", type: "A", ttl:
10, data: "0.1.1.0")
end
st = Prog::DnsZone::SetupDnsServerVm.assemble(DnsServer.first)
```
Note that concurrency between the VM creation, zone operations and
records are not handled in the best way. So it's advised to double-check
the results after the VM is created in prod environment.
We have a ton more to do for a proper DNS service lifecycle. A few
ideas:
- Health check for DNS servers and VMs
- Check-ups for consistency among the VMs of a DNS server
- Ability to add/remove DNS zones
- More validation about multiple DNS servers
- DnsServer belongs to a project