[openstack-dev] [murano] MuranoPL types question

Stan Lagun slagun at mirantis.com
Thu Mar 30 18:55:15 UTC 2017


Hi Paul,

> Here both key and value appear to be a string (note, I can't confirm this
as the typeinfo function doesn't appear to be available in Instance.yaml
for some reason... perhaps I'm using it wrong)

They are not strings. Reporter converts everything that is passed to it
into string by doing unicode(obj). What you see is the Python string
representation of lists and dicts, where every unicode string is prefixed
with "u".
Typinfo function works on objects (instances of MuranoPL classes), not on
primitive types like strings, dicts and lists.

> 1) Why is the content of this 'get_attr' coming from heat being stored in
the stack outputs as a string,
it is stored exactly as it comes from Heat. In theory conversion to string
could happen on Heat side, but most likely it just the output of reporter
made it look like this

> 2) Is there a way I can cast this to a list of dicts or similar structure
so it can be iterated as expected?
It's hard to answer without seeing your code and how you got the results
that you provided.

>  when I access this from a sample app, I end up with a list of strings,
shown by $reporter as: ...

Curly braces in the output indicate that this is not a list of strings but
rather the single dict converted to a string by reporter. So what you see
is the value of that 'vol-7c8ee61f-a444-46a1-ad70-fc6fce6a7b56-attachments'
output, which sounds like what you're wanted it to be. In MuranoPL you can
have very detailed contracts: not just [] (any list) but something like
Contract:
  - key1: string().notNull()
    key2: int().notNull()

which is a list of dicts with contract on each dict entry. If you don't get
contract violation exception, you can be sure that the list contains list
of dicts with appropriate keys/values rather than list of strings or
anything else


Sincerely yours,
Stan Lagun
Principal Software Engineer @ Mirantis

<slagun at mirantis.com>

On Thu, Mar 30, 2017 at 10:17 AM, Paul Bourke <paul.bourke at oracle.com>
wrote:

> Hi Stan,
>
> I had a quick(hopefully) question about MuranoPL that I hope you might be
> able to help with, Felipe had mentioned you are very knowledgeable in this
> area. If you don't have time please disregard!
>
> I'm working on a patch for the Murano core library to make volume
> attachment info available, which is available at
> https://review.openstack.org/451909. It's mostly working, but I'm having
> some issues getting the types correct in MuranoPL to make this info
> consumable by end users.
>
> The attachment info from a sample run in the stack $outputs looks like
> this (taken from the dashboard using $reporter)
>
> u'vol-7c8ee61f-a444-46a1-ad70-fc6fce6a7b56-attachments':
> u"[{u'server_id': u'2891067b-e7bb-4ab9-a759-9e81096c0682',
> u'attachment_id': u'7456a4b0-3abd-48a0-a0cb-f3fa0f2706bb',
> u'attached_at': u'2017-03-30T16:51:57.000000', u'host_name': None,
> u'volume_id': u'373e4a5a-46b6-4091-82d6-b3dba62d552b', u'device':
> u'/dev/vda', u'id': u'373e4a5a-46b6-4091-82d6-b3dba62d552b'}]"
>
> Here both key and value appear to be a string (note, I can't confirm this
> as the typeinfo function doesn't appear to be available in Instance.yaml
> for some reason... perhaps I'm using it wrong)
>
> My goal is to then set this into a property of CinderVolume.yaml, with a
> Contract of '[]'. However, when I access this from a sample app, I end up
> with a list of strings, shown by $reporter as:
>
> (u"[{u'server_id': u'2891067b-e7bb-4ab9-a759-9e81096c0682',
> u'attachment_id': u'f5bd50ab-4040-4e2b-8b50-790781d9bc37',
> u'attached_at': u'2017-03-30T16:51:59.000000', u'host_name': None,
> u'volume_id': u'ed7eb535-9e81-4c97-b063-86936d4ee306', u'device':
> u'/dev/vdb', u'id': u'ed7eb535-9e81-4c97-b063-86936d4ee306'}]",)
>
> So my question is:
>
> 1) Why is the content of this 'get_attr' coming from heat being stored in
> the stack outputs as a string, and
>
> 2) Is there a way I can cast this to a list of dicts or similar structure
> so it can be iterated as expected?
>
> Any tips much appreciated.
>
> Thanks,
> -Paul
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20170330/55055560/attachment.html>


More information about the OpenStack-dev mailing list