示例#1
0
def change_phy(args):
    npu = None
    port = None

    if 'npu' in args:
        npu = int(args['npu'])
    if 'port' in args:
        port = int(args['port'])
    l = nas_if.nas_os_phy_list(npu, port)
    if l is None or len(l) == 0 or len(l) > 1:
        print "Cound not find interface"
        sys.exit(1)

    obj = l[0]

    fill_obj(obj, args)

    print "Changing.. port"
    print obj

    ch = {'operation': 'set', 'change': obj}
    if 'operation' in args:
        ch['operation'] = args['operation']

    cps.transaction([ch])
    print_object(ch['change'])
def change_phy(args):
    npu = None
    port = None

    if 'npu' in args:
        npu = int(args['npu'])
    if 'port' in args:
        port = int(args['port'])
    l = nas_if.nas_os_phy_list(npu, port)
    if l is None or len(l) == 0 or len(l) > 1:
        print "Cound not find interface"
        sys.exit(1)

    obj = l[0]

    fill_obj(obj, args)

    print "Changing.. port"
    print obj

    ch = {'operation': 'set', 'change': obj}
    if 'operation' in args:
        ch['operation'] = args['operation']

    cps.transaction([ch])
    print_object(ch['change'])
示例#3
0
def nas_set_media_type_by_media_id(slot, media_id, media_type):
    l = []
    port_list = []
    o = cps_object.CPSObject(module='base-if-phy/front-panel-port',
                             data={'media-id': media_id})
    cps.get([o.get()], l)

    if len(l) == 0:
        nas_if.log_err("No such port found... for medial " + str(media_id))
        return

    #fetching 2 front panel port object from 1 phy media id for QSFP28-DD ports
    for fp_obj in l:
        obj = cps_object.CPSObject(obj=fp_obj)
        if _fp_port_key == obj.get_key():
            port_list = port_list + nas_if.physical_ports_for_front_panel_port(
                obj)

    if len(port_list) == 0:
        nas_if.log_err("There are no physical ports for front panel port ")
        nas_if.log_err(l[0])
        return

    for port in port_list:
        nas_if.log_info(" port id : " + str(port.get_attr_data('port-id')) +
                        ". media type: " + str(media_type))
        port.add_attr('phy-media', media_type)
        ch = {'operation': 'set', 'change': port.get()}
        cps.transaction([ch])
示例#4
0
def if_media_type_set(pas_media_obj):
    try:
        media_id = pas_media_obj.get_attr_data('port')
        media_type = pas_media_obj.get_attr_data('type')
    except:
        nas_if.log_info(
            "media Id or media type is not present in the media event")
        return
    # fetch FP info from media ID
    l = nas_if.nas_os_fp_list(d={'media-id': media_id})
    if len(l) == 0:
        nas_if.log_err("No such port found... for media  " + str(media_id))
        return

    #fetching 2 front panel port object from 1 phy media id for QSFP28-DD ports
    port_list = []
    for fp_obj in l:
        obj = cps_object.CPSObject(obj=fp_obj)
        if _fp_port_key == obj.get_key():
            port_list = port_list + nas_if.physical_ports_for_front_panel_port(
                obj)

    if len(port_list) == 0:
        nas_if.log_err("There are no physical ports for front panel port ")
        nas_if.log_err(l[0])
        return

    # create interface set RPC obj for each phy port in the list and send it
    for p in port_list:
        npu = p.get_attr_data('npu-id')
        port = p.get_attr_data('port-id')
        hwport_list = p.get_attr_data('hardware-port-list')

        nas_if.log_info("send if rpc for media id set for phy port " +
                        str(port))
        ifobj = cps_object.CPSObject(
            module='dell-base-if-cmn/set-interface',
            data={
                'dell-base-if-cmn/set-interface/input/operation': 3,
                'base-if-phy/if/interfaces/interface/npu-id': npu,
                'base-if-phy/if/interfaces/interface/port-id': port,
                'base-if-phy/if/interfaces/interface/phy-media': media_type,
                'if/interfaces/interface/type': "ianaift:ethernetCsmacd"
            })
        ch = {'operation': 'rpc', 'change': ifobj.get()}
        cps.transaction([ch])
        if_name = str(
            ch['change']['data']['if/interfaces/interface/name'])[:-1]
        if_details = nas_if.nas_os_if_list(
            d={'if/interfaces/interface/name': if_name})
        enable = ba.from_ba(
            if_details[0]['data']['if/interfaces/interface/enabled'],
            "uint64_t")
        for hwport in hwport_list:
            fp_details = fp.find_port_by_hwport(npu, hwport)
            _lane = fp_details.lane
            media_transceiver_set(1, fp_details.media_id, _lane, enable)
    nas_if.log_info("setting media id: " + str(media_id) + " media type: " +
                    str(media_type))
