ganeti

Safe HaskellNone

Ganeti.UDSServer

Contents

Description

Implementation of the Ganeti Unix Domain Socket JSON server interface.

Synopsis

Utility functions

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
Eq RecvResult # 
Instance details

Defined in Ganeti.UDSServer

Methods

(==) :: RecvResult -> RecvResult -> Bool

(/=) :: RecvResult -> RecvResult -> Bool

Show RecvResult # 
Instance details

Defined in Ganeti.UDSServer

Methods

showsPrec :: Int -> RecvResult -> ShowS

show :: RecvResult -> String

showList :: [RecvResult] -> ShowS

data MsgKeys Source #

Valid keys in the requests and responses.

Constructors

Method 
Args 
Success 
Result 

strOfKey :: MsgKeys -> String Source #

The serialisation of MsgKeys into strings in messages.

data ConnectConfig Source #

Constructors

ConnectConfig 

Fields

data Client Source #

A client encapsulation. Note that it has separate read and write handle. For sockets it is the same handle. It is required for bi-directional inter-process pipes though.

data Server Source #

A server encapsulation.

Unix sockets

openClientSocket Source #

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 #

Closes the handle. Performing the operation on a handle that has already been closed has no effect; doing so is not an error. All other operations on a closed handle will fail.

openServerSocket :: FilePath -> IO Socket Source #

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

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

acceptSocket :: Socket -> IO Handle Source #

Client and server

connectClient Source #

Arguments

:: ConnectConfig

configuration for the client

-> Int

connection timeout

-> FilePath

socket path

-> IO Client 

Connects to the master daemon and returns a Client.

connectServer :: ServerConfig -> Bool -> FilePath -> IO Server Source #

Creates and returns a server endpoint.

pipeClient :: ConnectConfig -> IO (Client, Client) Source #

Creates a new bi-directional client pipe. The two returned clients talk to each other through the pipe.

closeServer :: MonadBase IO m => Server -> m () Source #

Closes a server endpoint.

acceptClient :: Server -> IO Client Source #

Accepts a client

closeClient :: Client -> IO () Source #

Closes the client socket. Performing the operation on a client that has already been closed has no effect; doing so is not an error. All other operations on a closed client will fail with an exception.

clientToFd :: Client -> IO (Fd, Fd) Source #

Extracts the read (the first) and the write (the second) file descriptor of a client. This closes the underlying Handles, therefore the original client is closed and unusable after the call.

The purpose of this function is to keep the communication channel open, while replacing a Client with some other means.

clientToHandle :: Client -> (Handle, Handle) Source #

Extracts the read (first) and the write (second) handles of a client. The purpose of this function is to allow using a client's handles as input/output streams elsewhere.

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

Sends a message over a transport.

recvMsg :: Client -> IO String Source #

Waits for a message over a transport.

recvMsgExt :: Client -> IO RecvResult Source #

Extended wrapper over recvMsg.

buildCall Source #

Arguments

:: (JSON mth, JSON args) 
=> mth

The method

-> args

The arguments

-> String

The serialized form

Serialize a request to String.

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

Parse the required keys out of a call.

buildResponse Source #

Arguments

:: Bool

Success

-> JSValue

The arguments

-> String

The serialized form

Serialize the response to String.

parseResponse :: String -> ErrorResult JSValue Source #

Check that luxi responses contain the required keys and that the call was successful.

Processing client requests

data Handler i m 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 m o

    executes the handler on an input

listener :: (JSON o, MonadBaseControl IO m, MonadLog m) => Handler i m o -> Server -> m () Source #

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