Пример #1
0
 def __init__(self, host_and_port, adapter, log, device_id):
     self.log = log
     self.headers = {'Accept-Encoding': None}
     self.device_id = device_id
     """self.adapter_agent = adapter.adapter_agent
     self.adapter_name = adapter.name
     """
     self.host_and_port = host_and_port.split(
         ':')[0] + Defaults.redfish_port
     requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
     self.chassis_obj = Chassis(self)
     self.systems_obj = Systems(self)
     self.ethernet_obj = Ethernet(self)
     self.sys_info = {}
Пример #2
0
    def update(self):

        if self.visible():

            capi_update=self.patrol_list and self.system and self.capi_update
            journal_update=self.patrol_list and self.system

            if journal_update or capi_update:
                self.sort_patrol()
                p=Systems.edsmGetSystem(self.system)
                self.nearest=self.getNearest(p)
                self.hyperlink['text']=self.nearest.get("system")
                self.hyperlink['url']="https://www.edsm.net/en/system?systemName={}".format(quote_plus(self.nearest.get("system")))
                self.distance['text']="{}ly".format(Locale.stringFromNumber(getDistance(p,self.nearest.get("coords")),2))
                self.infolink['text']=self.nearest.get("instructions")
                self.infolink['url']=self.parseurl(self.nearest.get("url"))

                self.infolink.grid()
                self.distance.grid()
                self.prev.grid()
                self.next.grid()
                self.capi_update=False

            else:
                if self.system:
                    self.hyperlink['text'] = "Fetching patrols..."
                else:
                    self.hyperlink['text'] = "Waiting for location"
                self.infolink.grid_remove()
                self.distance.grid_remove()
                self.prev.grid_remove()
                self.next.grid_remove()
Пример #3
0
 def getBGSPatrol(self, bgs, BGSOSys):
     x, y, z = Systems.edsmGetSystem(bgs.get("system_name"))
     if bgs.get("system_name") in BGSOSys:
         return
     else:
         return newPatrol(
             "BGS", bgs.get("system_name"), (x, y, z),
             self.getBGSInstructions(bgs),
             "https://elitebgs.app/system/{}".format(bgs.get("system_id")))
Пример #4
0
def submit(cmdr, is_beta, system, station, entry, client):

    hyperdictionDetector.submit(cmdr, is_beta, system, station, entry, client)

    hdsystems = ("Electra", "Asterope", "Delphi", "Merope", "Celaeno", "Maia",
                 "HR 1185", "HIP 23759", "Witch Head Sector DL-Y d17",
                 "Pleiades Sector HR-W d1-79", "Pleione",
                 "Witch Head Sector GW-W c1-4")

    if entry.get("event") == "StartJump" and entry.get(
            "JumpType") == "Hyperspace":
        #post traffic from reference systems
        if system in hdsystems:
            post_traffic(system, entry)

        post_distance(system, 'Merope', entry)
        post_distance(system, 'Witch Head Sector IR-W c1-9', entry)

    if entry["event"] == "Statistics" and entry.get("TG_ENCOUNTERS"):
        # there is no guarentee TG_ENCOUNTER_TOTAL_LAST_SYSTEM will have a value
        if entry.get("TG_ENCOUNTERS").get("TG_ENCOUNTER_TOTAL_LAST_SYSTEM"):

            lastsystem = entry.get("TG_ENCOUNTERS").get(
                "TG_ENCOUNTER_TOTAL_LAST_SYSTEM")
            gametime = entry.get("TG_ENCOUNTERS").get(
                "TG_ENCOUNTER_TOTAL_LAST_TIMESTAMP")
            year, remainder = gametime.split("-", 1)
            tgtime = "{}-{}".format(str(int(year) - 1286), remainder)

            if lastsystem == "Pleiades Sector IR-W d1-55":
                lastsystem = "Delphi"

            debug({"cmdr": cmdr, "system": lastsystem, "timestamp": tgtime})
            x, y, z = Systems.edsmGetSystem(lastsystem)
            # we are going to submit the hyperdiction here.
            emitter.post(
                "https://europe-west1-canonn-api-236217.cloudfunctions.net/postHD",
                {
                    "cmdr": cmdr,
                    "system": lastsystem,
                    "timestamp": tgtime,
                    "x": x,
                    "y": y,
                    "z": z
                })

            if lastsystem:
                if HDReport.hdsystems.get(lastsystem) == lastsystem:
                    debug("Hyperdiction already recorded here - session ")
                else:
                    HDReport(cmdr, is_beta, lastsystem, entry, client).start()
                    gSubmitHD(cmdr, x, y, z, entry).start()
