Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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.

The --columns global option can also take jsonpath expressions to access sub-attributes and more. Its format is based on label=attribute in comma-separated format, but if no label is provided, it will use the attribute name.

vss-cli --columns ID=moref,Path=folder.path,name compute vm ls 

Output would be

vss-cli --columns ID=moref,Path=folder.path,Name=name compute vm ls -c 1
ID         Path                                        Name
---------  ------------------------------------------  --------------------------
vm-928584  Public > Customer > App > QA                2406Q-app-with-storage-qa1

You may be wondering, how do I get all available attributes per object? The simplest approach change the output (--output) global option to either yaml o json, then run an ls command with a single (-c 1) item as follows:

vss-cli --output yaml compute vm ls -c 1

If you are more familiar with json , replace yaml with json like --output json.

The above command works for other objects such as:

  • vss-cli compute [object] ls

  • vss-cli request [object] ls

  • vss-cli service [object] ls

Additional global options are shown in the ITS Private Cloud CLI (vss-cli) Cheat Sheet

\uD83D\uDCD8 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:

  • Moref

  • Name

  • Folder Path

  • Disks Capacity

  • Disks Labels

  • Networks Name

  1. Run the following command to obtain the equivalent attributes:

    vss-cli --output yaml compute vm ls -c 1
  2. Then identify object defined attribute disks and networks and their sub-attributes to require. In this case disks.label, disks.capacity_gib and networks.name.

  3. Use jsonpath to extract the proper values:

    1. disks[*].capacity_gib

    2. disks[*].label

    3. networks[*].name

  4. Join the columns in and add them to the --columns option as follows.

    vss-cli --columns moref,name,Folder=folder.path,"Disk Capacity=disks[*].capacity_gib,Disk Labels=disks[*].label,networks[*].name" compute vm ls
  5. An example result would be as follows:

    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

\uD83D\uDCD8 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.

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 Folder Path, and first we have to get the right attribute name.

  1. Filtering works on any object attribute, in case of virtual machines, you can show available attributes to filter with:

    vss-cli --output yaml compute vm ls -c 1
  2. Based on the previous output, folder path is an attribute of folder, thus it will be accessible using folder.path in the --filter-by option as follows:

    vss-cli compute vm ls -f folder.path="Public > Client > QA"

When using --filter-by only one sub-attribute is supported.

  • No labels