Juju数据库反思

juju-dbinspect的Python项目详细描述


提供内省工具以了解系统状态, 包括通常不透明的关系数据。

这是一个用于高级用户诊断的前导工具 或者检查环境状况。

*自担风险使用。这可以在任何JUJU版本之间断开*

这对于任何 给定juju版本,这是一个实现细节 更改而不另行通知。

也就是说,这里的实现在所有现有的 朱雀核。然而,过去的成功并不能保证将来的兼容性。

*不写入数据库*

不要试图写入这些结构中的任何一个,坏的东西会 如果发生了,你就可以保留所有的破碎的东西。如果 你需要修改一些东西。juju使用mongodb客户端事务 以原子方式执行多文档mods并依赖于 所有使用同一txn库的编写器。关于这个的更多细节 好奇者

http://blog.labix.org/2012/08/22/multi-doc-transactions-for-mongodb

安装

可通过pypi获得,依赖项为pymongo和pyyaml:

$ pip install juju-dbinspect

根据您的提供商和Juju版本,您可能需要打开 访问状态服务器上的端口37017(如果不是ha,则为计算机0)。

cli简介

通过内置帮助记录了cli的使用情况:

$ juju db --help

juju db --help
usage: juju-db [-h] [-e ENVIRONMENT] [-v] targets [targets ...]

Juju database introspection

  Drop into an interactive python shell.
    $ juju db shell

  Get the last n transactions (default 100) that have modified the
  environment.
    $ juju db history [n]

  Get the names of all the services in the system.
    $ juju db services

  Get the names of all the units in the system.
    $ juju db units

  Get the details on machine 0.
    $ juju db 0

  Get the details on the unit mysql/0.
    $ juju db mysql/0

  Get the details on the mysql service::
    $ juju db mysql

  Get the relation settings for the mysql/0 unit in the wordpress relation::
    $ juju db mysql/0 wordpress


positional arguments:
  targets

optional arguments:
  -h, --help            show this help message and exit
  -e ENVIRONMENT, --environment ENVIRONMENT
                      Juju environment to operate on
  -v, --verbose         Verbose output

DB交互式外壳

同样具有核心功能的还有一个python交互式shell,它可以访问 分贝。外壳可以使用以下命令启动:

kapil@realms-slice:~$ juju db shell -e syracuse
Juju DB Shell
>>>

基本实体迭代命令:

>>> units()
[u'message/0', u'db/0', u'identity/0', u'meter/0']
>>> machines()
[u'0', u'230', u'232', u'233', u'231']
>>> services()
[u'db', u'identity', u'message', u'meter']
>>> pprint(relations())
[u'db:cluster',
 u'message:cluster',
 u'identity:cluster',
 u'meter:identity-service identity:identity-service',
 u'identity:shared-db db:shared-db',
 u'meter:amqp message:amqp']

让我们检查机器0的约束:

>> machine('0').constraints
  {u'cpupower': None, u'container': None, u'cpucores': None,
   u'mem': None, u'arch': None, u'rootdisk': None}

机器230上有哪些单元:

>> machine('230').units

仪表/0发生了什么事:

>>> pprint(unit('meter/0'))

{u'_id': u'meter/0',
 u'charmurl': u'local:precise/ceilometer-52',
 u'life': 0,
 u'machineid': u'233',
 u'ports': [{u'number': 8777, u'protocol': u'tcp'}],
 u'principal': u'',
 u'privateaddress': u'10.0.3.103',
 u'publicaddress': u'10.0.3.103',
 u'resolved': u'',
 u'series': u'precise',
 u'service': u'meter',
 u'subordinates': [],
 u'tools': {u'sha256': u'',
            u'size': 0L,
            u'url': u'',
            u'version': u'1.17.3.1-precise-amd64'}}


 >>> unit('meter/0').status
 {u'status': u'started', u'statusinfo': u'', u'statusdata': {}}

让我们检查一下计量服务关系的标识并查看关系数据 单位:

>>> unit('meter/0').relation_data('identity')
 {u'_id': u'r#190#requirer#meter/0',
  u'admin_url': u'http://10.0.3.103:8777',
  u'internal_url': u'http://10.0.3.103:8777',
  u'private-address': u'10.0.3.103',
  u'public_url': u'http://10.0.3.103:8777',
  u'region': u'RegionOne',
  u'requested_roles': u'ResellerAdmin',
  u'service': u'ceilometer'}

>>> unit('identity/0').relation_data('meter')
 {u'_id': u'r#190#provider#identity/0',
  u'admin_token': u'witieweithoinaiwuojeFiepuneiseye',
  u'auth_host': u'10.0.3.27',
  u'auth_port': u'35357',
  u'auth_protocol': u'https',
  u'ca_cert': u'omitted for brevity',
  u'https_keystone': u'True',
  u'private-address': u'10.0.3.27',
  u'service_host': u'10.0.3.27',
  u'service_password': u'eingahVeehivaiHahnohngahTooYizei',
  u'service_port': u'5000',
  u'service_protocol': u'https',
  u'service_tenant': u'services',
  u'service_username': u'ceilometer',
  u'ssl_cert': u'omitted for brevity',
  u'ssl_key': u'omitted for brevity'}
