Ejemplo n.º 1
0
    def get_alarm_status(self, alarm):
        """
        get_alarm_status(auth, alarm) -> string

        Get an alarm's status.

        Parameters:
        alarm (string) - name of the alarm whose status will be returned

        Exceptions:
        get_alarm_statusFault - Alarm does not exist
        get_alarm_statusFault - Server Error.  Contact Support.
        """
        alarm = alarm.lower()

        alarm_enabled = Mgmt.get_value('/stats/config/alarm/%s/enable'
                                       % alarm)

        if alarm_enabled is None:
            raise ServiceError, 'Alarm %s does not exist' % alarm
        elif alarm_enabled == 'false':
            return 'disabled'
        elif alarm_enabled == 'true':
            # XXX/jshilkaitis: use mdc_iterate_binding_pattern one day, but
            # need to expose it first, and since it's non-trivial, I'm
            # punting on that for now.
            alarm_pfx = '/stats/state/alarm/' + alarm
            alarm_nodes = Mgmt.iterate(alarm_pfx, subtree=True)

            for node in alarm_nodes:
                if ((Mgmt.bn_name_pattern_match(
                    node[0], alarm_pfx + '/node/*/rising/error') or
                     Mgmt.bn_name_pattern_match(
                    node[0], alarm_pfx + '/node/*/falling/error')) and
                    node[2] == 'true'):
                    return 'ERROR'
        else:
            raise ServiceError, 'Server error. Contact Support.'

        return 'ok'
Ejemplo n.º 2
0
    def __get_top_talkers_list(self, node_path, value_type):
        """
        Internal function to support top talkers queries.

        Iterate subtree on node_path and use the results to generate
        a result list of value_type instances.
        """
        temp_result = {}

        bindings = Mgmt.iterate(node_path, subtree=True)

        for b in bindings:
            if Mgmt.bn_name_pattern_match(b[0], node_path + '/*/*'):
                parts = Mgmt.bn_name_to_parts(b[0])
                idx = int(parts[3]) - 1 # iterate results are 1-based
                attr_name = parts[4]

                curr_val = temp_result.setdefault(idx, value_type())

                setattr(curr_val, attr_name, b[2])

        return [temp_result[i] for i in xrange(len(temp_result))]