Ejemplo n.º 1
0
    def turn_off_port(self, port_id):

        try:
            oms_port_id = self.nodeCfgFile.GetOMSPortId(port_id)
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot turn_off_platform_port: %s" % str(e))

        log.debug("%r: turning off port: port_id=%s oms port_id = %s",
                  self._platform_id, port_id, oms_port_id)

        if self._rsn_oms is None:
            raise PlatformConnectionException(
                "Cannot turn_off_platform_port: _rsn_oms object required (created via connect() call)"
            )

        try:
            response = self._rsn_oms.port.turn_off_platform_port(
                self._platform_id, oms_port_id, 'CI - User')
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot turn_off_platform_port: %s" % str(e))

        log.debug("%r: turn_off_platform_port response: %s", self._platform_id,
                  response)

        dic_plat = self._verify_platform_id_in_response(response)
        self._verify_port_id_in_response(oms_port_id, dic_plat)

        return dic_plat  # note: return the dic for the platform
Ejemplo n.º 2
0
    def disconnect_instrument(self, port_id, instrument_id):
        if self._rsn_oms is None:
            raise PlatformConnectionException(
                "Cannot disconnect_instrument: _rsn_oms object required (created via connect() call)"
            )

        try:
            response = self._rsn_oms.instr.disconnect_instrument(
                self._platform_id, port_id, instrument_id)
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot disconnect_instrument: %s" % str(e))

        log.debug("%r: disconnect_instrument response: %s", self._platform_id,
                  response)

        dic_plat = self._verify_platform_id_in_response(response)
        port_dic = self._verify_port_id_in_response(port_id, dic_plat)
        instr_res = self._verify_instrument_id_in_response(
            port_id, instrument_id, port_dic)

        # update local image if instrument was actually disconnected in this call:
        if instr_res == NormalResponse.INSTRUMENT_DISCONNECTED:
            # TODO(OOIION-1495) review. This line was commented out, but the
            # PortNode.add_instrument/remove_instrument functionality is
            # being used to keep track of the connected instruments in a port.
            self._pnode.ports[port_id].remove_instrument(instrument_id)
            log.debug(
                "%r: port_id=%s disconnect_instrument: local image updated: %s",
                self._platform_id, port_id, instrument_id)

        return dic_plat  # note: return the dic for the platform
Ejemplo n.º 3
0
    def _register_event_listener(self, url):
        """
        Registers given url for all event types.
        """
        if self._rsn_oms is None:
            raise PlatformConnectionException(
                "Cannot _register_event_listener: _rsn_oms object required (created via connect() call)"
            )

        try:
            already_registered = self._rsn_oms.event.get_registered_event_listeners(
            )
        except Exception as e:
            raise PlatformConnectionException(
                msg="%r: Cannot get registered event listeners: %s" %
                (self._platform_id, e))

        if url in already_registered:
            log.debug("listener %r was already registered", url)
            return

        try:
            result = self._rsn_oms.event.register_event_listener(url)
        except Exception as e:
            raise PlatformConnectionException(
                msg="%r: Cannot register_event_listener: %s" %
                (self._platform_id, e))

        log.debug("%r: register_event_listener(%r) => %s", self._platform_id,
                  url, result)
Ejemplo n.º 4
0
    def _ping(self):
        """
        Verifies communication with external platform returning "PONG" if
        this verification completes OK.

        @retval "PONG" iff all OK.
        @raise PlatformConnectionException Cannot ping external platform or
               got unexpected response.
        """
        log.debug("%r: pinging OMS...", self._platform_id)
        if self._rsn_oms is None:
            raise PlatformConnectionException(
                "Cannot ping: _rsn_oms object required (created via connect() call)"
            )

        try:
            retval = self._rsn_oms.hello.ping()
        except Exception as e:
            raise PlatformConnectionException(msg="Cannot ping: %s" % str(e))

        if retval is None or retval.upper() != "PONG":
            raise PlatformConnectionException(
                msg="Unexpected ping response: %r" % retval)

        log.debug("%r: ping completed: response: %s", self._platform_id,
                  retval)

        return "PONG"
    def _register_event_listener(self, url):
        """
        Registers given url for all event types.
        """
        self._verify_rsn_oms('_register_event_listener')

        try:
            already_registered = self._rsn_oms.event.get_registered_event_listeners(
            )
        except Exception as e:
            raise PlatformConnectionException(
                msg="%r: Cannot get registered event listeners: %s" %
                (self._platform_id, e))

        if url in already_registered:
            log.debug("listener %r was already registered", url)
            return

        try:
            result = self._rsn_oms.event.register_event_listener(url)
        except Exception as e:
            raise PlatformConnectionException(
                msg="%r: Cannot register_event_listener: %s" %
                (self._platform_id, e))

        log.debug("%r: register_event_listener(%r) => %s", self._platform_id,
                  url, result)
Ejemplo n.º 6
0
    def set_attribute_values(self, attrs):
        """
        """
        if self._rsn_oms is None:
            raise PlatformConnectionException(
                "Cannot set_platform_attribute_values: _rsn_oms object required (created via connect() call)"
            )

        error_vals = self._validate_set_attribute_values(attrs)
        if len(error_vals) > 0:
            # remove offending attributes for the request below
            attrs_dict = dict(attrs)
            for bad_attr_name in error_vals:
                del attrs_dict[bad_attr_name]

            # no good attributes at all?
            if len(attrs_dict) == 0:
                # just immediately return with the errors:
                return error_vals

            # else: update attrs with the good attributes:
            attrs = attrs_dict.items()

        # ok, now make the request to RSN OMS:
        try:
            retval = self._rsn_oms.attr.set_platform_attribute_values(
                self._platform_id, attrs)
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot set_platform_attribute_values: %s" % str(e))

        log.debug("set_platform_attribute_values = %s", retval)

        if not self._platform_id in retval:
            raise PlatformException("Unexpected: response does not include "
                                    "requested platform '%s'" %
                                    self._platform_id)

        attr_values = retval[self._platform_id]

        # Note that the reported timestamps are in NTP.
        # (Timestamps indicate the time when the value was set for each attribute.)

        # ret_attr_values: dictionary to return, initialized with the error ones
        # determined above, if any:
        ret_attr_values = error_vals

        # add the info returned from RSN OMS:
        for attr_name, attr_val_ts in attr_values.iteritems():
            ret_attr_values[attr_name] = attr_val_ts

        log.debug("set_attribute_values: returning %s", ret_attr_values)

        return ret_attr_values
Ejemplo n.º 7
0
    def get_attribute_values(self, attrs):
        """
        """
        if not isinstance(attrs, (list, tuple)):
            raise PlatformException(
                'get_attribute_values: attrs argument must be a '
                'list [(attrName, from_time), ...]. Given: %s', attrs)

        if self._rsn_oms is None:
            raise PlatformConnectionException(
                "Cannot get_platform_attribute_values: _rsn_oms object required (created via connect() call)"
            )

        # convert the ION system time from_time to NTP, as this is the time
        # format used by the RSN OMS interface:

        # also convert the ION parameter names to RSN attribute IDs
        attrs_ntp = [(self.nodeCfgFile.GetAttrFromParameter(attr_id),
                      ion_ts_2_ntp(from_time))
                     for (attr_id, from_time) in attrs]

        log.debug("get_attribute_values(ntp): attrs=%s", attrs_ntp)

        try:
            retval = self._rsn_oms.attr.get_platform_attribute_values(
                self._platform_id, attrs_ntp)
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot get_platform_attribute_values: %s" % str(e))

        if not self._platform_id in retval:
            raise PlatformException("Unexpected: response does not include "
                                    "requested platform '%s'" %
                                    self._platform_id)

        attr_values = retval[self._platform_id]

        attrs_return = {}

        #convert back to ION parameter name and scale from OMS to ION
        for key in attr_values:
            newAttrList = []
            scaleFactor = self.nodeCfgFile.GetScaleFactorFromAttr(key)
            for v, ts in attr_values[key]:
                newAttrList.append((v * scaleFactor, ts))
            attrs_return[self.nodeCfgFile.GetParameterFromAttr(
                key)] = newAttrList

        log.debug("Back to ION=%s", attrs_return)

        # reported timestamps are already in NTP. Just return the dict:
        return attrs_return
    def start_profiler_mission(self, mission_name, src):
        def _verify_response(rsp):
            try:
                message = rsp[mission_name]

                if not message.startswith('OK'):
                    raise PlatformException(
                        msg="Error in starting mission %s: %s" %
                        (mission_name, message))
            except KeyError:
                raise PlatformException(
                    msg="Error in starting mission response: %s" % rsp)

        self._verify_rsn_oms('start_profiler_mission')

        try:
            response = self._rsn_oms.profiler.start_mission(
                self._platform_id, mission_name, src)
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot start_profiler_mission: %s" % str(e))

        log.debug("%r: start_profiler_mission response: %s", self._platform_id,
                  response)

        dic_plat = self._verify_platform_id_in_response(response)
        _verify_response(dic_plat)

        return dic_plat  # note: return the dic for the platform
    def set_overcurrent_limit(self, port_id, milliamps, microseconds, src):
        def _verify_response(rsp):
            try:
                message = rsp[port_id]

                if not message.startswith('OK'):
                    raise PlatformException(
                        msg="Error in setting overcurrent for port %s: %s" %
                        (port_id, message))
            except KeyError:
                raise PlatformException(msg="Error in response: %s" % rsp)

        self._verify_rsn_oms('set_overcurrent_limit')
        oms_port_cntl_id = self._verify_and_return_oms_port(
            port_id, 'set_overcurrent_limit')

        try:
            response = self._rsn_oms.port.set_over_current(
                self._platform_id, oms_port_cntl_id, int(milliamps),
                int(microseconds), src)
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot set_overcurrent_limit: %s" % str(e))

        response = self._convert_port_id_from_oms_to_ci(
            port_id, oms_port_cntl_id, response)
        log.debug("set_overcurrent_limit = %s", response)

        dic_plat = self._verify_platform_id_in_response(response)
        _verify_response(dic_plat)

        return dic_plat  # note: return the dic for the platform
Ejemplo n.º 10
0
    def set_over_current(self, port_id, ma, us, src=None):
        """
        @param port_id
        @param ma
        @param us
        @param src
                    Some provenance information: actor, mission, etc.
        """
        log.debug("%r: set_over_current: port_id=%s ma=%s us=%s src=%s",
                  self._platform_id, port_id, ma, us, src)

        try:
            response = self._rsn_oms.port.set_over_current(
                self._platform_id, port_id, ma, us, src)
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot set_over_current: %s" % str(e))

        log.debug("%r: set_over_current response: %s", self._platform_id,
                  response)

        dic_plat = self._verify_platform_id_in_response(response)
        self._verify_port_id_in_response(port_id, dic_plat)

        return dic_plat  # note: return the dic for the platform
Ejemplo n.º 11
0
    def turn_off_port(self, port_id, src=None):
        """
        Turns off a port.
        @param port_id
                    Port ID
        @param src
                    Some provenance information: actor, mission, etc.
        """
        log.debug("%r: turning off port: port_id=%s src=%s", self._platform_id,
                  port_id, src)

        try:
            response = self._rsn_oms.port.turn_off_platform_port(
                self._platform_id, port_id, src)
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot turn_off_platform_port: %s" % str(e))

        log.debug("%r: turn_off_platform_port response: %s", self._platform_id,
                  response)

        dic_plat = self._verify_platform_id_in_response(response)
        self._verify_port_id_in_response(port_id, dic_plat)

        return dic_plat  # note: return the dic for the platform
