首页 技术 正文
技术 2022年11月18日
0 收藏 388 点赞 2,461 浏览 1597 个字

Machine Readable Output机器可读的输出

每个vagrant命令都接受一个–machine-readable的标志,它支持机器可读的输出模式。在这种模式下,终端的输出被机器友好的输出所替代。

这种模式使以编程方式执行vagrant和从中读取数据变得容易。这种输出格式由我们的向后兼容策略保护。

然而,在Vagrant 2.0发布之前,随着我们为其确定更多的用例,机器可读的输出可能会发生变化。但是向后兼容的承诺应该使编写客户机库来解析输出格式变得安全。

⚠️这是一个高级主题,仅当你希望以编程方式执行Vagrant时才使用。如果你刚刚开始使用Vagrant,你可以安全地跳过这一部分。

1)Work-In-Progress 正在进行中

机器可读的输出是一个非常新的概念(作为Vagrant 1.4的一部分发布)。我们仍然在为它收集用例,并为每个命令构建输出。由于缺少信息,可能无法实现机器可读输出。

2)Format格式

机器可读格式是面向行的、逗号分隔的文本格式。这使得使用标准的Unix工具(如awk或grep)以及完整的编程语言(如Ruby或Python)来解析变得非常容易。

其格式为:

timestamp,target,type,data...

内容解释:

  • timestamp :消息打印时的UTC Unix时间戳
  • target : 目标是以下输出的目标。如果消息与全球Vagrant相关,则此值为空。否则,这通常是一个机器名,因此在使用多vm时,你可以将输出关联到特定的机器。
  • type : 类型是被输出的机器可读消息的类型。稍后将介绍一组标准类型。
  • data : 数据是与前一种类型相关联的零个或多个逗号分隔的值。该数据的确切数量和含义依赖于类型,因此必须阅读与该类型相关的文档才能完全理解。

在格式中,如果数据包含逗号,则用%!(VAGRANT_COMMA)替换。这是比如\’等转义字符更好的选择,因为它对如awk等工具更友好。

格式中的换行被替换为各自的标准转义序列。换行成为输出中的一个文本\n,回车变成文本\r。

3)Types类型

本节记录所有可用的类型,这些类型可以通过机器可读的输出输出。

Type Description
box-name Name of a box installed into Vagrant.
box-provider Provider for an installed box.
cli-command A subcommand of vagrant that is available.
error-exit An error occurred that caused Vagrant to exit. This contains that error. Contains two data elements: type of error, error message.
provider-name The provider name of the target machine. targeted
ssh-config The OpenSSH compatible SSH config for a machine. This is usually the result of the “ssh-config” command. targeted
state The state ID of the target machine. targeted
state-human-long Human-readable description of the state of the machine. This is the long version, and may be a paragraph or longer. targeted
state-human-short Human-readable description of the state of the machine. This is the short version, limited to at most a sentence. targeted

 

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,959
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,483
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,328
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,112
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,743
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,778