>>>

我们还可以通过对事务日志的自省来检查环境的历史:

>>> history()

2014/03/06-19:31:39 applied
  units:message/0 update {u'$set': {u'privateaddress': u'10.0.3.215'}}
2014/03/06-19:31:39 applied
  units:message/0 update {u'$set': {u'publicaddress': u'10.0.3.215'}}
2014/03/06-19:31:40 applied
  settingsrefs:s#message#local:precise/rabbitmq-server-146 update {u'$inc': {u'refcount': 1}}
  units:message/0 update {u'$set': {u'charmurl': u'local:precise/rabbitmq-server-146'}}
2014/03/06-19:33:07 applied
  units:message/0 update {u'$addToSet': {u'ports': {u'protocol': u'tcp', u'number': 5672}}}
2014/03/06-19:33:08 applied
  units:message/0 cond {u'life': {u'$ne': 2}}
  statuses:u#message/0 update {u'$set': {u'status': u'installed', u'statusdata': {}, u'statusinfo': u''}}
2014/03/06-19:33:08 applied
  units:message/0 update {u'$pull': {u'ports': {u'protocol': u'tcp', u'number': 55672}}}
2014/03/06-19:33:09 applied
  units:message/0 update {u'$addToSet': {u'ports': {u'protocol': u'tcp', u'number': 5671}}}
2014/03/06-19:33:13 applied
  units:message/0 cond {u'life': {u'$ne': 2}}
  statuses:u#message/0 update {u'$set': {u'status': u'started', u'statusdata': {}, u'statusinfo': u''}}
2014/03/06-19:33:13 applied
  units:message/0 cond {u'life': 0}
  relations:message:cluster update {u'$inc': {u'unitcount': 1}}
  settings:r#198#peer#message/0 create {u'private-address': u'10.0.3.215'}
  relationscopes:r#198#peer#message/0 create {u'_id': u'r#198#peer#message/0'}
2014/03/06-19:33:43 applied
  units:identity/0 cond {u'life': 0}
  relations:identity:cluster update {u'$inc': {u'unitcount': 1}}
  settings:r#197#peer#identity/0 create {u'private-address': u'10.0.3.80'}
  relationscopes:r#197#peer#identity/0 create {u'_id': u'r#197#peer#identity/0'}
2014/03/06-19:33:52 applied
  units:identity/0 cond {u'life': 0}
  relations:identity:shared-db db:shared-db update {u'$inc': {u'unitcount': 1}}
  settings:r#200#requirer#identity/0 create {u'private-address': u'10.0.3.80'}
  relationscopes:r#200#requirer#identity/0 create {u'_id': u'r#200#requirer#identity/0'}
2014/03/06-19:33:52 applied
  units:db/0 cond {u'life': 0}
  relations:identity:shared-db db:shared-db update {u'$inc': {u'unitcount': 1}}
  settings:r#200#provider#db/0 create {u'private-address': u'10.0.3.225'}
  relationscopes:r#200#provider#db/0 create {u'_id': u'r#200#provider#db/0'}
2014/03/06-19:33:52 applied
  units:message/0 cond {u'life': 0}
  relations:meter:amqp message:amqp update {u'$inc': {u'unitcount': 1}}
  settings:r#199#provider#message/0 create {u'private-address': u'10.0.3.215'}
  relationscopes:r#199#provider#message/0 create {u'_id': u'r#199#provider#message/0'}
2014/03/06-19:33:53 applied
  settings:r#199#provider#message/0 update {u'$set': {u'hostname':
  u'10.0.3.215', u'ssl_port': u'5671', u'ssl_ca':'value_omitted'}
  u'$unset': {}}

可用的助手命令

  • units
  • unit
  • services
  • service
  • machines
  • machine
  • relations
  • relation
  • charms

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Clojure关键字在内存中的大小是多少?   Java中有固定长度的通用数组对象吗?   PostgreSQL:通过Java更新我的用户表   错误:使用java解析xml   java Json显示列表中对象的名称   java比较JodaTime时区   与JAVA中的API和包的区别?   java的int值在for循环中不改变   谷歌应用引擎中的java RSA   迁移到spring 5后出现java非法字符错误   java Websphere管理控制台不工作   JavaGSON如何始终在json中包含毫秒?   带有空格和双引号的windows Java ProcessBuilder命令参数失败   java错误:重复的zip条目[43.jar:org/apache/http/annotation/NotThreadSafe.class]