rings: introduce RegionID, ZoneID and NodeID
and a Valid() method to check if their value is within the valid range. Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -1,3 +1,37 @@
|
|||||||
// Package rings provides logic to work with the four rings
|
// Package rings provides logic to work with the four rings
|
||||||
// of a cluster
|
// of a cluster
|
||||||
package rings
|
package rings
|
||||||
|
|
||||||
|
const (
|
||||||
|
// RegionMax indicates the highest number that can be used for a [RegionID].
|
||||||
|
RegionMax = (1 << 4) - 1
|
||||||
|
// ZoneMax indicates the highest number that can be used for a [ZoneID].
|
||||||
|
ZoneMax = (1 << 4) - 1
|
||||||
|
// NodeMax indicates the highest number that can be used for a [NodeID].
|
||||||
|
NodeMax = (1 << 12) - 1
|
||||||
|
// NodeZeroMax indicates the highest number that can be used for a [NodeID]
|
||||||
|
// when its a gateway connected to Ring 0 (backbone).
|
||||||
|
NodeZeroMax = (1 << 8) - 1
|
||||||
|
)
|
||||||
|
|
||||||
|
// RegionID is the identifier of a region, valid between 1 and [RegionMax].
|
||||||
|
type RegionID int
|
||||||
|
|
||||||
|
// Valid tells a [RegionID] is within the valid range.
|
||||||
|
func (n RegionID) Valid() bool { return n > 0 && n <= RegionMax }
|
||||||
|
|
||||||
|
// ZoneID is the identifier of a zone within a region, valid between 1 and [ZoneMax].
|
||||||
|
type ZoneID int
|
||||||
|
|
||||||
|
// Valid tells a [ZoneID] is within the valid range.
|
||||||
|
func (n ZoneID) Valid() bool { return n > 0 && n <= ZoneMax }
|
||||||
|
|
||||||
|
// NodeID is the identifier of a machine within a zone of a region, valid between
|
||||||
|
// 1 and [NodeMax], but between 1 and [NodeZeroMax] if it will be a zone gateway.
|
||||||
|
type NodeID int
|
||||||
|
|
||||||
|
// Valid tells a [NodeID] is within the valid range.
|
||||||
|
func (n NodeID) Valid() bool { return n > 0 && n <= NodeMax }
|
||||||
|
|
||||||
|
// ValidZero tells a [NodeID] is within the valid range for a gateway.
|
||||||
|
func (n NodeID) ValidZero() bool { return n > 0 && n <= NodeZeroMax }
|
||||||
|
|||||||
Reference in New Issue
Block a user