Ejemplo n.º 12
0
    def get_attribute_values(self, attrs):
        """
        """
        log.debug("get_attribute_values: attrs=%s", attrs)

        if not isinstance(attrs, (list, tuple)):
            raise PlatformException('get_attribute_values: attrs argument must be a '
                                    'list [(attrName, from_time), ...]. Given: %s', attrs)

        # convert the ION system time from_time to NTP, as this is the time
        # format used by the RSN OMS interface:
        attrs_ntp = [(attr_id, ion_ts_2_ntp(from_time))
                     for (attr_id, from_time) in attrs]

        try:
            retval = self._rsn_oms.attr.get_platform_attribute_values(self._platform_id,
                                                                      attrs_ntp)
        except Exception as e:
            raise PlatformConnectionException(msg="Cannot get_platform_attribute_values: %s" % str(e))

        if not self._platform_id in retval:
            raise PlatformException("Unexpected: response does not include "
                                    "requested platform '%s'" % self._platform_id)

        attr_values = retval[self._platform_id]

        # reported timestamps are already in NTP. Just return the dict:
        return attr_values
 def _verify_rsn_oms(*args, **kwargs):
     if args:
         driver = args[0]
         if hasattr(driver, '_rsn_oms'):
             if driver._rsn_oms is None:
                 raise PlatformConnectionException(
                     "Cannot %s: _rsn_oms object required (created via connect() call)" % func.__name__)
     return func(*args, **kwargs)
    def get_mission_status(self, *args, **kwargs):
        try:
            response = self._rsn_oms.profiler.get_mission_status(self._platform_id)
            dic_plat = self._verify_platform_id_in_response(response)
            return dic_plat  # note: return the dic for the platform

        except (Fault, ProtocolError, SocketError) as e:
            raise PlatformConnectionException(msg="Cannot get_mission_status: %s" % str(e))
    def _ping(self):
        """
        Verifies communication with external platform returning "PONG" if
        this verification completes OK.

        @retval "PONG" iff all OK.
        @raise PlatformConnectionException Cannot ping external platform or
               got unexpected response.
        """
        try:
            retval = self._rsn_oms.hello.ping()
            if retval is None or retval.upper() != "PONG":
                raise PlatformConnectionException(msg="Unexpected ping response: %r" % retval)
            return "PONG"

        except (Fault, ProtocolError, SocketError) as e:
            raise PlatformConnectionException(msg="Cannot ping: %s" % str(e))
    def stop_profiler_mission(self, flag, src):
        try:
            response = self._rsn_oms.profiler.stop_mission(self._platform_id, flag, src)
            dic_plat = self._verify_platform_id_in_response(response)
            self._verify_response(dic_plat, msg="stopping profiler")
            return dic_plat  # note: return the dic for the platform

        except (Fault, ProtocolError, SocketError) as e:
            raise PlatformConnectionException(msg="Cannot stop_profiler_mission: %s" % str(e))
Ejemplo n.º 17
0
    def _unregister_event_listener(self, url):
        """
        Unregisters given url for all event types.
        """
        if self._rsn_oms is None:
            raise PlatformConnectionException(
                "Cannot _unregister_event_listener: _rsn_oms object required (created via connect() call)"
            )

        try:
            result = self._rsn_oms.event.unregister_event_listener(url)
        except Exception as e:
            raise PlatformConnectionException(
                msg="%r: Cannot unregister_event_listener: %s" %
                (self._platform_id, e))

        log.debug("%r: unregister_event_listener(%r) => %s", self._platform_id,
                  url, result)
    def _register_event_listener(self, url):
        """
        Registers given url for all event types.
        """
        try:
            already_registered = self._rsn_oms.event.get_registered_event_listeners()
            if url in already_registered:
                log.debug("listener %r was already registered", url)
                return

        except (Fault, ProtocolError, SocketError) as e:
            raise PlatformConnectionException(
                msg="%r: Cannot get registered event listeners: %s" % (self._platform_id, e))

        try:
            result = self._rsn_oms.event.register_event_listener(url)
            log.debug("%r: register_event_listener(%r) => %s", self._platform_id, url, result)
        except (Fault, ProtocolError, SocketError) as e:
            raise PlatformConnectionException(
                msg="%r: Cannot register_event_listener: %s" % (self._platform_id, e))
    def _unregister_event_listener(self, url):
        """
        Unregisters given url for all event types.
        """
        try:
            result = self._rsn_oms.event.unregister_event_listener(url)
            log.debug("%r: unregister_event_listener(%r) => %s", self._platform_id, url, result)

        except (Fault, ProtocolError, SocketError) as e:
            raise PlatformConnectionException(
                msg="%r: Cannot unregister_event_listener: %s" % (self._platform_id, e))
