Ejemplo n.º 1
0
 def _deep_dive_lookup_for_ap(self, org_id, action, level, level_id,
                              level_name, ap_mac, retry):
     url = "https://%s/api/v1/orgs/%s/inventory" % (mist_cloud, org_id)
     headers = {
         'Content-Type': "application/json",
         "Authorization": "Token %s" % apitoken
     }
     resp = req.get(url, headers=headers)
     if resp and "result" in resp:
         for device in resp["result"]:
             if device["mac"] == ap_mac:
                 site_name, site_id = self._get_new_site_name(
                     device, level_name)
                 console.notice(
                     "MIST AP %s | Has been moved from site %s to site %s. Processing with the new site..."
                     % (ap_mac, level_name, site_name), self.thread_id)
                 self._initiate_conf_change(action, org_id, "sites",
                                            site_id, site_name, ap_mac,
                                            True)
                 break
     else:
         console.error(
             "MIST AP %s | May have been removed from the Org before I get the message. Unable to retrieve the required informations. Aborting...",
             self.thread_id)
         console.send_message(self.thread_id)
Ejemplo n.º 2
0
def site_online(level, level_id, level_name, ap_mac, console, thread_id):
    url = "https://%s/api/v1/%s/%s/stats/devices" % (mist_cloud, level,
                                                     level_id)
    headers = {
        'Content-Type': "application/json",
        "Authorization": "Token %s" % apitoken
    }
    resp = req.get(url, headers=headers)
    if "result" in resp:
        return _process_timestamp(level_name, resp["result"], console,
                                  thread_id)
Ejemplo n.º 3
0
 def _get_ap_details(self, level, level_id, mac):
     url = "https://%s/api/v1/%s/%s/devices/search?mac=%s" % (
         mist_cloud, level, level_id, mac)
     headers = {
         'Content-Type': "application/json",
         "Authorization": "Token %s" % apitoken
     }
     resp = req.get(url, headers=headers)
     if resp and "result" in resp:
         return resp["result"]
     else:
         return None
Ejemplo n.º 4
0
 def run(self):
     event = self.event
     switch_mac = event["mac"]
     switch_port = event["port"]
     ap_mac = event["ap_mac"] if "ap_mac" in event else None
     console.info("Switch: {0} | Port: {1} | AP: {2}".format(
         switch_mac, switch_port, ap_mac))
     url = "https://{0}/api/v1/orgs/{1}/inventory?mac={2}".format(
         mist_cloud, event["org_id"], switch_mac)
     headers = {
         'Content-Type': "application/json",
         "Authorization": "Token %s" % apitoken
     }
     resp = req.get(url, headers=headers)
     if resp and "result" in resp:
         try:
             switch = resp["result"][0]
         except:
             console.error(
                 "Unable to get the switch {0} in the organization inventory"
                 .format(switch_mac))
             switch = None
         if switch:
             switch_name = switch["name"]
             if "site_id" in switch:
                 level = "sites"
                 level_id = switch["site_id"]
                 org_id = switch["org_id"]
                 if "site_name" in event:
                     level_name = event["site_name"]
                 else:
                     level_name = "no site name"
             else:
                 level = "orgs"
                 level_id = event["org_id"]
                 org_id = event["org_id"]
                 level_name = "ROOT_ORG"
             action = event["type"]
             if level_id in site_id_ignored:
                 console.info(
                     "EXTERNAL | MIST SITE: {0} | RECEIVED message {1} on switch {2} port {3} but this site should be ignored. Discarding the message..."
                     .format(level_name, action, switch_name,
                             switch_port), self.thread_id)
             else:
                 console.notice(
                     "EXTERNAL | MIST SITE: {0} | RECEIVED message {1} on switch {2} port {3}."
                     .format(level_name, action, switch_name,
                             switch_port), self.thread_id)
                 self._route_request(action, org_id, level, level_id,
                                     level_name, ap_mac, switch_name,
                                     switch_port, True)
