summaryrefslogtreecommitdiff
path: root/designate/objects/record.py
blob: 9e72742493359b06ebf409ba58020cdca3bacda2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright (c) 2014 Rackspace Hosting
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
from designate.objects import base
from designate.objects import fields


@base.DesignateRegistry.register
class Record(base.DesignateObject, base.PersistentObjectMixin,
             base.DictObjectMixin):
    def __init__(self, *args, **kwargs):
        super(Record, self).__init__(*args, **kwargs)

    fields = {
        'shard': fields.IntegerFields(nullable=True, minimum=0, maximum=4095),
        'data': fields.AnyField(nullable=True),
        'zone_id': fields.UUIDFields(nullable=True),
        'managed': fields.BooleanField(nullable=True),
        'managed_resource_type': fields.StringFields(nullable=True,
                                                     maxLength=160),
        'managed_resource_id': fields.UUIDFields(nullable=True),
        'managed_plugin_name': fields.StringFields(nullable=True,
                                                   maxLength=160),
        'managed_plugin_type': fields.StringFields(nullable=True,
                                                   maxLength=160),
        'hash': fields.StringFields(nullable=True, maxLength=32),
        'description': fields.StringFields(nullable=True,
                                           maxLength=160),
        'status': fields.EnumField(
            valid_values=['ACTIVE', 'PENDING', 'ERROR', 'DELETED'],
            nullable=True
        ),
        'tenant_id': fields.StringFields(nullable=True),
        'recordset_id': fields.UUIDFields(nullable=True),
        'managed_tenant_id': fields.StringFields(nullable=True),
        'managed_resource_region': fields.StringFields(nullable=True,
                                                       maxLength=160),
        'managed_extra': fields.StringFields(nullable=True,
                                             maxLength=160),
        'action': fields.EnumField(
            valid_values=['CREATE', 'DELETE', 'UPDATE', 'NONE'],
            nullable=True
        ),
        'serial': fields.IntegerFields(nullable=True,
                                       minimum=1, maximum=4294967295),
    }

    @classmethod
    def get_recordset_schema_changes(cls):
        # This is to allow record types to override the validation on a
        # recordset
        return {}

    STRING_KEYS = [
        'id', 'recordset_id', 'data'
    ]

    def __repr__(self):
        record = self.to_dict()
        if 'data' in record:
            record['data'] = record['data'][:35]
        return self._make_obj_str(record)


@base.DesignateRegistry.register
class RecordList(base.ListObjectMixin, base.DesignateObject):
    LIST_ITEM_TYPE = Record

    fields = {
        'objects': fields.ListOfObjectsField('Record'),
    }