[tosca-parser] Failing to get functions from capabilities

Michael Still mikal at stillhq.com
Tue Dec 18 01:46:12 UTC 2018


Yeah, fair enough.

What leads me here is I am writing a converter from CSAR to Cloudify
blueprints (which is similar to the CSAR to Heat converter which already
exists). Cloudify blueprints are another TOSCA dialect, so I want to leave
the get_input line preserved and let Cloudify sort that out when it
executes the blueprint.

Thanks,
Michael


On Tue, Dec 18, 2018 at 12:20 PM Bob Haddleton <bobh at haddleton.net> wrote:

> I see what you mean.  It appears to be intentional, since there is code
> here [1] that explicitly replaces the GetInput function with the value of
> the passed parameter.
>
> At a minimum it might make sense to only replace the function with the
> parameter value if the parameter is not None.
>
> I don't there is a way to provide input values to the ToscaTemplate object
> after it has been created, so I don't know how any "future" input values
> would be handled.
>
> Is there a specific scenario you want to support that requires this?
>
> Thanks
>
> Bob
>
>
> [1] -
> https://github.com/openstack/tosca-parser/blob/master/toscaparser/topology_template.py#L282
> On 12/17/18 4:45 PM, Michael Still wrote:
>
> In my mind (and I might be wrong), the inconsistency is that for
> properties, interfaces and outputs if the value parsed is a reference to
> something else I get a function which will resolve the value if I ask it
> nicely. However for capabilities, I instead get None unless I have passed
> in parsed parameters. This is despite the functions code supporting
> get_input.
>
> The issue with parsed parameters is I now need to run the parser twice --
> the first run to detect what the inputs are, and then the second to provide
> values for those so that the substitution occurs. That seems like a
> confusing user interface to me.
>
> Michael
>
>
> On Tue, Dec 18, 2018 at 9:35 AM Bob Haddleton <bobh at haddleton.net> wrote:
>
>> I'm not sure where the inconsistency is?  Can you elaborate?
>>
>> You can get the inputs from the tosca.inputs attribute without passing
>> any input parameters:
>>
>> tosca = ToscaTemplate(sys.argv[1])
>>
>> print([input.name for input in tosca.inputs])
>>
>> ['cpus', 'db_name', 'db_user', 'db_pwd', 'db_root_pwd', 'db_port']
>>
>>
>> Bob
>>
>> On 12/17/18 1:22 PM, Michael Still wrote:
>>
>> Thanks for that.
>>
>> That approach seems fair enough, but inconsistent with how other things
>> are represented as functions. How am I meant to know what the inputs to the
>> CSAR are before the CSAR is parsed?
>>
>> Michael
>>
>>
>>
>> On Tue, Dec 18, 2018 at 1:28 AM Bob Haddleton <bobh at haddleton.net> wrote:
>>
>>> Hi Michael:
>>>
>>> tosca-parser expects that the input values will be defined already and
>>> passed to the ToscaTemplate object in the parsed_params argument.
>>>
>>> If you change:
>>>
>>> tosca = ToscaTemplate(sys.argv[1])
>>>
>>> to:
>>>
>>> tosca = ToscaTemplate(sys.argv[1], parsed_params={'cpus': 4})
>>>
>>> the output becomes:
>>>
>>> Processing node template server
>>>   disk_size: 10 GB
>>>   num_cpus: 4
>>>   mem_size: 4096 MB
>>>   architecture: x86_64
>>>   type: Linux
>>>   distribution: Fedora
>>>   version: 18.0
>>>   min_instances: 1
>>>   max_instances: 1
>>>   secure: True
>>>
>>>
>>> Hope this helps.
>>>
>>> Bob
>>>
>>>
>>> On 12/17/18 3:25 AM, Michael Still wrote:
>>>
>>> Hi,
>>>
>>> I'm trying to use tosca-parser to parse CSAR files. Its working quite
>>> well, until I hit a wall with capabilities today. Specifically I am testing
>>> with the single instance wordpress example CSAR, which uses a get_input for
>>> the num_cpus argument for host capabilities for the server.
>>>
>>> Based on how properties work, I would expect to get a function back for
>>> anything which requires referencing another value, but in the case of
>>> capabilities I either get the hardcoded value (strings, ints etc), or a
>>> None for values which would be functions if we were talking about
>>> prototypes.
>>>
>>> Here's a snippet of example code:
>>>
>>> #!/usr/bin/python
>>>
>>> import sys
>>>
>>> from jinja2 import Template
>>> import toscaparser.functions
>>> from toscaparser.tosca_template import ToscaTemplate
>>>
>>> tosca = ToscaTemplate(sys.argv[1])
>>>
>>> for nodetemplate in tosca.nodetemplates:
>>>     print
>>>     print('Processing node template %s'% nodetemplate.name)
>>>
>>>     capabilities = nodetemplate.get_capabilities_objects()
>>>     for cap in capabilities:
>>>         propobjs = cap.get_properties_objects()
>>>         if not propobjs:
>>>             continue
>>>
>>>         for po in propobjs:
>>>             print('  %s: %s' %(po.name, po.value))
>>>
>>> Which returns this:
>>>
>>> $ python _capabilities.py csar_wordpress.zip
>>> No handlers could be found for logger "tosca.model"
>>>
>>> Processing node template wordpress
>>>   network_name: PRIVATE
>>>   initiator: source
>>>   protocol: tcp
>>>   secure: False
>>>
>>> Processing node template webserver
>>>   network_name: PRIVATE
>>>   initiator: source
>>>   protocol: tcp
>>>   secure: False
>>>   secure: True
>>>
>>> Processing node template mysql_dbms
>>>
>>> Processing node template mysql_database
>>>
>>> Processing node template server
>>>   secure: True
>>>   min_instances: 1
>>>   max_instances: 1
>>>   mem_size: 4096 MB
>>>   num_cpus: None
>>>   disk_size: 10 GB
>>>   distribution: Fedora
>>>   version: 18.0
>>>   type: Linux
>>>   architecture: x86_64
>>>
>>> I would expect num_cpus for the "server" node_template to be a
>>> GetInput() function based on its definition in the CSAR, but instead I get
>>> None.
>>>
>>> Is there an example somewhere of how to correctly access functions for
>>> capabilities?
>>>
>>> Thanks,
>>> Michael
>>>
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-discuss/attachments/20181218/6b6806a2/attachment-0001.html>


More information about the openstack-discuss mailing list