packages feed

hsfacter 0.2.0.0 → 0.2.1

raw patch · 2 files changed

+34/−14 lines, 2 filesdep +textdep ~language-puppet

Dependencies added: text

Dependency ranges changed: language-puppet

Files

Facter.hs view
@@ -8,6 +8,10 @@ import Puppet.Interpreter.Types import Puppet.Init import PuppetDB.Rest+import System.Info+import qualified Data.Text as T+import Control.Arrow (first,second)+import Data.Monoid  storageunits = [ ("", 0), ("K", 1), ("M", 2), ("G", 3), ("T", 4) ] @@ -74,12 +78,14 @@             , ("hostname"               , hostname)             , ("lsbdistcodename"        , getval "DISTRIB_CODENAME")             , ("lsbdistdescription"     , getval "DISTRIB_DESCRIPTION")+            , ("hardwaremodel"          , arch)+            , ("architecture"           , arch)             ]  factMountPoints :: IO [(String, String)] factMountPoints = do     mountinfo <- readFile "/proc/mounts" >>= return . map words . lines-    let ignorefs = Set.fromList +    let ignorefs = Set.fromList                     ["NFS", "nfs", "nfs4", "nfsd", "afs", "binfmt_misc", "proc", "smbfs",                     "autofs", "iso9660", "ncpfs", "coda", "devpts", "ftpfs", "devfs",                     "mfs", "shfs", "sysfs", "cifs", "lustre_lite", "tmpfs", "usbfs", "udf",@@ -90,28 +96,36 @@         goodfs = map (\x -> x !! 1) goodlines     return [("mountpoints", intercalate " " goodfs)] -- version = return [("facterversion", "0.1"),("environment","test")] -allFacts :: String -> IO (Map.Map String ResolvedValue)-allFacts nodename = puppetDBFacts nodename "http://localhost:8080"+allFacts :: T.Text -> IO (Map.Map T.Text ResolvedValue)+allFacts nodename = puppetDBFacts (T.unpack nodename) "http://localhost:8080" -puppetDBFacts :: String -> String -> IO (Map.Map String ResolvedValue)+puppetDBFacts :: String -> String -> IO (Map.Map T.Text ResolvedValue) puppetDBFacts nodename url = do-        puppetDBFacts <- rawRequest url "facts" nodename+        puppetDBFacts <- rawRequest (T.pack url) "facts" (T.pack nodename)         case puppetDBFacts of             Right (ResolvedHash xs) ->                 let myhash = case (filter ((=="facts") . fst) xs) of-                                 [(_, ResolvedHash pfacts)] -> Map.fromList $ concatMap (\(a,b) -> [(a,b), ("::" ++ a, b)]) pfacts+                                 [(_, ResolvedHash pfacts)] -> Map.fromList $ concatMap (\(a,b) -> [(a,b), ("::" <> a, b)]) pfacts                                  _ -> error $ "Bad facts format: " ++ show xs                 in  return myhash             _ -> do-                rawFacts <- mapM id [factNET, factRAM, factOS, version, factMountPoints] >>= return . concat-                let ofacts = genFacts rawFacts+                rawFacts <- mapM id [factNET, factRAM, factOS, version, factMountPoints, factOS] >>= return . concat+                let ofacts = genFacts $ map (second T.pack . first T.pack) rawFacts                     (hostname, ddomainname) = break (== '.') nodename-                    domainname = tail $ ddomainname-                    nfacts = genFacts [("fqdn", nodename), ("hostname", hostname), ("domain", domainname), ("rootrsa", "xxx")]+                    domainname = if null ddomainname+                                     then []+                                     else tail $ ddomainname+                    nfacts = genFacts $ map (second T.pack) [ ("fqdn", nodename)+                                                            , ("hostname", hostname)+                                                            , ("domain", domainname)+                                                            , ("rootrsa", "xxx")+                                                            , ("operatingsystem", "Ubuntu")+                                                            , ("puppetversion", "language-puppet")+                                                            , ("virtual", "xenu")+                                                            , ("clientcert", nodename)+                                                            ]                     allfacts = Map.union nfacts ofacts                 return allfacts 
hsfacter.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                hsfacter-version:             0.2.0.0+version:             0.2.1 synopsis:            A small and ugly library that emulates the output of the puppet facter program. description:         This is a reimplementation of the facter module used by Puppet, as a library. It is supposed to be used in conjunction with the language-puppet library in order to compute catalogs. license:             GPL-3@@ -15,7 +15,13 @@ build-type:          Simple cabal-version:       >=1.8 +source-repository head+  type: git+  location: git://github.com/bartavelle/hsfacter.git+ library   exposed-modules:     Facter+  ghc-options:         -Wall+  extensions:          OverloadedStrings --  other-modules:       -  build-depends:       base >=4 && <5,containers, language-puppet >= 0.1.7.3+  build-depends:       base >=4 && <5,containers, language-puppet >= 0.4.0, text