Closed andy-maier closed 10 months ago
Have you tried to use string concatenation in option 1?
--ssc-network-info '[{"port": 444, "ipaddr-type": "static", "vlan-id": '$vlan_id', "static-ip-info": {"type": "ipv4", "ip-address": "'$ip_address'"}}]'
You need to put the shell variables in single quotation marks (basically end and start the string again). But at least bash typically concatenates everything and passes it as a single string to the program
Another observation: Option 2 looks very similar to the single line syntax of YAML. The most obvious difference is that you need commas between fields of an object and use :
instead of =
Option 3: Single line YAML (aka "Flow Style")
The YAML spec calls this Flow Collection Styles.
Some sources claim that quotes around property names and string values would be needed, but that does not seem to be the case. Example: https://yaml-online-parser.appspot.com/?yaml=prop%3A+%7Bresult%3A+42%2C+name%3A+alice%7D%0A&type=json Also the YAML spec confirms that no quotes are needed, see Example 7.15: https://yaml.org/spec/1.2.2/#rule-ns-s-flow-map-entries
Note that the flow collection style YAML is a superset of JSON, so double quotes around property names and string values can also be used.
Example for "ssc-network-info":
--ssc-network-info "[{port: 444, ipaddr-type: static, vlan-id: 53, static-ip-info: {type: ipv4, ip-address: '10.11.12.13'}}]"
Example for "ssc-network-info" when using shell/env variables:
--ssc-network-info "[{port: 444, ipaddr-type: static, vlan-id: $vlan_id, static-ip-info: {type: ipv4, ip-address: '$ip_address'}}]"
Examples with a (fantasy) escaped string value:
--properties '{description: ab\ncd}'
--properties "{description: ab\\ncd}"
I must say, I like option 3 the best.
We probably need to write a help topic with a short explanation of the syntax, since the YAML spec is hard to read for occasional users.
More understandable descriptions of flow style that we could refrence:
Probably not so good:
I have implemented option 3 in PR #537 - if we agree on that PR, I consider the decision made for using option 3.
We agreed on PR #537, so we will continue using option 3 in the future. This issue is now complete.
There is a number of create / update command options that are not yet implemented because they need to set parameters/properties that have complex data types, and we do not yet have an agreed-upon way to specify those. There are a few cases of comma-separated string values, but more complex things than that are a gap today.
Example: The "Create Image Activation Profile" operation has an input parameter "ssc-network-info" whose type is an array of "ssc-network" data structures, which are dictionaries with 5 properties, one of which is again a dictionary with 2 properties.
This issue is to discuss and agree on a way to specify the value of such complex parameters or properties in zhmc command line options.
I did some research on this problem, but could not find anything useful. My research was probably not exhaustive, though.
The following lists some options I could think of:
Option 1: JSON
Description:
Pro/Con:
Example for "ssc-network-info":
Example for "ssc-network-info" when using shell/env variables:
Option 2: name=value syntax
Description:
null
true
orfalse
int()
float()
{}
, their items use akey=value
syntax, with one or more blanks between the items. Alternative: The items are comma-separated instead of blank-separated.[]
, their items use avalue
syntax, with one or more blanks between the items. If the array items are dicts, the items are separated by zero or more blanks. Alternative: The items are comma-separated instead of blank-separated.\b
,\f
,\n
,\r
,\t
). Can optionally be surrounded by double quotes. Double quotes around the value are mandatory if the escaped string value contains blanks or backslash-escapes. When parsing a double quoted (=escaped) string, these backslash-escape sequences are supported:\"
,\\
,\/
,\b
,\f
,\n
,\r
,\t
,\uNNNN
,\uNNNNNN
. When creating an escaped string (in double quotes), then double quotes, backslashes, the whitespace chars (\b
,\f
,\n
,\r
,\t
) and (?) any Unicode character outside of 7-bit ASCII are mandatory to be backslash-escaped.Pro/Con:
Example for "ssc-network-info":
Example for "ssc-network-info" when using shell/env variables:
Examples with a (fantasy) escaped string value:
Option 2 is implemented in PR #516