了解和使用keystone(六)创建service和endpoint

前面的都是用户归属的关系,而service则是用户可以获取什么服务,endpoint则是服务位于那个访问点。一个service可以有多个endpoint,这很好理解,主备,负载均衡。

创建Service

下面的命令使用了环境变量,可以将设定OS_USERNAME以及OS_PASSWORD。

$ openstack service create --name demo-service --description "Demo Services" demo-type
 +-------------+----------------------------------+
 | Field       | Value                            |
 +-------------+----------------------------------+
 | description | Demo Services                    |
 | enabled     | True                             |
 | id          | 654dd649b03e448e9000dc6a8356d9e7 |
 | name        | demo-service                     |
 | type        | demo-type                        |
 +-------------+----------------------------------+

创建service的enpoint

$ openstack endpoint create demo-service internal http://localhost:8080/ep1
 +--------------+----------------------------------+
 | Field        | Value                            |
 +--------------+----------------------------------+
 | enabled      | True                             |
 | id           | 1fe7dd72d4e348b6807ee5dfc40625d6 |
 | interface    | internal                         |
 | region       | None                             |
 | region_id    | None                             |
 | service_id   | 654dd649b03e448e9000dc6a8356d9e7 |
 | service_name | demo-service                     |
 | service_type | demo-type                        |
 | url          | http://localhost:8080/ep1        |
 +--------------+----------------------------------+
$ openstack endpoint create demo-service internal http://localhost:8080/ep2
 +--------------+----------------------------------+
 | Field        | Value                            |
 +--------------+----------------------------------+
 | enabled      | True                             |
 | id           | 13f0ad36b94246e7ad28def1e90f56e5 |
 | interface    | internal                         |
 | region       | None                             |
 | region_id    | None                             |
 | service_id   | 654dd649b03e448e9000dc6a8356d9e7 |
 | service_name | demo-service                     |
 | service_type | demo-type                        |
 | url          | http://localhost:8080/ep2        |
 +--------------+----------------------------------+

在创建endpoint中有参数region,可以提供地域信息,user选择合适地域的服务。

获取service和enpoint信息

在获取token的时候,可以获取相关的信息,service位于catalog。

curl  -d @token-request.json -H "Content-type: application/json" http://localhost:35357/v3/auth/tokens | python -mjson.tool
 或者 curl  -H "X-Auth-Token:$USER_TOKEN" -H "X-Subject-Token:$USER_TOKEN" -H "Content-type: application/json" http://localhost:35357/v3/auth/tokens | python -mjson.tool

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1385  100   939  100   446   1381    656 --:--:-- --:--:-- --:--:--  1380
{
    "token": {
        "audit_ids": [
            "MQP0pIajQdi2L_02ifzeZw"
        ],
        "catalog": [
            {
                "endpoints": [
                    {
                        "id": "13f0ad36b94246e7ad28def1e90f56e5",
                        "interface": "internal",
                        "region": null,
                        "region_id": null,
                        "url": "http://localhost:8080/ep2"
                    },
                    {
                        "id": "1fe7dd72d4e348b6807ee5dfc40625d6",
                        "interface": "internal",
                        "region": null,
                        "region_id": null,
                        "url": "http://localhost:8080/ep1"
                    }
                ],
                "id": "654dd649b03e448e9000dc6a8356d9e7",
                "name": "demo-service",
                "type": "demo-type"
            }
        ],
        "expires_at": "2016-09-06T04:14:13.313439Z",
        "issued_at": "2016-09-06T03:14:13.313439Z",
        "methods": [
            "password"
        ],
        "project": {
            "domain": {
                "id": "32b54ffdebe84eba9cd10a8dbe647b70",
                "name": "demo-domain"
            },
            "id": "b65e9985801f4481bce7ba885b68cac3",
            "name": "project-A"
        },
        "roles": [
            {
                "id": "6abf3532fce440148a7f29abc7685142",
                "name": "demo-role"
            }
        ],
        "user": {
            "domain": {
                "id": "32b54ffdebe84eba9cd10a8dbe647b70",
                "name": "demo-domain"
            },
            "id": "459c2cc894844396bec6c16fbc28da87",
            "name": "userA2"
        }
    }
}

你可能感兴趣的:(了解和使用keystone(六)创建service和endpoint)