您的位置:首页 > 运维架构

OpenStack Client客户端的两种身份验证方式

2014-08-12 19:10 246 查看
OpenStackClient 是 OpenStack 提供的一个命令行CLI工具. OpenStackClient支持两种身份验证方式

通过用户名/密码验证
通过Token验证

OpenStack Client项目的wiki

https://wiki.openstack.org/wiki/OpenStackClient

下面通过两个例子, 演示怎样通过这两种不同的验证方式, 使用OpenStack Client获取nova的flavor列表

通过用户名密码验证方式, 使用OpenStackClient

把用户名(os-username), 密码(os-password)和租户(os-tenant-name)作为参数, 放在命令行当中, 获取 flavor 列表.

$ openstack --debug --os-tenant-name admin --os-username admin --os-password passw0rd --os-auth-url http://127.0.0.1:5000/v2.0/ flavor list

DEBUG: openstackclient.shell volume API version 1

DEBUG: openstackclient.shell image API version 1

DEBUG: openstackclient.shell compute API version 2

DEBUG: openstackclient.shell network API version 2

DEBUG: openstackclient.shell object_store API version 1

DEBUG: openstackclient.shell command groupopenstack.compute.v2

DEBUG: openstackclient.shell command groupopenstack.network.v2

DEBUG: openstackclient.shell command groupopenstack.image.v1

DEBUG: openstackclient.shell command groupopenstack.volume.v1

DEBUG: openstackclient.shell command groupopenstack.identity.v2_0

DEBUG: openstackclient.shell command groupopenstack.object_store.v1

DEBUG: stevedore.extension found extensionEntryPoint.parse('table = cliff.formatters.table:TableFormatter')

DEBUG: stevedore.extension found extensionEntryPoint.parse('csv = cliff.formatters.commaseparated:CSVLister')

DEBUG: openstackclient.shell prepare_to_run_command ListFlavor

DEBUG: openstackclient.shell validating authenticationoptions

DEBUG: openstackclient.identity.client Instantiatingidentity client: <class'openstackclient.identity.client.IdentityClientv2_0'>

DEBUG: openstackclient.identity.client Using password auth

DEBUG: keystoneclient.auth.identity.v2 Making authenticationrequest to http://127.0.0.1:5000/v2.0/tokens
INFO: requests.packages.urllib3.connectionpool Starting newHTTP connection (1): 127.0.0.1

DEBUG: requests.packages.urllib3.connectionpool "POST/v2.0/tokens HTTP/1.1" 200 7080

DEBUG: openstackclient.compute.v2.flavor.ListFlavortake_action(Namespace(columns=[], formatter='table', max_width=0,quote_mode='nonnumeric'))

DEBUG: openstackclient.compute.client Instantiating computeclient: <class 'novaclient.v1_1.client.Client'>

REQ: curl -i'http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/detail' -XGET -H "Accept: application/json" -H "User-Agent:python-novaclient" -H "X-Auth-Project-Id: admin" -H"X-Auth-Token: {SHA1}3e4acf89dcfc1397ed3607453c40549f6cc714ad"

RESP: [200] {'date': 'Tue, 12 Aug 2014 09:28:48 GMT','content-length': '3289', 'content-type': 'application/json','x-compute-request-id': 'req-343a7a78-0671-46ef-bad5-8bcd1c3d5de6'}

RESP BODY: {"flavors": [{"name":"m1.tiny", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/1","rel": "self"}, {"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/1","rel": "bookmark"}], "ram": 512,"OS-FLV-DISABLED:disabled":
false, "vcpus": 1,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral": 0,"disk": 1, "id": "1"}, {"name":"m1.small", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/2","rel": "self"},
{"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/2","rel": "bookmark"}], "ram": 2048,"OS-FLV-DISABLED:disabled": false, "vcpus": 1,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral": 0,"disk":
20, "id": "2"}, {"name":"m1.medium", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/3","rel": "self"}, {"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/3","rel": "bookmark"}], "ram": 4096,"OS-FLV-DISABLED:disabled":
false, "vcpus": 2,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral": 0,"disk": 40, "id": "3"}, {"name":"m1.large", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/4","rel": "self"},
{"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/4","rel": "bookmark"}], "ram": 8192, "OS-FLV-DISABLED:disabled":false, "vcpus": 4, "swap": "","os-flavor-access:is_public": true, "rxtx_factor": 1.0,"OS-FLV-EXT-DATA:ephemeral": 0, "disk":
80, "id":"4"}, {"name": "m1.nano", "links":[{"href": "http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/42","rel": "self"}, {"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/42","rel": "bookmark"}], "ram": 64,"OS-FLV-DISABLED:disabled":
false, "vcpus": 1,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral": 0,"disk": 0, "id": "42"}, {"name":"m1.heat", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/451","rel":
"self"}, {"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/451","rel": "bookmark"}], "ram": 512,"OS-FLV-DISABLED:disabled": false, "vcpus": 1,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral":
0,"disk": 0, "id": "451"}, {"name":"m1.xlarge", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/5","rel": "self"}, {"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/5","rel": "bookmark"}], "ram": 16384,"OS-FLV-DISABLED:disabled":
false, "vcpus": 8, "swap":"", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral": 0,"disk": 160, "id": "5"}, {"name":"m1.micro", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/84","rel":
"self"}, {"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/84","rel": "bookmark"}], "ram": 128,"OS-FLV-DISABLED:disabled": false, "vcpus": 1,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral":
0,"disk": 0, "id": "84"}]}

+-----+-----------+-------+------+-----------+------+-------+-------------+-----------+-------------+

| ID | Name | RAM | Disk | Ephemeral | Swap | VCPUs | RXTX Factor | Is Public | ExtraSpecs |

+-----+-----------+-------+------+-----------+------+-------+-------------+-----------+-------------+

| 1 | m1.tiny | 512 | 1 | 0 | | 1 | 1.0 | True | |

| 2 | m1.small | 2048| 20 | 0 | | 1 | 1.0 | True | |

| 3 | m1.medium| 4096 | 40 | 0 | | 2 | 1.0 | True | |

| 4 | m1.large | 8192| 80 | 0 | | 4 | 1.0 | True | |

| 42 | m1.nano | 64 | 0 | 0 | | 1 | 1.0 | True | |

| 451 | m1.heat | 512 | 0 | 0 | | 1 | 1.0 | True | |

| 5 | m1.xlarge |16384 | 160 | 0 | | 8 | 1.0 | True | |

| 84 | m1.micro | 128| 0 | 0 | | 1 | 1.0 | True | |

+-----+-----------+-------+------+-----------+------+-------+-------------+-----------+-------------+

DEBUG: openstackclient.shell clean_up ListFlavor

通过Token验证方式, 使用OpenStackClient

使用用户密码做验证的缺点是, 每次都需要传递用户密码到keystone 获得新的 token. 从性能角度考虑, 可以先获取一个 token, 然后在后续的REST中反复使用, 减少和keystone的交互. 这就是token验证方式.

1) 先用curl命令, 直接与keystone交互, 获得一个PKI格式的 scope token

$ curl -s -X POST http://127.0.0.1:5000/v2.0/tokens -H "Content-Type: application/json" -H "User-Agent: python-keystoneclient" -d '{"auth":{"tenantName": "admin", "passwordCredentials":{"username": "admin", "password":"passw0rd"}}}' |
python-mjson.tool

# Partial Result

{

"token": {

"expires": "2014-08-12T09:35:52Z",

"id": "<PKI Format Token>",

"issued_at": "2014-08-12T08:35:52.154208",

"tenant": {

"description": null,

"enabled": true,

"id": "71c452812dc845e3a0ddeefed3e4c030",

"name": "admin"

}

}

………………………………………………………………………………………………………………………………………………………………………………….

}

2) 通过keystone的命令, 获取nova的的public url地址

keystone --os-username admin --os-password passw0rd --os-tenant-name admin --os-auth-url http://127.0.0.1:5000/v2.0/ endpoint-list

3) 使用在第一步中获得的token, 和第二步中获得的nova public url, 放在命令行当中, 获取flaover列表

$ openstack --debug --os-url http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030 --os-token <PKIFormat Token> flavor list

DEBUG: openstackclient.shell volume API version 1

DEBUG: openstackclient.shell image API version 1

DEBUG: openstackclient.shell compute API version 2

DEBUG: openstackclient.shell network API version 2

DEBUG: openstackclient.shell object_store API version 1

DEBUG: openstackclient.shell command groupopenstack.compute.v2

DEBUG: openstackclient.shell command groupopenstack.network.v2

DEBUG: openstackclient.shell command groupopenstack.image.v1

DEBUG: openstackclient.shell command groupopenstack.volume.v1

DEBUG: openstackclient.shell command groupopenstack.identity.v2_0

DEBUG: openstackclient.shell command groupopenstack.object_store.v1

DEBUG: stevedore.extension found extensionEntryPoint.parse('table = cliff.formatters.table:TableFormatter')

DEBUG: stevedore.extension found extensionEntryPoint.parse('csv = cliff.formatters.commaseparated:CSVLister')

DEBUG: openstackclient.shell prepare_to_run_commandListFlavor

