ganeti
Safe HaskellNone

Ganeti.WConfd.TempRes

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 = ByteString Source #

type InstanceUUID = ByteString Source #

type DiskUUID = ByteString Source #

type NetworkUUID = ByteString Source #

type DRBDMinor = Int Source #

type DRBDMap = Map NodeUUID (Map DRBDMinor DiskUUID) Source #

A map of the usage of DRBD minors

type DRBDMap' = Map NodeUUID (Map DRBDMinor [DiskUUID]) Source #

A map of the usage of DRBD minors with possible duplicates

The state data structure

data IPv4ResAction Source #

Types of IPv4 reservation actions.

Constructors

IPv4Reserve 
IPv4Release 

Instances

Instances details
Bounded IPv4ResAction # 
Instance details

Defined in Ganeti.WConfd.TempRes

Enum IPv4ResAction # 
Instance details

Defined in Ganeti.WConfd.TempRes

Eq IPv4ResAction # 
Instance details

Defined in Ganeti.WConfd.TempRes

Ord IPv4ResAction # 
Instance details

Defined in Ganeti.WConfd.TempRes

Show IPv4ResAction # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

showsPrec :: Int -> IPv4ResAction -> ShowS

show :: IPv4ResAction -> String

showList :: [IPv4ResAction] -> ShowS

JSON IPv4ResAction # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

readJSON :: JSValue -> Result IPv4ResAction

showJSON :: IPv4ResAction -> JSValue

readJSONs :: JSValue -> Result [IPv4ResAction]

showJSONs :: [IPv4ResAction] -> JSValue

Arbitrary IPv4ResAction 
Instance details

Defined in Test.Ganeti.WConfd.TempRes

data IPv4Reservation Source #

The values stored in the IPv4 reservation table.

Instances

Instances details
Eq IPv4Reservation # 
Instance details

Defined in Ganeti.WConfd.TempRes

Ord IPv4Reservation # 
Instance details

Defined in Ganeti.WConfd.TempRes

Show IPv4Reservation # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

showsPrec :: Int -> IPv4Reservation -> ShowS

show :: IPv4Reservation -> String

showList :: [IPv4Reservation] -> ShowS

JSON IPv4Reservation # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

readJSON :: JSValue -> Result IPv4Reservation

showJSON :: IPv4Reservation -> JSValue

readJSONs :: JSValue -> Result [IPv4Reservation]

showJSONs :: [IPv4Reservation] -> JSValue

Arbitrary IPv4Reservation 
Instance details

Defined in Test.Ganeti.WConfd.TempRes

newtype TempRes j a Source #

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

Constructors

TempRes 

Fields

Instances

Instances details
(Eq j, Eq a) => Eq (TempRes j a) # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

(==) :: TempRes j a -> TempRes j a -> Bool

(/=) :: TempRes j a -> TempRes j a -> Bool

(Ord j, Ord a) => Ord (TempRes j a) # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

compare :: TempRes j a -> TempRes j a -> Ordering

(<) :: TempRes j a -> TempRes j a -> Bool

(<=) :: TempRes j a -> TempRes j a -> Bool

(>) :: TempRes j a -> TempRes j a -> Bool

(>=) :: TempRes j a -> TempRes j a -> Bool

max :: TempRes j a -> TempRes j a -> TempRes j a

min :: TempRes j a -> TempRes j a -> TempRes j a

(Show j, Show a) => Show (TempRes j a) # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

showsPrec :: Int -> TempRes j a -> ShowS

show :: TempRes j a -> String

showList :: [TempRes j a] -> ShowS

(Ord j, Ord a) => Semigroup (TempRes j a) # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

(<>) :: TempRes j a -> TempRes j a -> TempRes j a

sconcat :: NonEmpty (TempRes j a) -> TempRes j a

stimes :: Integral b => b -> TempRes j a -> TempRes j a

(Ord j, Ord a) => Monoid (TempRes j a) # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

mempty :: TempRes j a

mappend :: TempRes j a -> TempRes j a -> TempRes j a

mconcat :: [TempRes j a] -> TempRes j a

(JSON j, Ord j, JSON a, Ord a) => JSON (TempRes j a) # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

readJSON :: JSValue -> Result (TempRes j a)

showJSON :: TempRes j a -> JSValue

readJSONs :: JSValue -> Result [TempRes j a]

showJSONs :: [TempRes j a] -> JSValue

(Arbitrary k, Ord k, Arbitrary v, Ord v) => Arbitrary (TempRes k v) 
Instance details

Defined in Test.Ganeti.WConfd.TempRes

Methods

arbitrary :: Gen (TempRes k v)

shrink :: TempRes k v -> [TempRes k v]

mkTempRes :: MultiMap j a -> TempRes j a Source #

Create a temporary reservations from a given multi-map.

data TempResState Source #

The state of the temporary reservations

Instances

Instances details
Eq TempResState # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

(==) :: TempResState -> TempResState -> Bool

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

Show TempResState # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

showsPrec :: Int -> TempResState -> ShowS

show :: TempResState -> String

showList :: [TempResState] -> ShowS

JSON TempResState # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

readJSON :: JSValue -> Result TempResState

showJSON :: TempResState -> JSValue

readJSONs :: JSValue -> Result [TempResState]

showJSONs :: [TempResState] -> JSValue

ArrayObject TempResState # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

toJSArray :: TempResState -> [JSValue] Source #

fromJSArray :: [JSValue] -> Result TempResState Source #

DictObject TempResState # 
Instance details

Defined in Ganeti.WConfd.TempRes

Methods

toDict :: TempResState -> [(String, JSValue)] Source #

fromDictWKeys :: [(String, JSValue)] -> WriterT UsedKeys Result TempResState Source #

fromDict :: [(String, JSValue)] -> Result TempResState Source #

Arbitrary TempResState 
Instance details

Defined in Test.Ganeti.WConfd.TempRes

loadTempResState :: JSValue -> Result TempResState Source #

Utility functions

resError :: MonadError GanetiException m => String -> m a Source #

Issues a reservation error.

toResError :: MonadError GanetiException m => m a -> m a Source #

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

Filter values from the nested map and remove any nested maps that become empty.

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

Converts a lens that works on maybe values into a lens that works on regular ones. A missing value on the input is replaced by mempty. The output is is Just something iff something /= mempty.

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 DRBDMap Source #

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.

allocateDRBDMinor :: (MonadError GanetiException m, MonadState TempResState m) => ConfigData -> DiskUUID -> [NodeUUID] -> m [DRBDMinor] Source #

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

Other temporary resources

isReserved :: (Ord a, Ord j) => a -> TempRes j a -> Bool Source #

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 a Source #

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

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

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

Computes the set of all reserved resources and passes it to the given function. This allows it to avoid resources that are already in use.

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 #

Repeatedly tries to run a given monadic function until it succeeds and the returned value is free to reserve. If such a value is found, it's reserved and returned. Otherwise fails with an error.

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 #

A variant of generate for randomized computations.

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

Embeds a stateful computation in a stateful monad.

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

Embeds a state-modifying computation in a stateful monad.

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.

lookupNetwork :: MonadError GanetiException m => ConfigData -> NetworkUUID -> m Network Source #

Looks up a network by its UUID.

IDs

MAC addresses

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

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 DRBDSecret Source #

LVs

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

IPv4 addresses

usedIPv4Addrs :: NetworkUUID -> Set IPv4Reservation -> Set Ip4Address Source #

Lists all IPv4 addresses reserved for a given network.

reserveIp Source #

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 Ip4Address Source #

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

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

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

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

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

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.