1
0
mirror of https://github.com/vmware/vsphere-automation-sdk-python.git synced 2024-11-22 17:39:59 -05:00
vsphere-automation-sdk-python/vsphere/6.0/_modules/vmware/vapi/provider/lib.html
2018-08-07 16:42:25 -07:00

172 lines
13 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>vmware.vapi.provider.lib &mdash; vCloud Suite SDK for Python 6.0.0 documentation</title>
<link rel="stylesheet" href="../../../../_static/vapitheme.css" type="text/css" />
<link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../../../',
VERSION: '6.0.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../../../../_static/jquery.js"></script>
<script type="text/javascript" src="../../../../_static/underscore.js"></script>
<script type="text/javascript" src="../../../../_static/doctools.js"></script>
<link rel="top" title="vCloud Suite SDK for Python 6.0.0 documentation" href="../../../../index.html" />
<link rel="up" title="Module code" href="../../../index.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../../../index.html">vCloud Suite SDK for Python 6.0.0 documentation</a> &raquo;</li>
<li><a href="../../../index.html" accesskey="U">Module code</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<h1>Source code for vmware.vapi.provider.lib</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Utility library for Provider modules</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="n">__author__</span> <span class="o">=</span> <span class="s">&#39;VMware, Inc.&#39;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s">&#39;Copyright 2013 VMware, Inc. All rights reserved. -- VMware Confidential&#39;</span>
<span class="kn">from</span> <span class="nn">vmware.vapi.core</span> <span class="kn">import</span> <span class="n">MethodResult</span><span class="p">,</span> <span class="n">MethodDefinition</span>
<span class="kn">from</span> <span class="nn">vmware.vapi.data.value</span> <span class="kn">import</span> <span class="n">StructValue</span><span class="p">,</span> <span class="n">ListValue</span>
<span class="kn">from</span> <span class="nn">vmware.vapi.lib.constants</span> <span class="kn">import</span> <span class="n">Introspection</span>
<div class="viewcode-block" id="augment_method_result_with_errors"><a class="viewcode-back" href="../../../../vmware.vapi.provider.html#vmware.vapi.provider.lib.augment_method_result_with_errors">[docs]</a><span class="k">def</span> <span class="nf">augment_method_result_with_errors</span><span class="p">(</span><span class="n">service_id</span><span class="p">,</span> <span class="n">operation_id</span><span class="p">,</span> <span class="n">method_result</span><span class="p">,</span>
<span class="n">errors_to_augment</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Returns a new method result that is identical to `method_result` except that</span>
<span class="sd"> the `errors_definition` field in the `output` (which is of type Operation.Info</span>
<span class="sd"> from Introspection service) contains the errors from the Info structure in</span>
<span class="sd"> `method_result` plus the errors in `errors_to_augment`. This code will be</span>
<span class="sd"> executed only for &quot;get&quot; operation in vAPI Operation Introspection service.</span>
<span class="sd"> :type service_id: :class:`str`</span>
<span class="sd"> :param service_id: Service identifier</span>
<span class="sd"> :type operation_id: :class:`str`</span>
<span class="sd"> :param operation_id: Operation identifier</span>
<span class="sd"> :type method_result: :class:`vmware.vapi.core.MethodResult`</span>
<span class="sd"> :param method_result: Operation result</span>
<span class="sd"> :type errors_to_augment: :class:`list` of :class:`vmware.vapi.data.value.StructValue`</span>
<span class="sd"> :param errors_to_augment: Errors to augment. These are struct values of type</span>
<span class="sd"> com.vmware.vapi.std.introspection.Operation.DataDefinition whose `type`</span>
<span class="sd"> field has the value ERROR</span>
<span class="sd"> to the DataDefinition type in Introspection service IDL.</span>
<span class="sd"> :rtype: :class:`vmware.vapi.data.value.DataValue`</span>
<span class="sd"> :return: Output data value</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">method_result</span><span class="o">.</span><span class="n">success</span><span class="p">():</span>
<span class="k">if</span> <span class="p">(</span><span class="n">service_id</span> <span class="o">==</span> <span class="n">Introspection</span><span class="o">.</span><span class="n">OPERATION_SVC</span> <span class="ow">and</span>
<span class="n">operation_id</span> <span class="o">==</span> <span class="s">&#39;get&#39;</span><span class="p">):</span>
<span class="n">output</span> <span class="o">=</span> <span class="n">method_result</span><span class="o">.</span><span class="n">output</span>
<span class="n">augmented_output</span> <span class="o">=</span> <span class="n">StructValue</span><span class="p">(</span>
<span class="s">&#39;com.vmware.vapi.std.introspection.operation.info&#39;</span><span class="p">)</span>
<span class="n">augmented_output</span><span class="o">.</span><span class="n">set_field</span><span class="p">(</span>
<span class="s">&#39;input_definition&#39;</span><span class="p">,</span>
<span class="n">output</span><span class="o">.</span><span class="n">get_field</span><span class="p">(</span><span class="s">&#39;input_definition&#39;</span><span class="p">))</span>
<span class="n">augmented_output</span><span class="o">.</span><span class="n">set_field</span><span class="p">(</span>
<span class="s">&#39;output_definition&#39;</span><span class="p">,</span>
<span class="n">output</span><span class="o">.</span><span class="n">get_field</span><span class="p">(</span><span class="s">&#39;output_definition&#39;</span><span class="p">))</span>
<span class="n">errors</span> <span class="o">=</span> <span class="n">ListValue</span><span class="p">()</span>
<span class="n">error_names</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">error_def</span> <span class="ow">in</span> <span class="n">output</span><span class="o">.</span><span class="n">get_field</span><span class="p">(</span><span class="s">&#39;error_definitions&#39;</span><span class="p">):</span>
<span class="n">errors</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">error_def</span><span class="p">)</span>
<span class="n">error_names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">error_def</span><span class="o">.</span><span class="n">get_field</span><span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
<span class="k">for</span> <span class="n">error_def</span> <span class="ow">in</span> <span class="n">errors_to_augment</span><span class="p">:</span>
<span class="k">if</span> <span class="n">error_def</span><span class="o">.</span><span class="n">get_field</span><span class="p">(</span><span class="s">&#39;name&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">value</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">error_names</span><span class="p">:</span>
<span class="n">errors</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">error_def</span><span class="p">)</span>
<span class="n">augmented_output</span><span class="o">.</span><span class="n">set_field</span><span class="p">(</span><span class="s">&#39;error_definitions&#39;</span><span class="p">,</span> <span class="n">errors</span><span class="p">)</span>
<span class="k">return</span> <span class="n">MethodResult</span><span class="p">(</span><span class="n">output</span><span class="o">=</span><span class="n">augmented_output</span><span class="p">)</span>
<span class="k">return</span> <span class="n">method_result</span>
</div>
<div class="viewcode-block" id="augment_method_def_with_errors"><a class="viewcode-back" href="../../../../vmware.vapi.provider.html#vmware.vapi.provider.lib.augment_method_def_with_errors">[docs]</a><span class="k">def</span> <span class="nf">augment_method_def_with_errors</span><span class="p">(</span><span class="n">method_def</span><span class="p">,</span> <span class="n">errors</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Add errors reported by this ApiProviderFilter to a method definition.</span>
<span class="sd"> This method clones the input method definition and appends errors. It</span>
<span class="sd"> does not modify the parameter.</span>
<span class="sd"> :type method_def: :class:`vmware.vapi.core.MethodDefinition`</span>
<span class="sd"> :param method_def: Method definition</span>
<span class="sd"> :type errors: :class:`list` of :class:`vmware.vapi.data.definition.ErrorDefinition`</span>
<span class="sd"> :param errors: Error definitions to augment to MethodDefinition</span>
<span class="sd"> :rtype: :class:`vmware.vapi.core.MethodDefinition`</span>
<span class="sd"> :return: Method definition after augmenting the errors</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">method_errors</span> <span class="o">=</span> <span class="n">method_def</span><span class="o">.</span><span class="n">get_error_definitions</span><span class="p">()</span>
<span class="k">return</span> <span class="n">MethodDefinition</span><span class="p">(</span><span class="n">method_def</span><span class="o">.</span><span class="n">get_identifier</span><span class="p">(),</span>
<span class="n">method_def</span><span class="o">.</span><span class="n">get_input_definition</span><span class="p">(),</span>
<span class="n">method_def</span><span class="o">.</span><span class="n">get_output_definition</span><span class="p">(),</span>
<span class="n">method_errors</span><span class="o">.</span><span class="n">union</span><span class="p">(</span><span class="n">errors</span><span class="p">))</span></div>
</pre></div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../../../../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../../../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../../../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li><a href="../../../../index.html">vCloud Suite SDK for Python 6.0.0 documentation</a> &raquo;</li>
<li><a href="../../../index.html" >Module code</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2014, VMware, Inc..
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
</div>
</body>
</html>