Safe Haskell | None |
---|
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
- type NodeUUID = ByteString
- type InstanceUUID = ByteString
- type DiskUUID = ByteString
- type NetworkUUID = ByteString
- type DRBDMinor = Int
- type DRBDMap = Map NodeUUID (Map DRBDMinor DiskUUID)
- type DRBDMap' = Map NodeUUID (Map DRBDMinor [DiskUUID])
- data IPv4ResAction
- data IPv4Reservation = IPv4Res {}
- newtype TempRes j a = TempRes {
- getTempRes :: MultiMap j a
- mkTempRes :: MultiMap j a -> TempRes j a
- data TempResState = TempResState {}
- loadTempResState :: JSValue -> Result TempResState
- saveTempResState :: TempResState -> JSValue
- emptyTempResState :: TempResState
- trsMACsL :: Lens' TempResState (TempRes ClientId MAC)
- trsLVsL :: Lens' TempResState (TempRes ClientId LogicalVolume)
- trsIPv4sL :: Lens' TempResState (TempRes ClientId IPv4Reservation)
- trsDRBDSecretsL :: Lens' TempResState (TempRes ClientId DRBDSecret)
- trsDRBDL :: Lens' TempResState DRBDMap
- resError :: MonadError GanetiException m => String -> m a
- toResError :: MonadError GanetiException m => m a -> m a
- filterNested :: (Ord a, Ord b) => (c -> Bool) -> Map a (Map b c) -> Map a (Map b c)
- maybeLens :: (Monoid a, Monoid b, Eq b) => Lens s t (Maybe a) (Maybe b) -> Lens s t a b
- computeDRBDMap' :: MonadError GanetiException m => ConfigData -> TempResState -> m DRBDMap'
- computeDRBDMap :: MonadError GanetiException m => ConfigData -> TempResState -> m DRBDMap
- allocateDRBDMinor :: (MonadError GanetiException m, MonadState TempResState m) => ConfigData -> DiskUUID -> [NodeUUID] -> m [DRBDMinor]
- releaseDRBDMinors :: MonadState TempResState m => DiskUUID -> m ()
- isReserved :: (Ord a, Ord j) => a -> TempRes j a -> Bool
- reserve :: (MonadError GanetiException m, Show a, Ord a, Ord j) => j -> a -> TempRes j a -> m (TempRes j a)
- dropReservationsFor :: (Ord a, Ord j) => j -> TempRes j a -> TempRes j a
- reservedFor :: (Ord a, Ord j) => j -> TempRes j a -> Set a
- reserved :: (Ord a, Ord j) => TempRes j a -> Set a
- withReserved :: (MonadError GanetiException m, Show a, Ord a, Ord j) => j -> (Set a -> m a) -> TempRes j a -> m (a, TempRes j a)
- generate :: (MonadError GanetiException m, Show a, Ord a, Ord j) => j -> Set a -> m (Maybe a) -> TempRes j a -> m (a, TempRes j a)
- 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)
- stateM :: MonadState s m => (s -> m (a, s)) -> m a
- modifyM :: MonadState s m => (s -> m s) -> m ()
- dropAllReservations :: ClientId -> State TempResState ()
- lookupNetwork :: MonadError GanetiException m => ConfigData -> NetworkUUID -> m Network
- generateMAC :: (RandomGen g, MonadError GanetiException m, Functor m) => g -> ClientId -> Maybe NetworkUUID -> ConfigData -> StateT TempResState m MAC
- reserveMAC :: (MonadError GanetiException m, MonadState TempResState m, Functor m) => ClientId -> MAC -> ConfigData -> m ()
- generateDRBDSecret :: (RandomGen g, MonadError GanetiException m, Functor m) => g -> ClientId -> ConfigData -> StateT TempResState m DRBDSecret
- reserveLV :: (MonadError GanetiException m, MonadState TempResState m, Functor m) => ClientId -> LogicalVolume -> ConfigData -> m ()
- usedIPv4Addrs :: NetworkUUID -> Set IPv4Reservation -> Set Ip4Address
- reserveIp :: (MonadError GanetiException m, MonadState TempResState m, Functor m) => ClientId -> NetworkUUID -> Ip4Address -> Bool -> ConfigData -> m ()
- releaseIp :: (MonadError GanetiException m, MonadState TempResState m, Functor m) => ClientId -> NetworkUUID -> Ip4Address -> m ()
- generateIp :: (MonadError GanetiException m, MonadState TempResState m, Functor m) => ClientId -> NetworkUUID -> ConfigData -> m Ip4Address
- commitIp :: (MonadError GanetiException m, Functor m) => IPv4Reservation -> ConfigData -> m ConfigData
- commitReleaseIp :: (MonadError GanetiException m, Functor m) => NetworkUUID -> Ip4Address -> ConfigData -> m ConfigData
- commitReservedIps :: (MonadError GanetiException m, Functor m, MonadLog m) => ClientId -> TempResState -> ConfigData -> m ConfigData
- listReservedIps :: ClientId -> TempResState -> Set IPv4Reservation
The main reservation state
Aliases to make types more meaningful:
type InstanceUUID = ByteString Source #
type NetworkUUID = ByteString Source #
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.
Instances
data IPv4Reservation Source #
The values stored in the IPv4 reservation table.
Instances
A polymorphic data structure for managing temporary resources assigned to jobs.
TempRes | |
|
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) => Semigroup (TempRes j a) # | |
(Ord j, Ord a) => Monoid (TempRes j a) # | |
(JSON j, Ord j, JSON a, Ord a) => JSON (TempRes j a) # | |
(Arbitrary k, Ord k, Arbitrary v, Ord v) => Arbitrary (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
TempResState | |
|
Instances
loadTempResState :: JSValue -> Result TempResState Source #
saveTempResState :: TempResState -> JSValue Source #
trsLVsL :: Lens' TempResState (TempRes ClientId LogicalVolume) Source #
trsIPv4sL :: Lens' TempResState (TempRes ClientId IPv4Reservation) Source #
trsDRBDSecretsL :: Lens' TempResState (TempRes ClientId DRBDSecret) Source #
trsDRBDL :: Lens' TempResState DRBDMap Source #
Utility functions
resError :: MonadError GanetiException m => String -> m a Source #
Issues a reservation error.
toResError :: MonadError GanetiException m => m a -> m a Source #
Converts GenericError
into a ReservationError
.
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 #
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.
:: (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.
listReservedIps :: ClientId -> TempResState -> Set IPv4Reservation Source #