Add functions for managing DNS Entries
Add code for managing DNS Entries via hacluster. This is part of the effort to enable DNS HA in the reactive charms. Change-Id: I1a6cdeffa3aa8657b957ba68cd09face27f93b27 Partial-Bug: #1727376
This commit is contained in:
parent
c01416b7eb
commit
09ead5622e
36
common.py
36
common.py
|
@ -582,3 +582,39 @@ class VirtualIP(ResourceDescriptor):
|
||||||
if self.cidr:
|
if self.cidr:
|
||||||
res_params = '{} cidr_netmask="{}"'.format(res_params, self.cidr)
|
res_params = '{} cidr_netmask="{}"'.format(res_params, self.cidr)
|
||||||
crm.primitive(vip_key, res_type, params=res_params)
|
crm.primitive(vip_key, res_type, params=res_params)
|
||||||
|
|
||||||
|
|
||||||
|
class DNSEntry(ResourceDescriptor):
|
||||||
|
|
||||||
|
def __init__(self, service_name, ip, fqdn, endpoint_type):
|
||||||
|
"""Class for managing DNS entries
|
||||||
|
|
||||||
|
:param service_name: string - Name of service
|
||||||
|
:param ip: string - IP to point DNS entry at
|
||||||
|
:param fqdn: string - DNS Entry
|
||||||
|
:param endpoint_type: string - The type of the endpoint represented by
|
||||||
|
the DNS record eg public, admin etc
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
self.service_name = service_name
|
||||||
|
self.ip = ip
|
||||||
|
self.fqdn = fqdn
|
||||||
|
self.endpoint_type = endpoint_type
|
||||||
|
|
||||||
|
def configure_resource(self, crm, res_type='ocf:maas:dns'):
|
||||||
|
"""Configure new DNS resource in crm
|
||||||
|
|
||||||
|
:param crm: CRM() instance - Config object for Pacemaker resources
|
||||||
|
:param res_type: string - Corosync Open Cluster Framework resource
|
||||||
|
agent to use for DNS HA
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
res_key = 'res_{}_{}_hostname'.format(
|
||||||
|
self.service_name.replace('-', '_'),
|
||||||
|
self.endpoint_type)
|
||||||
|
res_params = ''
|
||||||
|
if self.fqdn:
|
||||||
|
res_params = '{} fqdn="{}"'.format(res_params, self.fqdn)
|
||||||
|
if self.ip:
|
||||||
|
res_params = '{} ip_address="{}"'.format(res_params, self.ip)
|
||||||
|
crm.primitive(res_key, res_type, params=res_params)
|
||||||
|
|
30
requires.py
30
requires.py
|
@ -132,3 +132,33 @@ class HAClusterRequires(RelationBase):
|
||||||
resources.add(
|
resources.add(
|
||||||
relations.hacluster.common.InitService(name, service, clone))
|
relations.hacluster.common.InitService(name, service, clone))
|
||||||
self.set_local(resources=resources)
|
self.set_local(resources=resources)
|
||||||
|
|
||||||
|
def add_dnsha(self, name, ip, fqdn, endpoint_type):
|
||||||
|
"""Add a DNS entry to self.resources
|
||||||
|
|
||||||
|
:param name: string - Name of service
|
||||||
|
:param ip: string - IP address dns entry should resolve to
|
||||||
|
:param fqdn: string - The DNS entry name
|
||||||
|
:param endpoint_type: string - Public, private, internal etc
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
resource_dict = self.get_local('resources')
|
||||||
|
if resource_dict:
|
||||||
|
resources = relations.hacluster.common.CRM(**resource_dict)
|
||||||
|
else:
|
||||||
|
resources = relations.hacluster.common.CRM()
|
||||||
|
resources.add(
|
||||||
|
relations.hacluster.common.DNSEntry(name, ip, fqdn, endpoint_type))
|
||||||
|
|
||||||
|
# DNS Group
|
||||||
|
group = 'grp_{}_hostnames'.format(name)
|
||||||
|
dns_res_group_members = []
|
||||||
|
if resource_dict:
|
||||||
|
dns_resources = resource_dict.get('resources')
|
||||||
|
if dns_resources:
|
||||||
|
for dns_res in dns_resources:
|
||||||
|
if 'hostname' in dns_res:
|
||||||
|
dns_res_group_members.append(dns_res)
|
||||||
|
resources.group(group, *dns_res_group_members)
|
||||||
|
|
||||||
|
self.set_local(resources=resources)
|
||||||
|
|
Loading…
Reference in New Issue