def configure_rule(rule_conf): if rule_conf['src'] == "name": # // use device name (via Installer APIs) #{ # "src": "name", # "expression": "[0:3]", // "abcdef" -> "abc" # "split(.)[1]", // "a.b.c" -> "b" # "split(-)[1][0:3], // "a1234-b5678-c90" -> "b56" # "prefix": "XX-", # "suffix": "-YY" # }, print("Expression to extract the site name from the LLDP system name") print("Example: \"[0:3]\", // \"abcdef\" -> \"abc\"") print(" \"split(.)[1]\", // \"a.b.c\" -> \"b\"") print(" \"split(-)[1][0:3]\", // \"a1234-b5678-c90\" -> \"b56\"") rule_conf['expression'] = input("Expression: ") rule_conf['prefix'] = input("Prefix (XX-): " ) rule_conf['suffix'] = input("Suffix (-XX): ") elif rule_conf['src'] == "subnet": # // use subnet # { # "src": "subnet", # "subnet": "10.1.2.0/18", # "value": "s1351" # }, rule_conf['subnet'] = input("Please enter the subnet value (ex: 10.1.2.0/18): ") site_id = cli.select_site(mist, org_id=org_id) rule_conf['value'] = mist_lib.requests.orgs.sites.stats(mist, site_id)['result']['name'] elif rule_conf['src'] == "lldp_system_name": # // use LLDP System Name # { # "src": "lldp_system_name", # "expression": "..." // same as above # }, print("Expression to extract the site name from the LLDP system name") print("Example: \"[0:3]\", // \"abcdef\" -> \"abc\"") print(" \"split(.)[1]\", // \"a.b.c\" -> \"b\"") print(" \"split(-)[1][0:3]\", // \"a1234-b5678-c90\" -> \"b56\"") rule_conf['expression'] = input("Expression: ") elif rule_conf['src'] == "dns_suffix": # // use DNS Suffix # { # "src": "dns_suffix", # "expression": "..." // same as above # }, print("Expression to extract the site name from the DNS suffix name") print("Example: \"[0:3]\", // \"abcdef\" -> \"abc\"") print(" \"split(.)[1]\", // \"a.b.c\" -> \"b\"") print(" \"split(-)[1][0:3]\", // \"a1234-b5678-c90\" -> \"b56\"") rule_conf['expression'] = input("Expression: ") elif rule_conf['src'] == "model": # { # "src": "model", # "model": "AP41", # "value": "s1351" # } rule_conf['model'] = input("Please enter the model of AP: ") site_id = cli.select_site(mist, org_id=org_id) rule_conf['value'] = mist_lib.requests.orgs.sites.stats(mist, site_id)['result']['name'] return rule_conf
def define_privileges(org_id): ''' Generate the privilege parameters for the specified orgs. Will ask if the privileges have to be applied to the entire org or to a specific site/s, and the privilege level. There is no return value, the new privileges are stored into the global "privilege" variable ''' role = "" while role not in roles: role = input( "Which level of privilege at the org level (\"s\" for Super Admin, \"n\" for Network Admin,\"o\" for observer,\"h\" for helpdesk)? " ) while True: all_sites = input("Do you want to select specific sites (y/N)? ") if all_sites.lower() == "y": site_ids = cli.select_site(mist, org_id, True) for site_id in site_ids: privileges.append({ "scope": "site", "org_id": org_id, "site_id": site_id, "role": roles[role] }) break elif all_sites.lower() == "n" or all_sites == "": site_ids = mist_lib.requests.orgs.sites.get(mist, org_id) site_id = "" for site in site_ids["result"]: if "site_id" in site: site_id = site["site_id"] break privileges.append({ "scope": "org", "org_id": org_id, "site_id": site_id, "role": roles[role] }) break
"username": username, "passphrase": passphrase, "ssid": ssid }) return psks except: print("Error while opening the CSV file... Aborting") def list_psks(site_id): print("") print("________________________________________") print("List of current PSKs for site %s" % (site_id)) psks = mist_lib.requests.sites.psks.get(mist, site_id)['result'] cli.show(psks) #### SCRIPT ENTRYPOINT ##### mist = mist_lib.Mist_Session() site_ids = cli.select_site(mist, allow_many=True) print("__________________") print(site_ids) psks = read_csv(sys.argv[1]) for site_id in site_ids: import_psk(site_id, psks) for site_id in site_ids: list_psks(site_id)
"name": 'myUser', "passphrase": 'myBadPassword', "ssid": 'mySSID', "usage": 'multi' } #### IMPORTS ##### import mlib as mist_lib from mlib import cli from tabulate import tabulate #### FUNCTIONS ##### #### SCRIPT ENTRYPOINT ##### mist = mist_lib.Mist_Session() site_id = cli.select_site(mist) psk = mist_lib.models.sites.psks.Psk() psk.define(psk) print(psk.toJSON()) mist_lib.requests.sites.psks.create(mist, site_id, psk.toJSON()) psks = mist_lib.requests.sites.psks.get(mist, site_id)['result'] cli.show(psks) exit(0) """ for psk in psks: mist_lib.requests.sites.psks.delete(mist, site_id, psk_id=psk['id']) print(mist_lib.requests.sites.psks.get(mist, site_id)['result']) """
print("Only numbers are allowed.") mist_lib.requests.sites.wlans.delete(mist, site_id, wlan["id"]) def display_wlan(site_id): fields = [ "id", "ssid", "enabled", "auth", "auth_servers", "acct_servers", "band", "interface", "vlan_id", "dynamic_vlan", "hide_ssid" ] site_wlans = mist_lib.requests.sites.wlans.report(mist, site_id, fields) print(tabulate(site_wlans, fields)) mist = mist_lib.Mist_Session("./session.py") #mist.save() site_id = cli.select_site(mist, allow_many=False) while True: print() print(" ===================") print(" == CURRENT WLANS ==") display_wlan(site_id) print(" ===================") print() actions = ["add WLAN", "remove WLAN"] print("What do you want to do:") i = -1 for action in actions: i += 1 print("%s) %s" % (i, action)) print()
def get_site_id(org_id=None): site_id = cli.select_site(session, org_id=org_id) print("") print("Selected site id: %s" % site_id) return site_id
bssids_from_sites(mist_session, org_sites, org_info, site_ids) # if the admin doesn't have access to the org level, but only the sites elif len(org_sites) >= 1: org_info = { "name":org_sites[0]["org_name"], "id":org_sites[0]["org_id"] } org_sites = [] # get the sites information for site_id in site_ids: org_sites.append(mist_lib.requests.sites.info.get(mist_session, site_id)["result"]) bssids_from_sites(mist_session, org_sites, org_info, site_ids) #### SCRIPT ENTRYPOINT #### mist = mist_lib.Mist_Session() org_ids = cli.select_org(mist, allow_many=True) if len(org_ids) == 1: site_ids = cli.select_site(mist, org_id=org_ids[0], allow_many=True) bssids_from_orgs(mist, org_ids, site_ids) fields.insert(0, "org_id") fields.insert(1, "org_name") fields.insert(2, "site_id") fields.insert(3, "site_name") cli.show(bssid_list, fields) cli.save_to_csv(csv_file, bssid_list, fields, csv_separator)
def start(mist_session): org_id = cli.select_org(mist_session)[0] org_name = mist_lib.orgs.info.get(mist_session, org_id)["result"]["name"] site_id = cli.select_site(mist_session, org_id=org_id, allow_many=True) start_site_backup(mist_session, org_id, org_name, site_id)
def generate_report(mist_session, site_ids, time): app_usage = [] if type(site_ids) == str: site_ids = [site_ids] for site_id in site_ids: site_name = _get_site_name(mist_session, site_id) console.info("Processing site %s (id %s)" % (site_name, site_id)) app_usage += _generate_site_report(mist_session, site_name, site_id, time["start"], time["stop"], time["interval"]) cli.show(app_usage) _save_report(app_usage) def _ask_period(hours): now = datetime.datetime.now() start = round((datetime.datetime.now() - datetime.timedelta(hours=hours)).timestamp(), 0) stop = round(now.timestamp(), 0) interval = 3600 return {"start": start, "stop": stop, "interval": interval} if __name__ == "__main__": mist_session = mist_lib.Mist_Session() site_id = cli.select_site(mist_session, allow_many=True) time = _ask_period(hours_to_report) generate_report(mist_session, site_id, time)
for site_id in site_ids: get_site_setting(mist, site_id) break def get_site_ids(mist, org_id): site_ids = [] sites = mist_lib.requests.orgs.sites.get(mist, org_id)["result"] for site in sites: site_ids.append(site["id"]) return site_ids ####### ENTRY POINT ####### mist = mist_lib.Mist_Session() org_id = cli.select_org(mist)[0] while True: resp = input( "Do you want to update the auto-upgrade settings on all the sites (y/N)?" ) if resp.lower() == 'n' or resp == "": site_id = cli.select_site(mist, org_id) confirm_action(mist, [site_id]) break elif resp.lower() == "y": site_ids = get_site_ids(mist, org_id) confirm_action(mist, site_ids) break
def get_site_id(): site_id = cli.select_site(session) print("") print("Selected site id: %s" % site_id) return site_id