server Package

server Package

asyncore_http Module

Asyncore http connection

class vmware.vapi.server.asyncore_http.AsyncChatWriteAdapter(chat_obj)[source]

Bases: object

Async chat write adapter

Async chat write adapter init

Parameters:chat_obj (asynchat.async_chat) – async chat object
close()[source]
flush()[source]
write(buf)[source]
Parameters:buf (str) – data to write
class vmware.vapi.server.asyncore_http.AsyncoreHttpConnection(server, sock_map, sock, from_addr, protocol_factory)[source]

Bases: asynchat.async_chat, BaseHTTPServer.BaseHTTPRequestHandler

Async Http connection with async chat

Async Http connection with async chat

Parameters:
  • sock_map (dict) – Global socket map
  • sock (socket.socket) – http connection socket
  • from_addr (tuple) – remote address bound to the socket
  • protocol_factory (HttpFactory) – protocol factory
cleanup()[source]

connection cleanup

close_when_done()[source]

close the connection after all data written

do_POST()[source]

Handle HTTP Post

finish()[source]

finish: Not used

handle()[source]

handle: Not used

handle_error()[source]

handle error callback

handle_expt()[source]

handle exception callback

handle_write()[source]

handle write

http_body_begin()[source]

request body begin

http_body_continue(data)[source]

request body continue

http_body_end()[source]

request body ended

http_headers_end(headers)[source]

http headers end callback

Parameters:headers (str) – http headers string
log_message(format, *args)[source]

Override the BaseHTTPServer.BaseHTTPRequestHandler method to send the log message to the log file instead of stderr.

:param format string :type args: tuple :param args: format argument(s)

protocol_version = 'HTTP/1.1'
readable()[source]

Can read more data?

:rtype bool :return True if this can handle more data

request_too_large(data_size, max_data_size)[source]

Send request too large error

Parameters:
  • data_size (int) – request data size
  • max_data_size (int) – max request data size allowed
send_error_(response_code, response_txt)[source]

Send http error

Parameters:
  • response_code (int) – http response code
  • response_txt (str) – http response text
set_handlers(found_term_handler, terminator, collect_in_data_handler)[source]

setup asynchat handlers

Parameters:
  • found_term_handler (function) – terminator found handler
  • terminator (str) – terminator string
  • collect_in_data_handler (function) – collect incoming data handler
setup()[source]

setup: Not used

setup_chunked_handler()[source]

setup asynchat http chunked handlers

setup_http_headers_handler()[source]

setup asynchat http headers handlers

setup_message_handler(content_len)[source]

setup asynchat http message body handlers

writable()[source]

Have something to write to http connection?

:rtype bool :return True if data is ready to write

class vmware.vapi.server.asyncore_http.ChunkedHandler(channel)[source]

Bases: vmware.vapi.server.asyncore_http.HttpBodyHandler

Async chat http chunked handler

Async chat http chunked handler init

Parameters:channel (HttpRequestHandler) – http request handler
chunked_data_collect_incoming_data(data)[source]

incoming data handler

Parameters:data (str) – incoming data
chunked_size_found_terminator()[source]

Found chunked size handler

chunked_trailer_found_terminator()[source]

Found chunked trailer terminator handler

class vmware.vapi.server.asyncore_http.ChunkedMessageBodyWriter(wfile, chunk_size=4096)[source]

Bases: object

Chunked message writer

Chunked message writer init

Parameters:
  • wfile (file) – file object to write to
  • chunk_size (int) – max write chunk size
close()[source]
flush()[source]
write(buf)[source]
Parameters:buf (str) – data to write
class vmware.vapi.server.asyncore_http.DataHandler(channel)[source]

Bases: object

Async chat data handler

Async chat data handler init

Parameters:channel (HttpRequestHandler) – http request handler
append_data_collect_incoming_data(data)[source]

Generic incoming data handler: Append data to self.data

Parameters:data (str) – incoming data
clear_data()[source]

Clear self.data

set_handlers(found_term_handler, terminator, collect_in_data_handler, max_data_size)[source]

Set asynchat handlers

Parameters:
  • found_term_handler (function) – terminator found handler
  • terminator (str) – terminator string
  • collect_in_data_handler (function) – collect incoming data handler
  • max_data_size (int) – max data size before abort
class vmware.vapi.server.asyncore_http.DeflateWriter(wfile, compresslevel=5)[source]

Bases: object

Deflate (zlib) writer

Deflate (zlib) writer init