DEBUG: openstackclient.shell validating authenticationoptions

DEBUG: openstackclient.identity.client Instantiatingidentity client: <class 'openstackclient.identity.client.IdentityClientv2_0'>

DEBUG: openstackclient.identity.client Using token auth

DEBUG: openstackclient.compute.v2.flavor.ListFlavortake_action(Namespace(columns=[], formatter='table', max_width=0,quote_mode='nonnumeric'))

DEBUG: openstackclient.compute.client Instantiating computeclient: <class 'novaclient.v1_1.client.Client'>

REQ: curl -i'http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/detail' -XGET -H "Accept: application/json" -H "User-Agent:python-novaclient" -H "X-Auth-Token: {SHA1}974a51f0ff97e3cc387c6f497236607238a5476c"

RESP: [200] {'date': 'Tue, 12 Aug 2014 09:26:21 GMT','content-length': '3289', 'content-type': 'application/json','x-compute-request-id': 'req-6987bea6-5878-4291-93f9-dd3bf9debbdb'}

RESP BODY: {"flavors": [{"name":"m1.tiny", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/1","rel": "self"}, {"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/1","rel": "bookmark"}], "ram": 512,"OS-FLV-DISABLED:disabled":
false, "vcpus": 1,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral": 0,"disk": 1, "id": "1"}, {"name":"m1.small", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/2","rel": "self"},
{"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/2","rel": "bookmark"}], "ram": 2048,"OS-FLV-DISABLED:disabled": false, "vcpus": 1,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral": 0,"disk":
20, "id": "2"}, {"name":"m1.medium", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/3","rel": "self"}, {"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/3","rel": "bookmark"}], "ram": 4096,"OS-FLV-DISABLED:disabled":
false, "vcpus": 2,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral": 0,"disk": 40, "id": "3"}, {"name":"m1.large", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/4","rel": "self"},
{"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/4","rel": "bookmark"}], "ram": 8192,"OS-FLV-DISABLED:disabled": false, "vcpus": 4,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral": 0,"disk":
80, "id": "4"}, {"name":"m1.nano", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/42","rel": "self"}, {"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/42","rel": "bookmark"}], "ram": 64,"OS-FLV-DISABLED:disabled":
false, "vcpus": 1,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral": 0,"disk": 0, "id": "42"}, {"name":"m1.heat", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/451","rel":
"self"}, {"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/451","rel": "bookmark"}], "ram": 512,"OS-FLV-DISABLED:disabled": false, "vcpus": 1,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral":
0,"disk": 0, "id": "451"}, {"name":"m1.xlarge", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/5","rel": "self"}, {"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/5","rel": "bookmark"}], "ram": 16384,"OS-FLV-DISABLED:disabled":
false, "vcpus": 8,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral": 0,"disk": 160, "id": "5"}, {"name":"m1.micro", "links": [{"href":"http://127.0.0.1:8774/v2/71c452812dc845e3a0ddeefed3e4c030/flavors/84","rel":
"self"}, {"href":"http://127.0.0.1:8774/71c452812dc845e3a0ddeefed3e4c030/flavors/84","rel": "bookmark"}], "ram": 128,"OS-FLV-DISABLED:disabled": false, "vcpus": 1,"swap": "", "os-flavor-access:is_public": true,"rxtx_factor": 1.0, "OS-FLV-EXT-DATA:ephemeral":
0,"disk": 0, "id": "84"}]}

+-----+-----------+-------+------+-----------+------+-------+-------------+-----------+-------------+

| ID | Name | RAM | Disk | Ephemeral | Swap | VCPUs | RXTX Factor | Is Public | ExtraSpecs |

+-----+-----------+-------+------+-----------+------+-------+-------------+-----------+-------------+

| 1 | m1.tiny | 512 | 1 | 0 | | 1 | 1.0 | True | |

| 2 | m1.small | 2048| 20 | 0 | | 1 | 1.0 | True | |

| 3 | m1.medium| 4096 | 40 | 0 | | 2 | 1.0 | True | |

| 4 | m1.large | 8192| 80 | 0 | | 4 | 1.0 | True | |

| 42 | m1.nano | 64 | 0 | 0 | | 1 | 1.0 | True | |

| 451 | m1.heat | 512 | 0 | 0 | | 1 | 1.0 | True | |

| 5 | m1.xlarge |16384 | 160 | 0 | | 8 | 1.0 | True | |

| 84 | m1.micro | 128| 0 | 0 | | 1 | 1.0 | True | |

+-----+-----------+-------+------+-----------+------+-------+-------------+-----------+-------------+

DEBUG: openstackclient.shell clean_up ListFlavor
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: