serializers Package

serializers Package

introspection Module

Convenient libraries for introspection data

vmware.vapi.data.serializers.introspection.convert_data_def_to_data_value(data_def)[source]

Convert vmware.vapi.data.definition.DataDefinition object to vmware.vapi.data.value.DataValue object. The type of the object returned is a struct value that corresponds to DataDefinition VMODL2 type present in introspection service.

Parameters:data_def (vmware.vapi.data.definition.DataDefinition) – Data definition
Return type:vmware.vapi.data.value.DataValue
Returns:Data value representing the data definition object
vmware.vapi.data.serializers.introspection.convert_data_value_to_data_def(data_value)[source]

Convert vmware.vapi.data.value.DataValue object that corresponds to DataDefinition structure in introspection VMODL2 into vmware.vapi.data.definition.DataDefinition object.

Parameters:data_value (vmware.vapi.data.value.DataValue) – Data value representing the data definition object
Return type:vmware.vapi.data.definition.DataDefinition
Returns:Data definition

jsonrpc Module

Json rpc de/serializer

class vmware.vapi.data.serializers.jsonrpc.DecimalEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]

Bases: json.encoder.JSONEncoder

Class that adds capability of encoding decimal in JSON

Constructor for JSONEncoder, with sensible defaults.

If skipkeys is False, then it is a TypeError to attempt encoding of keys that are not str, int, long, float or None. If skipkeys is True, such items are simply skipped.

If ensure_ascii is True, the output is guaranteed to be str objects with all incoming unicode characters escaped. If ensure_ascii is false, the output will be unicode object.

If check_circular is True, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an OverflowError). Otherwise, no such check takes place.

If allow_nan is True, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.

If sort_keys is True, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

If specified, separators should be a (item_separator, key_separator) tuple. The default is (‘, ‘, ‘: ‘). To get the most compact JSON representation you should specify (‘,’, ‘:’) to eliminate whitespace.

If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError.

If encoding is not None, then all input strings will be transformed into unicode using that encoding prior to JSON-encoding. The default is UTF-8.

default(o)[source]
exception vmware.vapi.data.serializers.jsonrpc.JsonRpc20Error(code, message=None, data=None)[source]

Bases: vmware.vapi.data.serializers.jsonrpc.JsonRpcError

json rpc 2.0 error

Json rpc 2.0 error

Parameters:
  • code (int) – error type that occurred
  • message (str) – a short description of the error
  • data (Primitive type / dict / None) – more info about the error
DEFAULT_MESSAGES = {-32700: 'Parse error.', -32603: 'Internal error.', -32602: 'Invalid params.', -32601: 'Method not found.', -32600: 'Invalid Request.', -32300: 'Transport error.'}
INTERNAL_ERROR = -32603
INVALID_PARAMS = -32602
INVALID_REQUEST = -32600
METHOD_NOT_FOUND = -32601
PARSE_ERROR = -32700
SERVER_ERROR_RANGE_MAX = -32000
SERVER_ERROR_RANGE_MIN = -32768
TRANSPORT_ERROR = -32300
class vmware.vapi.data.serializers.jsonrpc.JsonRpc20Request(**kwargs)[source]

Bases: vmware.vapi.data.serializers.jsonrpc.JsonRpcRequest

Json rpc 2.0 request

Json rpc 2.0 request init

Parameters:
  • jsonrpc (str or None) – json rpc request version
  • method (str) – json rpc method
  • params (dict or list or None) – json rpc method params
  • id (long or int or str or None) – json rpc request id. Do not set for notification
serialize()[source]

Serialize a json rpc 2.0 request

Return type:str
Returns:json rpc request str
serialize_notification()[source]

Serialize a json rpc 2.0 notification

Return type:str
Returns:json rpc notification str
validate_response(response)[source]

Validate a json rpc 2.0 response. Check for version / id mismatch with request

Parameters:response (JsonRpcResponse) – json rpc response object to validate
class vmware.vapi.data.serializers.jsonrpc.JsonRpc20Response(**kwargs)[source]