Parameters:wfile (file) – file object to write to
close()[source]
flush()[source]
write(buf)[source]
Parameters:buf (str) – data to write
class vmware.vapi.server.asyncore_http.GzipWriter(wfile)[source]

Bases: object

Gzip writer

Gzip writer init

Parameters:wfile (file) – file object to write to
close()[source]
flush()[source]
write(buf)[source]
Parameters:buf (str) – data to write
class vmware.vapi.server.asyncore_http.HeadOfLineWriter(wfile)[source]

Bases: object

Head of line writer

Head of line writer init

Parameters:wfile (file) – file object to write to
class Writer(parent)[source]

Chile writer

Chile writer init

Parameters:parent (HeadOfLineWriter) – Parent writer
close()[source]
flush()[source]
is_closed()[source]

is writer closed

Return type:bool
Returns:True if closed, False otherwise
write(data)[source]
Parameters:data (str) – data to write
HeadOfLineWriter.close(writer)[source]

Close a child writer

Parameters:writer (Writer) – child writer
HeadOfLineWriter.flush(writer)[source]

flush a child writer (only possible for head of line writer)

Parameters:writer (Writer) – child writer
HeadOfLineWriter.flush_pending_reply(writer)[source]

Flush pending reply

Parameters:writer (Writer) – child writer
HeadOfLineWriter.new_writer()[source]

Create a new child writer

Return type:Writer
Returns:A new writer
HeadOfLineWriter.write(writer, data)[source]

Write to child writer

Parameters:
  • writer (Writer) – child writer
  • data (str) – data to write
class vmware.vapi.server.asyncore_http.HttpBodyHandler(channel)[source]

Bases: vmware.vapi.server.asyncore_http.DataHandler

Async chat http body handler

Async chat http body handler init

Parameters:channel (HttpRequestHandler) – http request handler
http_body_collect_incoming_data(data)[source]

incoming data handler

Parameters:data (str) – incoming data
http_body_found_terminator()[source]

Found terminator handler

class vmware.vapi.server.asyncore_http.HttpFactory[source]

Bases: object

Http factory

Http factory init

HTTP_CONTENT_MAPPING = {'xml': 'text/xml', 'json': 'application/json'}
static abspath(path)[source]

Get posix absolute path

Parameters:path (str) – url path
Return type:str
Returns:posix style abs path
add_handler(path, msg_type, protocol_handler)[source]

add handler associated with url path and transport message

Parameters:
get_handler(path, content_type)[source]

get handler for a particular url path and content type

Parameters:
  • path (str) – url path
  • content_type (str) – http content-type
Return type:

vmware.vapi.protocol.server.transport.async_protocol_handler.AsyncProtocolHandler

Returns:

protocol handler

get_path_handlers(path)[source]

get handlers for a particular url path

Parameters:path (str) – url path
Return type:dict of tuple of (str, vmware.vapi.protocol.server.transport.async_protocol_handler.AsyncProtocolHandler)
Returns:a dict of content type to protocol handler mapping
handle_accept(server, sock_map, sock, from_addr)[source]

handle newly accepted socket connection

Parameters:
  • sock_map (dict) – Global socket map
  • sock (socket.socket) – accepted socket
  • from_addr (tuple) – remote address bound to the socket
class vmware.vapi.server.asyncore_http.HttpHeadersHandler(channel)[source]

Bases: vmware.vapi.server.asyncore_http.DataHandler

Async chat http header handler

Async chat http headers handler init

Parameters:channel (HttpRequestHandler) – http request handler
http_headers_found_terminator()[source]

Found terminator handler

class vmware.vapi.server.asyncore_http.HttpRequestHandler(http_conn, wfile, content_type, protocol_handler)[source]

Bases: object

Http request handler

Http request handler init

Parameters:
close()[source]
close_http_conn_when_done()[source]

close the connection after all data written

request_continue(data)[source]

request data continue

Parameters:data (str) – request data
request_end()[source]

request data ended

response_continue(response)[source]

response data continue

Parameters:response (str) – http response data
response_end()[source]

response data end

send_response_headers(response_code)[source]

send response headers

Parameters:response_code (int) – http response code
write(data)[source]
Parameters:data (str) – data to write
class vmware.vapi.server.asyncore_http.MessageHandler(channel, content_len=None)[source]

Bases: vmware.vapi.server.asyncore_http.HttpBodyHandler

Async chat http message handler

Async chat http message handler init

Parameters:
  • channel (HttpRequestHandler) – http request handler
  • content_len (int or None) – http content length
