Exemplo n.º 1
0
from threading import Thread


def cps_trace_usage():
    print ""
    print "Usage: cps_trace_events.py <qualifier> [object]"
    print "   qualifier (mandatory): ", cps.QUALIFIERS
    print "   object (optional): if object is not given all the event related to the qualifier will be captured"
    print "Example: cps_trace_events.py observed base-pas/media OR cps_trace_events.py observed"
    print ""
    print "Example for remote trace:"
    print "    cps_trace_events.py observed/fa-vlan/info cps/object-group/group=dnv"
    print ""


ids = cps.info("", False)['ids']


def _get_key(key):
    k = key.split('.')[-2]
    if k in ids:
        return ids[k]
    return key


def _get_obj_from_input():
    if (len(sys.argv) < 2):
        return None

    _qual_list = cps.QUALIFIERS
    _obj = cps_object.CPSObject(module="cps", qual="target")
#
# See the Apache Version 2.0 License for specific language governing
# permissions and limitations under the License.
#

import cps
import sys
import os

if __name__ == '__main__':
    # load the mapping file
    cps.init(
        '/localdisk/cwichmann/cps-api/workspace/debian/jessie/x86_64/sysroot/opt/dell/os10/lib/',
        'libcpsclass-')

    data = cps.info('19')
    print data
    data = cps.info('20')
    print data
    print cps.convdict({'1': 'dasra'})
    # Get the cps objects
    result = cps.get(['1.2.3.4'])

    # print discovered map
    print result
    # walk through the map and print the contents
    for d in result.keys():
        print d
        # convert to displayable info
        di = cps.arrayconv(d, result[d])
        cps.dictconv(d)
#  LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS
# FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
#
# See the Apache Version 2.0 License for specific language governing
# permissions and limitations under the License.
#

import cps
import sys

if __name__ == '__main__':

    del sys.argv[0]  #delete this program's name from the args

    for __arg in sys.argv:
        __obj_def = cps.info(__arg)
        if not 'names' in __obj_def:
            print('Failed to translate %s to a object.' % __arg)
            continue
        __names = __obj_def['names'].keys()

        for __name in __names:
            __elem = cps.type(__name)

            if 'data_type' not in __elem:
                print('Failed to get object details for %s' % __name)
                continue
            print('Name: %s\nData Type: %s\nID: %s\nAtrribute Type: %s\n\n' \
                  % (__elem['name'],__elem['data_type'],__elem['id'],__elem['attribute_type']) )