[tosca-parser] Failing to get functions from capabilities

Michael Still mikal at stillhq.com
Mon Dec 17 19:22:55 UTC 2018


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/668e502c/attachment-0001.html>


More information about the openstack-discuss mailing list