-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add read objects for dns related MAAS entities (#292)
- Loading branch information
1 parent
7c1374b
commit fec3b50
Showing
9 changed files
with
288 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Objects for dnsresourcerecords.""" | ||
|
||
__all__ = ["DNSResourceRecord", "DNSResourceRecords"] | ||
|
||
from . import check, check_optional, Object, ObjectField, ObjectSet, ObjectType | ||
|
||
|
||
class DNSResourceRecordType(ObjectType): | ||
"""Metaclass for `DNSResourceRecords`.""" | ||
|
||
async def read(cls): | ||
data = await cls._handler.read() | ||
return cls(map(cls._object, data)) | ||
|
||
|
||
class DNSResourceRecords(ObjectSet, metaclass=DNSResourceRecordType): | ||
"""The set of dnsresourcerecords stored in MAAS.""" | ||
|
||
|
||
class DNSResourceRecordType(ObjectType): | ||
async def read(cls, id): | ||
data = await cls._handler.read(id=id) | ||
return cls(data) | ||
|
||
|
||
class DNSResourceRecord(Object, metaclass=DNSResourceRecordType): | ||
"""A dnsresourcerecord stored in MAAS.""" | ||
|
||
id = ObjectField.Checked("id", check(int), readonly=True, pk=True) | ||
ttl = ObjectField.Checked("ttl", check_optional(int), check_optional(int)) | ||
rrtype = ObjectField.Checked("rrtype", check(str), check(str)) | ||
rrdata = ObjectField.Checked("rrdata", check(str), check(str)) | ||
fqdn = ObjectField.Checked("fqdn", check(str), check(str)) | ||
|
||
def __repr__(self): | ||
return super(DNSResourceRecord, self).__repr__( | ||
fields={"ttl", "rrtype", "rrdata", "fqdn"} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Objects for dnsresources.""" | ||
|
||
__all__ = ["DNSResource", "DNSResources"] | ||
|
||
from . import ( | ||
check, | ||
check_optional, | ||
Object, | ||
ObjectField, | ||
ObjectSet, | ||
ObjectType, | ||
ObjectFieldRelatedSet, | ||
) | ||
|
||
|
||
class DNSResourceType(ObjectType): | ||
"""Metaclass for `DNSResources`.""" | ||
|
||
async def read(cls): | ||
data = await cls._handler.read() | ||
return cls(map(cls._object, data)) | ||
|
||
|
||
class DNSResources(ObjectSet, metaclass=DNSResourceType): | ||
"""The set of dnsresources stored in MAAS.""" | ||
|
||
|
||
class DNSResourceType(ObjectType): | ||
async def read(cls, id): | ||
data = await cls._handler.read(id=id) | ||
return cls(data) | ||
|
||
|
||
class DNSResource(Object, metaclass=DNSResourceType): | ||
"""A dnsresource stored in MAAS.""" | ||
|
||
id = ObjectField.Checked("id", check(int), readonly=True, pk=True) | ||
address_ttl = ObjectField.Checked( | ||
"address_ttl", check_optional(int), check_optional(int) | ||
) | ||
fqdn = ObjectField.Checked("fqdn", check(str), check(str)) | ||
ip_addresses = ObjectFieldRelatedSet("ip_addresses", "IPAddresses") | ||
resource_records = ObjectFieldRelatedSet("resource_records", "DNSResourceRecords") | ||
|
||
def __repr__(self): | ||
return super(DNSResource, self).__repr__( | ||
fields={"address_ttl", "fqdn", "ip_addresses", "resource_records"} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Objects for ipaddresses.""" | ||
|
||
__all__ = ["IPAddress", "IPAddresses"] | ||
|
||
from . import ( | ||
check, | ||
parse_timestamp, | ||
Object, | ||
ObjectField, | ||
ObjectSet, | ||
ObjectType, | ||
ObjectFieldRelatedSet, | ||
ObjectFieldRelated, | ||
OriginObjectRef, | ||
) | ||
|
||
|
||
class IPAddressType(ObjectType): | ||
"""Metaclass for `IPAddresses`.""" | ||
|
||
async def read(cls): | ||
data = await cls._handler.read() | ||
return cls(map(cls._object, data)) | ||
|
||
|
||
class IPAddresses(ObjectSet, metaclass=IPAddressType): | ||
"""The set of ipaddresses stored in MAAS.""" | ||
|
||
_object = OriginObjectRef(name="IPAddress") | ||
|
||
|
||
class IPAddress(Object): | ||
"""An ipaddress stored in MAAS.""" | ||
|
||
alloc_type = ObjectField.Checked("alloc_type", check(int), check(int)) | ||
alloc_type_name = ObjectField.Checked("alloc_type_name", check(str), check(str)) | ||
created = ObjectField.Checked("created", parse_timestamp, readonly=True) | ||
ip = ObjectField.Checked("ip", check(str)) | ||
owner = ObjectFieldRelated("owner", "User") | ||
interface_set = ObjectFieldRelatedSet("interface_set", "Interfaces") | ||
subnet = ObjectFieldRelated("subnet", "Subnet", readonly=True, default=None) | ||
|
||
def __repr__(self): | ||
return super(IPAddress, self).__repr__( | ||
fields={ | ||
"alloc_type", | ||
"alloc_type_name", | ||
"created", | ||
"ip", | ||
"owner", | ||
"interface_set", | ||
"subnet", | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Tests for `maas.client.viscera.dnsresourcerecords`.""" | ||
|
||
import random | ||
|
||
from testtools.matchers import Equals | ||
|
||
from .. import dnsresourcerecords | ||
|
||
from ..testing import bind | ||
from ...testing import make_string_without_spaces, TestCase | ||
|
||
|
||
def make_origin(): | ||
""" | ||
Create a new origin with DNSResourceRecord and DNSResourceRecords. The former | ||
refers to the latter via the origin, hence why it must be bound. | ||
""" | ||
return bind( | ||
dnsresourcerecords.DNSResourceRecords, dnsresourcerecords.DNSResourceRecord | ||
) | ||
|
||
|
||
class TestDNSResourceRecords(TestCase): | ||
def test__dnsresourcerecords_read(self): | ||
"""DNSResourceRecords.read() returns a list of DNSResourceRecords.""" | ||
DNSResourceRecords = make_origin().DNSResourceRecords | ||
dnsresourcerecords = [ | ||
{"id": random.randint(0, 100), "fqdn": make_string_without_spaces()} | ||
for _ in range(3) | ||
] | ||
DNSResourceRecords._handler.read.return_value = dnsresourcerecords | ||
dnsresourcerecords = DNSResourceRecords.read() | ||
self.assertThat(len(dnsresourcerecords), Equals(3)) | ||
|
||
|
||
class TestDNSResourceRecord(TestCase): | ||
def test__dnsresourcerecord_read(self): | ||
DNSResourceRecord = make_origin().DNSResourceRecord | ||
dnsresourcerecord = { | ||
"id": random.randint(0, 100), | ||
"fqdn": make_string_without_spaces(), | ||
} | ||
DNSResourceRecord._handler.read.return_value = dnsresourcerecord | ||
self.assertThat( | ||
DNSResourceRecord.read(id=dnsresourcerecord["id"]), | ||
Equals(DNSResourceRecord(dnsresourcerecord)), | ||
) | ||
DNSResourceRecord._handler.read.assert_called_once_with( | ||
id=dnsresourcerecord["id"] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Tests for `maas.client.viscera.dnsresources`.""" | ||
|
||
import random | ||
|
||
from testtools.matchers import Equals | ||
|
||
from .. import dnsresources | ||
|
||
from ..testing import bind | ||
from ...testing import make_string_without_spaces, TestCase | ||
|
||
|
||
def make_origin(): | ||
""" | ||
Create a new origin with DNSResource and DNSResources. The former | ||
refers to the latter via the origin, hence why it must be bound. | ||
""" | ||
return bind(dnsresources.DNSResources, dnsresources.DNSResource) | ||
|
||
|
||
class TestDNSResources(TestCase): | ||
def test__dnsresources_read(self): | ||
"""DNSResources.read() returns a list of DNSResources.""" | ||
DNSResources = make_origin().DNSResources | ||
dnsresources = [ | ||
{"id": random.randint(0, 100), "fqdn": make_string_without_spaces()} | ||
for _ in range(3) | ||
] | ||
DNSResources._handler.read.return_value = dnsresources | ||
dnsresources = DNSResources.read() | ||
self.assertThat(len(dnsresources), Equals(3)) | ||
|
||
|
||
class TestDNSResource(TestCase): | ||
def test__dnsresource_read(self): | ||
DNSResource = make_origin().DNSResource | ||
dnsresource = { | ||
"id": random.randint(0, 100), | ||
"fqdn": make_string_without_spaces(), | ||
} | ||
DNSResource._handler.read.return_value = dnsresource | ||
self.assertThat( | ||
DNSResource.read(id=dnsresource["id"]), Equals(DNSResource(dnsresource)) | ||
) | ||
DNSResource._handler.read.assert_called_once_with(id=dnsresource["id"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Tests for `maas.client.viscera.ip_addresses`.""" | ||
|
||
from testtools.matchers import Equals | ||
|
||
from .. import ip_addresses | ||
|
||
from ..testing import bind | ||
from ...testing import TestCase | ||
|
||
|
||
def make_origin(): | ||
""" | ||
Create a new origin with IPAddress and IPAddresses. The former | ||
refers to the latter via the origin, hence why it must be bound. | ||
""" | ||
return bind(ip_addresses.IPAddresses, ip_addresses.IPAddress) | ||
|
||
|
||
class TestIPAddresses(TestCase): | ||
def test__ip_addresses_read(self): | ||
"""IPAddresses.read() returns a list of IPAddresses.""" | ||
IPAddresses = make_origin().IPAddresses | ||
ip_addresses = [ | ||
{"ip": "10.0.0.%s" % (i + 1), "alloc_type_name": "User reserved"} | ||
for i in range(3) | ||
] | ||
IPAddresses._handler.read.return_value = ip_addresses | ||
ip_addresses = IPAddresses.read() | ||
self.assertThat(len(ip_addresses), Equals(3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters