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/vmc/enumeration.html

272 lines
12 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interface definition language to python mapping for enumerated types &mdash; VMware Cloud on AWS Console API 1.13.0 documentation</title>
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></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>
<script type="text/javascript" src="_static/language_data.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home"> VMware Cloud on AWS Console API
</a>
<div class="version">
1.13.0
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="com.html">com package</a></li>
<li class="toctree-l1"><a class="reference internal" href="vmware.html">vmware package</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">VMware Cloud on AWS Console API</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> &raquo;</li>
<li>Interface definition language to python mapping for enumerated types</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/enumeration.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="interface-definition-language-to-python-mapping-for-enumerated-types">
<span id="enumeration-description"></span><h1>Interface definition language to python mapping for enumerated types<a class="headerlink" href="#interface-definition-language-to-python-mapping-for-enumerated-types" title="Permalink to this headline"></a></h1>
<p>The interface language definition type system includes enumerated types. Python
SDK supports both 2.x and 3.x versions of Python. Since Python 2.x does
not have first class support for enumerations, special classes are
generated to represent enumerated types from the interface definition
language. The special class contains class attributes which represent
the values of the enumerated type.</p>
<p>This documentation explains the following:</p>
<ul class="simple">
<li><p>How the class variables are defined in the module. This specifies the names that you can use in your program.</p></li>
<li><p>How you instantiate a class to use it for communication with future versions of the service.</p></li>
</ul>
<div class="section" id="example-of-an-enumerated-type-documentation">
<h2>Example of an enumerated type documentation<a class="headerlink" href="#example-of-an-enumerated-type-documentation" title="Permalink to this headline"></a></h2>
<dl>
<dt><em>class</em> com.vmware.vapi.metadata_client. <strong>SourceType</strong> (string)</dt><dd><p>Bases: vmware.vapi.bindings.enum.Enum</p>
<p>Metadata source type</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This class represents an enumerated type in the interface language definition type system. The class contains class attributes which represent the values in the current version of the enumerated type. Newer versions of the enumerated type may contain new values. To use new values of the enumerated type in communication with a server that supports a newer version of the API, you instantiate this class. See <a class="reference internal" href="#enumeration-description"><span class="std std-ref">enumerated type description page</span></a>.</p>
</div>
<p><strong>Parameters</strong> : <strong>string</strong> (<code class="docutils literal notranslate"><span class="pre">str</span></code>) String value for the SourceType instance.</p>
<dl class="simple">
<dt><strong>FILE</strong> = <em>SourceType(string=FILE)</em></dt><dd><p>If the source is backed by a file.</p>
</dd>
<dt><strong>REMOTE</strong> = <em>SourceType(string=REMOTE)</em></dt><dd><p>If the source is backed by a remote service.</p>
</dd>
</dl>
</dd>
</dl>
</div>
<div class="section" id="code-examples">
<h2>Code Examples<a class="headerlink" href="#code-examples" title="Permalink to this headline"></a></h2>
<p>The enumerated type classes are defined in python modules that your code
imports. You can use these in your code.</p>
<ol class="arabic simple">
<li><p>If you want to pass an enumerated type value in a method to a server, specify the class variable of the enumerated type class.</p></li>
</ol>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># SourceType is an enumerated type</span>
<span class="kn">from</span> <span class="nn">com.vmware.vapi.metadata_client</span> <span class="kn">import</span> <span class="n">SourceType</span>
<span class="c1"># SourceType has two class attrites, SourceType.FILE and SourceType.REMOTE</span>
<span class="n">spec</span> <span class="o">=</span> <span class="n">Source</span><span class="o">.</span><span class="n">CreateSpec</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="n">SourceType</span><span class="o">.</span><span class="n">FILE</span><span class="p">,</span> <span class="n">filepath</span><span class="o">=</span><span class="s1">&#39;entity_metadata.json&#39;</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s1">&#39;Entity service&#39;</span><span class="p">)</span>
<span class="n">source_svc</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="s1">&#39;entity&#39;</span><span class="p">,</span> <span class="n">spec</span><span class="o">=</span><span class="n">spec</span><span class="p">)</span>
</pre></div>
</div>
<ol class="arabic simple" start="2">
<li><p>When you receive an enumerated type value in the response from a server, allow for unknown enumerated type values.</p></li>
</ol>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># SourceType is an enumerated type</span>
<span class="kn">from</span> <span class="nn">com.vmware.vapi.metadata_client</span> <span class="kn">import</span> <span class="n">SourceType</span>
<span class="n">source_info</span> <span class="o">=</span> <span class="n">source_svc</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="s1">&#39;entity&#39;</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">source_info</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">SourceType</span><span class="o">.</span><span class="n">FILE</span><span class="p">)</span> <span class="p">{</span>
<span class="k">print</span> <span class="s1">&#39;Source is a file&#39;</span>
<span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="n">source_info</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">SourceType</span><span class="o">.</span><span class="n">REMOTE</span><span class="p">)</span> <span class="p">{</span>
<span class="k">print</span> <span class="s1">&#39;Source is a remote provider&#39;</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="k">print</span> <span class="s1">&#39;Unknown source type: </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">source_info</span><span class="o">.</span><span class="n">type</span><span class="p">)</span>
<span class="p">}</span>
</pre></div>
</div>
<ol class="arabic simple" start="3">
<li><p>Sending a new enumerated type value to a server that has a newer version of the enumerated type.</p></li>
</ol>
<p>To use new values of the enumerated type in communication with a server that supports a newer version of the API, you instantiate the
enumerated type class.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># If a newer version of SourceType has a new value FOLDER, FOLDER would be one</span>
<span class="c1"># of the class attributes for SourceType. In the older version, SourceType has</span>
<span class="c1"># only two class attributes, FILE and REMOTE</span>
<span class="kn">from</span> <span class="nn">com.vmware.vapi.metadata_client</span> <span class="kn">import</span> <span class="n">SourceType</span>
<span class="n">spec</span> <span class="o">=</span> <span class="n">Source</span><span class="o">.</span><span class="n">CreateSpec</span><span class="p">(</span><span class="nb">type</span><span class="o">=</span><span class="n">SourceType</span><span class="p">(</span><span class="s1">&#39;FOLDER&#39;</span><span class="p">),</span> <span class="n">filepath</span><span class="o">=</span><span class="s1">&#39;entity_metadata&#39;</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s1">&#39;Entity service&#39;</span><span class="p">)</span>
<span class="n">source_svc</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="s1">&#39;entity&#39;</span><span class="p">,</span> <span class="n">spec</span><span class="o">=</span><span class="n">spec</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2019, VMware, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>