Пример #5
0
def submit(cmdr, is_beta, system, station, entry, client):

    # The last system isnt always set so we can ignore

    if entry["event"] == "Statistics" and entry.get("TG_ENCOUNTERS"):
        # there is no guarentee TG_ENCOUNTER_TOTAL_LAST_SYSTEM will have a value
        if entry.get("TG_ENCOUNTERS").get("TG_ENCOUNTER_TOTAL_LAST_SYSTEM"):

            lastsystem = entry.get("TG_ENCOUNTERS").get(
                "TG_ENCOUNTER_TOTAL_LAST_SYSTEM")
            if lastsystem:
                if HDReport.hdsystems.get(lastsystem) == lastsystem:
                    debug("Hyperdiction already recorded here - session ")
                else:
                    HDReport(cmdr, is_beta, lastsystem, entry, client).start()
                    x, y, z = Systems.edsmGetSystem(lastsystem)
                    gSubmitHD(cmdr, x, y, z, entry).start()
Пример #6
0
 def Music(cls, system, cmdr, timestamp):
     if cls.state == 2:
         debug("Hyperdiction Detected")
         cls.show()
         x, y, z = Systems.edsmGetSystem(system)
         emitter.post(
             "https://europe-west1-canonn-api-236217.cloudfunctions.net/postHDDetected",
             {
                 "cmdr": cmdr,
                 "system": system,
                 "timestamp": timestamp,
                 "x": x,
                 "y": y,
                 "z": z
             })
         plug.show_error("Hyperdiction: Exit to main menu")
     else:
         debug("FSDJUMP resetting state back")
         cls.hide()
         cls.state == 0
Пример #7
0
    def gSubmitAXCZ(self, payload):
        p = payload.copy()
        p["x"], p["y"], p["z"] = Systems.edsmGetSystem(
            payload.get("systemName"))
        if p.get("isBeta"):
            p["isBeta"] = 'Y'
        else:
            p["isBeta"] = 'N'

        p["rawJson"] = json.dumps(payload.get("rawJson"),
                                  ensure_ascii=False).encode('utf8')

        url = "https://us-central1-canonn-api-236217.cloudfunctions.net/submitAXCZ"
        debug("gSubmitAXCZ {}".format(p.get("systemName")))

        getstr = "{}?{}".format(url, urllib.urlencode(p))

        debug("gsubmit {}".format(getstr))
        r = requests.get(getstr)

        if not r.status_code == requests.codes.ok:
            error(getstr)
            error(r.status_code)
Пример #8
0
    def run(self):
        payload = {}

        if self.entry["event"] == 'FSSSignalDiscovered':
            threatLevel = self.entry.get("ThreatLevel")
            type = "FSS"
        else:
            threatLevel = self.entry.get("USSThreat")
            type = "Drop"

        payload["systemName"] = self.system
        payload["cmdrName"] = self.cmdr
        payload["nhssRawJson"] = self.entry
        payload["threatLevel"] = threatLevel
        payload["isbeta"] = self.is_beta
        payload["clientVersion"] = self.client
        payload["reportStatus"] = "accepted"
        payload["reportComment"] = type

        url = self.getUrl()
        self.send(payload, url)

        x, y, z = Systems.edsmGetSystem(self.system)
        gSubmitNHSS(self.cmdr, self.system, x, y, z, threatLevel).start()