Bases: vmware.vapi.data.serializers.jsonrpc.JsonRpcResponse

Json rpc 2.0 response

Json rpc 2.0 response init Either result or error must be set, but not both

Parameters:
  • jsonrpc (str or None) – json rpc response version
  • result (dict) – json rpc response dict
  • error (JsonRpcError or dict) – json rpc response error
  • id (long or int or str) – json rpc response id
serialize()[source]

Serialize a json rpc 2.0 response

Return type:str
Returns:json rpc response str
class vmware.vapi.data.serializers.jsonrpc.JsonRpcDictToVapi[source]

Bases: object

Json rpc dict to vapi type

Json rpc dict to vapi type init

static app_ctx(ctx)[source]

get application context from jsonrpc dict

Parameters:ctx (dict) – json application context
Return type:str
Returns:operation identifier
static data_value(value)[source]

get data value from new jsonrpc dict

# TODO: Structure names and its fields are converted from # u’’ format to str format. This will break if we allow non # ASCII characters in the IDL

Parameters:value (dict) – json data value
Return type:subclass of vmware.vapi.data.value.DataValue
Returns:subclass of data value
static error_value(value)[source]

get error value from jsonrpc dict

Parameters:msg (dict) – json error value
Return type:vmware.vapi.data.value.ErrorValue
Returns:error value
static execution_context(ctx)[source]

get execution context from jsonrpc dict

Parameters:ctx (dict) – json execution context
Return type:vmware.vapi.core.ExecutionContext
Returns:execution context
static method_result(result)[source]

get method result from jsonrpc dict

Parameters:result (dict) – json method result
Return type:vmware.vapi.core.MethodResult
Returns:method result
static security_ctx(ctx)[source]

get security context from jsonrpc dict

Parameters:ctx (dict) – json security context
Return type:vmware.vapi.core.SecurityContext
Returns:json user session
exception vmware.vapi.data.serializers.jsonrpc.JsonRpcError(error)[source]

Bases: exceptions.Exception

json rpc error base class

json rpc error base class constructor

Parameters:error (dict) – json rpc error
class vmware.vapi.data.serializers.jsonrpc.JsonRpcRequest(version, method, params=None, notification=True, request_id=None)[source]

Bases: object

Json rpc request base class

Json rpc request base class constructor

Parameters:
  • version (str) – json rpc request version
  • method (str) – json rpc method
  • params (dict or list or None) – json rpc method params
  • notification (bool) – True for notification
  • request_id (long or int or str or None) – json rpc request id. Do not set for notification
serialize()[source]

Serialize a json rpc request

Return type:str
Returns:json rpc request str
validate_response(response)[source]

Validate a json rpc response. Check for version / id mismatch with request

Parameters:response (JsonRpcResponse) – json rpc response object to validate
class vmware.vapi.data.serializers.jsonrpc.JsonRpcResponse(version, response_id, result, error=None)[source]

Bases: object

Json rpc response base class

Json rpc response base class constructor

Parameters:
  • version (str) – json rpc response version
  • response_id (long or int or str or None) – json rpc response id
  • result (dict) – json rpc response dict
  • error (JsonRpcError) – json rpc error
serialize()[source]

Serialize a json rpc response

Return type:str
Returns:json rpc response str
class vmware.vapi.data.serializers.jsonrpc.VAPIJsonEncoder(*args, **kwargs)[source]

Bases: json.encoder.JSONEncoder

Custon JSON encoder that converts vAPI runtime types directly into JSON string representation.

encode(value)[source]

Encode a given vAPI runtime object

Parameters:value (object) – vAPI runtime object
Return type:str
Returns:JSON string
visit_default(value)[source]

This is the default visit method if the type of the input value does not match any type in the keys present in dispatch map.

Parameters:value (object) – Python object
Return type:str
Returns:JSON string
visit_dict(value)[source]

Visit a dictionary. Application context and Security Context in vAPI is a free form object, so it can contain a dictionary.