def if_media_type_set(pas_media_obj):
    try:
        media_id = pas_media_obj.get_attr_data('port')
        media_type = pas_media_obj.get_attr_data('type')
    except:
        nas_if.log_err(
            "media Id or media type is not present in the media event")
        return
    # fetch FP info from media ID
    l = nas_if.nas_os_fp_list(d={'media-id': media_id})
    if len(l) == 0:
        nas_if.log_err("No such port found... for media  " + str(media_id))
        return

    # fetch PHY port list for the FP port
    port_list = nas_if.physical_ports_for_front_panel_port(
        cps_object.CPSObject(obj=l[0]))
    if len(port_list) == 0:
        nas_if.log_err("There are no physical ports for front panel port ")
        nas_if.log_err(l[0])
        return

    # create interface set RPC obj for each phy port in the list and send it
    for p in port_list:
        npu = p.get_attr_data('npu-id')
        port = p.get_attr_data('port-id')
        fanout = p.get_attr_data('fanout-mode')
        hwport = p.get_attr_data('hardware-port-id')

        nas_if.log_info("send if rpc for media id set for phy port " +
                        str(port))
        ifobj = cps_object.CPSObject(
            module='dell-base-if-cmn/set-interface',
            data={
                'dell-base-if-cmn/set-interface/input/operation': 3,
                'base-if-phy/if/interfaces/interface/npu-id': npu,
                'base-if-phy/if/interfaces/interface/port-id': port,
                'base-if-phy/if/interfaces/interface/phy-media': media_type,
                'if/interfaces/interface/type': "ianaift:ethernetCsmacd"
            })
        ch = {'operation': 'rpc', 'change': ifobj.get()}
        cps.transaction([ch])
        if_name = ba.ba_to_str(
            ch['change']['data']['if/interfaces/interface/name'],
            len(_if_name))
        if_details = nas_if.nas_os_if_list(
            d={'if/interfaces/interface/name': if_name})
        enable = ba.from_ba(
            if_details[0]['data']['if/interfaces/interface/enabled'],
            "uint64_t")
        fp_details = fp.find_port_by_hwport(npu, hwport)
        if fanout == 2:  # then it is in 4x10G fanout mode BASE_PORT_BREAKOUT_MODE_BREAKOUT_4X1
            _lane = fp_details.lane
        else:  # non-fanout mode 1x40g mode
            _lane = None  # enable/disable all channels. Do not pass Lane #
        media_transceiver_set(1, fp_details.media_id, _lane, enable)
    nas_if.log_info("setting media id: " + str(media_id) + " media type: " +
                    str(media_type))
示例#6
0
def create_if(args):
    obj = nas_if.make_if_obj()

    fill_obj(obj, args)

    ch = {'operation': 'create', 'change': obj}
    print ch

    cps.transaction([ch])
    types.print_object(ch['change'])
def create_if(args):
    obj = nas_if.make_if_obj()

    fill_obj(obj, args)

    ch = {'operation': 'create', 'change': obj}
    print ch

    cps.transaction([ch])
    types.print_object(ch['change'])
示例#8
0
def create_if_rpc(args):
    obj = cps_object.CPSObject(module='dell-base-if-cmn/set-interface',
                               data={'dell-base-if-cmn/set-interface/input/operation': 1})

    fill_obj(obj, args)

    ch = {'operation': 'rpc', 'change': obj.get()}
    print ch

    cps.transaction([ch])
    types.print_object(ch['change'])