Ejemplo n.º 5
0
def _init(site_id, switch_name):
    url = "{0}/api/v1/sites/{1}/devices/search?type=switch{2}".format(
        url_prefix, site_id, "")
    headers = {
        'Content-Type': "application/json",
        "Authorization": "Token %s" % apitoken
    }

    resp = req.get(url, headers=headers)
    if resp and "result" in resp and "results" in resp["result"]:
        for sw in resp["result"]["results"]:
            if switch_name in sw["hostname"]:
                return "00000000-0000-0000-1000-{0}".format(sw["mac"])
    return None
Ejemplo n.º 6
0
def get_switch_conf(site_id, site_name, switch_id, switch_name, thread_id):
    url = "%s/api/v1/sites/%s/devices/%s" % (url_prefix, site_id, switch_id)
    headers = {
        'Content-Type': "application/json",
        "Authorization": "Token %s" % apitoken
    }
    resp = req.get(url, headers=headers)
    if resp and "result" in resp:
        return resp["result"]
    else:
        console.error(
            "MIST SITE: {0} | SWITCH {1} | Unable to find switch configuration..."
            .format(site_name, switch_name), thread_id)
        return None
Ejemplo n.º 7
0
 def _get_new_site_name(self, device, level_name):
     url = "https://%s/api/v1/sites/%s" % (mist_cloud, device["site_id"])
     headers = {
         'Content-Type': "application/json",
         "Authorization": "Token %s" % apitoken
     }
     resp = req.get(url, headers=headers)
     if resp and "result" in resp:
         return (resp["result"]["name"], resp["result"]["id"])
     else:
         console.error(
             "MIST AP %s | Not on site %s anymore, and unable to find where it is. Aborting..."
             % (device["mac"], level_name), self.thread_id)
         console.send_message(self.thread_id)
Ejemplo n.º 8
0
def _get_switch_info(level, level_id, level_name, switch_name, console,
                     thread_id):
    url = "https://%s/api/v1/%s/%s/devices/search?type=switch&name=%s" % (
        mist_cloud, level, level_id, switch_name)
    headers = {
        'Content-Type': "application/json",
        "Authorization": "Token %s" % apitoken
    }
    resp = req.get(url, headers=headers)
    if "result" in resp and "results" in resp["result"]:
        if len(resp["result"]["results"]) == 1:
            return resp["result"]["results"][0]
    console.error(
        "MIST SITE: %s | SWITCH: %s | Unable to get the switch info" %
        (level_name, switch_name), thread_id)
    console.send_message(thread_id)
    return resp[0]
Ejemplo n.º 9
0
Archivo: cso.py Proyecto: tmunzer/mesa
def _get_device_info(device_uuid):
    url = "%s/data-view-central/device/%s" % (url_prefix, device_uuid)
    headers = {"x-auth-token": apitoken["token"]}
    resp = req.get(url=url, headers=headers)["result"]
    return resp
Ejemplo n.º 10
0
Archivo: cso.py Proyecto: tmunzer/mesa
def _get_devices():
    url = "%s/data-view-central/device" % url_prefix
    headers = {"x-auth-token": apitoken["token"]}
    resp = req.get(url=url, headers=headers)
    return resp["result"]["device"]
Ejemplo n.º 11
0
Archivo: cso.py Proyecto: tmunzer/mesa
def _get_device_port(switch_uuid):
    url = "%s/data-view-central/device-port?parent_id=%s" % (url_prefix,
                                                             switch_uuid)
    headers = {"x-auth-token": apitoken["token"]}
    resp = req.get(url=url, headers=headers)["result"]
    return resp
Ejemplo n.º 12
0
Archivo: cso.py Proyecto: tmunzer/mesa
def _get_port_profile():
    url = "%s/tssm/port-profile" % url_prefix
    headers = {"x-auth-token": apitoken["token"]}
    resp = req.get(url=url, headers=headers)
    return resp["result"]["port-profile"]