示例#1
0
    def run(self, opts, flags):
        intf_token = context_get().obj
        condition = ['name', '==', str(intf_token)]
        intf_other_map = ovsdb.get_map('Interface', 'other_config',
                                       conditions=[condition])
        # TODO should get 'rxtx' from defaults
        old_state = intf_other_map.get('lldp_enable_dir', 'rxtx')
        rx = tx = True
        if old_state == 'off':
            rx = tx = False
        else:
            if old_state.find('rx') == -1:
                rx = False
            if old_state.find('tx') == -1:
                tx = False

        while opts:
            if opts[0] == 'reception':
                rx = F_NO not in flags
                opts.pop(0)
            elif opts[0] == 'transmission':
                tx = F_NO not in flags
                opts.pop(0)

        if not rx and not tx:
            new_state = 'off'
        else:
            new_state = ''
            if rx:
                new_state += 'rx'
            if tx:
                new_state += 'tx'
        if old_state != new_state:
            ovsdb.map_set_key('Interface', 'other_config', 'lldp_enable_dir',
                              new_state, conditions=[condition])
示例#2
0
文件: lldp.py 项目: skg-net/ops-cli
    def run(self, opts, flags):
        intf_token = context_get().obj
        condition = ['name', '==', str(intf_token)]
        intf_other_map = ovsdb.get_map('Interface',
                                       'other_config',
                                       conditions=[condition])
        # TODO should get 'rxtx' from defaults
        old_state = intf_other_map.get('lldp_enable_dir', 'rxtx')
        rx = tx = True
        if old_state == 'off':
            rx = tx = False
        else:
            if old_state.find('rx') == -1:
                rx = False
            if old_state.find('tx') == -1:
                tx = False

        while opts:
            if opts[0] == 'reception':
                rx = F_NO not in flags
                opts.pop(0)
            elif opts[0] == 'transmission':
                tx = F_NO not in flags
                opts.pop(0)

        if not rx and not tx:
            new_state = 'off'
        else:
            new_state = ''
            if rx:
                new_state += 'rx'
            if tx:
                new_state += 'tx'
        if old_state != new_state:
            ovsdb.map_set_key('Interface',
                              'other_config',
                              'lldp_enable_dir',
                              new_state,
                              conditions=[condition])
示例#3
0
    def run(self, opts, flags):
        while opts:
            if opts[0] == 'enable':
                value = F_NO not in flags
                ovsdb.map_set_key('System', 'other_config', 'lldp_enable',
                                  str(value).lower())
                opts.pop(0)

            elif opts[0] == 'management-address':
                if F_NO in flags:
                    ovsdb.map_delete_key('System', 'other_config',
                                         'lldp_mgmt_addr')
                else:
                    ovsdb.map_set_key('System', 'other_config',
                                      'lldp_mgmt_addr', str(opts[1]))
                opts.pop(0)
                opts.pop(0)

            elif opts[0] == 'holdtime':
                if F_NO in flags:
                    ovsdb.map_delete_key('System', 'other_config', 'lldp_hold')
                else:
                    ovsdb.map_set_key('System', 'other_config', 'lldp_hold',
                                      str(opts[1]))
                opts.pop(0)
                opts.pop(0)

            elif opts[0] == 'timer':
                if F_NO in flags:
                    ovsdb.map_delete_key('System', 'other_config',
                                         'lldp_tx_interval')
                else:
                    ovsdb.map_set_key('System', 'other_config',
                                      'lldp_tx_interval', str(opts[1]))
                opts.pop(0)
                opts.pop(0)

            elif opts[0] == 'select-tlv':
                for word, map_key, descr in tlv_keys:
                    if opts[1] == word:
                        key = map_key
                        break
                value = str(F_NO not in flags).lower()
                ovsdb.map_set_key('System', 'other_config', key, value)
                opts.pop(0)
                opts.pop(0)

            elif opts[0] == 'clear':
                if opts[1] == 'counters':
                    sem = 'lldp_num_clear_counters_requested'
                elif opts[1] == 'neighbors':
                    sem = 'lldp_num_clear_table_requested'
                req = ovsdb.get_map('System', 'status')
                counter = int(req.get(sem, 0))
                counter += 1
                ovsdb.map_set_key('System', 'status', sem, str(counter))
                opts.pop(0)
                opts.pop(0)
示例#4
0
文件: lldp.py 项目: skg-net/ops-cli
    def run(self, opts, flags):
        while opts:
            if opts[0] == 'enable':
                value = F_NO not in flags
                ovsdb.map_set_key('System', 'other_config', 'lldp_enable',
                                  str(value).lower())
                opts.pop(0)

            elif opts[0] == 'management-address':
                if F_NO in flags:
                    ovsdb.map_delete_key('System', 'other_config',
                                         'lldp_mgmt_addr')
                else:
                    ovsdb.map_set_key('System', 'other_config',
                                      'lldp_mgmt_addr', str(opts[1]))
                opts.pop(0)
                opts.pop(0)

            elif opts[0] == 'holdtime':
                if F_NO in flags:
                    ovsdb.map_delete_key('System', 'other_config', 'lldp_hold')
                else:
                    ovsdb.map_set_key('System', 'other_config', 'lldp_hold',
                                      str(opts[1]))
                opts.pop(0)
                opts.pop(0)

            elif opts[0] == 'timer':
                if F_NO in flags:
                    ovsdb.map_delete_key('System', 'other_config',
                                         'lldp_tx_interval')
                else:
                    ovsdb.map_set_key('System', 'other_config',
                                      'lldp_tx_interval', str(opts[1]))
                opts.pop(0)
                opts.pop(0)

            elif opts[0] == 'select-tlv':
                for word, map_key, descr in tlv_keys:
                    if opts[1] == word:
                        key = map_key
                        break
                value = str(F_NO not in flags).lower()
                ovsdb.map_set_key('System', 'other_config', key, value)
                opts.pop(0)
                opts.pop(0)

            elif opts[0] == 'clear':
                if opts[1] == 'counters':
                    sem = 'lldp_num_clear_counters_requested'
                elif opts[1] == 'neighbors':
                    sem = 'lldp_num_clear_table_requested'
                req = ovsdb.get_map('System', 'status')
                counter = int(req.get(sem, 0))
                counter += 1
                ovsdb.map_set_key('System', 'status', sem, str(counter))
                opts.pop(0)
                opts.pop(0)