Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print outputs to customized output templates #167

Open
tdviet opened this issue Sep 18, 2022 · 0 comments
Open

Print outputs to customized output templates #167

tdviet opened this issue Sep 18, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@tdviet
Copy link
Owner

tdviet commented Sep 18, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant