dnsprovider: Add IsEmpty method

When batching changes, it is often handy to know whether a changeset
IsEmpty, and thus does not need to be Apply-ed.
This commit is contained in:
Justin Santa Barbara 2017-01-16 10:16:24 -05:00
parent 8fa23586cf
commit 5d740dce6a
4 changed files with 15 additions and 1 deletions

View File

@ -45,7 +45,7 @@ type Zone interface {
Name() string Name() string
// ID returns the unique provider identifier for the zone // ID returns the unique provider identifier for the zone
ID() string ID() string
// ResourceRecordsets returns the provider's ResourceRecordSets interface, or false if not supported. // ResourceRecordSets returns the provider's ResourceRecordSets interface, or false if not supported.
ResourceRecordSets() (ResourceRecordSets, bool) ResourceRecordSets() (ResourceRecordSets, bool)
} }
@ -70,6 +70,8 @@ type ResourceRecordChangeset interface {
Remove(ResourceRecordSet) ResourceRecordChangeset Remove(ResourceRecordSet) ResourceRecordChangeset
// Apply applies the accumulated operations to the Zone. // Apply applies the accumulated operations to the Zone.
Apply() error Apply() error
// IsEmpty returns true if there are no accumulated operations.
IsEmpty() bool
} }
type ResourceRecordSet interface { type ResourceRecordSet interface {

View File

@ -99,3 +99,7 @@ func (c *ResourceRecordChangeset) Apply() error {
} }
return nil return nil
} }
func (c *ResourceRecordChangeset) IsEmpty() bool {
return len(c.removals) == 0 && len(c.additions) == 0
}

View File

@ -58,6 +58,10 @@ func (c *ResourceRecordChangeset) Remove(rrset dnsprovider.ResourceRecordSet) dn
return c return c
} }
func (c *ResourceRecordChangeset) IsEmpty() bool {
return len(c.changeset) == 0
}
func (c *ResourceRecordChangeset) Apply() error { func (c *ResourceRecordChangeset) Apply() error {
ctx := context.Background() ctx := context.Background()
etcdPathPrefix := c.zone.zones.intf.etcdPathPrefix etcdPathPrefix := c.zone.zones.intf.etcdPathPrefix

View File

@ -72,3 +72,7 @@ func (c *ResourceRecordChangeset) Apply() error {
return nil return nil
} }
func (c *ResourceRecordChangeset) IsEmpty() bool {
return len(c.additions) == 0 && len(c.removals) == 0
}