<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How would I iterate through containers in the variable syntax? in HPE Morpheus Enterprise Software</title>
    <link>https://community.hpe.com/t5/hpe-morpheus-enterprise-software/how-would-i-iterate-through-containers-in-the-variable-syntax/m-p/7251126#M4300</link>
    <description>&lt;P&gt;Variable replacement is done prior to script execution. It depends how you want to utilise the list of internal IPs. You could use the collect closure in groovy to return a list of internal ips for all containers:&lt;/P&gt;
&lt;PRE style="background : #f0f1f2;"&gt;&lt;CODE class="lang-auto"&gt;echo "&amp;lt;%= instance.containers.collect{it.internalIp} %&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 Apr 2022 13:35:16 GMT</pubDate>
    <dc:creator>cdtaylor</dc:creator>
    <dc:date>2022-04-11T13:35:16Z</dc:date>
    <item>
      <title>How would I iterate through containers in the variable syntax?</title>
      <link>https://community.hpe.com/t5/hpe-morpheus-enterprise-software/how-would-i-iterate-through-containers-in-the-variable-syntax/m-p/7251125#M4299</link>
      <description>&lt;P&gt;I am looking to get the internalip value from the containers list when using &amp;lt;%= instance.containers %&amp;gt; in bash script.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 10:38:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-morpheus-enterprise-software/how-would-i-iterate-through-containers-in-the-variable-syntax/m-p/7251125#M4299</guid>
      <dc:creator />
      <dc:date>2022-04-11T10:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: How would I iterate through containers in the variable syntax?</title>
      <link>https://community.hpe.com/t5/hpe-morpheus-enterprise-software/how-would-i-iterate-through-containers-in-the-variable-syntax/m-p/7251126#M4300</link>
      <description>&lt;P&gt;Variable replacement is done prior to script execution. It depends how you want to utilise the list of internal IPs. You could use the collect closure in groovy to return a list of internal ips for all containers:&lt;/P&gt;
&lt;PRE style="background : #f0f1f2;"&gt;&lt;CODE class="lang-auto"&gt;echo "&amp;lt;%= instance.containers.collect{it.internalIp} %&amp;gt;"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Apr 2022 13:35:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-morpheus-enterprise-software/how-would-i-iterate-through-containers-in-the-variable-syntax/m-p/7251126#M4300</guid>
      <dc:creator>cdtaylor</dc:creator>
      <dc:date>2022-04-11T13:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: How would I iterate through containers in the variable syntax?</title>
      <link>https://community.hpe.com/t5/hpe-morpheus-enterprise-software/how-would-i-iterate-through-containers-in-the-variable-syntax/m-p/7251127#M4301</link>
      <description>&lt;P&gt;Don’t have an answer on dynamically iterating.&lt;/P&gt;
&lt;P&gt;However, when using a fixed set of VMs in an instance I can use:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;echo “&amp;lt;%=instance.containers[0].hostname%&amp;gt;: &amp;lt;%=instance.containers[0].internalIp%&amp;gt;:  &amp;lt;%=instance.containers[0].externalIp%&amp;gt;”&lt;BR /&gt;
echo “&amp;lt;%=instance.containers[1].hostname%&amp;gt;: &amp;lt;%=instance.containers[1].internalIp%&amp;gt;:  &amp;lt;%=instance.containers[1].externalIp%&amp;gt;”&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It works for me because I know exactly how many VMs are in each instance.&lt;/P&gt;
&lt;P&gt;I could query the amount of  VMs in an instance by using:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;lt;%=instance.containers.size%&amp;gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;However, when iterating it fails for me:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;i=0&lt;BR /&gt;
while [ $i -ne &amp;lt;%=instance.containers.size%&amp;gt; ]&lt;BR /&gt;
do&lt;BR /&gt;
i=$(($i+1))&lt;BR /&gt;
echo “&amp;lt;%=instance.containers[$i].hostname%&amp;gt;: &amp;lt;%=instance.containers[$i].internalIp%&amp;gt;:  &amp;lt;%=instance.containers[$i].externalIp%&amp;gt;”&lt;BR /&gt;
done&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When I comment out the line echo "&amp;lt;%=instance.containers[$i].hostname%&amp;gt;, it still fails. Making me wonder if the variable replacement gets done before invoking the script. I think there’s some Groovy behind it.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 12:25:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/hpe-morpheus-enterprise-software/how-would-i-iterate-through-containers-in-the-variable-syntax/m-p/7251127#M4301</guid>
      <dc:creator />
      <dc:date>2022-04-11T12:25:58Z</dc:date>
    </item>
  </channel>
</rss>

