由于担心图片可能会丢失,当前使用的数据包括cli命令行拷贝(格式可能有点乱),以及cli命令行的截图显示
1. Bilean的简单使用
1.1. 获取当前用户
# bilean user-list
+----------------------------------+----------+---------+--------+------+--------+
| id | name | balance | credit | rate | status |
+----------------------------------+----------+---------+--------+------+--------+
|242e11d1e9ad49b8923bfe728837f192 | services | 0.00 | 0 | 0.00 | INIT |
|78b77c5903f0400dbc34ef280b68f4d9 | admin | -37.41 | 0 | 0.00 | ACTIVE |
|88179b858e7842e79c83777abb15150e | demo | 0.00 | 0 | 0.00 | INIT |
| a3dd90aff7174c3e8514b23a2347525c| lyh | 110.00 | 0 | 0.00 | FREE |
+----------------------------------+----------+---------+--------+------+--------+
这里的每一个账号对应的是keystone的一个项目
id: 为keystone 项目的id
balance: 为用户的余额
credit:用户的信用等级,暂时没看出在这个项目有啥用,可能需要其他项目关联
rate:使用费用,这个在数据库中的字段是有值的,是指这个用户下创建的资源每秒产生的费用,但是在cli命令行没有展示出来,可能是个bug
status:INIT初始从openstack同步项目的时候的状态
FREE 充钱后变成的状态
ACTIVE 创建资源后的状态
WARNING 费用即将不足的状态,这个可能需要其他模块的联动,当前及时欠费了,也还是ACTIVE
FREEZE 冻结状态,可能欠费后的状态,并且查看代码,欠费后会删除虚拟机。
1.2. 给账号充值
# bilean user-rechargea3dd90aff7174c3e8514b23a2347525c -v 100
+---------------+----------------------------------+
| Property | Value |
+---------------+----------------------------------+
| balance | 210.00 |
| created_at | 2017-07-06T02:39:47 |
| credit | 0 |
| deleted_at | None |
| id | a3dd90aff7174c3e8514b23a2347525c|
| last_bill | 0.00 |
| name | lyh |
| policy_id | None |
| rate | 0.00 |
| status | FREE |
| status_reason | Recharged |
| updated_at | 2017-07-06T03:16:49 |
+---------------+----------------------------------+
1.3. 查看用户信息
# bilean user-showa3dd90aff7174c3e8514b23a2347525c
+---------------+----------------------------------+
| Property | Value |
+---------------+----------------------------------+
| balance | 210.00 |
| created_at | 2017-07-06T02:39:47 |
| credit | 0 |
| deleted_at | None |
| id | a3dd90aff7174c3e8514b23a2347525c|
| last_bill | 0.00 |
| name | lyh |
| policy_id | None |
| rate | 0.00 |
| status | FREE |
| status_reason | Recharged |
| updated_at | 2017-07-07T01:55:43 |
+---------------+----------------------------------+
1.4. 创建rule
# curl -X POST -H "X-Auth-Token:1" -H'Content-type: application/json' -v http://127.0.0.1:8770/v1/rules -d \
'{"rule":
{
"name": "nova_instance_rule",
"spec": {"type": "os.nova.server",
"version":"1",
"properties":{"price_mapping": [{"flavor":"1","price": 10},{"flavor":"2", "price":20},{"flavor":"3", "price": 30}],"unit":"per_hour"}
},
"metadata": {}
}
}'
说明:token的值请自己从环境上获取
1.5. 查看rule列表
# bilean rule-list
+--------------------------------------+--------------------+------------------+---------------------+
| id | name | type | created_at |
+--------------------------------------+--------------------+------------------+---------------------+
| beec51ec-b070-4335-afd0-f66b925357a7 |nova_instance_rule | os.nova.server-1 | 2017-07-06T07:45:46 |
+--------------------------------------+--------------------+------------------+---------------------+
1.6. 查看具体rule
# bilean rule-showbeec51ec-b070-4335-afd0-f66b925357a7
+------------+----------------------------------------+
| Property | Value |
+------------+----------------------------------------+
| created_at | 2017-07-06T07:45:46 |
| deleted_at | None |
| id | beec51ec-b070-4335-afd0-f66b925357a7 |
| metadata | {} |
| name | nova_instance_rule |
| spec | +------------+-----------------------+ |
| | | property | value | |
| | +------------+-----------------------+ |
| | | properties | { | |
| | | | "price_mapping": [ | |
| | | | { | |
| | | | "flavor": "1", | |
| | | | "price": 10 | |
| | | | }, | |
| | | | { | |
| | | | "flavor": "2", | |
| | | | "price": 20 | |
| | | | }, | |
| | | | { | |
| | | | "flavor": "3", | |
| | | | "price": 30 | |
| | | | } | |
| | | | ], | |
| | | | "unit": "per_hour" | |
| | | | } | |
| | | type |os.nova.server | |
| | | version | 1 | |
| | +------------+-----------------------+ |
| type | os.nova.server-1 |
| updated_at | None |
+------------+----------------------------------------+
1.7. 创建policy
# curl -X POST -H "X-Auth-Token:1" -H'Content-type: application/json' -v http://127.0.0.1:8770/v1/policies -d \
'{"policy":
{
"name": "nova_instance_policy",
"rules":["beec51ec-b070-4335-afd0-f66b925357a7"],
"metadata": {}
}
}'
说明:token的值请自己从环境上获取
1.8. 查询policy列表
bilean policy-list
+--------------------------------------+----------------------+------------+---------------------+
| id | name | is_default | created_at |
+--------------------------------------+----------------------+------------+---------------------+
| 165ed790-4cbf-418a-94e7-b6cb806f24f0 | nova_instance_policy| True | 2017-07-06T07:55:56 |
+--------------------------------------+----------------------+------------+---------------------+
说明:当前尚未深入阅读代码,这里只是简单说下。第一个创建的策略为默认策略,如果用户没有绑定任何策略,则使用默认策略,如果用户绑定了具体的策略,则使用该用户定制化的策略。
1.9. 查询具体policy
# bilean policy-show165ed790-4cbf-418a-94e7-b6cb806f24f0
+------------+----------------------------------------------------------------------------------+
| Property | Value |
+------------+----------------------------------------------------------------------------------+
| created_at | 2017-07-06T07:55:56 |
| deleted_at | None |
| id | 165ed790-4cbf-418a-94e7-b6cb806f24f0 |
| is_default | True |
| metadata | {} |
| name | nova_instance_policy |
| rules | [{u'type': u'os.nova.server-1', u'id':u'beec51ec-b070-4335-afd0-f66b925357a7'}] |
| updated_at | None |
+------------+----------------------------------------------------------------------------------+
1.10. 停掉ceilometer-notification
如果环境上部署了ceilometer,需要将 notification消息队列停止,否则bilean会与抢事件,并且相关的nova需要开启事件通知功能
1. nova.conf
[DEFAULT]
control_exchange=nova
[oslo_messaging_notifications]
driver=messagingv2
topics=notifications
2.停止ceilometer notification
# systemctl stopopenstack-ceilometer-notification.service
1.11. 创建虚拟机
创建一个flavor id 为1的虚拟机,使用的是id,不是flavor的name
1.12. 登陆bilean的数据库
MariaDB [bilean]> select * fromresource;
+--------------------------------------+----------------------------------+--------------------------------------+----------------+---------------------+-------------------------------------------------------------+------------+---------------------+------------+------------+
| id |user_id |rule_id |resource_type | last_bill | properties | rate | created_at | updated_at | deleted_at |
+--------------------------------------+----------------------------------+--------------------------------------+----------------+---------------------+-------------------------------------------------------------+------------+---------------------+------------+------------+
| a7c6c4bd-9a00-4cfe-935a-e6e10d00a2e4 |78b77c5903f0400dbc34ef280b68f4d9 | beec51ec-b070-4335-afd0-f66b925357a7 |os.nova.server | 1499327971.64055109 | {"created_at":"2017-07-06T07:59:31.640551", "flavor": "1"} |0.00277778 | 2017-07-06 07:59:32 | NULL | NULL |
+--------------------------------------+----------------------------------+--------------------------------------+----------------+---------------------+-------------------------------------------------------------+------------+---------------------+------------+------------+
查询虚拟机
# nova list
+--------------------------------------+-------------+--------+------------+-------------+---------------------+
| ID | Name | Status | Task State | Power State |Networks |
+--------------------------------------+-------------+--------+------------+-------------+---------------------+
| a7c6c4bd-9a00-4cfe-935a-e6e10d00a2e4 |bliean-test | ACTIVE | - |Running | public=172.24.4.230 |
+--------------------------------------+-------------+--------+------------+-------------+---------------------+
可以看到 resource中的id即为虚拟机的id
last_bill 为初始时间
rate 是每秒的费用(10.0/3600= 0.00277778)
1.13. 获取统计信息
统计资源到现在的用的费用
# curl -X GET -H "X-Auth-Token:1" -H'Content-type: application/json' -v http://127.0.0.1:8770/v1/consumptions/statistics
{"statistics": [{"cost":"6.53", "end_time": "1499330321.49","id": null, "metadata": null, "rate":"0.00", "resource_id":"a7c6c4bd-9a00-4cfe-935a-e6e10d00a2e4", "resource_type":"os.nova.server", "start_time": "0.00","user_id": "78b77c5903f0400dbc34ef280b68f4d9"}]}
# curl -X GET -H"X-Auth-Token:950be0b9655f40c593e107d9e0453544" -H 'Content-type:application/json' -v http://127.0.0.1:8770/v1/consumptions/statistics?summary=true
{"statistics":{"os.nova.server": "8.22"}}
1.14. 计费说明
Bilean通过apscheduler来实现每天定时计算用户的资源使用费用,并从用户的blance中扣除。
通过简单的分析代码,Bilean是一个主备架构的服务,否则会出现多个engine服务同时计算用户费用的情况,当然也可能有更巧妙的方式来规避这个问题,而我没有发现。
以上分析难免有所错误,有更深入了解的哥们,也可以分享出来看看。看到关于bilean相关的 资料太少了。