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

    _qual_list = cps.QUALIFIERS
    _obj = cps_object.CPSObject(module="cps", qual="target")

    _inp = sys.argv[1].lower()
    _lst = _inp.split(cps.PATH_SEP, 1)

    #Only 'qualifier' provided as first argument
    if len(_lst) == 1:
        in_qual = _lst[0]
        if in_qual not in cps.QUALIFIERS:
            print "\nCheck the qualifier, not a valid qualifier "
            return None
        #Second argument is the 'module'
        if len(sys.argv) == 3:
            _key = cps.key_from_name(in_qual, sys.argv[2])
        else:
            _key = cps.key_from_qual(in_qual)
        _obj.set_key(_key)
        print " Registering for " + _key
    else:
        try:
            _obj = cps_object.object_from_parameters(prog='cps_trace_events',
                                                     description="")
        except ValueError:
            return None
        _key = _obj.get_key()
        print " Registering for object ..."
        cps_utils.print_obj(_obj.get())
    print "----------------------------------"

    if ((_key == "") or (_key == None)):
        print "Check the object name, not a valid object\n"
        return None

    return _obj
Exemple #2
0
# CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
# 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 cps_utils
import cps_object

if __name__ == '__main__':
    _obj = cps_object.object_from_parameters(prog='cps_get_oid',
                                             description='This process \
                    will perform a CPS get and return the results.  \
        The command line supports getting a single object with many attributes.  \
        An example is: %(prog)s cps/node-group -attr name=\'localhost\'')

    k = [_obj.get()]
    l = []

    _cur_key = ''
    cps.get(k, l)
    for entry in l:
        o = cps_object.CPSObject(obj=entry)
        if (_cur_key != o.get_key()):
            _cur_key = o.get_key()
            print('\n============%s==========\n' %
                  cps.name_from_key(_cur_key, 1))
# 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 cps_object
import cps_utils

if __name__ == '__main__':
    _obj = cps_object.object_from_parameters(
        prog='cps_send_event.py',
        description=
        """Send a CPS event taking the object specified on the command line.
    An example would be: %(prog)s -oper=create observed/dell-base-if-cmn/if/interfaces-state/interface \
        if/interfaces-state/interface/name=e101-007-0 if/interfaces-state/interface/oper-status=2""",
        optional_fields=['oper'])

    handle = cps.event_connect()
    print " Sending event for...."

    cur_obj = _obj.get()
    ev = {
        'operation': _obj.get_property('oper'),
        'key': cur_obj['key'],
        'data': cur_obj['data']
    }
    cps.event_send(handle, ev)
    if 'operation' in ev:
Exemple #4
0
# a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
# 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 cps_utils
import cps_object

if __name__ == '__main__':

    _obj = cps_object.object_from_parameters(
        prog='cps_set_oid',
        description="""Perform a CPS \
    commit operation taking the object specified on the command line.
    An example would be:
    %(prog)s target delete if/interfaces/interface name=e001""",
        optional_fields=['oper', 'commit-event'])

    ch = {'operation': _obj.get_property('oper'), 'change': _obj.get()}

    if cps.transaction([ch]):
        print "Success"
        cps_utils.print_obj(ch['change'])