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/8.0.3.0/bora/vspherevmodl2/enumeration.html
bhagatp10 44eb68437b
Updated VC docs for v8.0.3.0 (#424)
Signed-off-by: Prajwal Bhagat <prajwal.bhagat@broadcom.com>

Co-authored-by: Prajwal Bhagat <prajwal.bhagat@broadcom.com>
2024-07-03 17:44:27 +05:30

182 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>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Interface definition language to python mapping for enumerated types &mdash; vSphere Automation SDK for Python. 8.0.3.0 documentation</title>
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
<script src="../../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script src="../../_static/jquery.js"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/sphinx_highlight.js"></script>
<script src="../../_static/js/theme.js"></script>
<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">
vSphere Automation SDK for Python.
</a>
<div class="version">
8.0.3.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" aria-label="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="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../com.html">com 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="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">vSphere Automation SDK for Python.</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item active">Interface definition language to python mapping for enumerated types</li>
<li class="wy-breadcrumbs-aside">
<a href="../../_sources/bora/vspherevmodl2/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">
<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 heading"></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>
<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 heading"></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>
</section>
<section id="code-examples">
<h2>Code Examples<a class="headerlink" href="#code-examples" title="Permalink to this heading"></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="nb">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="nb">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="nb">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>
</section>
</section>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>&#169; Copyright 2024, Broadcom, Inc..</p>
</div>
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>