In this way, we can export some of those constants via Ganeti/Constants.hs to the python world while still keeping all the special htools prefixes togehter in an HTools module. (Note that Ganeti/Constants.hs cannot depend on Ganeti/HTools/Tags.hs as this would cause a cylic dependency.)
Signed-off-by: Klaus Aehlig <[email protected]> --- Makefile.am | 2 + src/Ganeti/HTools/Loader.hs | 7 +-- src/Ganeti/HTools/Program/Harep.hs | 2 +- src/Ganeti/HTools/Program/Hsqueeze.hs | 3 +- src/Ganeti/HTools/Tags.hs | 59 ++------------------- src/Ganeti/HTools/Tags/Constants.hs | 96 +++++++++++++++++++++++++++++++++++ 6 files changed, 110 insertions(+), 59 deletions(-) create mode 100644 src/Ganeti/HTools/Tags/Constants.hs diff --git a/Makefile.am b/Makefile.am index 5068050..a8e6f3c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -144,6 +144,7 @@ HS_DIRS = \ src/Ganeti/HTools/Backend \ src/Ganeti/HTools/Cluster \ src/Ganeti/HTools/Program \ + src/Ganeti/HTools/Tags \ src/Ganeti/Hypervisor \ src/Ganeti/Hypervisor/Xen \ src/Ganeti/JQScheduler \ @@ -932,6 +933,7 @@ HS_LIB_SRCS = \ src/Ganeti/HTools/Program/Hroller.hs \ src/Ganeti/HTools/Program/Main.hs \ src/Ganeti/HTools/Tags.hs \ + src/Ganeti/HTools/Tags/Constants.hs \ src/Ganeti/HTools/Types.hs \ src/Ganeti/Hypervisor/Xen.hs \ src/Ganeti/Hypervisor/Xen/XmParser.hs \ diff --git a/src/Ganeti/HTools/Loader.hs b/src/Ganeti/HTools/Loader.hs index e08cce0..10d96b9 100644 --- a/src/Ganeti/HTools/Loader.hs +++ b/src/Ganeti/HTools/Loader.hs @@ -71,6 +71,7 @@ import qualified Ganeti.HTools.Cluster.Moves as Moves import Ganeti.BasicTypes import qualified Ganeti.HTools.Tags as Tags +import qualified Ganeti.HTools.Tags.Constants as TagsC import Ganeti.HTools.Types import Ganeti.Utils import Ganeti.Types (EvacMode) @@ -249,8 +250,8 @@ setArPolicy ctags gl nl il time = getArPolicy :: [String] -> ClockTime -> Maybe AutoRepairPolicy getArPolicy tags time = let enabled = mapMaybe (autoRepairTypeFromRaw <=< - chompPrefix Tags.autoRepairTagEnabled) tags - suspended = mapMaybe (chompPrefix Tags.autoRepairTagSuspended) tags + chompPrefix TagsC.autoRepairTagEnabled) tags + suspended = mapMaybe (chompPrefix TagsC.autoRepairTagSuspended) tags futureTs = filter (> time) . map (flip TOD 0) $ mapMaybe (tryRead "auto-repair suspend time") suspended in @@ -275,7 +276,7 @@ longestDomain (x:xs) = -- | Extracts the exclusion tags from the cluster configuration. extractExTags :: [String] -> [String] -extractExTags = filter (not . null) . mapMaybe (chompPrefix Tags.exTagsPrefix) +extractExTags = filter (not . null) . mapMaybe (chompPrefix TagsC.exTagsPrefix) -- | Extracts the common suffix from node\/instance names. commonSuffix :: Node.List -> Instance.List -> String diff --git a/src/Ganeti/HTools/Program/Harep.hs b/src/Ganeti/HTools/Program/Harep.hs index ee2299d..afeccaa 100644 --- a/src/Ganeti/HTools/Program/Harep.hs +++ b/src/Ganeti/HTools/Program/Harep.hs @@ -63,7 +63,7 @@ import qualified Ganeti.Path as Path import Ganeti.HTools.CLI import Ganeti.HTools.Loader import Ganeti.HTools.ExtLoader -import qualified Ganeti.HTools.Tags as Tags +import qualified Ganeti.HTools.Tags.Constants as Tags import Ganeti.HTools.Types import qualified Ganeti.HTools.Container as Container import qualified Ganeti.HTools.Instance as Instance diff --git a/src/Ganeti/HTools/Program/Hsqueeze.hs b/src/Ganeti/HTools/Program/Hsqueeze.hs index 0a29b77..6bdb8e5 100644 --- a/src/Ganeti/HTools/Program/Hsqueeze.hs +++ b/src/Ganeti/HTools/Program/Hsqueeze.hs @@ -58,7 +58,8 @@ import Ganeti.HTools.ExtLoader import qualified Ganeti.HTools.Instance as Instance import Ganeti.HTools.Loader import qualified Ganeti.HTools.Node as Node -import Ganeti.HTools.Tags (hasStandbyTag, standbyAuto) +import Ganeti.HTools.Tags (hasStandbyTag) +import Ganeti.HTools.Tags.Constants (standbyAuto) import Ganeti.HTools.Types import Ganeti.JQueue (currentTimestamp, reasonTrailTimestamp) import Ganeti.JQueue.Objects (Timestamp) diff --git a/src/Ganeti/HTools/Tags.hs b/src/Ganeti/HTools/Tags.hs index 8e466a3..6fd7ebb 100644 --- a/src/Ganeti/HTools/Tags.hs +++ b/src/Ganeti/HTools/Tags.hs @@ -6,7 +6,7 @@ This module holds all the tag interpretation done by htools. {- -Copyright (C) 2014 Google Inc. +Copyright (C) 2014, 2015 Google Inc. All rights reserved. Redistribution and use in source and binary forms, with or without @@ -35,14 +35,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -} module Ganeti.HTools.Tags - ( exTagsPrefix - , standbyAuto - , hasStandbyTag - , autoRepairTagPrefix - , autoRepairTagEnabled - , autoRepairTagPending - , autoRepairTagResult - , autoRepairTagSuspended + ( hasStandbyTag , getMigRestrictions , getRecvMigRestrictions , getLocations @@ -54,51 +47,9 @@ import Data.Maybe (mapMaybe) import qualified Data.Set as S import qualified Ganeti.HTools.Node as Node - --- * Constants - --- | The exclusion tag prefix. Instance tags starting with this prefix --- describe a service provided by the instance. Instances providing the --- same service at not places on the same node. -exTagsPrefix :: String -exTagsPrefix = "htools:iextags:" - --- | The tag-prefix indicating that hsqueeze should consider a node --- as being standby. -standbyPrefix :: String -standbyPrefix = "htools:standby:" - --- | The prefix for migration tags -migrationPrefix :: String -migrationPrefix = "htools:migration:" - --- | Prefix of tags allowing migration -allowMigrationPrefix :: String -allowMigrationPrefix = "htools:allowmigration:" - --- | The prefix for location tags. -locationPrefix :: String -locationPrefix = "htools:nlocation:" - --- | The tag to be added to nodes that were shutdown by hsqueeze. -standbyAuto :: String -standbyAuto = "htools:standby:auto" - --- | Auto-repair tag prefix -autoRepairTagPrefix :: String -autoRepairTagPrefix = "ganeti:watcher:autorepair:" - -autoRepairTagEnabled :: String -autoRepairTagEnabled = autoRepairTagPrefix - -autoRepairTagPending :: String -autoRepairTagPending = autoRepairTagPrefix ++ "pending:" - -autoRepairTagResult :: String -autoRepairTagResult = autoRepairTagPrefix ++ "result:" - -autoRepairTagSuspended :: String -autoRepairTagSuspended = autoRepairTagPrefix ++ "suspend:" +import Ganeti.HTools.Tags.Constants ( standbyPrefix + , migrationPrefix, allowMigrationPrefix + , locationPrefix ) -- * Predicates diff --git a/src/Ganeti/HTools/Tags/Constants.hs b/src/Ganeti/HTools/Tags/Constants.hs new file mode 100644 index 0000000..47bf8db --- /dev/null +++ b/src/Ganeti/HTools/Tags/Constants.hs @@ -0,0 +1,96 @@ +{-| Tag constants + +This module holds all the special tag prefixes honored +by Ganeti's htools. The module itself does not depend +on anything Ganeti specific so that it can be imported +anywhere. + +-} + +{- + +Copyright (C) 2014, 2015 Google Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS +IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +-} + +module Ganeti.HTools.Tags.Constants + ( exTagsPrefix + , standbyPrefix + , migrationPrefix + , allowMigrationPrefix + , locationPrefix + , standbyAuto + , autoRepairTagPrefix + , autoRepairTagEnabled + , autoRepairTagPending + , autoRepairTagResult + , autoRepairTagSuspended + ) where + +-- | The exclusion tag prefix. Instance tags starting with this prefix +-- describe a service provided by the instance. Instances providing the +-- same service at not places on the same node. +exTagsPrefix :: String +exTagsPrefix = "htools:iextags:" + +-- | The tag-prefix indicating that hsqueeze should consider a node +-- as being standby. +standbyPrefix :: String +standbyPrefix = "htools:standby:" + +-- | The prefix for migration tags +migrationPrefix :: String +migrationPrefix = "htools:migration:" + +-- | Prefix of tags allowing migration +allowMigrationPrefix :: String +allowMigrationPrefix = "htools:allowmigration:" + +-- | The prefix for location tags. +locationPrefix :: String +locationPrefix = "htools:nlocation:" + +-- | The tag to be added to nodes that were shutdown by hsqueeze. +standbyAuto :: String +standbyAuto = "htools:standby:auto" + +-- | Auto-repair tag prefix +autoRepairTagPrefix :: String +autoRepairTagPrefix = "ganeti:watcher:autorepair:" + +autoRepairTagEnabled :: String +autoRepairTagEnabled = autoRepairTagPrefix + +autoRepairTagPending :: String +autoRepairTagPending = autoRepairTagPrefix ++ "pending:" + +autoRepairTagResult :: String +autoRepairTagResult = autoRepairTagPrefix ++ "result:" + +autoRepairTagSuspended :: String +autoRepairTagSuspended = autoRepairTagPrefix ++ "suspend:" + -- 2.2.0.rc0.207.ga3a616c
