ganeti

Safe HaskellNone

Ganeti.WConfd.TempRes

Contents

Description

Pure functions for manipulating reservations of temporary objects

NOTE: Reservations aren't released specifically, they're just all released at the end of a job. This could be improved in the future.

Synopsis

The main reservation state

Aliases to make types more meaningful:

type NodeUUID = ByteStringSource

type InstanceUUID = ByteStringSource

type DiskUUID = ByteStringSource

type NetworkUUID = ByteStringSource

type DRBDMinor = IntSource

type DRBDMap = Map NodeUUID (Map DRBDMinor DiskUUID)Source

A map of the usage of DRBD minors

The state data structure

data IPv4ResAction Source

Types of IPv4 reservation actions.

Constructors

IPv4Reserve 
IPv4Release 

Instances

data IPv4Reservation Source

The values stored in the IPv4 reservation table.

newtype TempRes j a Source

A polymorphic data structure for managing temporary resources assigned to jobs.

Constructors

TempRes 

Fields

getTempRes :: MultiMap j a
 

Instances

(Eq j, Eq a) => Eq (TempRes j a) 
(Ord j, Ord a) => Ord (TempRes j a) 
(Show j, Show a) => Show (TempRes j a) 
(Ord j, Ord a) => Monoid (TempRes j a) 
(Arbitrary k, Ord k, Arbitrary v, Ord v) => Arbitrary (TempRes k v) 
(JSON j, Ord j, JSON a, Ord a) => JSON (TempRes j a) 

mkTempRes :: MultiMap j a -> TempRes j aSource

Create a temporary reservations from a given multi-map.

Utility functions

resError :: MonadError GanetiException m => String -> m aSource

toResError :: MonadError GanetiException m => m a -> m aSource

filterNested :: (Ord a, Ord b) => (c -> Bool) -> Map a (Map b c) -> Map a (Map b c)Source

maybeLens :: (Monoid a, Monoid b, Eq b) => Lens s t (Maybe a) (Maybe b) -> Lens s t a bSource

DRBD functions

computeDRBDMap' :: MonadError GanetiException m => ConfigData -> TempResState -> m DRBDMap'Source

Compute the map of used DRBD minor/nodes, including possible duplicates. An error is returned if the configuration isn't consistent (for example if a referenced disk is missing etc.).

computeDRBDMap :: MonadError GanetiException m => ConfigData -> TempResState -> m DRBDMapSource

Compute the map of used DRBD minor/nodes. Report any duplicate entries as an error.

Unlike computeDRBDMap', includes entries for all nodes, even if empty.

releaseDRBDMinors :: MonadState TempResState m => DiskUUID -> m ()Source

Other temporary resources

isReserved :: (Ord a, Ord j) => a -> TempRes j a -> BoolSource

Tests if a given value is reserved for a given job.

reserve :: (MonadError GanetiException m, Show a, Ord a, Ord j) => j -> a -> TempRes j a -> m (TempRes j a)Source

Tries to reserve a given value for a given job.

dropReservationsFor :: (Ord a, Ord j) => j -> TempRes j a -> TempRes j aSource

reservedFor :: (Ord a, Ord j) => j -> TempRes j a -> Set aSource

reserved :: (Ord a, Ord j) => TempRes j a -> Set aSource

withReserved :: (MonadError GanetiException m, Show a, Ord a, Ord j) => j -> (Set a -> m a) -> TempRes j a -> m (a, TempRes j a)Source

generate :: (MonadError GanetiException m, Show a, Ord a, Ord j) => j -> Set a -> m (Maybe a) -> TempRes j a -> m (a, TempRes j a)Source

generateRand :: (MonadError GanetiException m, Show a, Ord a, Ord j, RandomGen g) => g -> j -> Set a -> (g -> (Maybe a, g)) -> TempRes j a -> m (a, TempRes j a)Source

stateM :: MonadState s m => (s -> m (a, s)) -> m aSource

modifyM :: MonadState s m => (s -> m s) -> m ()Source

Functions common to all reservations

dropAllReservations :: ClientId -> State TempResState ()Source

Removes all resources reserved by a given job.

If a new reservation resource type is added, it must be added here as well.

IDs

MAC addresses

generateMAC :: (RandomGen g, MonadError GanetiException m, Functor m) => g -> ClientId -> Maybe NetworkUUID -> ConfigData -> StateT TempResState m MACSource

reserveMAC :: (MonadError GanetiException m, MonadState TempResState m, Functor m) => ClientId -> MAC -> ConfigData -> m ()Source

DRBD secrets

generateDRBDSecret :: (RandomGen g, MonadError GanetiException m, Functor m) => g -> ClientId -> ConfigData -> StateT TempResState m DRBDSecretSource

LVs

reserveLV :: (MonadError GanetiException m, MonadState TempResState m, Functor m) => ClientId -> LogicalVolume -> ConfigData -> m ()Source

IPv4 addresses

reserveIpSource

Arguments

:: (MonadError GanetiException m, MonadState TempResState m, Functor m) 
=> ClientId 
-> NetworkUUID 
-> Ip4Address 
-> Bool

whether to check externally reserved IPs

-> ConfigData 
-> m () 

Reserve a given IPv4 address for use by an instance.

releaseIp :: (MonadError GanetiException m, MonadState TempResState m, Functor m) => ClientId -> NetworkUUID -> Ip4Address -> m ()Source

Give a specific IP address back to an IP pool. The IP address is returned to the IP pool designated by network id and marked as reserved.

generateIp :: (MonadError GanetiException m, MonadState TempResState m, Functor m) => ClientId -> NetworkUUID -> ConfigData -> m Ip4AddressSource

commitIp :: (MonadError GanetiException m, Functor m) => IPv4Reservation -> ConfigData -> m ConfigDataSource

commitReleaseIp :: (MonadError GanetiException m, Functor m) => NetworkUUID -> Ip4Address -> ConfigData -> m ConfigDataSource

Immediately release an IP address, without using the reservations pool.

commitReservedIps :: (MonadError GanetiException m, Functor m, MonadLog m) => ClientId -> TempResState -> ConfigData -> m ConfigDataSource

Commit all reserved/released IP address to an IP pool. The IP addresses are taken from the network's IP pool and marked as reserved/free for instances.

Note that the reservations are kept, they are supposed to be cleaned when a job finishes.