Parameters:value (dict) – Dictionary value
Return type:str
Returns:JSON string
static visit_double_value(value)[source]

Visit a DoubleValue object

Parameters:value (vmware.vapi.data.value.DoubleValue) – Double value object
Return type:str
Returns:JSON string
visit_execution_context(value)[source]

Visit an ExecutionContext object

Parameters:value (vmware.vapi.core.ExecutionContext) – ExecutionContext object
Return type:str
Returns:JSON string
visit_list(value)[source]

Visit a ListValue object

Parameters:value (vmware.vapi.data.value.ListValue) – List value object
Return type:str
Returns:JSON string
visit_method_result(value)[source]

Visit a MethodResult object

Parameters:value (vmware.vapi.core.MethodResult) – MethodResult object
Return type:str
Returns:JSON string
visit_optional_value(value)[source]

Visit a OptionalValue object

Parameters:value (vmware.vapi.data.value.OptionalValue) – Optional value object
Return type:str
Returns:JSON string
visit_primitive_value(value)[source]

Visit one of StringValue, IntegerValue, BooleanValue or VoidValue

Parameters:value (vmware.vapi.data.value.StringValue (or) vmware.vapi.data.value.IntegerValue (or) vmware.vapi.data.value.BooleanValue (or) vmware.vapi.data.value.VoidValue (or)) – StringValue, IntegerValue, BooleanValue or VoidValue object
Return type:str
Returns:JSON string
visit_primitive_value_with_type_name(value)[source]

Visit one of BlobValue or SecretValue

Parameters:value (vmware.vapi.data.value.BlobValue (or) vmware.vapi.data.value.SecretValue) – BlobValue or SecretValue object
Return type:str
Returns:JSON string
visit_struct_value(value)[source]

Visit a StructValue object

Parameters:value (vmware.vapi.data.value.StructValue) – Struct value object
Return type:str
Returns:JSON string
vmware.vapi.data.serializers.jsonrpc.canonicalize_double(o)[source]

Canonicalize double based on XML schema double canonical format

The exponent must be indicated by “E”. Leading zeroes and the preceding optional “+” sign are prohibited in the exponent. If the exponent is zero, it must be indicated by “E0”. For the mantissa, the preceding optional “+” sign is prohibited and the decimal point is required. Leading and trailing zeroes are prohibited subject to the following: number representations must be normalized such that there is a single digit which is non-zero to the left of the decimal point and at least a single digit to the right of the decimal point unless the value being represented is zero. The canonical representation for zero is 0.0E0 http://www.w3.org/TR/xmlschema-2/#double

Parameters:o (decimal.Decimal) – Decimal object to be canonicalized
Return type:str
Returns:Canonical string representation of the decimal
vmware.vapi.data.serializers.jsonrpc.deserialize_request(request_str)[source]

Deserialize a json rpc request

Parameters:request_str (str or bytes: or file) – json rpc request str or a file like object
Return type:JsonRpcRequest
Returns:json rpc request
vmware.vapi.data.serializers.jsonrpc.deserialize_response(response_str)[source]

Deserialize a json rpc response

Parameters:response_str (str or bytes) – json rpc response str
Return type:JsonRpcResponse
Returns:json rpc response
vmware.vapi.data.serializers.jsonrpc.jsonrpc_request_factory(**kwargs)[source]

Json rpc request factory For json 2.0: set jsonrpc to ‘2.0’ For json 1.1: set version to ‘1.1’ For json 1.0: set neither jsonrpc / version The parameters accepted depends on json version See corresponding json rpc request class for init parameters

Parameters:
  • jsonrpc (str or None) – json rpc request version (2.0)
  • version (str or None) – json rpc request version (1.1)
  • method (str) – json rpc method
  • params (dict or list or None) – json rpc method params
  • id (long or int or str or None) – json rpc request id. Do not set for notification
Return type:

JsonRpcRequest

Returns:

json rpc request object

vmware.vapi.data.serializers.jsonrpc.jsonrpc_response_factory(**kwargs)[source]