message_body_collect_incoming_data(data)[source]

incoming data handler

Parameters:data (str) – incoming data
message_body_found_terminator()[source]

Found http message terminator handler

vmware.vapi.server.asyncore_http.find_token(tokens, token_to_find)[source]

Find token and token value from a comma separated tokens

Parameters:
  • tokens (str) – comma separated tokens string
  • token_to_find (str) – a string to find in the tokens

:rtype tuple of str, str if token is found, None otherwise :return: tuple of (token_to_find, value)

vmware.vapi.server.asyncore_http.log_exception(msg, err)[source]

Handy function to log exception with stack trace

Parameters:
  • msg (str) – error message
  • err (Exception) – exception to log

asyncore_server Module

Asyncore server

class vmware.vapi.server.asyncore_server.AsyncoreLoopController(sock_map)[source]

Bases: asyncore.dispatcher

Asyncore loop controller

Asyncore loop controller init

Parameters:sock_map (dict) – Global socket map
handle_close()[source]

handle close callback

handle_error()[source]

handle error callback

handle_expt()[source]

handle exception callback

handle_read()[source]

read data available callback

intr()[source]

Interrupt the asyncore loop

readable()[source]

Can accept more data?

:rtype bool :return True if this can handle more data

writable()[source]

Have something to write to this connection?

:rtype bool :return True if data is ready to write

class vmware.vapi.server.asyncore_server.AsyncoreSslConnection(server, sock_map, sock, from_addr, protocol_factory)[source]

Bases: asyncore.dispatcher

Asyncore ssl connection

Asyncore ssl connection init

Parameters:
  • sock_map (dict) – Global socket map
  • sock (socket.socket) – connection socket
  • from_addr (tuple) – remote address bound to the socket
  • protocol_factory (object with method handle_accept) – protocol factory
cleanup(close_socket=False)[source]

connection cleanup

Parameters:close_socket (bool) – close internal socket (or not)
do_handshake_continue()[source]

ssl do handshake continue

handle_close()[source]

handle close callback

handle_error()[source]

handle error callback

handle_expt()[source]

handle exception callback

handle_read()[source]

read data available callback

handle_write()[source]

write ready callback

readable()[source]

Can read more data?

:rtype bool :return True if this can handle more data

writable()[source]

Have something to write to ssl connection?

:rtype bool :return True if data is ready to write

class vmware.vapi.server.asyncore_server.AsyncoreTcpListener(loop_controller, sock_map, addr, ssl_args, protocol_factory)[source]

Bases: asyncore.dispatcher

Asyncore tcp listener

Asyncore tcp listener init

Parameters:
  • loop_controller (AsyncoreLoopController) – loop controller
  • sock_map (dict) – Global socket map
  • addr (tuple of str, int) – tcp addr and port
  • ssl_args (dict) – ssl arguments
  • protocol_factory (object with method handle_accept) – protocol factory
handle_accept()[source]

accept connection callback

handle_close()[source]

handle close callback

handle_error()[source]

handle error callback

handle_expt()[source]

handle exception callback

init_ssl(ssl_args)[source]

Setup SSL arguments

Parameters:ssl_args (dict) – ssl arguments
writable()[source]

Have something to write to this connection?

:rtype bool :return True if data is ready to write

class vmware.vapi.server.asyncore_server.AsyncoreTcpServer[source]

Bases: vmware.vapi.server.server_interface.ServerInterface

Asyncore tcp server

Asyncore tcp server init

SUPPORTED_SCHEMES = ('http', 'https')
register_handler(addr, msg_type, protocol_handler, ssl_args=None)[source]

Register protocol handler

Parameters:
serve_forever()[source]

Server loop

shutdown()[source]

Server shutdown

class vmware.vapi.server.asyncore_server.SyncWriteToAsyncWriteAdapter(async_socket)[source]

Bases: object

Sync write to async write adapter

Sync write to async write adapter init

Parameters:async_socket (socket.socket) – async socket
close()[source]
close_when_done()[source]

close when all data written

flush()[source]
tcp_cork(enable)[source]

tcp cork

Python failed to merge small send into big packet, which is very inefficient. Use TCP_CORK to queue partial packets to bigger packet before sending it. Alternatively we should use writev, but it is not available on standard python socket lib.

Parameters:enable (int) – 1 => turn TCP_CORK on, 0 => off
Raise :socket.error if TCP_CORK is not supported on this socket
writable()[source]

Have something to write to http connection?

