nova --debug list
1. 在已经配置好环境变量的终端中,调用过程,可见首先经过认证过程,在获取合法得token之后调用Nova API 中server/detail来获取各个server list.
park@park-ThinkPad-T420:~/openstack/devstack$ nova --debug list
DEBUG (session:186) REQ: curl -g -i --cacert "/opt/stack/data/CA/int-ca/ca-chain.pem" -X GET http://localhost:5000/v2.0 -H "Accept: application/json" -H "User-Agent: python-keystoneclient"
RESP BODY: {"version": {"status": "stable", "updated": "2014-04-17T00:00:00Z", "media-types": [{"base": "application/json", "type": "application/vnd.openstack.identity-v2.0+json"}], "id": "v2.0", "links": [{"href": "http://localhost:5000/v2.0/", "rel": "self"}, {"href": "http://docs.openstack.org/", "type": "text/html", "rel": "describedby"}]}}
DEBUG (session:186) REQ: curl -g -i --cacert "/opt/stack/data/CA/int-ca/ca-chain.pem" -X GET http://xxxxx:8774/v2/e46fc3bb07da4987831fc4fe65d532ea/servers/detail -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-Auth-Token: {SHA1}067cafad6460a7d21af1f66c4711c78d666d6866"
RESP BODY: {"servers": []}
+----+------+--------+------------+-------------+----------+
| ID | Name | Status | Task State | Power State | Networks |
+----+------+--------+------------+-------------+----------+
+----+------+--------+------------+-------------+----------+
2. novaclient在哪里呢?他是怎么运行起来的呢?代码是最好的答案。
$ vim /usr/local/bin/nova
1 #!/usr/bin/python
2
3 # -*- coding: utf-8 -*-
4 import re
5 import sys
6
7 from novaclient.shell import main
8 ...
见第7行,继续追踪novaclient.shell.main
$ vim /home/park/python-novaclient/novaclient/shell.py,
813 def main():
814 try:
815 argv = [encodeutils.safe_decode(a) for a in sys.argv[1:]]
816 OpenStackComputeShell().main(argv)
816行,继续找这个main method, 还好继续在这个文件中....
516 def main(self, argv):
517 # Parse args once to find version and debug settings
518 parser = self.get_base_parser()
519 (options, args) = parser.parse_known_args(argv)
520 self.setup_debugging(options.debug)...
靠谱了,开始解析变量和参数了。没错,这里就是novaclient真正的入口。
按照上面的调用关系,我关心两个问题:
1. novaclient是如何根据环境变量和参数进行用户认证的?
2. novaclient各种具体命令是如何和nova API进行交互的呢?
第一个用户认证问题这里不想详细描述,有兴趣同学可以利用下面命令逐一测试
在一个未设置相关环境变量得终端中输入
$ nova --debug --os-username abc --os-project-name 123 --os-auth-url http://localhost:5000/v2.0 list
正常情况下应该会有如下错误,不再一一阐述。
Namespace(all_tenants=0, bypass_url='', debug=True, deleted=False, endpoint_type='publicURL', fields=None, flavor=None, func=<function do_list at 0x7fa3fd8856e0>, help=False, host&#