Пример #9
0
    def cmdr_data(self, data, is_beta):
        """
        We have new data on our commander

        Lets get a list of ships
        """
        self.cmdr = data.get('commander').get('name')

        self.ships = []
        self.system = data.get("lastSystem").get("name")

        current_ship = data.get("commander").get("currentShipId")

        shipsystems = {}

        # debug(json.dumps(data.get("ships"),indent=4))

        for ship in data.get("ships").keys():

            if int(ship) != int(current_ship):
                ship_system = data.get("ships").get(ship).get(
                    "starsystem").get("name")
                if not shipsystems.get(ship_system):
                    debug("first: {}".format(ship_system))
                    shipsystems[ship_system] = []
                # else:
                #    debug("second: {}".format(ship_system))

                shipsystems[ship_system].append(data.get("ships").get(ship))
                # if ship_system == "Celaeno":
                #    debug(json.dumps(shipsystems[ship_system],indent=4))
            # else:
            # debug("skipping {}".format(ship))

        for system in shipsystems.keys():
            ship_pos = Systems.edsmGetSystem(system)
            ship_count = len(shipsystems.get(system))
            # if system == "Celaeno":
            #    debug(json.dumps(shipsystems.get(system),indent=4))
            if ship_count == 1:
                # debug(shipsystems.get(system))
                ship_type = getShipType(shipsystems.get(system)[0].get("name"))
                ship_name = shipsystems.get(system)[0].get("shipName")
                ship_station = shipsystems.get(system)[0].get("station").get(
                    "name")
                ship_info = "Your {}, {} is docked at {}".format(
                    ship_type, ship_name, ship_station)
            elif ship_count == 2:

                if shipsystems.get(system)[0].get("station").get(
                        "name") == shipsystems.get(system)[1].get(
                            "station").get("name"):
                    ship_info = "Your {} ({}) and {} ({}) are docked at {}".format(
                        getShipType(shipsystems.get(system)[0].get("name")),
                        getShipType(
                            shipsystems.get(system)[0].get("shipName")),
                        getShipType(shipsystems.get(system)[1].get("name")),
                        getShipType(
                            shipsystems.get(system)[1].get("shipName")),
                        shipsystems.get(system)[0].get("station").get("name"))
                    debug(ship_info)
                else:

                    ship_info = "Your {} ({}) is docked at {} and your {} ({}) is docked at {}".format(
                        getShipType(shipsystems.get(system)[0].get("name")),
                        getShipType(
                            shipsystems.get(system)[0].get("shipName")),
                        shipsystems.get(system)[1].get("station").get("name"),
                        getShipType(shipsystems.get(system)[1].get("name")),
                        getShipType(
                            shipsystems.get(system)[1].get("shipName")),
                        shipsystems.get(system)[0].get("station").get("name"))
                    debug(ship_info)
            else:
                ship_info = "You have {} ships stored in this system".format(
                    ship_count)
                debug(ship_info)

            self.ships.append(
                newPatrol("SHIPS", system, ship_pos, ship_info, None))

        self.capi_update = True
        if self.system and not self.started:
            debug("Patrol download cycle commencing")
            self.started = True
            self.patrol_update()
Пример #10
0
 def keyval(self, k):
     x, y, z = Systems.edsmGetSystem(self.system)
     return getDistance((x, y, z), k.get("coords"))
