2
Created on May 14, 2015
8
from .apidriver import APIDriver
10
log = logging.getLogger('vmaas.main')
13
class MAASException(Exception):
17
class MAASDriverException(Exception):
21
class MAASClient(object):
23
A wrapper for the python maas client which makes using the API a bit
27
def __init__(self, api_url, api_key, **kwargs):
28
self.driver = self._get_driver(api_url, api_key, **kwargs)
30
def _get_driver(self, api_url, api_key, **kwargs):
31
return APIDriver(api_url, api_key)
33
def _validate_maas(self):
35
resp = self.driver.validate_maas()
36
logging.info("Validated MAAS API")
38
except Exception as e:
39
logging.error("MAAS API validation has failed. "
40
"Check maas_url and maas_credentials. Error: {}"
44
###########################################################################
45
# DNS API - http://maas.ubuntu.com/docs2.0/api.html#dnsresource
46
###########################################################################
47
def get_dnsresources(self):
49
Get a listing of DNS resources which are currently defined.
51
:returns: a list of DNS objects
52
DNS object is a dictionary of the form:
53
{'fqdn': 'keystone.maas',
54
'resource_records': [],
56
'resource_uri': '/MAAS/api/2.0/dnsresources/1/',
60
resp = self.driver.get_dnsresources()
65
def update_dnsresource(self, rid, fqdn, ip_address):
67
Updates a DNS resource with a new ip_address
69
:param rid: The dnsresource_id i.e.
70
/api/2.0/dnsresources/{dnsresource_id}/
71
:param fqdn: The fqdn address to update
72
:param ip_address: The ip address to update the A record to point to
73
:returns: True if the DNS object was updated, False otherwise.
75
resp = self.driver.update_dnsresource(rid, fqdn, ip_address)
80
def create_dnsresource(self, fqdn, ip_address, address_ttl=None):
82
Creates a new DNS resource
84
:param fqdn: The fqdn address to update
85
:param ip_address: The ip address to update the A record to point to
86
:param adress_ttl: DNS time to live
87
:returns: True if the DNS object was updated, False otherwise.
89
resp = self.driver.create_dnsresource(fqdn, ip_address, address_ttl)
94
###########################################################################
95
# IP API - http://maas.ubuntu.com/docs2.0/api.html#ip-address
96
###########################################################################
97
def get_ipaddresses(self):
99
Get a list of ip addresses
101
:returns: a list of ip address dictionaries
103
resp = self.driver.get_ipaddresses()
108
def create_ipaddress(self, ip_address, hostname=None):
110
Creates a new IP resource
112
:param ip_address: The ip address to register
113
:param hostname: the hostname to register at the same time
114
:returns: True if the DNS object was updated, False otherwise.
116
resp = self.driver.create_ipaddress(ip_address, hostname)