Ejemplo n.º 20
0
    def get_connected_instruments(self, port_id):
        if self._rsn_oms is None:
            raise PlatformConnectionException(
                "Cannot get_connected_instruments: _rsn_oms object required (created via connect() call)"
            )

        try:
            response = self._rsn_oms.instr.get_connected_instruments(
                self._platform_id, port_id)
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot get_connected_instruments: %s" % str(e))

        log.debug("%r: port_id=%r: get_connected_instruments response: %s",
                  self._platform_id, port_id, response)

        dic_plat = self._verify_platform_id_in_response(response)
        port_dic = self._verify_port_id_in_response(port_id, dic_plat)

        return dic_plat  # note: return the dic for the platform
Ejemplo n.º 21
0
    def _get_ports(self):

        try:
            response = self._rsn_oms.port.get_platform_ports(self._platform_id)
            ports = response[self._platform_id]

        except Exception as e:
            msg = "Cannot get_platform_ports(platform_id=%r): %s" % (self._platform_id, e)
            raise PlatformConnectionException(msg=msg)

        log.debug("%r: _get_ports: %s", self._platform_id, ports)
        return ports
Ejemplo n.º 22
0
    def _unregister_event_listener(self, url):
        """
        Unregisters given url for all event types.
        """
        log.debug("%r: unregistering event listener: %s", self._platform_id, url)
        try:
            result = self._rsn_oms.event.unregister_event_listener(url)
        except Exception as e:
            raise PlatformConnectionException(
                msg="%r: Cannot unregister_event_listener: %s" % (self._platform_id, e))

        log.debug("%r: unregister_event_listener(%r) => %s", self._platform_id, url, result)
    def turn_off_port(self, port_id, src):
        oms_port_cntl_id = self._verify_and_return_oms_port(port_id, 'turn_off_port')

        try:
            response = self._rsn_oms.port.turn_off_platform_port(self._platform_id, oms_port_cntl_id, src)
            response = self._convert_port_id_from_oms_to_ci(port_id, oms_port_cntl_id, response)
            dic_plat = self._verify_platform_id_in_response(response)
            self._verify_response(dic_plat, key=port_id, msg="turn off port")
            return dic_plat  # note: return the dic for the platform

        except (Fault, ProtocolError, SocketError) as e:
            raise PlatformConnectionException(msg="Cannot turn_off_platform_port: %s" % str(e))
Ejemplo n.º 24
0
    def abort_profiler_mission(self):
        if self._rsn_oms is None:
            raise PlatformConnectionException(
                "Cannot abort_profiler_mission: _rsn_oms object required (created via connect() call)"
            )

        try:
            response = self._rsn_oms.profiler.abort_profiler_mission(
                self._platform_id)
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot abort_profiler_mission: %s" % str(e))

        log.debug("%r: abort_profiler_mission response: %s", self._platform_id,
                  response)

        dic_plat = self._verify_platform_id_in_response(response)
        # TODO commented
        #self._verify_port_id_in_response(port_id, dic_plat)

        return dic_plat  # note: return the dic for the platform
Ejemplo n.º 25
0
    def get_metadata(self):
        """
        """
        if self._rsn_oms is None:
            raise PlatformConnectionException(
                "Cannot get_platform_metadata: _rsn_oms object required (created via connect() call)"
            )
        try:
            retval = self._rsn_oms.config.get_platform_metadata(
                self._platform_id)
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot get_platform_metadata: %s" % str(e))

        log.debug("get_platform_metadata = %s", retval)

        if not self._platform_id in retval:
            raise PlatformException("Unexpected: response does not include "
                                    "requested platform '%s'" %
                                    self._platform_id)

        md = retval[self._platform_id]
        return md