Пример #11
0
class RestClient(object):
    def __init__(self, host_and_port, adapter, log, device_id):
        self.log = log
        self.headers = {'Accept-Encoding': None}
        self.device_id = device_id
        """self.adapter_agent = adapter.adapter_agent
        self.adapter_name = adapter.name
        """
        self.host_and_port = host_and_port.split(
            ':')[0] + Defaults.redfish_port
        requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
        self.chassis_obj = Chassis(self)
        self.systems_obj = Systems(self)
        self.ethernet_obj = Ethernet(self)
        self.sys_info = {}

    def get_system_details(self):
        """
        Method to fetch OLT info.
        This method is supposed to get invoked from NBI API get_device_details.
        Currently the get_device_details() is in NotImplemented stated
        """

        self.systems_obj.system_get(self.sys_info)
        return self.sys_info

    def start_health_monitoring(self):
        """
        Method to fetch health status of asfvolt16 olt hardware modules
        """
        self.chassis_obj.get_chassis_health()
        self.ethernet_obj.get_ethernet_health()

    def stop_health_monitoring(self):
        """
        Method to stop health monitoring of asfvolt16 olt modules
        are not controlled by bal
        """
        self.chassis_obj.stop_chassis_monitoring()
        self.ethernet_obj.stop_ether_monitoring()

    def reboot_device(self):
        """
        Reboot asfvolt16 olt through Redfish service
        """
        self.systems_obj.reboot_olt()

    """def generate_alarm(self, status, alarm, alarm_severity):
        Method to create and submit alarms.
        if(alarm_severity == "Warning"):
            al_severity = AlarmEventSeverity.WARNING
        elif (alarm_severity == "Critical"):
            al_severity = AlarmEventSeverity.CRITICAL
        try:
            ts = arrow.utcnow().timestamp
            alarm_event = self.adapter_agent.create_alarm(
                id='voltha.{}.{}.olt'.format(self.adapter_name,
                                             self.device_id),
                resource_id='olt',
                type=AlarmEventType.EQUIPMENT,
                severity=al_severity,
                category=AlarmEventCategory.OLT,
                state=AlarmEventState.RAISED if status else
                AlarmEventState.CLEARED,
                description='OLT Alarm - Health Monitoring asfvolt16 olt - {}'
                .format('Raised'
                        if status
                        else 'Cleared'),
                context=alarm,
                raised_ts=ts)

            self.adapter_agent.submit_alarm(self.device_id, alarm_event)
        except Exception as e:
            self.log.exception('failed-to-submit-alarm', e=e)
    """

    def http_get(self, uri=UriConst.base_uri):
        """
        Method to send http GET request.
        """
        url = UriConst.HTTPS + self.host_and_port + uri
        #print ("http_get url[%s]"%url)
        try:
            ret = requests.request(RestConst.GET,
                                   url=url,
                                   headers=self.headers,
                                   auth=None,
                                   verify=False)
            return ret
        except requests.exceptions.ConnectTimeout:
            print("Connection-timed-out.")
        except Exception as e:
            print("Exception1-occurred-:", str(e))

    def http_put(self, uri=UriConst.base_uri, data=None):
        """
        Method to send http PUT request.
        """
        url = UriConst.HTTPS + self.host_and_port + uri
        try:
            ret = requests.request(RestConst.PUT,
                                   url=url,
                                   headers=self.headers,
                                   auth=None,
                                   verify=False,
                                   data=data)
            return ret
        except requests.exceptions.ConnectTimeout:
            print("Connection-timed-out.")
        except Exception as e:
            print("Exception1-occurred-:", str(e))

    def http_post(self, uri=UriConst.base_uri, data=None):
        """
        Method to send http POST request.
        """
        url = UriConst.HTTPS + self.host_and_port + uri
        try:
            ret = requests.request(RestConst.POST,
                                   url=url,
                                   headers=self.headers,
                                   auth=None,
                                   verify=False,
                                   data=data)
            return ret
        except requests.exceptions.ConnectTimeout:
            print("Connection-timed-out.")
        except Exception as e:
            print("Exception1-occurred-:", str(e))

    def http_patch(self, uri=UriConst.base_uri, data=None):
        """
        Method to send http Patch request.
        """
        url = UriConst.HTTPS + self.host_and_port + uri
        try:
            ret = requests.request(RestConst.PATCH,
                                   url=url,
                                   headers=self.headers,
                                   auth=None,
                                   verify=False,
                                   data=data)
            return ret
        except requests.exceptions.ConnectTimeout:
            print("Connection-timed-out.")
        except Exception as e:
            print("Exception1-occurred-:", str(e))
Пример #12
0
def get_distance(a, b):
    x, y, z = Systems.edsmGetSystem(a)
    a, b, c = Systems.edsmGetSystem(b)
    return math.sqrt(
        math.pow(x - a, 2) + math.pow(y - b, 2) + math.pow(z - c, 2))