Skip to content

Print outputs to customized output templates #167

@tdviet

Description

@tdviet

There are requests for non-standard formats, e.g. Terraform (#140). Instead of providing custom formatting functions, it may be easier and more flexible to print outputs using user-supplied Template strings.

Examples:

  • The outputs of the commands are dicts (JSON formats), e.g.
$ fedcloud select flavor  --site IISAS-FedCloud --vo eosc-synergy.eu --vcpus 2
[
    {
        "ID": "df25f80f-ed19-4e0b-805e-d34620ba0334",
        "Name": "m1.medium",
        "RAM": 4096,
        "Disk": 20,
        "Ephemeral": 0,
        "VCPUs": 2,
        "Is Public": true,
        "Swap": "",
        "RXTX Factor": 1.0,
        "Properties": {
            "aggregate_instance_extra_specs:gpu": "false"
        }
    }
]
  • User provides template string "The selected flavor is $Name", via option --output-template

  • The output from the command will be the result of output_template.safe_substitute(results), which replaces $Name in the template with value m1.medium from results and print "The selected flavor is m1.medium".

  • Custom delimiters can be used for distinguishing different outputs with the same names. For examples different $Names likes $Network.Name, $Flavor.Name, $Image.Name may be used in the same template.

  • safe_substitute() only replaces valid values it can find, and leaves the rest intact. For example, the first run may be fedcloud select network with custom delimiter $Network. and replaces only the $Network.Name in the template, the next run will be fedcloud select image with delimiter $Image. for substituting $Image.Name, ...

So for generating something like CESNET-MCC.tfvars, we can use single template and execute fedcloud select commands 3x, each command replaces a parameter without conflicts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions