-
-
Notifications
You must be signed in to change notification settings - Fork 12
Description
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$Namein the template with valuem1.mediumfromresultsand print"The selected flavor is m1.medium". -
Custom delimiters can be used for distinguishing different outputs with the same names. For examples different
$Nameslikes$Network.Name,$Flavor.Name,$Image.Namemay 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 befedcloud select networkwith custom delimiter$Network.and replaces only the$Network.Namein the template, the next run will befedcloud select imagewith 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.