sonic config 配置方法介绍

本文详细解读了SonicConfig工具的功能,包括通过config命令修改hostname、使用sonic-cfggen读写配置数据、配置MTU的实例,以及涉及configdb、clishow和asicdb的操作。了解如何通过SonicConfig进行设备配置和数据库交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Sonic config 介绍

官网的一些参考如下链接。

https://github.com/Azure/sonic-utilities/blob/master/doc/Command-Reference.md

笔记如下

1:source code

sonic-utilitie/config  对应源码都可以在main.py中找到。

举例修改hostname, 代码如下,主要三部操作,1:连接configdb  2:修改db里面对应数据 3:使能配置以及相关

# 'hostname' command

#

@config.command('hostname')

@click.argument('new_hostname', metavar='<new_hostname>', required=True)

def hostname(new_hostname):

    """Change device hostname without impacting the traffic."""

    config_db = ConfigDBConnector()

    config_db.connect()

    config_db.mod_entry('DEVICE_METADATA' , 'localhost', {"hostname" : new_hostname})

2: cli show

admin@cel-seastone-01:~$ sudo config ?

Usage: config [OPTIONS] COMMAND [ARGS]...

  SONiC command line - 'config' command

Options:

  -?, -h, --help  Show this message and exit.

Commands:

  aaa                    AAA command line

  acl                    ACL-related configuration tasks

.。。。。。。。。。。。。

3:sonic-cfggen

"""sonic-cfggen

A tool to read SONiC config data from one or more of the following sources:

minigraph file, config DB, json file(s), yaml files(s), command line input,

and write the data into DB, print as json, or render a jinja2 config template.

Examples:

    Render template with minigraph:

        sonic-cfggen -m -t /usr/share/template/bgpd.conf.j2

    Dump config DB content into json file:

        sonic-cfggen -d --print-data > db_dump.json

    Load content of json file into config DB:

        sonic-cfggen -j db_dump.json --write-to-db

See usage string for detail description for arguments.

配置mtu example

1:sudo config interface mtu Ethernet124 4800

2:config db

redis-cli  select 4

127.0.0.1:6379[4]> hgetall PORT|Ethernet124

1) "index"

2) "32"

3) "lanes"

4) "125,126,127,128"

5) "description"

6) "etp32"

7) "mtu"

8) "4800"

9) "alias"

10) "etp32"

11) "pfc_asym"

12) "off"

13) "speed"

14) "100000"

15) "fec"

16) "rs"

3: appl db

select 0

127.0.0.1:6379> hgetall PORT_TABLE:Ethernet124

1) "index"

2) "32"

3) "lanes"

4) "125,126,127,128"

5) "description"

6) "etp32"

7) "mtu"

8) "4800"

9) "alias"

10) "etp32"

11) "pfc_asym"

12) "off"

13) "speed"

14) "100000"

15) "fec"

16) "rs"

17) "oper_status"

18) "down"

19) "admin_status"

20) "down"

4:  asic db 没找到端口映射关系

(这里oid映射关系oid:0x10000000000021),猜测可能对应bcmsh ceXX, oid从1开始的,对应关系为oid-2=XX

但是还是找到了

127.0.0.1:6379[1]> hgetall "ASIC_STATE:SAI_OBJECT_TYPE_PORT:oid:0x1000000000021"

1) "NULL"

2) "NULL"

3) "SAI_PORT_ATTR_ADMIN_STATE"

4) "false"

5) "SAI_PORT_ATTR_SPEED"

6) "100000"

7) "SAI_PORT_ATTR_MTU"

8) "4822"

9) "SAI_PORT_ATTR_FEC_MODE"

10) "SAI_PORT_FEC_MODE_RS"

5:bcmsh  可以看到有4822有在上次显示的是4800,22这个交换芯片内部处理的时候可以加上的字节数

drivshell>port ce31

port ce31

PORT: Status (* indicates PHY link up)

  ce31    (Disabled LS(SW Forced((100GFD) STP(Forward) Lrn(ARL,FWD) UtPri(0) Pfm(FloodNone) IF(KR4) PH(Slave) Max_frame(4822) MDIX(ForcedNormal, Normal) Medium(None) Fault(Local) VLANFILTER(3) Mac driver(CLMAC Driver)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值