Ejemplo n.º 26
0
    def get_attribute_values_from_oms(self, attrs):
        """
        """
        def _verify_returned_dict(attr_dict):
            try:
                for key in attr_dict.iterkeys():
                    value_list = attr_dict[key]
                    if value_list == 'INVALID_ATTRIBUTE_ID':
                        continue

                    if not isinstance(value_list, list):
                        raise PlatformException(
                            msg="Error in getting values for attribute %s.  %s"
                            % (key, value_list))

                    if value_list and value_list[0][
                            0] == "ERROR_DATA_REQUEST_TOO_FAR_IN_PAST":
                        raise PlatformException(
                            msg="Time requested for %s too far in the past" %
                            key)
            except AttributeError:
                raise PlatformException(
                    msg="Error returned in requesting attributes: %s" %
                    attr_dict)

        if not isinstance(attrs, (list, tuple)):
            raise PlatformException(
                'get_attribute_values: attrs argument must be a '
                'list [(attrName, from_time), ...]. Given: %s', attrs)

        self._verify_rsn_oms('get_attribute_values_from_oms')

        log.debug("get_attribute_values: attrs=%s", self._platform_id)
        log.debug("get_attribute_values: attrs=%s", attrs)

        try:
            response = self._rsn_oms.attr.get_platform_attribute_values(
                self._platform_id, attrs)
        except Exception as e:
            raise PlatformConnectionException(
                msg=
                "get_attribute_values_from_oms Cannot get_platform_attribute_values: %s"
                % str(e))

        dic_plat = self._verify_platform_id_in_response(response)
        _verify_returned_dict(dic_plat)

        # reported timestamps are already in NTP. Just return the dict:
        return dic_plat
Ejemplo n.º 27
0
    def get_external_checksum(self):
        """
        Returns the checksum of the external platform associated with this
        driver.

        @return SHA1 hash value as string of hexadecimal digits.
        """
        log.debug("%r: get_checksum...", self._platform_id)

        if self._rsn_oms is None:
            raise PlatformConnectionException(
                "Cannot get_checksum: _rsn_oms object required (created via connect() call)"
            )

        try:
            response = self._rsn_oms.config.get_checksum(self._platform_id)
        except Exception as e:
            raise PlatformConnectionException(msg="Cannot get_checksum: %s" %
                                              str(e))

        checksum = self._verify_platform_id_in_response(response)
        log.debug("%r: get_checksum... checksum=%s" %
                  (self._platform_id, checksum))
        return checksum
Ejemplo n.º 28
0
    def get_available_missions(self, *args, **kwargs):
        self._verify_rsn_oms('get_available_missions')

        try:
            response = self._rsn_oms.profiler.get_available_missions(
                self._platform_id)
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot get_available_missions: %s" % str(e))

        log.debug("%r: get_available_missions response: %s", self._platform_id,
                  response)

        dic_plat = self._verify_platform_id_in_response(response)

        return dic_plat  # note: return the dic for the platform
    def set_overcurrent_limit(self, port_id, milliamps, microseconds, src):
        oms_port_cntl_id = self._verify_and_return_oms_port(port_id, 'set_overcurrent_limit')

        try:
            response = self._rsn_oms.port.set_over_current(self._platform_id,
                                                           oms_port_cntl_id,
                                                           int(milliamps),
                                                           int(microseconds),
                                                           src)
            response = self._convert_port_id_from_oms_to_ci(port_id, oms_port_cntl_id, response)
            dic_plat = self._verify_platform_id_in_response(response)
            self._verify_response(dic_plat, key=port_id, msg="setting overcurrent")
            return dic_plat  # note: return the dic for the platform

        except (Fault, ProtocolError, SocketError) as e:
            raise PlatformConnectionException(msg="Cannot set_overcurrent_limit: %s" % str(e))
Ejemplo n.º 30
0
    def stop_profiler_mission(self, flag, src):
        def _verify_response(rsp):
            if not rsp.startswith('OK'):
                raise PlatformException(msg="Error in stopping profiler: %s" %
                                        rsp)

        self._verify_rsn_oms('stop_profiler_mission')

        try:
            response = self._rsn_oms.profiler.stop_mission(
                self._platform_id, flag, src)
        except Exception as e:
            raise PlatformConnectionException(
                msg="Cannot stop_profiler_mission: %s" % str(e))

        log.debug("%r: stop_profiler_mission response: %s", self._platform_id,
                  response)

        dic_plat = self._verify_platform_id_in_response(response)
        _verify_response(dic_plat)

        return dic_plat  # note: return the dic for the platform