{ "info": { "author": "Lingxian Kong", "author_email": "anlin.kong@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Environment :: OpenStack", "Intended Audience :: Developers", "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" ], "description": "# python-cliclient\nA python CLI client example using python-openstackclient plugin mechanism.\n\n## \u8fd8\u662f\u9700\u8981 python-openstackclient\n\n\u9996\u5148\uff0copenstack client\u662f\u7528[cliff](http://docs.openstack.org/developer/cliff/)\u5b9e\u73b0\uff0c\u6240\u4ee5\u5efa\u8bae\u5148\u719f\u8bfbcliff\u7684\u5b98\u65b9\u6587\u6863\uff0c\u77e5\u9053cliff\u7684\u5b9e\u73b0\u673a\u5236\uff0c\u8fd9\u6837\u624d\u80fd\u5bf9openstack client\u7684\u673a\u5236\u6709\u4e86\u89e3\uff0c\u8fd9\u662f\u719f\u6089openstack client\u7684\u57fa\u7840\u3002\u5982\u679c\u4f60\u4e0d\u662f\u4e3a\u4e86\u5b9e\u73b0 openstack \u547d\u4ee4\uff0c\u53ef\u4ee5\u8df3\u8fc7\u6b64\u6587\u76f4\u63a5\u53c2\u8003 cliff \u7ed9\u51fa\u7684\u4e00\u4e2a[\u793a\u4f8b](https://docs.openstack.org/cliff/latest/user/demoapp.html)\u7167\u732b\u753b\u864e\u5373\u53ef\u3002\n\ncliff \u4e2d App \u521d\u59cb\u5316\u65f6\uff0c\u521d\u59cb\u5316\u53c2\u6570 `command_manager=CommandManager('cliff.demo')` \u544a\u8bc9\u4f60\uff0c\u547d\u4ee4\u90fd\u5728 setup.cfg \u4e2d\u7684 `cliff.demo` \u547d\u540d\u7a7a\u95f4\u4e2d\u5b9a\u4e49\u3002\n\n\u4eceOSC 2.4.0\u7248\u672c\u4ee5\u540e\uff0c\u4eceopenstack client\u53c8\u63d0\u53d6\u51fa\u4e00\u4e2a\u53ebosc-lib\u7684\u53ef\u91cd\u7528\u7684\u5e93\uff0c\u65b0\u7684plugin\u53ef\u4ee5\u7ee7\u627f\u8fd9\u4e2aosc-lib\u6765\u96c6\u6210openstack\u547d\u4ee4\uff0c\u4f46\u662fplugin\u7684\u52a0\u8f7d\u8fd8\u662f\u7531openstack client\u6765\u5b8c\u6210\u3002\u4ece\u8bbe\u8ba1\u5c42\u6b21\u4e0a\u8bb2\uff0cosc-lib\u7ee7\u627f\u81eacliff\uff0c\u800copenstack client\u548c\u5176\u4ed6\u7684extension\u5176\u5b9e\u662f\u5e73\u7ea7\u7ed3\u6784\uff0c\u90fd\u7ee7\u627f\u81eaosc-lib\uff0c\u53ea\u662f\u7531openstack client\u5165\u53e3\u800c\u5df2\u3002\n\n> \u6240\u4ee5\uff0c\u4f60\u81ea\u5df1\u7684 CLI \u547d\u4ee4\u8981\u751f\u6548\uff0c\u8fd8\u9700\u8981\u4f9d\u8d56 python-openstackclient\uff0c\u56e0\u4e3a CLI \u4e2d\u7684 openstack \u547d\u4ee4\u662f\u5b89\u88c5\u5b8c python-openstackclient \u540e\u624d\u6709\u3002\n\n## python-openstackclient \u90fd\u505a\u4e86\u4ec0\u4e48\n\n\u5165\u53e3\u5728 `openstackclient.shell:main`\n\nOpenStackShell \u7c7b\u6700\u7ec8\u7ee7\u627f\u81ea cliff \u4e2d\u7684 App\u3002python-openstackclient \u7684\u5b9e\u73b0\u4e4b\u6240\u4ee5\u590d\u6742\uff0c\u662f\u56e0\u4e3a\u5b83\u9664\u4e86\u626e\u6f14 CLI \u603b\u5165\u53e3\u7684\u8d23\u4efb\u5916\uff0c\u8fd8\u9700\u8981\u4e3a\u5176\u4ed6 plugin \u63d0\u4f9b\u652f\u6301\uff0c\u627f\u62c5\u4e00\u4e9b\u516c\u5171\u4e8b\u52a1\uff08\u6bd4\u5982 keystone \u9274\u6743\uff09\uff0c\u8ba9 plugin \u53ea\u9700\u8981\u5173\u6ce8\u81ea\u5df1\u7684\u4e1a\u52a1\u5b9e\u73b0\u3002\n\n\u6240\u4ee5\uff0c\u5f53\u4f60\u5728 CLI \u4e0b\u6bcf\u6b21\u6267\u884c openstack \u547d\u4ee4\u65f6\uff0cpython-openstackclient \u90fd\u4f1a\u52a8\u6001\u7684[\u52a0\u8f7d](https://github.com/openstack/python-openstackclient/blob/cc47c075a067e3f4f3bb80dd933cdd4d483b8105/openstackclient/common/clientmanager.py#L131)\u7cfb\u7edf\u4e2d\u6240\u6709\u5df2\u6ce8\u518c\u7684 plugin\uff0c\u6839\u636e\u7ea6\u5b9a\u597d\u7684\u89c4\u5219\uff0c\u83b7\u53d6\u5b83\u4eec\u7684\u540d\u5b57\uff0c\u7248\u672c\uff0c\u547d\u4ee4\u884c\u53c2\u6570\u7b49\uff0c\u5e76\u628a\u8fd9\u4e9b plugin module \u6ce8\u518c\u5230 osc-lib \u7684 clientmanager.ClientManager \u7c7b\u4e2d\uff0c\u5c5e\u6027\u540d\u7531 `API_NAME` \u5b9a\u4e49\uff0c\u5c5e\u6027\u7684\u503c\u662f\u4e00\u4e2a[\u63cf\u8ff0\u7b26\u5bf9\u8c61](https://lingxiankong.github.io/2014-03-28-python-descriptor.html)\uff0c\u88ab\u8bbf\u95ee\u65f6\u4f1a\u83b7\u53d6\u51fd\u6570 `def make_client(instance)` \u7684\u8fd4\u56de\u503c\uff0c\u5176\u4e2d\u7684 instance \u5c31\u662f\u4e00\u4e2a clientmanager.ClientManager \u5b9e\u4f8b\u3002\n\n\u5728 `initialize_app` \u51fd\u6570\u6267\u884c\u65f6\uff0c\u547d\u4ee4\u884c\u53c2\u6570\u5df2\u7ecf\u7ecf\u8fc7\u89e3\u6790\u3002\u6b64\u65f6\uff0c\u9664\u4e86 OpenStackShell \u521d\u59cb\u5316\u65f6 command_manager \u53c2\u6570\u6307\u5b9a\u7684\u547d\u540d\u7a7a\u95f4\uff0c\u5728\u8fd9\u91cc\u8fd8\u6709\u673a\u4f1a\u518d\u6ce8\u518c\u5176\u4ed6\u547d\u4ee4\u3002\u5404\u4e2a openstack plugin \u547d\u4ee4\u5c31\u662f\u5728\u6b64\u65f6\u6ce8\u518c\u3002\n\n\u5728 `prepare_to_run_command` \u51fd\u6570\u4e2d\u4e3b\u8981\u662f\u5b9e\u4f8b\u5316 clientmanager.ClientManager\uff0c\u5982\u679c `command.auth_required = True` \u5219\u8fdb\u884c\u9274\u6743\u64cd\u4f5c\uff0c\u56e0\u4e3a\u5927\u5bb6\u5728\u4f7f\u7528\u547d\u4ee4\u884c\u65f6\uff0c\u540c\u6837\u7684\u4e24\u4e2a\u547d\u4ee4\uff0c\u4f20\u9012\u7684\u9274\u6743\u4fe1\u606f\u4f1a\u4e0d\u4e00\u6837\uff0c\u56e0\u6b64\u5fc5\u987b\u5728\u6bcf\u4e2a\u547d\u4ee4\u6267\u884c\u524d\u8fdb\u884c\u9274\u6743\u3002\u6240\u4ee5 ClientManager \u5bf9\u8c61\u4fdd\u5b58\u4e86\u9274\u6743\u4fe1\u606f\u3002\n\n\u901a\u8fc7openstack client\u5de5\u7a0b\u7684setup.cfg\u53ef\u4ee5\u770b\u51fa\uff0copenstack client\u9ed8\u8ba4\u96c6\u6210\u4e86Nova, Keystone, Glance, Neutron, Swift, Cinder\u8fd96\u4e2a\u9879\u76ee\uff08\u5728openstack.cli.base\u547d\u540d\u7a7a\u95f4\u4e2d\uff09\uff0c\u540c\u65f6\uff0c\u4ecesetup.cfg\u4e2d\u4e5f\u53ef\u4ee5\u770b\u5230\uff0copenstack client\u6709\u4e24\u4e2a\u5168\u5c40\u7684\u547d\u4ee4\uff0c\u5206\u522b\u662fopenstack command list\u548copenstack module list\uff08\u5728openstack.cli\u547d\u540d\u7a7a\u95f4\u4e2d\uff09\uff0c\u7528\u4ee5\u67e5\u8be2\u52a0\u8f7d\u7684\u6a21\u5757\u548c\u652f\u6301\u7684\u547d\u4ee4\u5217\u8868\u3002\n\n\u6700\u7ec8\uff0c\u5728command\u5904\u7406\u65f6\uff0c\u6bd4\u5982\u547d\u4ee4\u884c\uff1aopenstack compute agent list\uff0c\u4f1a\u8c03\u7528`self.app.client_manager.compute.agents.list`\u5904\u7406\u3002\u8fd8\u8bb0\u5f97\u90a3\u4e2aClientManager\u7c7b\u53d8\u91cf\u4e48\uff1fcompute\u5c31\u662f\u7c7b\u53d8\u91cf\u4e4b\u4e00\uff0c\u5f53\u8bbf\u95eeclientmanager.compute\u65f6\uff0c\u5c31\u4f1a\u8c03\u7528openstackclient.compute.client\u63d0\u4f9b\u7684`make_client`\u65b9\u6cd5\uff0c\u4f20\u5165clientmanager\u5bf9\u8c61\u3002\n\n## \u4f60\u7684 client \u9700\u8981\u505a\u4ec0\u4e48\n\n\u6839\u636e\u4e0a\u8ff0\u7684\u8fc7\u7a0b\uff0cpython-openstackclient \u628a\u8be5\u505a\u7684\u90fd\u505a\u4e86\uff0c\u4f60\u53ea\u9700\u8981\u6309\u7167\u7ea6\u5b9a\u586b\u7a7a\u5373\u53ef\u3002\n\n1. setup.cfg\n \u4f60\u9700\u8981\u5b9a\u4e49\uff1a\n\n ```python\n openstack.cli.extension =\n runit = mycli.osc.plugin\n openstack.runit.v1 =\n runit_echo = mycli.echo:Echo\n ```\n\n \u8ba9 python-openstackclient \u627e\u5230\u4f60\u7684 plugin \u5b9a\u4e49\u3002\n\n2. \u5728 `mycli/osc/plugin.py` \u6587\u4ef6\u4e2d\uff0c\u6309\u7167[\u8fd9\u91cc](https://github.com/openstack/python-openstackclient/blob/cc47c075a067e3f4f3bb80dd933cdd4d483b8105/openstackclient/shell.py#L68)\u7684\u4ee3\u7801\u6d41\u7a0b\u5b9a\u4e49\u4e00\u4e9b\u53d8\u91cf\u3002\u6bd4\u5982\uff1a\n\n - `API_NAME`\uff0c\u4f60\u7684 plugin \u540d\u5b57\uff0c\u6bd4\u5982 runit\n - `API_VERSION_OPTION`\uff0c\u6bd4\u5982 `os_runit_version`\n - `DEFAULT_API_VERSION`\uff0c\u6bd4\u5982 1\uff0c\u8fd9\u4e2a\u53d8\u91cf\u6700\u597d\u5b9a\u4e49\uff0c\u5426\u5219\u4f60\u7684 command \u4e0d\u4f1a\u751f\u6548\u3002\u6700\u7ec8\uff0c\u6839\u636e\u5b57\u7b26\u4e32\u62fc\u63a5\u4f1a\u6ce8\u518c\u547d\u540d\u7a7a\u95f4 `openstack.runit.v1` \u4e0b\u7684 commands\n\n3. \u5982\u679c runit \u8fd9\u4e2a\u7a0b\u5e8f\u4e0d\u662f\u4e00\u4e2a openstack service client\uff0c\u5c31\u6ca1\u6709\u5fc5\u8981\u5b9e\u73b0 `make_client` \u65b9\u6cd5\u3002\n\n4. \u5728 `mycli/echo.py` \u6587\u4ef6\u4e2d\uff1a\n\n ```python\n from osc_lib.command import command\n\n\n class Echo(command.Command):\n auth_required = False\n\n def get_parser(self, prog_name):\n parser = super(Echo, self).get_parser(prog_name)\n parser.add_argument(\n '-m', '--message', default='Hello, World!', help='Echo message.'\n )\n return parser\n\n def take_action(self, parsed_args):\n print(parsed_args.message)\n ```\n\n5. \u5b89\u88c5\u548c\u8bd5\u7528\u3002\n\n ```shell\n $ mkvirtualenv openstack\n $ cd ~/code/python-cliclient\n $ pip install -e .\n $ openstack runit echo\n Hello, World!\n ```\n\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "", "license": "Apache License, Version 2.0", "maintainer": "", "maintainer_email": "", "name": "python-cliclient", "package_url": "https://pypi.org/project/python-cliclient/", "platform": "", "project_url": "https://pypi.org/project/python-cliclient/", "project_urls": null, "release_url": "https://pypi.org/project/python-cliclient/1.0.0/", "requires_dist": [ "pbr (!=2.1.0,>=2.0.0)", "python-openstackclient (>=3.12.0)" ], "requires_python": "", "summary": "python-cliclient", "version": "1.0.0" }, "last_serial": 3480715, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "36b4cc5fd1c33cce7ed5d64a74f14fd2", "sha256": "b96ac70a672d23affce04da86f0fa097650bef0abef2146966bc8e036db52383" }, "downloads": -1, "filename": "python_cliclient-1.0.0-py2-none-any.whl", "has_sig": false, "md5_digest": "36b4cc5fd1c33cce7ed5d64a74f14fd2", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 10457, "upload_time": "2018-01-11T12:46:33", "url": "https://files.pythonhosted.org/packages/1d/42/a1fbadd401a2e1f154e41eb6ebdd3bf0c0807ac62803ad2934da209d0557/python_cliclient-1.0.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4683cec8b0ee44f31581669e57fa39a0", "sha256": "18ccb106e9630a54c434333b8812cc3b2a4d58992379b22cd4d86573dc3d9b1c" }, "downloads": -1, "filename": "python-cliclient-1.0.0.tar.gz", "has_sig": false, "md5_digest": "4683cec8b0ee44f31581669e57fa39a0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9693, "upload_time": "2018-01-11T12:46:35", "url": "https://files.pythonhosted.org/packages/12/2b/bbbc6c372876c2317b97111ec2c50a248220b7c68b85efb9239809f7b33a/python-cliclient-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "36b4cc5fd1c33cce7ed5d64a74f14fd2", "sha256": "b96ac70a672d23affce04da86f0fa097650bef0abef2146966bc8e036db52383" }, "downloads": -1, "filename": "python_cliclient-1.0.0-py2-none-any.whl", "has_sig": false, "md5_digest": "36b4cc5fd1c33cce7ed5d64a74f14fd2", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 10457, "upload_time": "2018-01-11T12:46:33", "url": "https://files.pythonhosted.org/packages/1d/42/a1fbadd401a2e1f154e41eb6ebdd3bf0c0807ac62803ad2934da209d0557/python_cliclient-1.0.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4683cec8b0ee44f31581669e57fa39a0", "sha256": "18ccb106e9630a54c434333b8812cc3b2a4d58992379b22cd4d86573dc3d9b1c" }, "downloads": -1, "filename": "python-cliclient-1.0.0.tar.gz", "has_sig": false, "md5_digest": "4683cec8b0ee44f31581669e57fa39a0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9693, "upload_time": "2018-01-11T12:46:35", "url": "https://files.pythonhosted.org/packages/12/2b/bbbc6c372876c2317b97111ec2c50a248220b7c68b85efb9239809f7b33a/python-cliclient-1.0.0.tar.gz" } ] }