Example #1
0
    def get_iterdata(self, *args, **kwargs):
        """ Return a generator for the combined stream of outputs from each source object
        """
        threshold = timedelta(seconds=1)
        if 'time_thresh' in kwargs:
            threshold = kwargs['time_thresh']
            del kwargs['time_thresh']

        template = [None] * len(self._legend)
        iters = [s.output.get_iterdata(*args, **kwargs) for s in self._sources]
        inputs = [next(i, None) for i in iters]

        # XXX
        infinity = datetime(year=9999, month=12, day=31, tzinfo=tzutc())

        def get_sample_time(s):
            if s is None:
                return infinity
            return s.t

        def min_sample():
            return min(inputs, key=get_sample_time)

        ms = min_sample()
        sample_time = ms.t
        vals = list(template)
        while ms is not None:
            i = inputs.index(ms)
            inputs[i] = next(iters[i], None)

            delta = ms.t - sample_time
            if delta >= threshold:
                yield DictObject.create_from_dict(
                    dict(t=sample_time,
                         vals=[vals],
                         processed_pkts=None,
                         unprocessed_pkts=None))

                sample_time = ms.t
                vals = list(template)

            assert len(ms.vals) == 1

            V = ms.vals[0]
            off = self._sources[i].offset
            for j in range(len(V)):
                vals[off + j] = V[j]

            ms = min_sample()

        yield DictObject.create_from_dict(
            dict(t=sample_time,
                 processed_pkts=None,
                 unprocessed_pkts=None,
                 vals=[vals]))
    def get_iterdata(self, *args, **kwargs):
        """ Return a generator for the combined stream of outputs from each source object
        """
        threshold = timedelta(seconds=1)
        if 'time_thresh' in kwargs:
            threshold = kwargs['time_thresh']
            del kwargs['time_thresh']

        template = [None] * len(self._legend)
        iters = [s.output.get_iterdata(*args, **kwargs) for s in self._sources]
        inputs = [next(i, None) for i in iters]

        # XXX
        infinity = datetime(year=9999, month=12, day=31, tzinfo=tzutc())

        def get_sample_time(s):
            if s is None:
                return infinity
            return s.t

        def min_sample():
            return min(inputs, key=get_sample_time)

        ms = min_sample()
        sample_time = ms.t
        vals = list(template)
        while ms is not None:
            i = inputs.index(ms)
            inputs[i] = next(iters[i], None)

            delta = ms.t - sample_time
            if delta >= threshold:
                yield DictObject.create_from_dict(dict(t=sample_time,
                                                       vals=[vals],
                                                       processed_pkts=None,
                                                       unprocessed_pkts=None))

                sample_time = ms.t
                vals = list(template)

            assert len(ms.vals) == 1

            V = ms.vals[0]
            off = self._sources[i].offset
            for j in range(len(V)):
                vals[off + j] = V[j]

            ms = min_sample()

        yield DictObject.create_from_dict(dict(t=sample_time,
                                               processed_pkts=None,
                                               unprocessed_pkts=None,
                                               vals=[vals]))
Example #3
0
 def __init__(self, data, servicedef=None, datarep=None):
     logger.debug('Initialized {} object with data {}'.format(
         self.__class__.__name__, data))
     self.data = DictObject.create_from_dict(data)
     if not datarep:
         self.datarep = servicedef.bind(self.resource, id=self.data.id)
     else:
         self.datarep = datarep
Example #4
0
 def __init__(self, data, servicedef=None, datarep=None):
     # Override super class to use name instead of id
     logger.debug('Initialized {} object with data {}'.format(
         self.__class__.__name__, data))
     self.data = DictObject.create_from_dict(data)
     if not datarep:
         self.datarep = servicedef.bind(self.resource, name=self.data.name)
     else:
         self.datarep = datarep
