【Ovirt 笔记】engine-upgrade-check 的实现原理

文前说明

作为码农中的一员,需要不断的学习,我工作之余将一些分析总结和学习笔记写成博客与大家一起交流,也希望采用这种方式记录自己的学习之旅。

本文仅供学习交流使用,侵权必删。
不用于商业目的,转载请注明出处。

分析整理的版本为 Ovirt 3.4.5 版本。

命令使用方式:engine-upgrade-check [options]

Options:
  -h, --help   show this help message and exit
  -q, --quiet  quiet mode

命令采用了 python 方式进行实现。

  • 主要调用了 otopi

otopi

otopioVirt 面向任务的可插拔安装/实施。是用于安装独立插件的系统组件。插件只需提供简单的添加的安装功能而无需复杂的事务管理。

使用方式:otopi [variables]

variables ::= name=type:value variables | APPEND:name=type:value | ''
type ::= none | bool | int | str | multi-str

APPEND: prefix appends as colon list string.

CUSTOMIZATION
-------------

Set the following environment:

    DIALOG/customization=bool:True

This will trigger command-line prompt before validation and
before termination.

Refer to README.dialog for more information.

FILES
-----

CONFIGURATION

Configuration files used to override the environment.

System environment:
    OTOPI_CONFIG
Environment:
    CORE/configFileName
Default:
    /etc/otopi.conf

Config files to be read:
    @configFileName@
    @[email protected]/*.conf (sorted)

Structure:

    [environment:default]
    key=type:value

    [environment:init]
    key=type:value

    [environment:override]
    key=type:value

    [environment:enforce]
    key=type:value

default is applied during setup without override.
init is applied during setup with override.
override is applied before customization with override.
enforce is applied after customization with override.

type ::= none | bool | int | str | multi-str

ENVIRONMENT
-----------

Refer to README.environment

UNPRIVILEDGE EXECUTION
----------------------

Using sudo it is possible to escalate privilege. Use the following
configuration:

/etc/sudoers.d/50-otopi.conf

    Defaults:user1 !requiretty
    user1 ALL=(ALL) NOPASSWD: /bin/sh

COMPATIBILITY
-------------

- Python-2.6
- Python-2.7
- Python-3.2
  • 调用 otopi 中的 miniyum 检查是否有更新。
myum = miniyum.MiniYum(
    sink=(
        None if options.quiet
        else _MyMiniYumSink()
    ),
    disabledPlugins=('versionlock',),
)
with myum.transaction():
    myum.update(
        packages=setup_packages,
    )
    if myum.buildTransaction():
        exit = 0
......
  • 查看 otopi 系统组件的源码,可以看出 miniyum 是读取 yum 源,从 yum 仓库中判断是否有新的包。
with miniyum.transaction():
            miniyum.remove(('cman',), ignoreErrors=True)
            miniyum.install(('qemu-kvm-tools',))
            miniyum.install(('vdsm', 'vdsm-client'))
            miniyum.update(('vdsm', 'vdsm-client'))
            if miniyum.buildTransaction():
                miniyumsink.info('Transaction Summary:')
                for p in miniyum.queryTransaction():
                    miniyumsink.info('    %s - %s' % (
                        p['operation'],
                        p['display_name']
                    ))
miniyum.processTransaction()
......
def update(self, packages, **kwargs):
        """Update packages.
        Keyword arguments:
        packages -- packages to install.
        ignoreErrors - to ignore errors, will return False
        """
        return self._queue(
            'update',
            lambda h: h.available,
            self._yb.update,
            packages,
            **kwargs
)

你可能感兴趣的:(【Ovirt 笔记】engine-upgrade-check 的实现原理)