:rtype bool :return True if data is ready to write

write(data)[source]

Write the given bytes

Parameters:data (bytes) – data to write
write_ready()[source]

write ready callback

vmware.vapi.server.asyncore_server.get_server(cfg)[source]

Get asyncore server

Parameters:cfg (ConfigParser.SafeConfigParser) – Config parser
Return type:vmware.vapi.server.server_interface.ServerInterface
Returns:subclass of ServerInterface

server_interface Module

Server interface

class vmware.vapi.server.server_interface.ServerInterface[source]

Bases: object

Server interface

Server interface init

register_handler(addr, msg_type, protocol_handler, ssl_args=None)[source]

Register protocol handler

Parameters:
serve_forever()[source]

Server loop

shutdown()[source]

Server shutdown

stdio_server Module

STDIO server : This handles all protocol requests over stdin/out

class vmware.vapi.server.stdio_server.StdioServer[source]

Bases: vmware.vapi.server.server_interface.ServerInterface

stdio server

Initialize the Stdio Server instance

register_handler(addr, msg_type, protocol_handler, ssl_args=None)[source]

Returns the struct definition corresponding to the method’s input parameters. The field names in the struct definition are the parameter names and the field values correspond to the data definition of the respective fields.

Parameters:
serve_forever()[source]

Receives the input from the std in of the process. Processes the message, handles it via the protocol_handler and then sends the response back.

shutdown()[source]
vmware.vapi.server.stdio_server.get_server(cfg)[source]

get stdio server

Parameters:cfg (ConfigParser.SafeConfigParser) – Config parser
Return type:vmware.vapi.server.server_interface.ServerInterface
Returns:subclass of ServerInterface

twisted_server Module

Twisted server

class vmware.vapi.server.twisted_server.TwistedAsyncProtocolHandlerAdapter[source]

Bases: twisted.internet.protocol.Protocol

Twisted async protocol handler adapter

connectionLost(reason)[source]

Twisted connection lost

Parameters:reason (str) – Connection lost reason
connectionMade()[source]

connection established callback

dataReceived(data)[source]

data received

Parameters:data (str) – data to write
class vmware.vapi.server.twisted_server.TwistedConnectionAdapter(transport)[source]

Bases: object

Twisted connection adapter

Twisted connection adapter init

Parameters:transport (twisted.internet.interfaces.ITransport) – Twisted transport
close()[source]
write(data)[source]
Parameters:data (str) – data to write
class vmware.vapi.server.twisted_server.TwistedHttpConnectionAdapter(request)[source]

Bases: object

Twisted http connection adapter

Twisted http connection init

Parameters:request (twisted.web.http.Request) – Twisted http request object
close()[source]
write(data)[source]
Parameters:data (str) – data to write
class vmware.vapi.server.twisted_server.TwistedHttpSite[source]

Bases: twisted.web.server.Site

Twisted http site

Http site site init

HTTP_CONTENT_MAPPING = {'xml': 'text/xml', '': '', 'json': 'application/json'}
add_res_handler(path, msg_type, protocol_handler)[source]

Add resource handler for a path

Parameters:
Return type:

bool

Returns:

True if added. False otherwise

class vmware.vapi.server.twisted_server.TwistedServer[source]

Bases: vmware.vapi.server.server_interface.ServerInterface

Twisted server

Twisted server init

SUPPORTED_SCHEMES = ('vmware', 'vmwares', 'http', 'https')
get_ssl_context(ssl_args)[source]

get ssl context

Parameters:ssl_args (dict) – ssl arguments
Return type:twisted.internet.ssl.DefaultOpenSSLContextFactory
Returns:twisted ssl context factory instance
register_handler(addr, msg_type, protocol_handler, ssl_args=None)[source]

Register protocol handler

Parameters:
serve_forever()[source]

Server loop

Note: Twisted limitation: Must be running from main thread

shutdown()[source]

Server shutdown

class vmware.vapi.server.twisted_server.TwistedVapiResource[source]

Bases: twisted.web.resource.Resource

Twisted vapi resource

Twisted vapi resource init

add_handler(content_type, protocol_handler)[source]

add content handler

Parameters:
handle_error(failure, request, response_code, text_msg)[source]

Handle error

Parameters:
  • failure (twisted.python.failure.Failure) – Twisted failure instance
  • request (twisted.web.http.Request) – Twisted http request object
  • response_code (int) – Http response code
  • text_msg (int) – Http error code
handle_read(request)[source]

Handle read

