SONIC config_db.json文件的前生今世

2023-05-16

config_db.json的使用

  1. 系统启动时从config_db.json中读取数据并写入CONFIG_DB数据库,前提是config_db.json存在;
  2. 保存当前系统的一些配置信息,通过config save命令;
  3. 与CONFIG_DB存在联系,CONFIG_DB为系统实时配置数据库;

sonic_installer

sonic_buildimage/src/sonic-utilities/sonic_installer/main.py
安装新的镜像时会备份/etc/sonic下的配置文件: cp -ar /etc/sonic /host/old_config

if (binary_image_type != running_image_type) and not force:
    click.echo("Image file '{}' is of a different type than running image.\n" +
     "If you are sure you want to install this image, use -f|--force.\n" +
     "Aborting...".format(image_path))
        raise click.Abort()
        
    click.echo("Installing image {} and setting it as default...".format(binary_image_version))
    
    if running_image_type == IMAGE_TYPE_ABOOT:
        run_command("/usr/bin/unzip -od /tmp %s boot0" % image_path)
        run_command("swipath=%s target_path=/host sonic_upgrade=1 . /tmp/boot0" % image_path)
    else:
        os.chmod(image_path, stat.S_IXUSR)
        run_command(image_path)
        run_command('grub-set-default --boot-directory=' + HOST_PATH + ' 0')
        
    run_command("rm -rf /host/old_config")
   # copy directories and preserve original file structure, attributes and associated metadata
    run_command("cp -ar /etc/sonic /host/old_config")

rc.local

rc.local会检查firsttime(路径:/host/image-xxxx/platform/firsttime,image-xxxx为当前SONIC系统 version)标志文件判断是否第一次启动,如果是第一次启动,会在这期间从/host/sonic/old_config/恢复config_db.json,前提是必须存在old_config
 

# Try to take old configuration saved during installation
# and create a flag in /tmp/ to let updategraph service know
if [ -d /host/old_config ]; then
        mv -f /host/old_config /etc/sonic/
        rm -rf /etc/sonic/old_config/old_config
        touch /tmp/pending_config_migration
        
elif [ -f /host/minigraph.xml ]; then                                                     
        mkdir -p /etc/sonic/old_config                                          
        mv /host/minigraph.xml /etc/sonic/old_config/                                             touch /tmp/pending_config_migration      
        
elif [ -n "$migration" ] && [ -f /host/migration/minigraph.xml ];  then                           mkdir -p /etc/sonic/old_config
        mv /host/migration/minigraph.xml /etc/sonic/old_config/                                   [ -f /host/migration/acl.json ] && mv /host/migration/acl.json /etc/sonic/old_config/                                           
        [ -f /host/migration/snmp.yml ] && mv /host/migration/snmp.yml /etc/sonic/old_config/                                           
        touch /tmp/pending_config_migration                                                                                             
        [ -f /etc/sonic/updategraph.conf ] && sed -i -e "s/enabled=false/enabled=true/g" /etc/sonic/updategraph.conf    
else                                                                                            
touch /tmp/pending_config_initialization                                         
fi                          

firsttime标志文件

文件被创建于sonic-buildimage/build_debian.sh
关于build_debian.sh的一些说明可参考以下注释:

## This script is to automate the preparation for a debian file system, 
## which will be used for an ONIE installer image.
## USAGE:
##   USERNAME=username PASSWORD=password ./build_debian
...
## Prepare the file system directory
if [[ -d $FILESYSTEM_ROOT ]]; then
    sudo rm -rf $FILESYSTEM_ROOT || die "Failed to clean chroot directory"
fi
mkdir -p $FILESYSTEM_ROOT
mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR
mkdir -p $FILESYSTEM_ROOT/$PLATFORM_DIR/x86_64-grub
touch $FILESYSTEM_ROOT/$PLATFORM_DIR/firsttime

build_debian.sh在编译SONIC镜像时会被执行,在slave.mk中

updategraph

sonic_buildimage/files/image_config/updategraph/updategraph
捕捉rc.local创建的标志文件pending_config_initialization或pending_config_migration,生成config_db.json;
 

if [ -f /tmp/pending_config_migration ]; then
    copy_config_files_and_directories $copy_list
    if [ x"${WARM_BOOT}" == x"true" ]; then
        echo "Warm reboot detected..."
    elif [ "$enabled" = "true" ]; then
        echo "Use minigraph.xml from old system..."
        reload_minigraph
        sonic-cfggen -d --print-data > /etc/sonic/config_db.json
    else
        echo "Use config_db.json from old system..."
        sonic-cfggen -j /etc/sonic/config_db.json --write-to-db
    fi
    rm -f /tmp/pending_config_migration
    sed -i "/enabled=/d" /etc/sonic/updategraph.conf
    echo "enabled=false" >> /etc/sonic/updategraph.conf
    exit 0
fi

if [ -f /tmp/pending_config_initialization ]; then
    rm -f /tmp/pending_config_initialization
    if [ "$enabled" != "true" ]; then
        PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
        PRESET=(`head -n 1 /usr/share/sonic/device/$PLATFORM/default_sku`)
        sonic-cfggen -H -k ${PRESET[0]} --preset ${PRESET[1]} > /etc/sonic/config_db.json
        redis-cli -n $CONFIG_DB_INDEX FLUSHDB
        sonic-cfggen -j /etc/sonic/config_db.json --write-to-db
        redis-cli -n $CONFIG_DB_INDEX SET "CONFIG_DB_INITIALIZED" "1"
        exit 0
    fi
