def template_for_lag_creation(self, have, diff_members, diff_portchannels, state_name): commands = list() requests = list() if diff_members: commands_portchannels, requests = self.call_create_port_channel( diff_members, have) if commands_portchannels: po_list = [{ 'name': x['name'] } for x in commands_portchannels if x['name']] else: po_list = [] if po_list: commands.extend(update_states(po_list, state_name)) diff_members_remove_none = [ x for x in diff_members if x["members"] ] if diff_members_remove_none: request = self.create_lag_interfaces_requests( diff_members_remove_none) if requests: requests.extend(request) else: requests = request commands.extend(update_states(diff_members, state_name)) if diff_portchannels: portchannels, po_requests = self.call_create_port_channel( diff_portchannels, have) requests.extend(po_requests) commands.extend(update_states(portchannels, state_name)) return commands, requests
def _state_overridden(self, want, have, diff): """ The command generator when state is overridden :param want: the desired configuration as a dictionary :param obj_in_have: the current configuration as a dictionary :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ commands = [] commands_del = self.filter_comands_to_change(want, have) requests = self.get_delete_interface_requests(commands_del, have) del_req_count = len(requests) if commands_del and del_req_count > 0: commands_del = update_states(commands_del, "deleted") commands.extend(commands_del) commands_over = diff requests.extend(self.get_modify_interface_requests( commands_over, have)) if commands_over and len(requests) > del_req_count: commands_over = update_states(commands_over, "overridden") commands.extend(commands_over) return commands, requests
def _state_overridden(self, want, have, diff): """ The command generator when state is overridden :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ commands = [] requests = [] commands_del = get_diff(have, want, ["name", "vlan"]) requests_del = self.get_delete_all_switchport_requests(commands_del) if len(requests_del): requests.extend(requests_del) commands_del = update_states(commands_del, "deleted") commands.extend(commands_del) commands_over = diff requests_over = self.get_create_l2_interface_request(commands_over) if requests_over: requests.extend(requests_over) commands_over = update_states(commands_over, "overridden") commands.extend(commands_over) return commands, requests
def _state_deleted(self, want, have, diff): """ The command generator when state is deleted :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ # Delete a community # https://100.94.81.19/restconf/data/openconfig-routing-policy:routing-policy/defined-sets/openconfig-bgp-policy:bgp-defined-sets/community-sets/community-set=extest # Delete all members but not community # https://100.94.81.19/restconf/data/openconfig-routing-policy:routing-policy/defined-sets/openconfig-bgp-policy:bgp-defined-sets/community-sets/community-set=extest/config/community-member # Dete a memeber from the expanded community # https://100.94.81.19/restconf/data/openconfig-routing-policy:routing-policy/defined-sets/openconfig-bgp-policy:bgp-defined-sets/community-sets/community-set=extest/config/community-member=REGEX%3A100.100 # Delete ALL Bgp_communities and its members # https://100.94.81.19/restconf/data/openconfig-routing-policy:routing-policy/defined-sets/openconfig-bgp-policy:bgp-defined-sets/community-sets is_delete_all = False # if want is none, then delete ALL if not want: commands = have is_delete_all = True else: commands = want requests = self.get_delete_bgp_communities(commands, have, is_delete_all) if commands and len(requests) > 0: commands = update_states(commands, "deleted") else: commands = [] return commands, requests
def _state_deleted(self, want, have, diff): """ The command generator when state is deleted :param want: the objects from which the configuration should be removed :param obj_in_have: the current configuration as a dictionary :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ # if want is none, then delete all the bgp_afs is_delete_all = False if not want: commands = have is_delete_all = True else: commands = want requests = self.get_delete_bgp_af_requests(commands, have, is_delete_all) if commands and len(requests) > 0: commands = update_states(commands, "deleted") else: commands = [] return commands, requests
def _state_deleted(self, want, have, diff): """ The command generator when state is deleted :param want: the objects from which the configuration should be removed :param have: the current configuration as a dictionary :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ is_delete_all = False if not want: is_delete_all = True if is_delete_all: commands = have new_have = have else: new_have = self.remove_default_entries(have) d_diff = get_diff(want, new_have, TEST_KEYS, is_skeleton=True) delete_diff = get_diff(want, d_diff, TEST_KEYS, is_skeleton=True) commands = delete_diff requests = self.get_delete_bgp_neighbor_requests( commands, new_have, is_delete_all) if commands and len(requests) > 0: commands = update_states(commands, "deleted") else: commands = [] return commands, requests
def _state_deleted(self, want, have, diff): """ The command generator when state is deleted :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ # To Delete a single member # data/openconfig-routing-policy:routing-policy/defined-sets/openconfig-bgp-policy:bgp-defined-sets/as-path-sets/as-path-set=xyz/config/as-path-set-member=11 # This will delete the as path and its all members # data/openconfig-routing-policy:routing-policy/defined-sets/openconfig-bgp-policy:bgp-defined-sets/as-path-sets/as-path-set=xyz # This will delete ALL as path completely # data/openconfig-routing-policy:routing-policy/defined-sets/openconfig-bgp-policy:bgp-defined-sets/as-path-sets is_delete_all = False # if want is none, then delete ALL if not want: commands = have is_delete_all = True else: commands = want requests = self.get_delete_as_path_requests(commands, have, is_delete_all) if commands and len(requests) > 0: commands = update_states(commands, "deleted") else: commands = [] return commands, requests
def _state_replaced(self, want, have, diff_members, diff_portchannels): """ The command generator when state is replaced :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ requests = list() commands = list() delete_list = list() delete_list = get_diff(have, want, ["name", "member"]) delete_members, delete_portchannels = self.diff_list_for_member_creation( delete_list) replaced_list = list() for i in want: list_obj = search_obj_in_list(i['name'], delete_members, "name") if list_obj: replaced_list.append(list_obj) requests = self.get_delete_lag_interfaces_requests(replaced_list) if requests: commands.extend(update_states(replaced_list, "replaced")) replaced_commands, replaced_requests = self.template_for_lag_creation( have, diff_members, diff_portchannels, "replaced") if replaced_requests: commands.extend(replaced_commands) requests.extend(replaced_requests) return commands, requests
def _state_overridden(self, want, have, diff_members, diff_portchannels): """ The command generator when state is overridden :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ requests = list() commands = list() delete_list = list() delete_list = get_diff(have, want, TEST_KEYS) delete_members, delete_portchannels = self.diff_list_for_member_creation( delete_list) replaced_list = list() for i in want: list_obj = search_obj_in_list(i['name'], delete_members, "name") if list_obj: replaced_list.append(list_obj) requests = self.get_delete_lag_interfaces_requests(replaced_list) commands.extend(update_states(replaced_list, "overridden")) delete_members = get_diff(delete_members, replaced_list, TEST_KEYS) commands_overridden, requests_overridden = self.template_for_lag_deletion( have, delete_members, delete_portchannels, "overridden") requests.extend(requests_overridden) commands.extend(commands_overridden) override_commands, override_requests = self.template_for_lag_creation( have, diff_members, diff_portchannels, "overridden") commands.extend(override_commands) requests.extend(override_requests) return commands, requests
def _state_merged(self, want, have, diff): """ The command generator when state is merged :rtype: A list :returns: the commands necessary to merge the provided into the current configuration """ commands = update_states(diff, "merged") requests = self.get_create_l3_interfaces_requests(commands, have, want) return commands, requests
def template_for_lag_deletion(self, have, delete_members, delete_portchannels, state_name): commands = list() requests = list() portchannel_requests = list() if delete_members: delete_members_remove_none = [ x for x in delete_members if x["members"] ] requests = self.get_delete_lag_interfaces_requests( delete_members_remove_none) delete_all_members = [ x for x in delete_members if "members" in x.keys() and not x["members"] ] delete_all_list = list() if delete_all_members: for i in delete_all_members: list_obj = search_obj_in_list(i['name'], have, "name") if list_obj['members']: delete_all_list.append(list_obj) if delete_all_list: deleteall_requests = self.get_delete_lag_interfaces_requests( delete_all_list) else: deleteall_requests = [] if requests and deleteall_requests: requests.extend(deleteall_requests) elif deleteall_requests: requests = deleteall_requests if requests: commands.extend(update_states(delete_members, state_name)) if delete_portchannels: portchannel_requests = self.get_delete_portchannel_requests( delete_portchannels) commands.extend(update_states(delete_portchannels, state_name)) if requests: requests.extend(portchannel_requests) else: requests = portchannel_requests return commands, requests
def _state_overridden(self, want, have, diff): """ The command generator when state is overridden :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ ret_requests = list() commands = list() vlans_to_delete = get_diff(have, want, TEST_KEYS) if vlans_to_delete: delete_vlans_requests = self.get_delete_vlans_requests(vlans_to_delete) ret_requests.extend(delete_vlans_requests) commands.extend(update_states(vlans_to_delete, "deleted")) if diff: vlans_to_create_requests = self.get_create_vlans_requests(diff) ret_requests.extend(vlans_to_create_requests) commands.extend(update_states(diff, "merged")) return commands, ret_requests
def _state_replaced(self, want, have, diff): """ The command generator when state is replaced :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ ret_requests = list() commands = list() l3_interfaces_to_delete = get_diff(have, want, TEST_KEYS) obj = self.get_object(l3_interfaces_to_delete, want) diff = get_diff(obj, want, TEST_KEYS) if diff: delete_l3_interfaces_requests = self.get_delete_all_requests(want) ret_requests.extend(delete_l3_interfaces_requests) commands.extend(update_states(want, "deleted")) l3_interfaces_to_create_requests = self.get_create_l3_interfaces_requests( want, have, want) ret_requests.extend(l3_interfaces_to_create_requests) commands.extend(update_states(want, "merged")) return commands, ret_requests
def _state_merged(self, want, have, diff): """ The command generator when state is merged :rtype: A list :returns: the commands necessary to merge the provided into the current configuration """ commands = diff requests = self.get_modify_as_path_list_requests(commands, have) if commands and len(requests) > 0: commands = update_states(commands, "merged") else: commands = [] return commands, requests
def _state_merged(self, want, have, diff): """ The command generator when state is merged :rtype: A list :returns: the commands necessary to merge the provided into the current configuration at position-0 Requests necessary to merge to the current configuration at position-1 """ commands = diff requests = self.get_create_l2_interface_request(commands) if commands and len(requests): commands = update_states(commands, "merged") return commands, requests
def _state_deleted(self, want, have, diff): """ The command generator when state is deleted :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ commands = list() # if want is none, then delete all the vlans if not want: commands = have else: # delete specific vlans commands = get_diff(want, diff, TEST_KEYS) requests = self.get_delete_vlans_requests(commands) commands = update_states(commands, "deleted") return commands, requests
def _state_merged(self, want, have, diff): """ The command generator when state is merged :param want: the additive configuration as a dictionary :param obj_in_have: the current configuration as a dictionary :rtype: A list :returns: the commands necessary to merge the provided into the current configuration """ commands = diff requests = self.get_modify_interface_requests(commands, have) if commands and len(requests) > 0: commands = update_states(commands, "merged") else: commands = [] return commands, requests
def _state_replaced(self, want, have, diff): """ The command generator when state is replaced :param want: the desired configuration as a dictionary :param have: the current configuration as a dictionary :param interface_type: interface type :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ commands = self.filter_comands_to_change(diff, have) requests = self.get_delete_interface_requests(commands, have) requests.extend(self.get_modify_interface_requests(commands, have)) if commands and len(requests) > 0: commands = update_states(commands, "replaced") else: commands = [] return commands, requests
def _state_deleted(self, want, have, diff): """ The command generator when state is deleted :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ commands = list() if not want: commands = have requests = self.get_delete_all_completely_requests(commands) else: commands = want requests = self.get_delete_l3_interfaces_requests(commands, have) if len(requests) == 0: commands = [] if commands: commands = update_states(commands, "deleted") return commands, requests
def _state_deleted(self, want, have, diff): """ The command generator when state is deleted :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ # if want is none, then delete all the vlans if not want or len(have) == 0: commands = have requests = self.get_delete_all_switchport_requests(commands) else: commands = want requests = self.get_delete_specifig_switchport_requests(want, have) if len(requests) == 0: commands = [] if commands: commands = update_states(commands, "deleted") return commands, requests
def _state_deleted(self, want, have, diff): """ The command generator when state is deleted :rtype: A list :returns: the commands necessary to remove the current configuration of the provided objects """ commands = list() requests = list() portchannel_requests = list() # if want is none, then delete all the lag interfaces and all portchannels if not want: requests = self.get_delete_all_lag_interfaces_requests() portchannel_requests = self.get_delete_all_portchannel_requests() requests.extend(portchannel_requests) commands.extend(update_states(have, "Deleted")) else: # delete specific lag interfaces and specific portchannels commands = get_diff(want, diff, TEST_KEYS) commands = remove_empties_from_list(commands) want_members, want_portchannels = self.diff_list_for_member_creation( commands) commands, requests = self.template_for_lag_deletion( have, want_members, want_portchannels, "deleted") return commands, requests
def _state_replaced(self, want, have, diff): """ The command generator when state is replaced :rtype: A list :returns: the commands necessary to migrate the current configuration to the desired configuration """ requests = [] commands = diff if commands: requests_del = self.get_delete_all_switchport_requests(commands) if requests_del: requests.extend(requests_del) requests_rep = self.get_create_l2_interface_request(commands) if len(requests_del) or len(requests_rep): requests.extend(requests_rep) commands = update_states(commands, "replaced") else: commands = [] return commands, requests