示例#9
0
def nas_set_media_type_by_phy_port(npu, phy_port, media_type):
    port = cps_object.CPSObject(module='base-if-phy/physical',
                                data={
                                    'npu-id': npu,
                                    'port-id': phy_port,
                                    'phy-media': media_type
                                })
    print " port id : %d.. media type: %d " % (port.get_attr_data('port-id'),
                                               media_type)
    ch = {'operation': 'set', 'change': port.get()}
    cps.transaction([ch])
示例#10
0
def nas_set_media_type_by_phy_port(npu, phy_port, media_type):
    port = cps_object.CPSObject(module='base-if-phy/physical',
                                data={
                                    'npu-id': npu,
                                    'port-id': phy_port,
                                    'phy-media': media_type
                                })
    nas_if.log_info(" port id : " + str(port.get_attr_data('port-id')) +
                    ". media type: " + str(media_type))
    ch = {'operation': 'set', 'change': port.get()}
    cps.transaction([ch])
示例#11
0
def media_transceiver_set(slot, media_id, channel, enable):
    media_channel = cps_object.CPSObject(module='base-pas/media-channel',
                                         qual='target',
                                         data={
                                             'slot': slot,
                                             'port': media_id,
                                             'state': enable
                                         })
    if channel != None:
        media_channel.add_attr('channel', channel)
    ch = {'operation': 'set', 'change': media_channel.get()}
    cps.transaction([ch])
def create_interface(obj):

    ifobj = nas_if.make_interface_from_phy_port(obj)

    if if_cache.exists(ifobj.get_attr_data('if/interfaces/interface/name')):
        nas_if.log_err("Already exists.... " + str(ifobj.get_attr_data('if/interfaces/interface/name')))
        return

    # create the object
    ch = {'operation': 'rpc', 'change': ifobj.get()}
    cps.transaction([ch])
    nas_if.log_info("Interface Created : " + str(ifobj.get_attr_data('if/interfaces/interface/name')))
示例#13
0
def create_if_rpc(args):
    obj = cps_object.CPSObject(
        module='dell-base-if-cmn/set-interface',
        data={'dell-base-if-cmn/set-interface/input/operation': 1})

    fill_obj(obj, args)

    ch = {'operation': 'rpc', 'change': obj.get()}
    print ch

    cps.transaction([ch])
    types.print_object(ch['change'])
示例#14
0
def media_led_set(slot, media_id, channel, speed):
    media_channel = cps_object.CPSObject(module='base-pas/media-channel',
                                         qual='target',
                                         data={
                                             'slot': slot,
                                             'port': media_id,
                                             'channel': channel,
                                             'speed': speed
                                         })
    ch = {'operation': 'set', 'change': media_channel.get()}
    nas_if.log_info("set speed for media Id : " + str(media_id) + " channel " +
                    str(channel) + " speed " + str(speed))
    cps.transaction([ch])
def create_interface(obj):

    ifobj = nas_if.make_interface_from_phy_port(obj)

    if if_cache.exists(ifobj.get_attr_data('if/interfaces/interface/name')):
        print "Already exists.... " + ifobj.get_attr_data('if/interfaces/interface/name')
        return

    # create the object
    ch = {'operation': 'rpc', 'change': ifobj.get()}
    cps.transaction([ch])
    print "Interface Created : " + ifobj.get_attr_data('if/interfaces/interface/name')
    cps_utils.print_obj(ch['change'])
def set_hg(hg_name, profile=None, port_id=None, br_mode=None, port_speed=None, phy_mode=None):
    cps_obj = cps_object.CPSObject(module="base-pg/dell-pg/port-groups/hybrid-group", data={})
    cps_obj.add_attr(hg_attr('id'), hg_name)

    if profile is not None:
        cps_obj.add_attr(hg_attr('profile'), profile)

    if port_id is not None and br_mode is not None and port_speed is not None and phy_mode is not None:
        cps_obj.add_embed_attr([hg_attr('port'), "0", "port-id"], str(port_id), 4)
        cps_obj.add_embed_attr([hg_attr('port'), "0", "breakout-mode"], br_mode, 4)
        cps_obj.add_embed_attr([hg_attr('port'), "0", "port-speed"], port_speed, 4)
        cps_obj.add_embed_attr([hg_attr('port'), "0", "phy-mode"], phy_mode, 4)

    cps.transaction([{"operation": "set", "change": cps_obj.get()}])
示例#17
0
def media_led_set(slot, media_id, channel, speed):
    media_channel = cps_object.CPSObject(module='base-pas/media-channel',
                                         qual='target',
                                         data={
                                             'slot': slot,
                                             'port': media_id,
                                             'channel': channel,
                                             'speed': speed
                                         })
    cps_utils.print_obj(media_channel.get())
    ch = {'operation': 'set', 'change': media_channel.get()}
    print "set speed for media Id : %d channel %d speed %d " % (media_id,
                                                                channel, speed)
    cps.transaction([ch])
示例#18
0
def nas_set_interface_attribute(if_index, speed, duplex, autoneg):
    if if_index == None:
        print 'not a valid interface index'
        return
    _data = {'if-index': if_index}
    if speed != None:
        _data['dell-if/if/interfaces/interface/speed'] = speed
    if duplex != None:
        _data['dell-if/if/interfaces/interface/duplex'] = duplex
    if autoneg != None:
        _data['dell-if/if/interfaces/interface/auto-negotiation'] = autoneg
    # TODO try this make_if_obj(d={}):
    intf = cps_object.CPSObject(module=get_if_key(), data=_data)
    ch = {'operation': 'set', 'change': intf.get()}
    cps.transaction([ch])
示例#19
0
def create_interface(obj):

    ifobj = nas_if.make_interface_from_phy_port(obj)

    if if_cache.exists(ifobj.get_attr_data('if/interfaces/interface/name')):
        print "Already exists.... " + ifobj.get_attr_data(
            'if/interfaces/interface/name')
        return

    # create the object
    ch = {'operation': 'rpc', 'change': ifobj.get()}
    cps.transaction([ch])
    print "Interface Created : " + ifobj.get_attr_data(
        'if/interfaces/interface/name')
    cps_utils.print_obj(ch['change'])
def nas_set_interface_attribute(if_index, speed, duplex, autoneg):
    if if_index == None:
        print 'not a valid interface index'
        return
    _data = {'if-index':if_index}
    if speed != None:
        _data['dell-if/if/interfaces/interface/speed']= speed
    if duplex != None:
        _data['dell-if/if/interfaces/interface/duplex']= duplex
    if autoneg != None:
        _data['dell-if/if/interfaces/interface/auto-negotiation']= autoneg
     # TODO try this make_if_obj(d={}):
    intf = cps_object.CPSObject(module=get_if_key(), data=_data)
    ch = {'operation':'set', 'change':intf.get()}
    cps.transaction([ch])
 def commit(self):
     """
     Commit the transaction list and return the response.
     """
     if cps.transaction(self.tr_list):
         return self.tr_list
     return False
示例#22
0
def delete_vtep(name):
    cps_obj = cps_object.CPSObject(module='dell-base-if-cmn/set-interface',
                                   data={})
    cps_obj.add_attr('dell-base-if-cmn/set-interface/input/operation', _delete)
    cps_obj.add_attr("if/interfaces/interface/name", name)
    cps_obj.add_attr('if/interfaces/interface/type', "base-if:vxlan")
    return cps.transaction([{'operation': 'rpc', 'change': cps_obj.get()}])
示例#23
0
def create_bridge_interface(name, member_interfaces):
    cps_obj = cps_object.CPSObject(module='bridge-domain/set-bridge', data={})
    cps_obj.add_attr('bridge-domain/set-bridge/input/operation', _create)
    cps_obj.add_attr("bridge-domain/bridge/name", name)
    cps_obj.add_list('bridge-domain/bridge/member-interface',
                     member_interfaces)
    return cps.transaction([{'operation': 'rpc', 'change': cps_obj.get()}])
示例#24
0
def add_untagged_access_ports_to_bridge_interface(name, untagged_access_ports):
    cps_obj = cps_object.CPSObject(module='bridge-domain/set-bridge', data={})
    cps_obj.add_attr('bridge-domain/set-bridge/input/operation', _add_member)
    cps_obj.add_attr("bridge-domain/bridge/name", name)
    cps_obj.add_list('bridge-domain/bridge/member-interface',
                     untagged_access_ports)
    return cps.transaction([{'operation': 'rpc', 'change': cps_obj.get()}])
示例#25
0
def remove_remote_endpoint(name, remote_endpoints):
    cps_obj = cps_object.CPSObject(module='dell-base-if-cmn/set-interface',
                                   data={})
    cps_obj.add_attr('dell-base-if-cmn/set-interface/input/operation', _update)
    cps_obj.add_attr("if/interfaces/interface/name", name)
    cps_obj.add_attr('if/interfaces/interface/type', "base-if:vxlan")

    cps_obj.add_attr('dell-base-if-cmn/set-interface/input/member-op', _remove)
    idx = 0
    for re in remote_endpoints:
        cps_utils.cps_attr_types_map.add_type(
            cps_obj.generate_path([
                'dell-if/if/interfaces/interface/remote-endpoint',
                str(idx), 'addr'
            ]), re.addr_family)
        cps_obj.add_embed_attr([
            'dell-if/if/interfaces/interface/remote-endpoint',
            str(idx), 'addr'
        ], re.ip, 4)
        cps_obj.add_embed_attr([
            'dell-if/if/interfaces/interface/remote-endpoint',
            str(idx), 'addr-family'
        ], INET_TO_STR_MAP[re.addr_family], 4)
        cps_obj.add_embed_attr([
            'dell-if/if/interfaces/interface/remote-endpoint',
            str(idx), 'flooding-enabled'
        ], re.flooding_enabled, 4)
        idx += 1
    return cps.transaction([{'operation': 'rpc', 'change': cps_obj.get()}])
示例#26
0
def remove_vteps_from_bridge_interface(name, tunnel_endpoints):
    cps_obj = cps_object.CPSObject(module='bridge-domain/set-bridge', data={})
    cps_obj.add_attr('bridge-domain/set-bridge/input/operation',
                     _delete_member)
    cps_obj.add_attr("bridge-domain/bridge/name", name)
    cps_obj.add_list('bridge-domain/bridge/member-interface', tunnel_endpoints)
    return cps.transaction([{'operation': 'rpc', 'change': cps_obj.get()}])
示例#27
0
def delete_vlan_subintf(parent_intf, vlan_id):
    cps_obj = cps_object.CPSObject(module='dell-base-if-cmn/set-interface', data={})
    cps_obj.add_attr('dell-base-if-cmn/set-interface/input/operation', _delete)
    cps_obj.add_attr("dell-if/if/interfaces/interface/parent-interface", parent_intf)
    cps_obj.add_attr('if/interfaces/interface/type', "base-if:vlanSubInterface")
    cps_obj.add_attr("dell-if/if/interfaces/interface/vlan-id", vlan_id)
    return cps.transaction([{'operation': 'rpc', 'change': cps_obj.get()}])
示例#28
0
 def commit(self):
     """
     Commit the transaction list and return the response.
     """
     if cps.transaction(self.tr_list):
         return self.tr_list
     return False
示例#29
0
 def commit(self):
     '''Commit - commit the existing transaction list'''
     if len(self._cps_tx) == 0:
         return True
     result = cps.transaction(self._cps_tx)
     if result:
         return True
     # The mapping between set/create in ODL and CPS is not
     # perfect, sometimes CPS needs to be given a set where
     # ODL expects a create. Due to the fact that ODL
     # always checks for existance first this will not give
     # rise to conflicts
     for oper in self._cps_tx:
         if oper['operation'] == 'create':
             oper['operation'] = 'set'
     return cps.transaction(self._cps_tx)
def ip_address_config(operation, address_family, prefix_length):
    if address_family == "ipv4":
        mod = "base-ip/ipv4/address"
        name_attr = "base-ip/ipv4/name"
        name = "e101-001-0"
        ip_addr = "01010101"

    elif address_family == "ipv6":
        mod = "base-ip/ipv6/address"
        name_attr = "base-ip/ipv6/name"
        name = "br1"
        ip_addr = "01010101010101010101010101010101"
    else:
        print "Unsupported address family"
        assert 0

    cps_obj = cps_object.CPSObject(module = mod)
    cps_obj.add_attr(name_attr, name)
    cps_obj.add_attr('ip', ip_addr)
    cps_obj.add_attr('prefix-length', prefix_length)

    ch = {'operation': operation, 'change': cps_obj.get()}

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

    if operation == "create":
        ip_add_verify(address_family, prefix_length)
    elif operation == "delete":
        ip_delete_verify(address_family, prefix_length)
    else:
        print "Unsupported operation"
示例#31
0
def change_if(args):
    _phy = 'base-port/interface'
    obj = get_if_obj(args[0])

    args = args[1:]

    if len(args) == 0:
        types.print_object(obj)
    else:
        change_int(_phy, obj, args, 'mtu')
        change_int(_phy, obj, args, 'admin-status')

        ch = {'change': obj, 'operation': 'set'}

        cps.transaction([ch])
        types.print_object(ch['change'])
示例#32
0
def change_if(args):
    _phy = 'base-port/interface'
    obj = get_if_obj(args[0])

    args = args[1:]

    if len(args) == 0:
        types.print_object(obj)
    else:
        change_int(_phy, obj, args, 'mtu')
        change_int(_phy, obj, args, 'admin-status')

        ch = {'change': obj, 'operation': 'set'}

        cps.transaction([ch])
        types.print_object(ch['change'])
示例#33
0
def cps_set(obj, q='target', attrs={}):
    ''' CPS Set '''
    if cps.transaction([{
            'operation':
            'set',
            'change':
            cps_object.CPSObject(obj, qual=q, data=attrs).get()
    }]):
        return True
    raise Cps_Exception
示例#34
0
def delete_if_rpc(args):
    obj = cps_object.CPSObject(module='dell-base-if-cmn/set-interface',
                               data = {'dell-base-if-cmn/set-interface/input/operation': 2,
                                       'if/interfaces/interface/name': args[0]})
    ch = {'change': obj.get(), 'operation': 'rpc'}

    if cps.transaction([ch]) != True:
        print "Failed...."
    else:
        types.print_object(ch['change'])
示例#35
0
def delete_if(args):
    _phy = 'base-port/interface'
    obj = get_if_obj(args[0])
    args = args[1:]
    ch = {'change': obj, 'operation': 'delete'}

    if cps.transaction([ch]) != True:
        print "Failed...."
    else:
        types.print_object(ch['change'])
示例#36
0
def delete_if(args):
    _phy = 'base-port/interface'
    obj = get_if_obj(args[0])
    args = args[1:]
    ch = {'change': obj, 'operation': 'delete'}

    if cps.transaction([ch]) != True:
        print "Failed...."
    else:
        types.print_object(ch['change'])
示例#37
0
def create_vtep(name, vni, ip_addr, addr_family):
    cps_obj = cps_object.CPSObject(module='dell-base-if-cmn/set-interface', data={})
    cps_obj.add_attr('dell-base-if-cmn/set-interface/input/operation', _create)
    cps_obj.add_attr("if/interfaces/interface/name", name)
    cps_obj.add_attr('if/interfaces/interface/type', "base-if:vxlan")
    cps_obj.add_attr("dell-if/if/interfaces/interface/vni", vni)
    cps_obj.add_attr("dell-if/if/interfaces/interface/source-ip/addr-family", INET_TO_STR_MAP[addr_family])
    cps_utils.cps_attr_types_map.add_type("dell-if/if/interfaces/interface/source-ip/addr", addr_family)
    cps_obj.add_attr("dell-if/if/interfaces/interface/source-ip/addr", ip_addr)
    return cps.transaction([{'operation': 'rpc', 'change': cps_obj.get()}])
示例#38
0
def delete_if_rpc(args):
    obj = cps_object.CPSObject(
        module='dell-base-if-cmn/set-interface',
        data={'dell-base-if-cmn/set-interface/input/operation': 2})
    fill_obj(obj, args)
    ch = {'change': obj.get(), 'operation': 'rpc'}

    if cps.transaction([ch]) != True:
        print "Failed...."
    else:
        types.print_object(ch['change'])
def commit(obj, op):
    l = []
    tr_obj = {'change': obj.get(), 'operation': op}
    l.append(tr_obj)
    ret = cps.transaction(l)
    if ret:
        print "Success"
        return l

    print "Failed"
    return False