fi

 

 

 

 

 

 

 

 

 

 

 

 

 

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SONIC config_db.json文件的前生今世 的相关文章

  • 使用把手显示来自 parse.com 的 json 响应

    我想将 json 响应传递给车把 我已经查看了解析文档和 stackoverflow 问题 但我似乎无法弄清楚这一点 这是回应 results address 755 W Yale createdAt 2013 02 09T01 12 15
  • PostgreSQL:有效地将 JSON 数组拆分为行

    我有一个表 表 A 其中包含一个包含 JSON 编码数据的文本列 JSON 数据始终是一个包含一到几千个普通对象的数组 我有另一个表 表 B 其中有几列 包括数据类型为 JSON 的列 我想从表 A 中选择所有行 将 json 数组拆分为其
  • 将类转换为 JSONObject

    我有好几堂这样的课 我想将类转换为 JSONObject 格式 import java io Serializable import com google gson annotations SerializedName public cla
  • 如何在具有现有记录的 json 数据表顶部添加新行

    我试图在数据表顶部添加一行 显示 金额 列的总和 我正在使用 json 数据表 jquery 插件 列表来显示数据表 如何将此行与现有行一起添加到数据表顶部 我认为这段代码会对你有所帮助 var json uid user123 first
  • 如何轻松地将 Ajax、perl 和 JSON 结合使用?

    我正在尝试使用 Ajax 制作一个网页 Example 我创建了一个 Perl CGU 文件来触发一个简单的帖子 文件 test cgi name 托马斯 回复短信 你的名字是托马斯 我创建了一个可以使用该帖子的 html 文件 但随后页面
  • 使用 ActiveAndroid 库存储 HashMap

    我有一堂课 Table name Control public class Control extends Model Column private String name Column private Map
  • Java GSON:获取JSONObject下所有键的列表

    我已经将 GSON 作为 Java 中的 JSON 解析器 但密钥并不总是相同 例如 我有以下 JSON 我已经知道的对象 键1 值1 键2 值2 AnotherObject anotherKey1 anotherValue1 anothe
  • 使用 ng-options 在 AngularJS 中使用 JSON 填充 select

    编辑 我的代码实际上确实有效 我只是一个有不相关问题的白痴 感谢大家的意见 所以我有一个 JSON 对象数组 格式如下 id id1 text text1 id id2 text text2 我想使用这些填充 AngularJS 选择字段
  • 从 JSON 文件注入的编译指令 AngularJS

    希望有人能帮助我应对这一挑战 我使用以下命令从服务器请求 JSON 数据 http get 来自服务器的数据返回一个对象 对象中的一个值包含 HTML 标记 该标记使用以下方式注入到页面中 div div 在标记内 有一个名为的自定义指令
  • init 后用 JSON 填充 select2 不起作用

    我正在尝试使用 JSON 数组填充 select2 元素 但我无法得到它 我有下一个数组 data id Foo text Foo id Bar text Bar 我初始化 select2 如下 selectElement select2
  • SQL Server 抱怨无效的 json

    我正在使用 Azure 数据工厂和 Azure SQL 数据库编写 ETL 工具 数据工厂捕获映射数据流的输出并将其作为字符串插入到 SQL Server 表 Audit OperationsEventLog 的 StatusMessage
  • Swift 3 中的 JSON 解析

    有没有人能够找到一种在 Swift 3 中解析 JSON 文件的方法 我已经能够返回数据 但在将数据分解为特定字段时我没有成功 我会发布示例代码 但我已经尝试了很多不同的方法但没有成功 并且没有保存任何代码 我想要解析的基本格式是这样的 提
  • 如何在 Firebase 远程配置中从 JSON 获取值

    我是 Android 应用开发和 Firebase 的新手 我想知道如何获取存储在 Firebase 远程配置中的 JSONArray 文件中的值 String 和 Int 我使用 Firebase Remote Config 的最终目标是
  • Azure 应用服务在配置中添加字符串数组

    Net core 应用程序并在 Azure 应用服务中部署该应用程序 在我的应用程序中 我有一个包含以下内容的应用程序 settings json 文件 Roles Roles Admins Users 我的 ARM 模板中有以下配置 参数
  • Postgres JSONB:数组数组的 where 子句

    postgres 中有 v 9 5 如果有的话 create table json test id varchar NOT NULL data jsonb NOT NULL PRIMARY KEY id 其中 data 是 json 并且包
  • 如何在golang中解析JSON而不需要解组两次

    我有一个 Web 套接字连接 它在 JSON 对象中发送不同类型的消息 并且我想将内容解组到一些已知的结构中 为此 我认为我应该执行以下操作 步骤 1 将 JSON 解组为通用映射 字符串 接口 步骤 2 找到我要找的钥匙 步骤 3 尝试将
  • Ruby on Rails 服务器在 HTTPS POST 请求期间崩溃

    我正在尝试与你沟通城市飞艇API http urbanairship com docs push html broadcast使用 ROR Web 应用程序 在我的控制器中 我有以下代码 require net http require n
  • 如何在 select 和 option 标签中添加 JSON 数据?

    我有这个html代码 div class searchfilter div class searchwrapper div div
  • pyspark 将 twitter json 流式传输到 DF

    我正在从事集成工作spark streaming with twitter using pythonAPI 我看到的大多数示例或代码片段和博客是他们从Twitter JSON文件进行最终处理 但根据我的用例 我需要所有字段twitter J
  • Elasticsearch:预期的字段名称,但得到了 START_OBJECT

    我一直在尝试运行以下查询 但每次运行时都会收到以下错误 nested ElasticsearchParseException Expected field name but got START OBJECT field value fact

随机推荐