def _delete_vsx_interface_vlan_v1(vlan_id, **kwargs): """ Perform PUT calls on a VLAN interface to remove VSX IPv4 settings. :param vlan_id: Numeric ID of VLAN to that will be configured :param kwargs: keyword s: requests.session object with loaded cookie jar keyword url: URL in main() function :return: True if successful, False otherwise """ ports_list = port.get_all_ports(**kwargs) vlan_name = "vlan" + str(vlan_id) if "/rest/v1/system/ports/%s" % vlan_name not in ports_list: logging.warning( "FAIL: Deleting VSX information from VLAN Interface '%d' failed " "because VLAN Interface doesn't exist" % vlan_id) return False else: port_data = port.get_port(vlan_name, depth=0, selector="configuration", **kwargs) port_data["vsx_active_forwarding_enable"] = False port_data["vsx_sync"] = [] port_data["vsx_virtual_ip4"] = [] port_data.pop('vsx_virtual_gw_mac_v4', None) port_data.pop( 'name', None ) # must remove this item from the json since name can't be modified port_data.pop( 'origin', None ) # must remove this item from the json since origin can't be modified target_url = kwargs["url"] + "system/ports/%s" % vlan_name put_data = json.dumps(port_data, sort_keys=True, indent=4) response = kwargs["s"].put(target_url, data=put_data, verify=False) if not common_ops._response_ok(response, "PUT"): logging.warning( "FAIL: Deleting VSX information from VLAN Interface '%d' failed with status code %d: %s" % (vlan_id, response.status_code, response.text)) return False else: logging.info( "SUCCESS: Deleting VSX information from VLAN Interface '%d' succeeded" % vlan_id) return True
def _update_ospfv3_interface_authentication_v1(vrf, ospf_id, interface_name, auth_type, digest_key, auth_pass, **kwargs): """ Perform PUT calls to update an Interface with OSPFv3 to have authentication :param vrf: Alphanumeric name of the VRF the OSPFv3 ID belongs to :param ospf_id: OSPFv3 process ID between numbers 1-63 :param interface_name: Alphanumeric name of the interface that will be attached to the OSPFv3 area :param auth_type: Alphanumeric type of authentication, chosen between 'md5', 'null', and 'text' :param digest_key: Integer between 1-255 that functions as the digest key for the authentication method :param auth_pass: Alphanumeric text for the authentication password. Note that this will be translated to a base64 String in the configuration and json. :param kwargs: keyword s: requests.session object with loaded cookie jar keyword url: URL in main() function :return: True if successful, False otherwise """ ports_list = port.get_all_ports(**kwargs) port_name_percents = common_ops._replace_special_characters(interface_name) if "/rest/v1/system/ports/%s" % port_name_percents not in ports_list: port.add_l3_ipv4_port(interface_name, vrf=vrf, **kwargs) port_data = port.get_port(interface_name, depth=0, selector="configuration", **kwargs) # must remove these fields from the data since they can't be modified port_data.pop('name', None) port_data.pop('origin', None) port_data['ospf_auth_type'] = auth_type port_data['ospf_auth_md5_keys'] = {str(digest_key): auth_pass} port_data['ospf_if_type'] = "ospf_iftype_broadcast" port_data['routing'] = True port_data['vrf'] = "/rest/v1/system/vrfs/" + vrf target_url = kwargs["url"] + "system/ports/%s" % port_name_percents put_data = json.dumps(port_data, sort_keys=True, indent=4) response = kwargs["s"].put(target_url, data=put_data, verify=False) if not common_ops._response_ok(response, "PUT"): logging.warning("FAIL: Updating OSPFv3 %s Authentication for Port '%s' failed with status code %d: %s" % (ospf_id, interface_name, response.status_code, response.text)) return False else: logging.info("SUCCESS: Updating OSPFv3 %s Authentication for Port '%s' succeeded" % (ospf_id, interface_name)) return True
def _update_ospf_interface_type_v1(vrf, ospf_id, interface_name, interface_type, **kwargs): """ Perform PUT calls to update the type of OSPFv2 Interface given, as well as enable routing on the interface :param vrf: Alphanumeric name of the VRF the OSPF ID belongs to :param ospf_id: OSPF process ID between numbers 1-63 :param interface_name: Alphanumeric name of the interface that will be attached to the OSPF area :param interface_type: Alphanumeric type of OSPF interface. The options are 'broadcast', 'loopback', 'nbma', 'none', 'pointomultipoint', 'pointopoint', and 'virtuallink' :param kwargs: keyword s: requests.session object with loaded cookie jar keyword url: URL in main() function :return: True if successful, False otherwise """ ports_list = port.get_all_ports(**kwargs) port_name_percents = common_ops._replace_special_characters(interface_name) if "/rest/v1/system/ports/%s" % port_name_percents not in ports_list: port.add_l3_ipv4_port(interface_name, vrf=vrf, **kwargs) port_data = port.get_port(interface_name, depth=0, selector="configuration", **kwargs) # must remove these fields from the data since they can't be modified port_data.pop('name', None) port_data.pop('origin', None) port_data['ospf_if_type'] = "ospf_iftype_%s" % interface_type port_data['routing'] = True port_data['vrf'] = "/rest/v1/system/vrfs/" + vrf target_url = kwargs["url"] + "system/ports/%s" % port_name_percents put_data = json.dumps(port_data, sort_keys=True, indent=4) response = kwargs["s"].put(target_url, data=put_data, verify=False) if not common_ops._response_ok(response, "PUT"): logging.warning("FAIL: Updating OSPF %s interface type for Port '%s' failed with status code %d: %s" % (ospf_id, interface_name, response.status_code, response.text)) return False else: logging.info("SUCCESS: Updating OSPF %s interface type for Port '%s' succeeded" % (ospf_id, interface_name)) return True
def _create_l2_lag_interface_v1(name, phys_ports, lacp_mode="passive", mc_lag=False, fallback_enabled=False, vlan_ids_list=[], desc=None, admin_state="up", **kwargs): """ Perform a POST call to create a Port table entry for L2 LAG interface. :param name: Alphanumeric name of LAG Port :param phys_ports: List of physical ports to aggregate (e.g. ["1/1/1", "1/1/2", "1/1/3"]) :param lacp_mode: Should be either "passive" or "active." Defaults to "passive" if not specified. :param mc_lag: Boolean to determine if the LAG is multi-chassis. Defaults to False if not specified. :param fallback_enabled: Boolean to determine if the LAG uses LACP fallback. Defaults to False if not specified. :param vlan_ids_list: Optional list of integer VLAN IDs to add as trunk VLANS. Defaults to empty list if not specified. :param desc: Optional description for the interface. Defaults to nothing if not specified. :param admin_state: Optional administratively-configured state of the port. Defaults to "up" if not specified :param kwargs: keyword s: requests.session object with loaded cookie jar keyword url: URL in main() function :return: True if successful, False otherwise """ ports_list = port.get_all_ports(**kwargs) port_name_percents = common_ops._replace_special_characters(name) if "/rest/v1/system/ports/%s" % port_name_percents not in ports_list: # Extract LAG ID from LAG name lag_id = int(re.search('\d+', name).group()) # For each port, add LAG ID to the Interface table entry, and delete the Port table entry for phys_port in phys_ports: interface.add_port_to_lag(phys_port, lag_id, **kwargs) interfaces = ["/rest/v1/system/interfaces/%s" % common_ops._replace_special_characters(phys_port) for phys_port in phys_ports] port_data = {"admin": admin_state, "interfaces": interfaces, "name": name, "routing": False, "vlan_trunks": ["/rest/v1/system/vlans/%d" % vlan_id for vlan_id in vlan_ids_list], "lacp": lacp_mode, "other_config": { "mclag_enabled": mc_lag, "lacp-fallback": fallback_enabled }, "vlan_mode": "native-untagged", "vlan_tag": "/rest/v1/system/vlans/1" } if desc is not None: port_data['description'] = desc target_url = kwargs["url"] + "system/ports" post_data = json.dumps(port_data, sort_keys=True, indent=4) response = kwargs["s"].post(target_url, data=post_data, verify=False) if not common_ops._response_ok(response, "POST"): logging.warning("FAIL: Adding Port table entry '%s' failed with status code %d: %s" % (name, response.status_code, response.text)) return False else: logging.info("SUCCESS: Adding Port table entry '%s' succeeded" % name) return True else: logging.info("SUCCESS: No need to add Port table entry '%s' because it already exists" % name) return True
def _update_vsx_interface_vlan_v1(vlan_id, active_forwarding, vsx_sync, act_gw_mac, act_gw_ip, **kwargs): """ Perform PUT calls on a VLAN interface to configure VSX IPv4 settings. :param vlan_id: Numeric ID of VLAN to that will be configured :param active_forwarding: True or False Boolean to set VSX active forwarding :param vsx_sync: Set of alphanumeric values to enable VSX configuration synchronization. The options are any combination of 'active-gateways', 'irdp', and 'policies' :param act_gw_mac: Alphanumeric value of the Virtual MAC address for the interface active gateway :param act_gw_ip: Alphanumeric value of the Virtual IP address for the interface active gateway :param kwargs: keyword s: requests.session object with loaded cookie jar keyword url: URL in main() function :return: True if successful, False otherwise """ ports_list = port.get_all_ports(**kwargs) vlan_name = "vlan" + str(vlan_id) if "/rest/v1/system/ports/%s" % vlan_name not in ports_list: logging.warning( "FAIL: Adding VSX information to VLAN Interface '%d' failed because VLAN " "Interface doesn't exist" % vlan_id) return False else: port_data = port.get_port(vlan_name, depth=0, selector="configuration", **kwargs) vsx_sync_set = [] if vsx_sync == None: vsx_sync = {} if "active-gateways" in vsx_sync: vsx_sync_set.append("^vsx_virtual.*") if "irdp" in vsx_sync: vsx_sync_set.append(".irdp.*") if "policies" in vsx_sync: vsx_sync_set.append("^policy.*") port_data["vsx_active_forwarding_enable"] = active_forwarding port_data["vsx_sync"] = vsx_sync_set port_data["vsx_virtual_gw_mac_v4"] = act_gw_mac port_data["vsx_virtual_ip4"] = [act_gw_ip] port_data.pop( 'name', None ) # must remove this item from the json since name can't be modified port_data.pop( 'origin', None ) # must remove this item from the json since origin can't be modified target_url = kwargs["url"] + "system/ports/%s" % vlan_name put_data = json.dumps(port_data, sort_keys=True, indent=4) response = kwargs["s"].put(target_url, data=put_data, verify=False) if not common_ops._response_ok(response, "PUT"): logging.warning( "FAIL: Adding VSX information to VLAN Interface '%d' failed with status code %d: %s" % (vlan_id, response.status_code, response.text)) return False else: logging.info( "SUCCESS: Adding VSX information to VLAN Interface '%d' succeeded" % vlan_id) return True