1
0
mirror of https://github.com/github/octodns.git synced 2024-05-11 05:55:00 +00:00
Files
github-octodns/octodns/record/change.py
2023-01-02 10:12:59 -05:00

56 lines
1.4 KiB
Python

#
#
#
from ..equality import EqualityTupleMixin
class Change(EqualityTupleMixin):
def __init__(self, existing, new):
self.existing = existing
self.new = new
@property
def record(self):
'Returns new if we have one, existing otherwise'
return self.new or self.existing
def _equality_tuple(self):
return (self.CLASS_ORDERING, self.record.name, self.record._type)
class Create(Change):
CLASS_ORDERING = 1
def __init__(self, new):
super().__init__(None, new)
def __repr__(self, leader=''):
source = self.new.source.id if self.new.source else ''
return f'Create {self.new} ({source})'
class Update(Change):
CLASS_ORDERING = 2
# Leader is just to allow us to work around heven eating leading whitespace
# in our output. When we call this from the Manager.sync plan summary
# section we'll pass in a leader, otherwise we'll just let it default and
# do nothing
def __repr__(self, leader=''):
source = self.new.source.id if self.new.source else ''
return (
f'Update\n{leader} {self.existing} ->\n'
f'{leader} {self.new} ({source})'
)
class Delete(Change):
CLASS_ORDERING = 0
def __init__(self, existing):
super().__init__(existing, None)
def __repr__(self, leader=''):
return f'Delete {self.existing}'