使用python中的云本机应用程序包的模块

cnab的Python项目详细描述


python cnab库

work-in-progress用于在python中使用CNAB的库。

CNAB客户可能有三个主要的兴趣领域:

  1. 处理bundle.json格式(101
  2. 构建调用映像(102
  3. 对cnab运行操作(103

索赔和签字是可选的,但一旦上述情况稳定,将继续进行。

安装

模块发布在PyPi上,可以从那里安装。

pip install cnab

解析bundle.json

这里没有什么特别之处,Bundle类有一个from_dict静态方法 生成完整的Bundle对象。

importjsonfromcnabimportBundlewithopen("bundle.json")asf:data=json.load(f)bundle=Bundle.from_dict(data)

例如,这可以用于验证目的,或者为bundle.json文件构建用户界面。

用python描述bundle.json

您还可以用python描述bundle.json文件。这将正确地验证 基于当前规范的结构,允许构建自定义DSL或其他 生成bundle.json文件的用户界面。

fromcnabimportBundle,InvocationImagebundle=Bundle(name="hello",version="0.1.0",invocation_images=[InvocationImage(image_type="docker",image="technosophos/helloworld:0.1.0",digest="sha256:aaaaaaa...",)],)print(bundle.to_json())

运行CNABS

该模块支持使用docker驱动程序在cnab上运行操作。

fromcnabimportCNAB# The first argument can be a path to a bundle.json file, a dictionary# or a full `Bundle` objectapp=CNAB("fixtures/helloworld/bundle.json")# list available actionsprint(app.actions)# list available parametersprint(app.parameter)# run the install actionprint(app.run("install"))# run the install action specifying a parametersprint(app.run("install",parameters={"port":9090}))# Many applications will require credentialsapp=CNAB("fixtures/hellohelm/bundle.json")# list required credentialsprint(app.credentials)# Here we pass the value for the required credential# in this case by reading the existing configuration from diskwithopen("/home/garethr/.kube/config")asf:print(app.run("status",credentials={"kubeconfig":f.read()}))

请注意,这方面的错误处理正在进行中。

使用调用图像

pycnab还有一个用于处理调用映像的类。

fromcnabimportCNABDirectorydirectory=CNABDirectory("fixtures/invocationimage")# Check whether the directory is valid# Raises `InvalidCNABDirectory` exception if invaliddirectory.valid()# Returns the text of the associated README file if presentdirectory.readme()# Returns the text of the associated LICENSE file if presentdirectory.license()

谢谢

感谢QuickType的引导,创建了基于当前json模式操作bundle.json的python代码。

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

推荐PyPI第三方库


热门话题
java在Android中维护应用程序状态   javajavacc:如何指定在特定上下文中需要哪些令牌?   java为什么改型会在重新加载数据时设置以前的响应?   java如何将键转换为字符串,反之亦然   java JDOM解析器插入#固定手动属性   java按元素对XML数据排序?   java Android中有哪些哈希算法?   java为什么使用可选返回类型进行单元测试失败?   Gson和argonauts使用Gson将javascript数组转换为json字符串并转换为javapojo时遇到的问题。试图让我的结构正确   java中的空格   java SQLite高分,草率IndexOutofBounds Android   使用Spring OAUTH2的java Make客户端   netbeans如何在java中创建一个JPopupMenu,其中包含一个要复制文本的项