每个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
 

相关文章:

  • 2021-07-29
  • 2022-02-14
  • 2021-09-17
  • 2021-08-11
  • 2022-02-06
  • 2022-02-20
  • 2021-10-29
  • 2021-11-07
猜你喜欢
  • 2021-10-02
  • 2021-08-28
  • 2022-03-09
  • 2021-07-16
  • 2021-08-07
  • 2021-09-13
  • 2021-07-10
相关资源
相似解决方案