Skip to content

Commit

Permalink
Merge pull request #131 from eric-ch/s8-oxt-796
Browse files Browse the repository at this point in the history
STABLE-8: OXT-796: xenmgr: Match multi-strings in dmi chassis type.
  • Loading branch information
jean-edouard authored Nov 6, 2018
2 parents db93ba3 + ab58e71 commit 08ef585
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions xenmgr/XenMgr/Host.hs
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,14 @@ hostCheckFreeStorage = do
haveSystemAmtPt :: Rpc Bool
haveSystemAmtPt = dbReadWithDefault False "system-amt-pt-active"

-- Check if this is laptop by testing the chassis type string
isLaptop :: IO Bool
isLaptop =
do hi <- readHostInfo
let chassis = map toLower . strip $ hostChassisType hi
return (chassis == "laptop" || chassis == "notebook" || chassis == "portable")
-- Check if this is laptop by testing the chassis type string against list of
-- known keywords.
isLaptopStr :: String -> Bool
isLaptopStr chassisTypeStr =
let keywords = [ "laptop", "notebook", "portable" ]
chassisStrs = lines $ strip $ map toLower chassisTypeStr
in
foldl (||) False $ map (`elem` keywords) chassisStrs

-- Check if host contains PCI devices required to turn AMT on
isAMTCapable :: IO Bool
Expand Down Expand Up @@ -457,9 +459,7 @@ readHostInfo = do
eth0Addr <- future $ maybe "" id <$> eth0Mac
wifiAddr <- future $ maybe "" id <$> wlan0Mac
amt_cap <- future $ isAMTCapable
chassisType <- getHostChassisType
let chassis = map toLower . strip $ chassisType
is_laptop = (chassis == "laptop" || chassis == "notebook" || chassis == "portable")
chassisType <- getHostChassisType
force $ HostInfo <$>
vendor
<*> model
Expand All @@ -472,7 +472,7 @@ readHostInfo = do
<*> wifiAddr
<*> wifiModel
<*> pure chassisType
<*> pure is_laptop
<*> pure (isLaptopStr chassisType)
<*> amt_cap
where
fetch s regex = case s `matchG` regex of [] -> ""
Expand Down

0 comments on commit 08ef585

Please sign in to comment.