Create DNS records when using DNS HA
Deficiencies in the older maas API client that is used to manage DNS records for DNS HA prevent DNS records being created. This change creates the DNS records by directly interacting with the REST maas api (v2). If the old approach of pre-creating the DNS records is followed then those are used rather than creating new ones. Change-Id: I6e1d7e5f0a7d813c78dfc1e78743ae7b218fbd01 Closes-Bug: 1764832
This commit is contained in:
parent
e251aec359
commit
526ffd7587
|
@ -55,8 +55,9 @@ does not require the clustered nodes to be on the same subnet.
|
|||
Currently the DNS HA feature is only available for MAAS 2.0 or greater
|
||||
environments. MAAS 2.0 requires Juju 2.0 or greater. The MAAS 2.0 client
|
||||
requires Ubuntu 16.04 or greater. The clustered nodes must have static or
|
||||
"reserved" IP addresses registered in MAAS. The DNS hostname(s) must be
|
||||
pre-registered in MAAS before use with DNS HA.
|
||||
"reserved" IP addresses registered in MAAS. If using a version of MAAS earlier
|
||||
than 2.3 the DNS hostname(s) should be pre-registered in MAAS before use with
|
||||
DNS HA.
|
||||
|
||||
The charm will throw an exception in the following circumstances:
|
||||
If running on a version of Ubuntu less than Xenial 16.04
|
||||
|
|
|
@ -99,7 +99,7 @@ COROSYNC_CONF_FILES = [
|
|||
]
|
||||
|
||||
PACKAGES = ['crmsh', 'corosync', 'pacemaker', 'python-netaddr', 'ipmitool',
|
||||
'libnagios-plugin-perl']
|
||||
'libnagios-plugin-perl', 'python3-requests-oauthlib']
|
||||
SUPPORTED_TRANSPORTS = ['udp', 'udpu', 'multicast', 'unicast']
|
||||
DEPRECATED_TRANSPORT_VALUES = {"multicast": "udp", "unicast": "udpu"}
|
||||
|
||||
|
|
|
@ -14,10 +14,12 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import maasclient
|
||||
import argparse
|
||||
import sys
|
||||
import requests_oauthlib
|
||||
import logging
|
||||
import sys
|
||||
|
||||
import maasclient
|
||||
|
||||
|
||||
class MAASDNS(object):
|
||||
|
@ -33,6 +35,8 @@ class MAASDNS(object):
|
|||
self.ttl = str(options.ttl)
|
||||
# String representation of the ip
|
||||
self.ip = options.ip_address
|
||||
self.maas_server = options.maas_server
|
||||
self.maas_creds = options.maas_credentials
|
||||
|
||||
def get_dnsresource(self):
|
||||
""" Get a dnsresource object """
|
||||
|
@ -56,11 +60,29 @@ class MAASDNS(object):
|
|||
def create_dnsresource(self):
|
||||
""" Create a DNS resource object
|
||||
Due to https://bugs.launchpad.net/maas/+bug/1555393
|
||||
This is currently unused
|
||||
this is implemented outside of the maas lib.
|
||||
"""
|
||||
return self.maas.create_dnsresource(self.fqdn,
|
||||
self.ip,
|
||||
self.ttl)
|
||||
dns_url = '{}/api/2.0/dnsresources/?format=json'.format(
|
||||
self.maas_server)
|
||||
(consumer_key, access_token, token_secret) = self.maas_creds.split(':')
|
||||
|
||||
# The use of PLAINTEXT signature is inline with libmaas
|
||||
# https://goo.gl/EJPrM7 but as noted there should be switched
|
||||
# to HMAC once it works server-side.
|
||||
maas_session = requests_oauthlib.OAuth1Session(
|
||||
consumer_key,
|
||||
signature_method='PLAINTEXT',
|
||||
resource_owner_key=access_token,
|
||||
resource_owner_secret=token_secret)
|
||||
fqdn_list = self.fqdn.split('.')
|
||||
payload = {
|
||||
'fqdn': self.fqdn,
|
||||
'name': fqdn_list[0],
|
||||
'domain': '.'.join(fqdn_list[1:]),
|
||||
'address_ttl': self.ttl,
|
||||
'ip_addresses': self.ip,
|
||||
}
|
||||
return maas_session.post(dns_url, data=payload)
|
||||
|
||||
|
||||
class MAASIP(object):
|
||||
|
@ -144,8 +166,7 @@ def dns_ha():
|
|||
|
||||
dns_obj = MAASDNS(options)
|
||||
if not dns_obj.dnsresource:
|
||||
logging.info('DNS Resource does not exist. '
|
||||
'Create it with the maas cli.')
|
||||
dns_obj.create_dnsresource()
|
||||
elif dns_obj.dnsresource.get('ip_addresses'):
|
||||
# TODO: Handle multiple IPs returned for ip_addresses
|
||||
for ip in dns_obj.dnsresource['ip_addresses']:
|
||||
|
|
2
tox.ini
2
tox.ini
|
@ -30,7 +30,7 @@ deps = -r{toxinidir}/requirements.txt
|
|||
basepython = python2.7
|
||||
deps = -r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
commands = flake8 {posargs} hooks unit_tests tests actions lib
|
||||
commands = flake8 {posargs} hooks unit_tests tests actions lib ocf/maas
|
||||
charm-proof
|
||||
|
||||
[testenv:venv]
|
||||
|
|
Loading…
Reference in New Issue