Clarifying charm format 2
Jim Baker
jim.baker at canonical.com
Tue Aug 28 21:27:29 UTC 2012
On 08/28/2012 01:07 PM, Gustavo Niemeyer wrote:
> On Tue, Aug 28, 2012 at 3:43 PM, Kapil Thangavelu
> <kapil.thangavelu at canonical.com> wrote:
>> On that note, i wanted to confirm/clarify the changes for format 2 for
>> pyjuju, since it doesn't have a specification, and it needs to agree between
>> the two implementations.
>>
>> To recap for charms with the 'format': 2 metadata marker, the hook cli api
>> changes such that
>>
>> - relation-get/set both return raw strings.
>> - config-get/set both type 'str' as a raw string.
These changes to use raw strings make sense for more readily working
with shell scripts and the output of other programs.
> Thanks for bringing this up, and +1. In addition, config-get will
> serialize int, float and bool using their usual Python repr ("1",
> "1.0", and "True", respectively and without the quotes). I felt quite
> tempted to suggest lowercasing bools, which was the original
> intention, but by now it's not relevant really. In the end, I expect
> quite a lot of charms to be able to switch to format 2 without any
> changes.
There are two additional cases that should be addressed, as suggested by
this last comment:
1. Booleans for config-get/config-set
Currently the support for format: 2 that's in trunk ensures that
config-set/config-get work with the YAML serializations of these types
(bool, int, float). In addition, because YAML is used to parse these
value, there is coercion. For example, true, True, and TRUE all work
with config-set; e.g., config-set foo=TRUE; config-get then
returns the serialization of true. This is also a safe coercion because
the config setting is validated against the type.
Question: do we want to keep the trunk support for config usage of
booleans in the final format: 2?
2. Dictionary output of relation-get - using smart format (implied if
not set with --format)
For format: 1, the Python str repr of a dict is used for relation-get
for retrieving multiple values if the format is not specified (smart).
So relation-get - mysql/0 results in output like so:
{u'private-address': u'mysql-0.example.com', u'foo': u'ascii'}
Clearly the u'XYZ' representation is going away. Based on the current
discussion in the thread, we will instead be using raw strings. So let's
look at this case a little more to ensure we get the desired output.
For format: 2 in trunk, relation-get - returns a YAML output. So using a
raw string in our example, this would result in the following output,
which can be parsed by any YAML parser:
bar: !!binary |
yv4=
foo: ascii
private-address: mysql-0.example.com
If we were to use a modified format: 1 and keep the Python str repr,
this would result in output like the following. It should be possible to
eval any version of this in Python, given the use of raw strings. It may
be readily parseable by other tools.
{'private-address': 'mysql-0.example.com', 'foo': 'ascii', 'bar':
'\xca\xfe'}
Question: which output format do we prefer for relation-get - ?
- Jim
--
Jim Baker
Ubuntu Server team
jim.baker at canonical.com
jimbaker on freenode
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ubuntu.com/archives/juju/attachments/20120828/83d4b506/attachment.pgp>
More information about the Juju
mailing list