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.
- 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 = ByteStringSource
type NetworkUUID = ByteStringSource
The state data structure
data IPv4ResAction Source
Types of IPv4 reservation actions.
Bounded IPv4ResAction | |
Enum IPv4ResAction | |
Eq IPv4ResAction | |
Ord IPv4ResAction | |
Show IPv4ResAction | |
Arbitrary IPv4ResAction | |
JSON IPv4ResAction |
data IPv4Reservation Source
The values stored in the IPv4 reservation table.
Eq IPv4Reservation | |
Ord IPv4Reservation | |
Show IPv4Reservation | |
Arbitrary IPv4Reservation | |
JSON IPv4Reservation |
A polymorphic data structure for managing temporary resources assigned to jobs.
TempRes | |
|
mkTempRes :: MultiMap j a -> TempRes j aSource
Create a temporary reservations from a given multi-map.
data TempResState Source
The state of the temporary reservations
Eq TempResState | |
Show TempResState | |
Arbitrary TempResState | |
JSON TempResState | |
ArrayObject TempResState | |
DictObject TempResState |
loadTempResState :: JSValue -> Result TempResStateSource
saveTempResState :: TempResState -> JSValueSource
trsLVsL :: Lens' TempResState (TempRes ClientId LogicalVolume)Source
trsIPv4sL :: Lens' TempResState (TempRes ClientId IPv4Reservation)Source
trsDRBDSecretsL :: Lens' TempResState (TempRes ClientId DRBDSecret)Source
trsDRBDL :: Lens' TempResState DRBDMapSource
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
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.
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 -> 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
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
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 NetworkSource
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
usedIPv4Addrs :: NetworkUUID -> Set IPv4Reservation -> Set Ip4AddressSource
:: (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.
listReservedIps :: ClientId -> TempResState -> Set IPv4ReservationSource