serializers Package

serializers Package

cleanjson Module

Serializer vAPI data values to clean (human readable/writable) json documents

class vmware.vapi.data.serializers.cleanjson.DataValueConverter[source]

Bases: object

Converter class that converts values from vAPI DataValue to clean JSON objects.

static convert_to_json(data_value)[source]

Convert the given data value to a JSON string representation

Parameters:data_value (vmware.vapi.data.value.DataValue) – Data value to be converted
Return type:str
Returns:JSON representation of the data value
class vmware.vapi.data.serializers.cleanjson.DataValueToJSONEncoder(*args, **kwargs)[source]

Bases: json.encoder.JSONEncoder

Custon JSON encoder that converts vAPI runtime values 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_blob_value(value)[source]

Visit BlobValue

Parameters:value (vmware.vapi.data.value.BlobValue) – BlobValue 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
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_list(value)[source]

Visit a ListValue object

Parameters:value (vmware.vapi.data.value.ListValue) – List value 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_struct_value(value)[source]

Visit a StructValue object

Parameters:value (vmware.vapi.data.value.StructValue) – Struct value object
Return type:str
Returns:JSON string

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

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

Custom 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_blob_value_with_type_name(value)[source]

Visit BlobValue

Parameters:value (vmware.vapi.data.value.BlobValue) – BlobValue 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 SecretValue

Parameters:value (vmware.vapi.data.value.SecretValue) – 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.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

Subpackages

Table Of Contents

Previous topic

data Package

Next topic

debug Package

This Page