def list_delete(login, password, fos_ip_addr, module_name, list_name, fos_version, is_https, auth, vfid, result, entries, ssh_hostkeymust, timeout): """ update existing user config configurations :param fos_ip_addr: ip address of FOS switch :type fos_ip_addr: str :param is_https: indicate to use HTTP or HTTPS :type is_https: bool :param auth: authorization struct from login :type struct: dict :param result: dict to keep track of execution msgs :type result: dict :param diff_attributes: list of attributes for update :type ports: dict :return: code to indicate failure or success :rtype: int :return: list of dict of chassis configurations :rtype: list """ full_url, validate_certs = full_url_get( is_https, fos_ip_addr, REST_PREFIX + module_name + "/" + list_name) xml_str = list_xml_str(result, module_name, list_name, entries) result["delete_str"] = xml_str return url_delete(fos_ip_addr, is_https, auth, vfid, result, full_url, xml_str, timeout)
def user_config_delete(fos_ip_addr, is_https, auth, vfid, result, users): """ delete existing user config configurations :param fos_ip_addr: ip address of FOS switch :type fos_ip_addr: str :param is_https: indicate to use HTTP or HTTPS :type is_https: bool :param auth: authorization struct from login :type struct: dict :param result: dict to keep track of execution msgs :type result: dict :param diff_attributes: list of attributes for update :type ports: dict :return: code to indicate failure or success :rtype: int :return: list of dict of chassis configurations :rtype: list """ full_url = (HTTPS if is_https else HTTP) +\ fos_ip_addr + REST_USER_CONFIG xml_str = user_config_xml_str(result, users) result["delete_user_config_str"] = xml_str return url_delete(fos_ip_addr, is_https, auth, vfid, result, full_url, xml_str)
def ipfilter_policy_delete(fos_ip_addr, is_https, auth, vfid, result, policies): """ delete existing ipfilter policy configurations :param fos_ip_addr: ip address of FOS switch :type fos_ip_addr: str :param is_https: indicate to use HTTP or HTTPS :type is_https: bool :param auth: authorization struct from login :type struct: dict :param result: dict to keep track of execution msgs :type result: dict :param diff_attributes: list of attributes for update :type ports: dict :return: code to indicate failure or success :rtype: int :return: list of dict of chassis configurations :rtype: list """ full_url, validate_certs = full_url_get(is_https, fos_ip_addr, REST_IPFILTER_POLICY) xml_str = ipfilter_policy_xml_str(result, policies) result["delete_ipfilter_policy_str"] = xml_str return url_delete(fos_ip_addr, is_https, auth, vfid, result, full_url, xml_str)
def alias_set(fos_ip_addr, is_https, auth, vfid, result, aliases, method): """ set aliases in Zone Database :param fos_ip_addr: ip address of FOS switch :type fos_ip_addr: str :param is_https: indicate to use HTTP or HTTPS :type is_https: bool :param auth: authorization struct from login :type auth: dict :param result: dict to keep track of execution msgs :type result: dict :param aliases: list of aliases to set :type aliases: list :param method: "POST", "PATCH", or "DELETE" :type method: str :return: code to indicate failure or success :rtype: int """ full_defined_url, validate_certs = full_url_get(is_https, fos_ip_addr, REST_DEFINED) alias_str = "<defined-configuration>" for alias in aliases: alias_str = alias_str + "<alias><alias-name>" +\ alias["name"] + "</alias-name>" if "members" in alias: alias_str = alias_str + "<member-entry>" for member in alias["members"]: alias_str = alias_str + "<alias-entry-name>" +\ member + "</alias-entry-name>" alias_str = alias_str + "</member-entry>" alias_str = alias_str + "</alias>" alias_str = alias_str + "</defined-configuration>" result["alias_str"] = alias_str result["method"] = method if method == "POST": return url_post(fos_ip_addr, is_https, auth, vfid, result, full_defined_url, alias_str) elif method == "PATCH": return url_patch(fos_ip_addr, is_https, auth, vfid, result, full_defined_url, alias_str) elif method == "DELETE": return url_delete(fos_ip_addr, is_https, auth, vfid, result, full_defined_url, alias_str) else: result["invalid method"] = method result["failed"] = True result["msg"] = "url_get_to_dict failed" return -1
def cfg_set(fos_ip_addr, is_https, auth, vfid, result, cfgs, method): """ set cfgs in Zone Database :param fos_ip_addr: ip address of FOS switch :type fos_ip_addr: str :param is_https: indicate to use HTTP or HTTPS :type is_https: bool :param auth: authorization struct from login :type auth: dict :param result: dict to keep track of execution msgs :type result: dict :param cfgs: list of cfgs to set :type cfgs: list :param method: "POST", "PATCH", or "DELETE" :type method: str :return: code to indicate failure or success :rtype: int """ full_defined_url, validate_certs = full_url_get(is_https, fos_ip_addr, REST_DEFINED) cfg_str = "<defined-configuration>" for cfg in cfgs: cfg_str = cfg_str + "<cfg><cfg-name>" + cfg["name"] + "</cfg-name>" if "members" in cfg: cfg_str = cfg_str + "<member-zone>" for member in cfg["members"]: cfg_str = cfg_str + "<zone-name>" + member + "</zone-name>" cfg_str = cfg_str + "</member-zone>" cfg_str = cfg_str + "</cfg>" cfg_str = cfg_str + "</defined-configuration>" # result["cfg_str"] = cfg_str if method == "POST": return url_post(fos_ip_addr, is_https, auth, vfid, result, full_defined_url, cfg_str) elif method == "PATCH": return url_patch(fos_ip_addr, is_https, auth, vfid, result, full_defined_url, cfg_str) elif method == "DELETE": return url_delete(fos_ip_addr, is_https, auth, vfid, result, full_defined_url, cfg_str) else: result["invalid method"] = method result["failed"] = True result["msg"] = "url_get_to_dict failed" return -1
def syslog_server_delete(fos_ip_addr, is_https, auth, vfid, result, servers): """ delete existing syslog-server configurations :param fos_ip_addr: ip address of FOS switch :type fos_ip_addr: str :param is_https: indicate to use HTTP or HTTPS :type is_https: bool :param auth: authorization struct from login :type struct: dict :param result: dict to keep track of execution msgs :type result: dict :param diff_attributes: list of attributes for update :type ports: dict :return: code to indicate failure or success :rtype: int :return: list of dict of chassis configurations :rtype: list """ full_url, validate_certs = full_url_get(is_https, fos_ip_addr, REST_LOGGING_SYSLOG_SERVER) syslog_str = "" for server in servers: syslog_str = syslog_str + "<syslog-server>" syslog_str = syslog_str + "<server>" + server["server"] + "</server>" for k, v in server.items(): if k != "server": k = k.replace("_", "-") syslog_str = syslog_str + "<" + k + ">" +\ str(v) + "</" + k + ">" syslog_str = syslog_str + "</syslog-server>" result["delete_syslog_str"] = syslog_str return url_delete(fos_ip_addr, is_https, auth, vfid, result, full_url, syslog_str)
def zone_set(fos_ip_addr, is_https, auth, vfid, result, zones, method): """ set zones in Zone Database :param fos_ip_addr: ip address of FOS switch :type fos_ip_addr: str :param is_https: indicate to use HTTP or HTTPS :type is_https: bool :param auth: authorization struct from login :type auth: dict :param result: dict to keep track of execution msgs :type result: dict :param zones: list of zones to set :type zones: list :param method: "POST", "PATCH", or "DELETE" :type method: str :return: code to indicate failure or success :rtype: int """ full_defined_url, validate_certs = full_url_get(is_https, fos_ip_addr, REST_DEFINED) zone_str = "<defined-configuration>" for zone in zones: zone_str = zone_str + "<zone><zone-name>" +\ zone["name"] + "</zone-name>" # if zone_type is passed, we are talking about an existing # zone. keep type type. Otherwise, add the zone type of # 1 as peer if pmembers are present if "zone_type" in zone: zone_str = zone_str + "<zone-type>" + zone["zone_type"] + "</zone-type>" else: if "principal_members" in zone and len(zone["principal_members"]) > 0: zone_str = zone_str + "<zone-type>1</zone-type>" if "principal_members" in zone or "members" in zone: zone_str = zone_str + "<member-entry>" if "principal_members" in zone: for member in zone["principal_members"]: zone_str = zone_str + "<principal-entry-name>" +\ member + "</principal-entry-name>" if "members" in zone: for member in zone["members"]: zone_str = zone_str + "<entry-name>" + member + "</entry-name>" if "principal_members" in zone or "members" in zone: zone_str = zone_str + "</member-entry>" zone_str = zone_str + "</zone>" zone_str = zone_str + "</defined-configuration>" # result["zone_str"] = zone_str if method == "POST": return url_post(fos_ip_addr, is_https, auth, vfid, result, full_defined_url, zone_str) elif method == "PATCH": return url_patch(fos_ip_addr, is_https, auth, vfid, result, full_defined_url, zone_str) elif method == "DELETE": return url_delete(fos_ip_addr, is_https, auth, vfid, result, full_defined_url, zone_str) else: result["invalid method"] = method result["failed"] = True result["msg"] = "url_get_to_dict failed" return -1