示例#40
0
def cps_transaction(obj):

    RESULT = dict()
    ch = {'operation': obj.get_property('oper'), 'change': obj.get()}
    if cps.transaction([ch]):
        RESULT["response"] = convert_cps_raw_list([ch['change']])
        RESULT["changed"] = True
    else:
        error_msg = "Transaction error while " + obj.get_property('oper')
        raise RuntimeError(error_msg)
    return RESULT
def do_transaction(obj, op):
    """Perfrom the transaction
    @obj - cps object
    @op- opertaion to be perfromed
    @return true if successful otherwise false
    """
    tr_obj = {'change': obj.get(), 'operation': op}
    l = [tr_obj]
    if cps.transaction(l):
        return True
    else:
        return False
        print "To add embedded attribute specify the all arguments in comma followed by = and its value"
        print "For eg. base-stg/entry/intf,0,ifindex=17 base-stg/entry/intf,0,state=1"
        exit(1)

    qual_list = ["target","observed","proposed","realtime"]
    if sys.argv[1] in qual_list:
        ch = {'operation': sys.argv[2], 'change': {}}
        cur_obj = cps_object.CPSObject(qual=sys.argv[1],module=sys.argv[3])
        arg_list = sys.argv[4:]
    else:
        ch = {'operation': sys.argv[1], 'change': {}}
        cur_obj = cps_object.CPSObject(qual="target",module=sys.argv[2])
        arg_list = sys.argv[3:
                            ]
    for e in arg_list:
        res = e.split('=', 1)
        # For embedded attribute check if comma seperated attribute list is given
        # then add it as embedded
        embed_attrs = res[0].split(',')
        if len(embed_attrs) == 3:
            cur_obj.add_embed_attr(embed_attrs,res[1])
        else:
            cur_obj.add_attr(res[0], res[1])


    ch['change'] = cur_obj.get()

    if cps.transaction([ch]):
        print "Success"
        cps_utils.print_obj(ch['change'])
if __name__ == '__main__':
    if len(sys.argv) < 2:
        print "Missing parameters.. please provide interface name eg.. e00-1"
        sys.exit(1)

    l = nas_if.nas_os_if_list()

    if_names = create_if_map(l)

    if not sys.argv[1] in if_names:
        print "Interface is invalid... " + sys.argv[1]
        sys.exit(1)

    obj = if_names[sys.argv[1]]
    # disable the port first before delteting the interface
    obj.add_attr('enabled', False)

    ch = {'operation': 'set', 'change': obj.get()}
    if cps.transaction([ch]) != True:
        print "Failed to shutdown interface, exiting..."
        sys.exit(0)

    ch = {'operation': 'delete', 'change': obj.get()}
    if cps.transaction([ch]):
        print "Successful"
        sys.exit(0)

    print "Failed to delete interface..."
    print obj.get()
示例#44
0
import cps_utils

if __name__ == '__main__':

    cps.config('10', '2.3', 'pyobj', '', True, "node")
    cps.config('11', '2.3.1', 'pyobj/node', '', False, "node")
    cps.config('12', '2.3.2', 'pyobj/time', '', False, "node")

    l = []
    if cps.get([{'key': '1.2.3.4.5', 'data': {}}], l):
        for i in l:
            print i

    single_update = {}
    obj = {'key': '', 'data': {}}
    single_update['change'] = obj
    single_update['operation'] = "set"
    obj['key'] = '1.2.3.4'
    obj['data'] = {'pyobj/node': 'Cliff'}
    l = [single_update]

    another_update = {
        'change': {
            'key': '1.2.3.5',
            'data': {
                'pyobj/node': 'Joe'}},
        'operation': 'create'}
    l.append(another_update)
    cps.transaction(l)
    print l
#
# Copyright (c) 2015 Dell Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# 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_object
# Create CPS Object
cps_obj = cps_object.CPSObject('dell-base-if-cmn/if/interfaces/interface')
# Populate the Vlan attributes VLAN_ID='br100'
VLAN_ID='br100'
cps_obj.add_attr('if/interfaces/interface/name',VLAN_ID)
# Associate a CPS Set Operation with the CPS Object
cps_update = {'change':cps_obj.get(),'operation': 'delete'}
# Add the CPS operation,obj pair to a new CPS Transaction
transaction = cps.transaction([cps_update])
# Check for failure
if not transaction:
    raise RuntimeError ("Error in deleting Vlan")
print "successful"