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.
This documentation explains the following:
Bases: vmware.vapi.bindings.enum.Enum
Metadata source type
Note
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 enumerated type description page.
Parameters : string (str) – String value for the SourceType instance.
The enumerated type classes are defined in python modules that your code imports. You can use these in your code.
# SourceType is an enumerated type
from com.vmware.vapi.metadata_client import SourceType
# SourceType has two class attrites, SourceType.FILE and SourceType.REMOTE
spec = Source.CreateSpec(type=SourceType.FILE, filepath='entity_metadata.json', description='Entity service')
source_svc.create(id='entity', spec=spec)
# SourceType is an enumerated type
from com.vmware.vapi.metadata_client import SourceType
source_info = source_svc.get(id='entity')
if (source_info.type == SourceType.FILE) {
print 'Source is a file'
} else if (source_info.type == SourceType.REMOTE) {
print 'Source is a remote provider'
} else {
print 'Unknown source type: %s' % str(source_info.type)
}
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.
# If a newer version of SourceType has a new value FOLDER, FOLDER would be one
# of the class attributes for SourceType. In the older version, SourceType has
# only two class attributes, FILE and REMOTE
from com.vmware.vapi.metadata_client import SourceType
spec = Source.CreateSpec(type=SourceType('FOLDER'), filepath='entity_metadata', description='Entity service')
source_svc.create(id='entity', spec=spec)