ganeti

Safe HaskellNone

Ganeti.UDSServer

Contents

Description

Implementation of the Ganeti Unix Domain Socket JSON server interface.

Synopsis

Utility functions

withTimeout :: Int -> String -> IO a -> IO aSource

Generic protocol functionality

data RecvResult Source

Result of receiving a message from the socket.

Constructors

RecvConnClosed

Connection closed

RecvError String

Any other error

RecvOk String

Successfull receive

Instances

eOM :: Word8Source

bEOM :: ByteStringSource

data MsgKeys Source

Valid keys in the requests and responses.

Constructors

Method 
Args 
Success 
Result 

strOfKey :: MsgKeys -> StringSource

The serialisation of MsgKeys into strings in messages.

data ConnectConfig Source

Constructors

ConnectConfig 

Fields

connDaemon :: GanetiDaemon
 
recvTmo :: Int
 
sendTmo :: Int
 

data Client Source

A client encapsulation.

Constructors

Client 

Fields

socket :: Handle
 
rbuf :: IORef ByteString
 
clientConfig :: ConnectConfig
 

data Server Source

A server encapsulation.

Constructors

Server 

Fields

sSocket :: Socket
 
sPath :: FilePath
 
serverConfig :: ConnectConfig
 

Unix sockets

openClientSocketSource

Arguments

:: Int

connection timeout

-> FilePath

socket path

-> IO Handle 

Creates a Unix socket and connects it to the specified path, where timeout specifies the connection timeout.

closeClientSocket :: Handle -> IO ()Source

openServerSocket :: FilePath -> IO SocketSource

Creates a Unix socket and binds it to the specified path.

closeServerSocket :: Socket -> FilePath -> IO ()Source

acceptSocket :: Socket -> IO HandleSource

Client and server

connectClientSource

Arguments

:: ConnectConfig

configuration for the client

-> Int

connection timeout

-> FilePath

socket path

-> IO Client 

Connects to the master daemon and returns a Client.

connectServer :: ConnectConfig -> Bool -> FilePath -> IO ServerSource

Creates and returns a server endpoint.

closeServer :: Server -> IO ()Source

Closes a server endpoint.

acceptClient :: Server -> IO ClientSource

Accepts a client

closeClient :: Client -> IO ()Source

Closes the client socket.

sendMsg :: Client -> String -> IO ()Source

Sends a message over a transport.

recvUpdate :: ConnectConfig -> Handle -> ByteString -> IO (ByteString, ByteString)Source

recvMsg :: Client -> IO StringSource

Waits for a message over a transport.

recvMsgExt :: Client -> IO RecvResultSource

Extended wrapper over recvMsg.

parseCall :: (JSON mth, JSON args) => String -> Result (mth, args)Source

Parse the required keys out of a call.

buildResponseSource

Arguments

:: Bool

Success

-> JSValue

The arguments

-> String

The serialized form

Serialize the response to String.

logMsg :: (Show e, JSON e, MonadLog m) => Handler i o -> i -> GenericResult e JSValue -> m ()Source

prepareMsg :: JSON e => GenericResult e JSValue -> (Bool, JSValue)Source

Processing client requests

data Handler i o Source

Constructors

Handler 

Fields

hParse :: JSValue -> JSValue -> Result i

parses method and its arguments into the input type

hInputLogShort :: i -> String

short description of an input, for the INFO logging level

hInputLogLong :: i -> String

long description of an input, for the DEBUG logging level

hExec :: i -> HandlerResult o

executes the handler on an input

handleJsonMessage :: JSON o => Handler i o -> i -> HandlerResult JSValueSource

handleRawMessage :: JSON o => Handler i o -> String -> IO (Bool, String)Source

handleClient :: JSON o => Handler i o -> Client -> IO BoolSource

clientLoop :: JSON o => Handler i o -> Client -> IO ()Source

listener :: JSON o => Handler i o -> Server -> IO ()Source

Main listener loop: accepts clients, forks an I/O thread to handle that client.