<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<div class="moz-cite-prefix">On 11/14/2014 04:41 PM, Aline Manera
wrote:<br>
</div>
<blockquote cite="mid:54664CF4.6080408@linux.vnet.ibm.com"
type="cite">
<br>
On 11/14/2014 04:36 PM, Crístian Viana wrote:
<br>
<blockquote type="cite">On 14-11-2014 15:15, Aline Manera wrote:
<br>
<blockquote type="cite">The reset() function is to clean up all
the mockup resources as it is running for the first time.
<br>
<br>
The whole code is:
<br>
<br>
params = {'vms': [u'test'], 'templates': [],
<br>
'networks': [u'default'], 'storagepools':
[u'default-pool']}
<br>
<br>
for res, items in params.iteritems():
<br>
resources = getattr(self, '%s_get_list' % res)()
<br>
for i in resources:
<br>
if i in items:
<br>
continue
<br>
<br>
try:
<br>
getattr(self, '%s_deactivate' %
res[:-1])(i)
<br>
except:
<br>
pass
<br>
<br>
getattr(self, '%s_delete' % res[:-1])(i)
<br>
<br>
<br>
"params" hold the first time configuration - so one only VM
named "test" must persist on 'test:///default' URI and the
same for storagepools and networks.
<br>
<br>
The first loop (for res, items in params.iteritems()) is to go
by the "params" list.
<br>
Then I collect all the resources for the API (resources =
getattr(self, '%s_get_list' % res)()).
<br>
The seconds loop is to identify the resources that need to be
removed, ie, will not be in the first run time. So I compared
the item against the "params" values.
<br>
<br>
Does that make sense?
<br>
</blockquote>
<br>
The logic makes sense but that's not what that code snippet
does. The keyword "continue" will skip the current iteration of
the *inner loop*, not the outer one - which I guess is what you
intended. In other words, the inner loop doesn't do anything.
<br>
</blockquote>
<br>
No - I want to skip only the inner loop
<br>
<br>
<blockquote type="cite">
<br>
Try removing the inner loop entirely; the code will still work
as before.
<br>
</blockquote>
<br>
No! The outer loop is for pass along vms, storagepools, networks.
The inner loop is for each VM, each storage pools, each network.
<br>
<br>
The inner loop will be skipped *only if* the resource is in the
default config (represented by "params")
<br>
</blockquote>
<br>
To clarify the inner loop could be replaced by:<br>
<br>
params = {'vms': [u'test'], 'templates': [],
<br>
'networks': [u'default'], 'storagepools':
[u'default-pool']}
<br>
<br>
for res, items in params.iteritems():
<br>
resources = getattr(self, '%s_get_list' % res)()
<br>
<br>
<b>for i in list(set(resources) - set(items):</b><br>
try:
<br>
getattr(self, '%s_deactivate' % res[:-1])(i)
<br>
except:
<br>
pass
<br>
<br>
getattr(self, '%s_delete' % res[:-1])(i)
<br>
<br>
<br>
<blockquote cite="mid:54664CF4.6080408@linux.vnet.ibm.com"
type="cite">
<br>
<br>
_______________________________________________
<br>
Kimchi-devel mailing list
<br>
<a class="moz-txt-link-abbreviated" href="mailto:Kimchi-devel@ovirt.org">Kimchi-devel@ovirt.org</a>
<br>
<a class="moz-txt-link-freetext" href="http://lists.ovirt.org/mailman/listinfo/kimchi-devel">http://lists.ovirt.org/mailman/listinfo/kimchi-devel</a>
<br>
</blockquote>
<br>
</body>
</html>