Json rpc response factory For json 2.0: set jsonrpc to ‘2.0’ For json 1.1: set version to ‘1.1’ For json 1.0: set neither jsonrpc / version The parameters accepted depends on json version See corresponding json rpc response class for init parameters

Parameters:
  • jsonrpc (str or None) – json rpc response version (2.0)
  • version (str or None) – json rpc response version (1.1)
  • method (str) – json rpc method
  • params (dict or list or None) – json rpc method params
  • id (long or int or str) – json rpc response id
Return type:

JsonRpcResponse

Returns:

json rpc response object

vmware.vapi.data.serializers.jsonrpc.to_strkey_dict(dictionary)[source]

Convert a unicode key dict into str key dict

Parameters:dictionary (dict) – unicode dictionary
Return type:dict
Returns:string key dict
vmware.vapi.data.serializers.jsonrpc.vapi_jsonrpc_error_internal_error(data=None)[source]

vapi json rpc internal error

Parameters:data (dict) – json rpc error object
Return type:JsonRpcError
Returns:json rpc error object
vmware.vapi.data.serializers.jsonrpc.vapi_jsonrpc_error_invalid_params(data=None)[source]

vapi json rpc invalid params error

Parameters:data (dict) – json rpc error object
Return type:JsonRpcError
Returns:json rpc error object
vmware.vapi.data.serializers.jsonrpc.vapi_jsonrpc_error_invalid_request(data=None)[source]

vapi json rpc invalid request error

Parameters:data (dict) – json rpc error object
Return type:JsonRpcError
Returns:json rpc error object
vmware.vapi.data.serializers.jsonrpc.vapi_jsonrpc_error_method_not_found(data=None)[source]

vapi json rpc method not found error

Parameters:data (dict) – json rpc error object
Return type:JsonRpcError
Returns:json rpc error object
vmware.vapi.data.serializers.jsonrpc.vapi_jsonrpc_error_parse_error(data=None)[source]

vapi json rpc parse error

Parameters:data (dict) – json rpc error object
Return type:JsonRpcError
Returns:json rpc error object
vmware.vapi.data.serializers.jsonrpc.vapi_jsonrpc_error_transport_error(data=None)[source]

vapi json rpc transport error

Parameters:data (dict) – json rpc error object
Return type:JsonRpcError
Returns:json rpc error object
vmware.vapi.data.serializers.jsonrpc.vapi_jsonrpc_notification_factory(**kwargs)[source]

vapi json rpc notification factory

Parameters:
  • method (str) – json rpc method
  • params (dict or list or None) – json rpc method params
Return type:

JsonRpcRequest

Returns:

json rpc request object

vmware.vapi.data.serializers.jsonrpc.vapi_jsonrpc_request_factory(**kwargs)[source]

Json rpc request factory

Parameters:
  • method (str) – json rpc method
  • params (dict or list or None) – json rpc method params
  • id (long or int or str or None) – json rpc request id. Do not set for notification
Return type:

JsonRpcRequest

Returns:

json rpc request object

vmware.vapi.data.serializers.jsonrpc.vapi_jsonrpc_response_factory(request, **kwargs)[source]

vapi json rpc response factory

Parameters:
  • request (JsonRpcRequest) – json rpc request object
  • kwargs (dict) – See JsonRpc20Response for constructor parameters
Return type:

JsonRpcResponse

Returns:

json rpc response object

python Module

Convenience methods to convert to/from python native values to data values

vmware.vapi.data.serializers.python.build_data_value(py_value, data_def)[source]

Converts a native python value to data value using the provided data definition

Parameters:
Return type:

vmware.vapi.data.value.DataValue

Returns:

Data value

vmware.vapi.data.serializers.python.build_py_value(data_value, data_def=None, impl=None)[source]

” Converts a data value to python native value impl input is required to create Struct class instances

Parameters:
Return type:

object

Returns:

Native python value

Table Of Contents

Previous topic

data Package

Next topic

debug Package

This Page