Introduction
One of the most powerful options in the ITS Private Cloud Command-Line interface (vss-cli
) is the --columns
global option. This option allows to show/hide any object attribute to customize the output of the vss-cli
.
...
If you are more familiar with json
, replace yaml
with json
like --output json
.
If you would like to get csv
formatted table, use --table-format csv
as a global option
The above command works for other objects such as:
...
Tip |
---|
Additional global options are shown in the ITS Private Cloud CLI (vss-cli) Cheat Sheet |
...
Example: List Virtual Machines disks and networks (compute vm ls
)
In this example we need to get a list of virtual machines with the following attributes:
...
Run the following command to obtain the equivalent attributes:
Code Block vss-cli --output yaml compute vm ls -c 1
Then identify object defined attribute
disks
andnetworks
and their sub-attributes to require. In this casedisks.label
,disks.capacity_gib
andnetworks.name
.Use
jsonpath
to extract the proper values:disks[*].capacity_gib
disks[*].label
networks[*].name
Join the columns in and add them to the
--columns
option as follows.Code Block vss-cli --columns moref,name,Folder=folder.path,"Disk Capacity=disks[*].capacity_gib,Disk Labels=disks[*].label,networks[*].name" compute vm ls
An example result would be as follows:
Code Block moref name Folder Disk Capacity Disk Labels networks[*].name --------- -------------------------- -------------------- --------------- ------------------------ ------------------- vm-123455 2406Q-app-10-no-storage-qa Public > Client > QA 150.0, 100.0 Hard disk 2, Hard disk 1 VL-0253-EIS-VSS-CGN
...
Example: List Virtual Machines disks and networks (compute vm ls
) and filter by folder path
In addition to the previous example, you can add the local --filter-by
option to the ls
command, in this case, to the vss-cli compute vm ls
. Filtering with the vss-cli
has the following format: <field_name>=<operator>,<value>
. Where operator
is any of the following:
like
: default value. Matches value as substring.eq
: equal, or exact value.ne
: non-equal to value.lt
: lower than value.le
: lower or equal value.gt
: greater than value.ge
: greater and equal to value.in
: in multiple values.
...
Filtering works on any object attribute, in case of virtual machines, you can show available attributes to filter with:
Code Block vss-cli --output yaml compute vm ls -c 1
Based on the previous output, folder
path
is an attribute offolder
, thus it will be accessible usingfolder.path
in the--filter-by
option as follows:Code Block vss-cli --columns moref,name,Folder=folder.path,"Disk Capacity=disks[*].capacity_gib,Disk Labels=disks[*].label,networks[*].name" \ compute vm ls -f folder.path="Public > Client > QA"
Note |
---|
When using |
Example: List Virtual Machines disks and networks (compute vm ls
) and filter by multiple names
Filtering by multiple values is also possible with the --filter-by/-f
option added to the ls
command, in this case, to the vss-cli compute vm ls
. Filtering with the vss-cli
has the following format: <field_name>=<operator>,<value>
. Where operator
is any of the following:
like
: default value. Matches value as substring.eq
: equal, or exact value.ne
: non-equal to value.lt
: lower than value.le
: lower or equal value.gt
: greater than value.ge
: greater and equal to value.in
: in multiple values. *
Now that we know the --filter-by/-f
syntax and the possible operators, let's get on to the example.
In this case, we need to filter by multiple names, and first we have to get the right attribute name.
Filtering works on any object attribute, in case of virtual machines, you can show available attributes to filter with:
Code Block vss-cli --output yaml compute vm ls -c 1
Based on the previous output,
name
is the attribute to use, along with thein
operator as follows:Code Block vss-cli --columns moref,name,Folder=folder.path,"Disk Capacity=disks[*].capacity_gib,Disk Labels=disks[*].label,networks[*].name" \ compute vm ls --filter-by "name=in,2407P-name1,2407P-name2"
\uD83D\uDCCB Related articles
Filter by label (Content by label) | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|