Parameters:request (twisted.web.http.Request) – Twisted http request object
handle_request(request_msg, request, handler)[source]

Handle request

Parameters:
render_GET(request)[source]

Handle HTTP GET

Parameters:request (twisted.web.http.Request) – Twisted http request object
render_POST(request)[source]

Handle POST

Parameters:request (twisted.web.http.Request) – Twisted http request object
class vmware.vapi.server.twisted_server.TwistedVmwareProtocolFactory(protocol_handler)[source]

Bases: twisted.internet.protocol.Factory

Twisted vmacre protocol factory

Twisted vmacre protocol factory init

Parameters:protocol_handler (vmware.vapi.protocol.server.transport.async_protocol_handler.AsyncProtocolHandler) – protocol handler for this addr
protocol

alias of TwistedAsyncProtocolHandlerAdapter

vmware.vapi.server.twisted_server.get_server(cfg)[source]

Get twisted server

Parameters:cfg (ConfigParser.SafeConfigParser) – Config parser
Return type:vmware.vapi.server.server_interface.ServerInterface
Returns:subclass of ServerInterface

vapid Module

Vapi server

vmware.vapi.server.vapid.check_file_exists(filename)[source]

Check if name is a file and exists

:type str :param file name

vmware.vapi.server.vapid.configure_logging(log_config=None)[source]

Configure logging using properties file

Parameters:log_config (str) – File path of the properties file
vmware.vapi.server.vapid.create_servers(spec, singleton=True)[source]

Create RPC servers

Parameters:
  • spec (dict) – Protocol configurations
  • singleton (bool) – Specify whether to create new instances of Providers or use existing ones
Return type:

list of vmware.vapi.server.server_interface.ServerInterface

Returns:

list of servers

vmware.vapi.server.vapid.get_ssl_args(cfg, protocol_prefix)[source]

Extract the ssl arguments

Parameters:
  • cfg (configparser.SafeConfigParser) – Configuration
  • protocol_prefix (str) – Prefix of the protocol configuration
Return type:

dict

Returns:

SSL arguments for this protocol configuration

vmware.vapi.server.vapid.main()[source]
vmware.vapi.server.vapid.set_process_title(cfg)[source]

If setproctitle library is available, set the process title :type cfg: configparser :param cfg: configparser object

vmware.vapi.server.vapid.setup_provider_chain(cfg, singleton)[source]

Setup the API Provider chain

In the properties file, users would specify the order of ApiProviders For ex: InterposerProvider, ApiAggregator. In this case all incoming requests would first go to InterposerProvider and then forwarded to ApiAggregator after processing.

This function initializes all these providers in the reverse order and passes the reference of n+1th provider to nth provider.

Parameters:
  • cfg (configparser.SafeConfigParser) – Configuration
  • singleton (bool) – Specify whether to create new instances of Providers or use existing ones
Return type:

list of vmware.vapi.core.ApiProvider

Returns:

List of API Providers

vmware.vapi.server.vapid.shutdown_servers(servers)[source]

Shutdown all servers

:type list of servers :param List of servers to shutdown

windows_vapid Module

wsgi_server Module

Wsgi Server

class vmware.vapi.server.wsgi_server.WsgiApplication(msg_handler_map)[source]

Bases: object

Python WSGI application. For more details about WSGI specification, see PEP 333.

Initialize WsgiApplication

Parameters:msg_handler_map (dict of str and vmware.vapi.protocol.server.api_handler.ApiHandler) – Map of content type to the message handler for that content type
class vmware.vapi.server.wsgi_server.WsgiServer[source]

Bases: vmware.vapi.server.server_interface.ServerInterface

Server wrapper class for Wsgi application.

Initialize WsgiServer

HTTP_CONTENT_MAPPING = {'xml': 'text/xml', '': '', 'json': 'application/json'}
SUPPORTED_SCHEMES = ('http', 'https')
get_wsgi_application()[source]

Returns the WSGI application.

Return type:vmware.vapi.server.wsgi_server.WsgiApplication
Returns:WSGI application.
register_handler(addr, msg_type, protocol_handler, ssl_args=None)[source]

Register protocol handler

Parameters:
serve_forever()[source]
shutdown()[source]
vmware.vapi.server.wsgi_server.get_server(cfg)[source]

Get wsgi server

Parameters:cfg (ConfigParser.SafeConfigParser) – Config parser
Return type:vmware.vapi.server.server_interface.ServerInterface
Returns:subclass of ServerInterface