def logout(fos_ip_addr, is_https, auth, result): """ logout from the fos switch at ip address specified :param fos_ip_addr: fos switch ip address :type fos_ip_addr: str :param is_https: indicate to use HTTPS or HTTP :type fos_password: Bool :param auth: return authorization struct at the time of login :type auth: dict :return: 0 for success or -1 for failure :rtype: int """ full_logout_url, validate_certs = full_url_get(is_https, fos_ip_addr, REST_LOGOUT) return url_post(fos_ip_addr, is_https, auth, None, result, full_logout_url, None)
def syslog_server_post(fos_ip_addr, is_https, auth, vfid, result, servers): """ add to 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["post_syslog_str"] = syslog_str return url_post(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