Skip to content

Commit 140f37d

Browse files
irwen-rescaleYingchao Huang
authored andcommitted
Make the vm list command outputs json.
1 parent 5f41574 commit 140f37d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

SoftLayer/CLI/virt/list.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# :license: MIT, see LICENSE for more details.
33

44
import click
5+
import json
56

67
import SoftLayer
78
from SoftLayer.CLI import columns as column_helper
@@ -67,9 +68,10 @@
6768
help='How many results to get in one api call, default is 100',
6869
default=100,
6970
show_default=True)
71+
@click.option('--output-json', is_flag=True, default=False)
7072
@environment.pass_env
7173
def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network,
72-
hourly, monthly, tag, columns, limit, transient):
74+
hourly, monthly, tag, columns, limit, transient, output_json):
7375
"""List virtual servers."""
7476

7577
vsi = SoftLayer.VSManager(env.client)
@@ -86,6 +88,10 @@ def cli(env, sortby, cpu, domain, datacenter, hostname, memory, network,
8688
mask=columns.mask(),
8789
limit=limit)
8890

91+
if output_json:
92+
env.fout(json.dumps({'vm': guests}))
93+
return
94+
8995
table = formatting.Table(columns.columns)
9096
table.sortby = sortby
9197
for guest in guests:

0 commit comments

Comments
 (0)