跳转到主要内容

基于twisted的Juju客户端。

项目描述

txjuju提供了twisted基础工具,用于与Juju交互。这包括API客户端和CLI包装器。该库仅限于Python 2,但支持Juju 1.x和2.x。Python 3的支持正在计划中。

请注意,txjuju只公开了Juju的部分功能。这是因为代码起源于Landscape项目,并且没有超出Landscape的需求。Juju的官方Python绑定(python-libjuju)通常提供更好的体验。在某个时刻,python-libjuju可能会完全取代txjuju。

关键组件

以下是txjuju的基本类

此外,txjuju.prepare_for_bootstrap()特别有用。

更多信息请参阅DOC.rst

示例使用

API客户端

from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from txjuju.api import Endpoint

endpoint = Endpoint(reactor, "ec2-1-2-3-4.compute-1.amazonaws.com")
deferred = endpoint.connect()

@inlineCallbacks
def connected(client):
    yield client.login("user-admin", "54830489236383334d1d9fd84adae72c")
    yield client.setAnnotations("unit", "1", {"foo": "bar"})

deferred.addCallback(connected)

reactor.run()

CLI包装器

import pprint
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue
from txjuju import prepare_for_bootstrap
from txjuju.cli import BootstrapSpec, Juju1CLI

cfgdir = "/tmp/my-juju"
spec = BootstrapSpec("my-env", "lxd")
cli = Juju1CLI(cfgdir)

@inlineCallbacks
def bootstrap():
    prepare_for_bootstrap(spec, "1.25.6", cfgdir)
    yield cli.boostrap(spec.name, "0")
    raw = yield cli.api_info(spec.name)
    returnValue(raw)

deferred = bootstrap()
deferred.addCallback(lambda v: pprint.pprint(v))

reactor.run()

贡献

如果您想为txjuju做出贡献,请随意打开一个问题或向我们发送pull请求。就txjuju的借用而言,代码是LGPLv3许可的。

打包

可以使用python2 setup.py sdist创建Python包。有关构建deb包的信息,请参阅BUILDbuild.sh

风格

txjuju代码遵循PEP 8。在做出更改时经常运行类似flake8的东西是个好主意。其他txjuju特定指南

  • 使用双引号字符串

  • 测试方法应包含文档字符串

测试

要运行测试套件,请运行make testpython2 -m unittest txjuju.tests.test_XXX

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

txjuju-0.9.0a2.tar.gz (41.1 kB 查看哈希值)

上传时间

由以下支持