<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
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.<br>
<br>
At a minimum it might make sense to only replace the function with
the parameter value if the parameter is not None.<br>
<br>
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.<br>
<br>
Is there a specific scenario you want to support that requires this?<br>
<br>
Thanks<br>
<br>
Bob<br>
<br>
<br>
[1] -
<a class="moz-txt-link-freetext" href="https://github.com/openstack/tosca-parser/blob/master/toscaparser/topology_template.py#L282">https://github.com/openstack/tosca-parser/blob/master/toscaparser/topology_template.py#L282</a><br>
<div class="moz-cite-prefix">On 12/17/18 4:45 PM, Michael Still
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAEd1pt4ARRvcakxrsiW_UkshGC38WMFysSPAOZGBb47Q59TbtQ@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">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.
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>Michael</div>
<div><br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr">On Tue, Dec 18, 2018 at 9:35 AM Bob Haddleton
<<a href="mailto:bobh@haddleton.net" moz-do-not-send="true">bobh@haddleton.net</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF"> I'm not sure where the inconsistency
is? Can you elaborate?<br>
<br>
You can get the inputs from the tosca.inputs attribute
without passing any input parameters:<br>
<br>
tosca = ToscaTemplate(sys.argv[1])<br>
<br>
print([<a href="http://input.name" target="_blank"
moz-do-not-send="true">input.name</a> for input in
tosca.inputs])<br>
<br>
['cpus', 'db_name', 'db_user', 'db_pwd', 'db_root_pwd',
'db_port']<br>
<br>
<br>
Bob<br>
<br>
<div class="gmail-m_8559250796182448623moz-cite-prefix">On
12/17/18 1:22 PM, Michael Still wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Thanks for that.
<div><br>
</div>
<div>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?</div>
<div><br>
</div>
<div>Michael</div>
<div><br>
</div>
<div><br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr">On Tue, Dec 18, 2018 at 1:28 AM Bob
Haddleton <<a href="mailto:bobh@haddleton.net"
target="_blank" moz-do-not-send="true">bobh@haddleton.net</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px
0px 0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF"> Hi Michael:<br>
<br>
tosca-parser expects that the input values will be
defined already and passed to the ToscaTemplate
object in the parsed_params argument.<br>
<br>
If you change:<br>
<br>
tosca = ToscaTemplate(sys.argv[1])<br>
<br>
to:<br>
<br>
tosca = ToscaTemplate(sys.argv[1],
parsed_params={'cpus': 4})<br>
<br>
the output becomes:<br>
<br>
Processing node template server<br>
disk_size: 10 GB<br>
num_cpus: 4<br>
mem_size: 4096 MB<br>
architecture: x86_64<br>
type: Linux<br>
distribution: Fedora<br>
version: 18.0<br>
min_instances: 1<br>
max_instances: 1<br>
secure: True<br>
<br>
<br>
Hope this helps.<br>
<br>
Bob<br>
<br>
<br>
<div
class="gmail-m_8559250796182448623gmail-m_2800331163805999778moz-cite-prefix">On
12/17/18 3:25 AM, Michael Still wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Hi,
<div><br>
</div>
<div>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.</div>
<div><br>
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.</div>
<div><br>
</div>
<div>Here's a snippet of example code:</div>
<div><br>
</div>
<div>
<div>#!/usr/bin/python</div>
<div><br>
</div>
<div>import sys</div>
<div><br>
</div>
<div>from jinja2 import Template</div>
<div>import toscaparser.functions</div>
<div>from toscaparser.tosca_template
import ToscaTemplate</div>
<div><br>
</div>
<div>tosca = ToscaTemplate(sys.argv[1])</div>
<div><br>
</div>
<div>for nodetemplate in
tosca.nodetemplates:</div>
<div> print</div>
<div> print('Processing node template
%s'% <a href="http://nodetemplate.name"
target="_blank" moz-do-not-send="true">nodetemplate.name</a>)</div>
<div><br>
</div>
<div> capabilities =
nodetemplate.get_capabilities_objects()</div>
<div> for cap in capabilities:</div>
<div> propobjs =
cap.get_properties_objects()</div>
<div> if not propobjs:</div>
<div> continue</div>
<div><br>
</div>
<div> for po in propobjs:</div>
<div> print(' %s: %s' %(<a
href="http://po.name" target="_blank"
moz-do-not-send="true">po.name</a>,
po.value))</div>
</div>
<div><br>
</div>
<div>Which returns this:</div>
<div><br>
</div>
<div>
<div>$ python _capabilities.py
csar_wordpress.zip </div>
<div>No handlers could be found for logger
"tosca.model"</div>
<div><br>
</div>
<div>Processing node template wordpress</div>
<div> network_name: PRIVATE</div>
<div> initiator: source</div>
<div> protocol: tcp</div>
<div> secure: False</div>
<div><br>
</div>
<div>Processing node template webserver</div>
<div> network_name: PRIVATE</div>
<div> initiator: source</div>
<div> protocol: tcp</div>
<div> secure: False</div>
<div> secure: True</div>
<div><br>
</div>
<div>Processing node template mysql_dbms</div>
<div><br>
</div>
<div>Processing node template
mysql_database</div>
<div><br>
</div>
<div>Processing node template server</div>
<div> secure: True</div>
<div> min_instances: 1</div>
<div> max_instances: 1</div>
<div> mem_size: 4096 MB</div>
<div> num_cpus: None</div>
<div> disk_size: 10 GB</div>
<div> distribution: Fedora</div>
<div> version: 18.0</div>
<div> type: Linux</div>
<div> architecture: x86_64</div>
</div>
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>Is there an example somewhere of how to
correctly access functions for
capabilities?</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Michael</div>
</div>
</div>
</div>
</blockquote>
<br>
</div>
</blockquote>
</div>
</blockquote>
<br>
</div>
</blockquote>
</div>
</blockquote>
<br>
</body>
</html>