Example #5
0
    def update(self, obj):
        """Update the HostGroup on an appresponse appliance.

        :param obj: an HostGroupConfig object. Note that the Hostgroup
            on the appresponse will be totally overwritten by the
            HostGroup object.
        """

        resp = self.datarep.execute('set', _data=obj)
        self.data = DictObject.create_from_dict(resp.data)
Example #6
0
    def __init__(self, host, port=None, auth=None):
        """Establishes a connection to a NetProfiler appliance.

        :param str host: name or IP address of the NetProfiler to
            connect to

        :param int port: TCP port on which the NetProfiler appliance
            listens.  If this parameter is not specified, the function will try
            to automatically determine the port.

        :param auth: defines the authentication method and credentials
            to use to access the NetProfiler.  It should be an instance of
            :py:class:`UserAuth<steelscript.common.service.UserAuth>` or
            :py:class:`OAuth<steelscript.common.service.OAuth>`

        :param str force_version: API version to use when communicating.
            if unspecified, this will use the latest version supported by both
            this implementation and the NetProfiler appliance.

        See the base :py:class:`Service<steelscript.common.service.Service>` class
        for more information about additional functionality supported.
        """
        super(NetProfiler, self).__init__("profiler",
                                          host,
                                          port,
                                          auth=auth,
                                          versions=[APIVersion("1.0")])

        self.api = _api1.Handler(self)

        self.groupbys = DictObject.create_from_dict(_constants.groupbys)
        self.realms = _constants.realms
        self.centricities = _constants.centricities

        self._info = None

        # checking if the profiler supports 1.2
        # if yes, then use column dsc
        # otherwise, use column qos
        if (self.supported_versions is None
                or APIVersion("1.2") in self.supported_versions):
            _key, _value = ('dsc', 'dsc')
        else:
            _key, _value = ('qos', 'qos')
        self.groupbys[_key] = _value

        self._load_file_caches()
        self.columns = ColumnContainer(self._unique_columns())
        self.colnames = set(c.key for c in self.columns)

        self.areas = AreaContainer(self._areas_dict.iteritems())
Example #7
0
    def __init__(self, host, port=None, auth=None):
        """Establishes a connection to a NetProfiler appliance.

        :param str host: name or IP address of the NetProfiler to
            connect to

        :param int port: TCP port on which the NetProfiler appliance
            listens.  If this parameter is not specified, the function will try
            to automatically determine the port.

        :param auth: defines the authentication method and credentials
            to use to access the NetProfiler.  It should be an instance of
            :py:class:`UserAuth<steelscript.common.service.UserAuth>` or
            :py:class:`OAuth<steelscript.common.service.OAuth>`

        :param str force_version: API version to use when communicating.
            if unspecified, this will use the latest version supported by both
            this implementation and the NetProfiler appliance.

        See the base :py:class:`Service<steelscript.common.service.Service>` class
        for more information about additional functionality supported.
        """
        super(NetProfiler, self).__init__("profiler", host, port,
                                          auth=auth,
                                          versions=[APIVersion("1.0")])

        self.api = _api1.Handler(self)

        self.groupbys = DictObject.create_from_dict(_constants.groupbys)
        self.realms = _constants.realms
        self.centricities = _constants.centricities

        self._info = None

        # checking if the profiler supports 1.2
        # if yes, then use column dsc
        # otherwise, use column qos
        if (self.supported_versions is None or
           APIVersion("1.2") in self.supported_versions):
            _key, _value = ('dsc', 'dsc')
        else:
            _key, _value = ('qos', 'qos')
        self.groupbys[_key] = _value

        self._load_file_caches()
        self.columns = ColumnContainer(self._unique_columns())
        self.colnames = set(c.key for c in self.columns)

        self.areas = AreaContainer(self._areas_dict.iteritems())
 def update(self, data):
     """Update the data of the current object
     with new data from the server
     """
     assert self.id == data['id']
     self.data = DictObject.create_from_dict(data)
Example #9
0
 def update(self, data):
     """Update the data of the current object
     with new data from the server
     """
     assert self.id == data['id']
     self.data = DictObject.create_from_dict(data)