def _set_commands(self, want_ace, have_ace): """A helped method that checks if there is a delta between the `have_ace` and `want_ace`. If there is a delta then it calls `_compute_commands` to create the ACE line. :rtype: A string :returns: An ACE generated from a structured ACE dictionary via a call to `_compute_commands` """ if 'line' in want_ace: if want_ace['line'] != have_ace.get('line'): return self._compute_commands(want_ace) else: if ('prefix' in want_ace.get('source', {})) or ('prefix' in want_ace.get('destination', {})): self._prepare_for_diff(want_ace) protocol_opt_delta = {} delta = dict_diff(have_ace, want_ace) # `dict_diff` doesn't work properly for `protocol_options` diff, # so we need to handle it separately if want_ace.get('protocol_options', {}): protocol_opt_delta = set(flatten_dict(have_ace.get('protocol_options', {}))) ^ \ set(flatten_dict(want_ace.get('protocol_options', {}))) if delta or protocol_opt_delta: want_ace = self._dict_merge(have_ace, want_ace) return self._compute_commands(want_ace)
def _purge_attribs(self, intf): """ The command generator for purging attributes :rtype: A list :returns: the commands necessary to purge attributes """ commands = [] have_copy = deepcopy(intf) members = have_copy.pop('members', []) to_delete = dict_delete(have_copy, remove_empties({'name': have_copy['name']})) if to_delete: for key, value in iteritems(flatten_dict( remove_empties(to_delete))): commands.append( self._compute_commands(key=key, value=value, remove=True)) if commands: pad_commands(commands, intf['name']) if members: members = param_list_to_dict(deepcopy(members), unique_key='member') for key in members: member_cmd = ['no bundle id'] pad_commands(member_cmd, key) commands.extend(member_cmd) return commands
def _state_deleted(self, want, have): """ The command generator when state is deleted :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ commands = [] for key, value in iteritems(flatten_dict(dict_delete(have, remove_empties(want)))): cmd = self._compute_commands(key, value, remove=True) if cmd: commands.append(cmd) return commands
def _state_merged(self, want, have): """ The command generator when state is merged :rtype: A list :returns: the commands necessary to merge the provided into the current configuration """ commands = [] updates = dict_diff(have, want) if updates: for key, value in iteritems(flatten_dict(remove_empties(updates))): commands.append(self._compute_commands(key, value)) return commands
def _state_merged(want, have): """ The command generator when state is merged :rtype: A list :returns: the commands necessary to merge the provided into the current configuration """ commands = [] updates = dict_diff(have, want) if updates: for key, value in iteritems( flatten_dict(remove_empties(updates['system']))): commands.append('lacp system {0} {1}'.format( key.replace('address', 'mac'), value)) return commands
def _state_deleted(want, have): """ The command generator when state is deleted :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ commands = [] for key, value in iteritems( flatten_dict(dict_delete(have, remove_empties(want)))): commands.append( Lacp_interfaces._compute_commands(key, value, remove=True)) if commands: pad_commands(commands, have['name']) return commands
def _state_merged(self, want, have): """ The command generator when state is merged :rtype: A list :returns: the commands necessary to merge the provided into the current configuration """ commands = [] if not have: have = {'name': want['name']} for key, value in iteritems(flatten_dict(remove_empties(dict_diff(have, want)))): commands.append(self._compute_commands(key, value)) if commands: pad_commands(commands, want['name']) return commands
def _render_bundle_updates(self, want, have): """ The command generator for updates to bundles :rtype: A list :returns: the commands necessary to update bundles """ commands = [] if not have: have = {'name': want['name']} want_copy = deepcopy(want) have_copy = deepcopy(have) want_copy.pop('members', []) have_copy.pop('members', []) bundle_updates = dict_diff(have_copy, want_copy) if bundle_updates: for key, value in iteritems( flatten_dict(remove_empties(bundle_updates))): commands.append(self._compute_commands(key=key, value=value)) return commands
def _render_bundle_del_commands(self, want, have): """ The command generator for delete commands w.r.t bundles :rtype: A list :returns: the commands necessary to update member interfaces """ commands = [] if not want: want = {'name': have['name']} want_copy = deepcopy(want) have_copy = deepcopy(have) want_copy.pop('members', []) have_copy.pop('members', []) to_delete = dict_delete(have_copy, remove_empties(want_copy)) if to_delete: for key, value in iteritems(flatten_dict( remove_empties(to_delete))): commands.append( self._compute_commands(key=key, value=value, remove=True)) return commands