• 【云计算】之trove源码走读


    阅读trove代码

    2021-8-9

    下载完trove代码(内部叫ktrove),好开始读代码啦,希望可以加深理解trove业务,以及可以学习python这双重功效!加油!

    代码结构这样子:

     4个文件夹,以及一堆特殊文件,先上层特殊文件是干啥的

    一堆特殊文件

    setup.py

    最重要的2个setup.cfg,setup.py打包用的

     setup.py怎么写,好了,参考如下

    https://zhuanlan.zhihu.com/p/261579357

    https://zhuanlan.zhihu.com/p/276461821?utm_oi=948852089393336320

    例如下面的代码

    是用pbr打包神奇,把setup.cfg中的参数过滤出来,作为参数传入到setup.py的setup()函数中

    import setuptools
    import sys

    # In python < 2.7.4, a lazy loading of package `pbr` will break
    # setuptools if some other modules registered functions in `atexit`.
    # solution from: http://bugs.python.org/issue15881#msg170215
    try:
    import multiprocessing # noqa
    except ImportError:
    pass

    data_files = []
    if sys.platform == 'linux2':
    from glob import glob
    data_files = [("/etc/init.d", glob("etc/trove/init.d/*")),
    ("/etc/logrotate.d", glob("etc/trove/logrotate.d/*"))]

    setuptools.setup(
    setup_requires=['pbr>=2.0.0'],
    pbr=True,
    data_files=data_files,
    )

      

    setup.cfg

    好了,那么看看setup.cfg是怎么写的 ,主要是name和entry_points参数

    [metadata]
    name = trove     包名称                        
    summary = OpenStack DBaaS   
    description-file =   
        README.rst
    author = OpenStack  程序作者
    author-email = openstack-dev@lists.openstack.org  程序作者邮箱
    home-page = https://wiki.openstack.org/wiki/Trove
    classifier =
        Environment :: OpenStack
        Intended Audience :: Information Technology
        Intended Audience :: System Administrators
        License :: OSI Approved :: Apache Software License
        Operating System :: POSIX :: Linux
        Programming Language :: Python
        Programming Language :: Python :: 2
        Programming Language :: Python :: 2.7
        Programming Language :: Python :: 3
        Programming Language :: Python :: 3.5
    
    [files]
    packages =
        trove
    
    [entry_points]    关键参数,动态发现配置和插件
    console_scripts =
        ktrove-api = trove.cmd.api:main
        ktrove-taskmanager = trove.cmd.taskmanager:main
        monitor-taskmanager = trove.cmd.taskmanager:main
        trove-mgmt-taskmanager = trove.cmd.taskmanager:mgmt_main
        trove-conductor = trove.cmd.conductor:main
        ktrove-manage = trove.cmd.manage:main
        trove-guestagent = trove.cmd.guest:main
        trove-fake-mode = trove.cmd.fakemode:main
        monitor-api = trove.cmd.monapi:main
        ktrove-minister = trove.cmd.minister:main
    
    trove.api.extensions =
        account = trove.extensions.routes.account:Account
        mgmt = trove.extensions.routes.mgmt:Mgmt
        mysql = trove.extensions.routes.mysql:Mysql
        security_group = trove.extensions.routes.security_group:Security_group
    
    trove.guestagent.module.drivers =
        ping = trove.guestagent.module.drivers.ping_driver:PingDriver
        new_relic_license = trove.guestagent.module.drivers.new_relic_license_driver:NewRelicLicenseDriver
    
    # These are for backwards compatibility with Havana notification_driver configuration values
    oslo.messaging.notify.drivers =
        trove.openstack.common.notifier.log_notifier = oslo_messaging.notify._impl_log:LogDriver
        trove.openstack.common.notifier.no_op_notifier = oslo_messaging.notify._impl_noop:NoOpDriver
        trove.openstack.common.notifier.rpc_notifier2 = oslo_messaging.notify.messaging:MessagingV2Driver
        trove.openstack.common.notifier.rpc_notifier = oslo_messaging.notify.messaging:MessagingDriver
        trove.openstack.common.notifier.test_notifier = oslo_messaging.notify._impl_test:TestDriver
    
    tempest.test_plugins =
        trove_tests = trove.tests.tempest.plugin:TroveTempestPlugin
    
    [global]
    setup-hooks =
        pbr.hooks.setup_hook
    
    [build_sphinx]
    all_files = 1
    build-dir = doc/build
    source-dir = doc/source
    warning-is-error = 1
    
    [compile_catalog]
    directory = trove/locale
    domain = trove
    
    [update_catalog]
    domain = trove
    output_dir = trove/locale
    input_file = trove/locale/trove.pot
    
    [extract_messages]
    keywords = _ gettext ngettext l_ lazy_gettext
    mapping_file = babel.cfg
    output_file = trove/locale/trove.pot
    
    [wheel]
    universal = 1
    

     

    trove命令行与代码

    [entry_points]    关键参数,动态发现配置和插件
    console_scripts =
        ktrove-api = trove.cmd.api:main
        ktrove-taskmanager = trove.cmd.taskmanager:main
        monitor-taskmanager = trove.cmd.taskmanager:main
        trove-mgmt-taskmanager = trove.cmd.taskmanager:mgmt_main
        trove-conductor = trove.cmd.conductor:main
        ktrove-manage = trove.cmd.manage:main
        trove-guestagent = trove.cmd.guest:main
        trove-fake-mode = trove.cmd.fakemode:main
        monitor-api = trove.cmd.monapi:main
        ktrove-minister = trove.cmd.minister:main

    看到这里恍然大悟,打包后的模块名是ktrove-manage,在执行 ktrove-manage  param_xxx时候,其实等于调用了 trove.cmd.manage:main param_xxx

    那么我们来具体看看,平时使用的命令,是怎么执行的吧:

    例如1,  ktrove-manage flow-list   $instance_id

    例如2, trove命令创建实例:

    trove create liurong_0421_pm15 HA --flavor  RDSOpenAPI_76f7d523d28b9f66 --datastore_type ebs_sqlserver --datastore_version 2014  --admin_user admin --admin_password LIUrong123@ 

    4个文件夹

    etc-

    init-

    tools-

    trove-

    大道至简
  • 相关阅读:
    [require-js]向下滑动ajax加载的javascript实现
    Date的ToString方法
    GMAT语法总结
    流程控制语句:if、if else、if else if、嵌套if
    Random类
    Scanner类
    java运算符
    java数据类型转换
    mysql查询语句
    mysql常用语句
  • 原文地址:https://www.cnblogs.com/liurong07/p/15120371.html
Copyright © 2020-2023  润新知