def find_modified(self, previous=[], current=[], exception_map={}): """ Find any objects that have been changed since the last run of the watcher. Add these items to the changed_items list. """ prev_map = {item.location(): item for item in previous} curr_map = {item.location(): item for item in current} item_locations = list(Set(curr_map).intersection(Set(prev_map))) item_locations = [ item_location for item_location in item_locations if not self.locationInExceptionMap(item_location, exception_map) ] for location in item_locations: prev_item = prev_map[location] curr_item = curr_map[location] if not sub_dict(prev_item.config) == sub_dict(curr_item.config): change_item = ChangeItem.from_items(old_item=prev_item, new_item=curr_item) self.changed_items.append(change_item) app.logger.debug( "%s %s/%s/%s changed" % (self.i_am_singular, change_item.account, change_item.region, change_item.name) )
def find_modified(self, previous=[], current=[], exception_map={}): """ Find any objects that have been changed since the last run of the watcher. Add these items to the changed_items list. """ prev_map = {item.location(): item for item in previous} curr_map = {item.location(): item for item in current} item_locations = list(Set(curr_map).intersection(Set(prev_map))) item_locations = [item_location for item_location in item_locations if not self.locationInExceptionMap(item_location, exception_map)] for location in item_locations: prev_item = prev_map[location] curr_item = curr_map[location] # ChangeItem with and without ephemeral changes eph_change_item = None dur_change_item = None if not sub_dict(prev_item.config) == sub_dict(curr_item.config): eph_change_item = ChangeItem.from_items(old_item=prev_item, new_item=curr_item) if self.ephemerals_skipped(): # deepcopy configs before filtering dur_prev_item = deepcopy(prev_item) dur_curr_item = deepcopy(curr_item) # filter-out ephemeral paths in both old and new config dicts for path in self.ephemeral_paths: for cfg in [dur_prev_item.config, dur_curr_item.config]: try: dpath.util.delete(cfg, path, separator='$') except PathNotFound: pass # now, compare only non-ephemeral paths if not sub_dict(dur_prev_item.config) == sub_dict(dur_curr_item.config): dur_change_item = ChangeItem.from_items(old_item=dur_prev_item, new_item=dur_curr_item) # store all changes, divided in specific categories if eph_change_item: self.ephemeral_items.append(eph_change_item) app.logger.debug("%s: ephemeral changes in item %s/%s/%s" % (self.i_am_singular, eph_change_item.account, eph_change_item.region, eph_change_item.name)) if dur_change_item: self.changed_items.append(dur_change_item) app.logger.debug("%s: durable changes in item %s/%s/%s" % (self.i_am_singular, dur_change_item.account, dur_change_item.region, dur_change_item.name)) elif eph_change_item is not None: # store all changes, handle them all equally self.changed_items.append(eph_change_item) app.logger.debug("%s: changes in item %s/%s/%s" % (self.i_am_singular, eph_change_item.account, eph_change_item.region, eph_change_item.name))
def find_modified(self, previous=[], current=[], exception_map={}): """ Find any objects that have been changed since the last run of the watcher. Add these items to the changed_items list. """ prev_map = {item.location(): item for item in previous} curr_map = {item.location(): item for item in current} item_locations = list(Set(curr_map).intersection(Set(prev_map))) item_locations = [item_location for item_location in item_locations if not self.locationInExceptionMap(item_location, exception_map)] for location in item_locations: prev_item = prev_map[location] curr_item = curr_map[location] if not sub_dict(prev_item.config) == sub_dict(curr_item.config): change_item = ChangeItem.from_items(old_item=prev_item, new_item=curr_item) self.changed_items.append(change_item) app.logger.debug("%s %s/%s/%s changed" % (self.i_am_singular, change_item.account, change_item.region, change_item.name))
def find_modified(self, previous=[], current=[], exception_map={}): """ Find any objects that have been changed since the last run of the watcher. Add these items to the changed_items list. """ prev_map = {item.location(): item for item in previous} curr_map = {item.location(): item for item in current} item_locations = list(Set(curr_map).intersection(Set(prev_map))) item_locations = [ item_location for item_location in item_locations if not self.locationInExceptionMap(item_location, exception_map) ] for location in item_locations: prev_item = prev_map[location] curr_item = curr_map[location] # ChangeItem with and without ephemeral changes eph_change_item = None dur_change_item = None if not sub_dict(prev_item.config) == sub_dict(curr_item.config): eph_change_item = ChangeItem.from_items(old_item=prev_item, new_item=curr_item) if self.ephemerals_skipped(): # deepcopy configs before filtering dur_prev_item = deepcopy(prev_item) dur_curr_item = deepcopy(curr_item) # filter-out ephemeral paths in both old and new config dicts for path in self.ephemeral_paths: for cfg in [dur_prev_item.config, dur_curr_item.config]: try: dpath.util.delete(cfg, path, separator='$') except PathNotFound: pass # now, compare only non-ephemeral paths if not sub_dict(dur_prev_item.config) == sub_dict( dur_curr_item.config): dur_change_item = ChangeItem.from_items( old_item=dur_prev_item, new_item=dur_curr_item) # store all changes, divided in specific categories if eph_change_item: self.ephemeral_items.append(eph_change_item) app.logger.debug( "%s: ephemeral changes in item %s/%s/%s" % (self.i_am_singular, eph_change_item.account, eph_change_item.region, eph_change_item.name)) if dur_change_item: self.changed_items.append(dur_change_item) app.logger.debug( "%s: durable changes in item %s/%s/%s" % (self.i_am_singular, dur_change_item.account, dur_change_item.region, dur_change_item.name)) elif eph_change_item is not None: # store all changes, handle them all equally self.changed_items.append(eph_change_item) app.logger.debug( "%s: changes in item %s/%s/%s" % (self.i_am_singular, eph_change_item.account, eph_change_item.region, eph_change_item.name))