Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snf-ganeti
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
itminedu
snf-ganeti
Commits
3bf75b7d
Commit
3bf75b7d
authored
14 years ago
by
Iustin Pop
Browse files
Options
Downloads
Patches
Plain Diff
Move text serialization functions to Text.hs
Currently these are in hscan, and cannot be reused easily.
parent
57ef88df
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Ganeti/HTools/Text.hs
+40
-1
40 additions, 1 deletion
Ganeti/HTools/Text.hs
hscan.hs
+2
-35
2 additions, 35 deletions
hscan.hs
with
42 additions
and
36 deletions
Ganeti/HTools/Text.hs
+
40
−
1
View file @
3bf75b7d
...
...
@@ -7,7 +7,7 @@ files, as produced by gnt-node and gnt-instance list.
{-
Copyright (C) 2009 Google Inc.
Copyright (C) 2009
, 2010
Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
...
...
@@ -31,16 +31,55 @@ module Ganeti.HTools.Text
loadData
,
loadInst
,
loadNode
,
serializeInstances
,
serializeNodes
)
where
import
Control.Monad
import
Data.List
import
Text.Printf
(
printf
)
import
Ganeti.HTools.Utils
import
Ganeti.HTools.Loader
import
Ganeti.HTools.Types
import
qualified
Ganeti.HTools.Container
as
Container
import
qualified
Ganeti.HTools.Node
as
Node
import
qualified
Ganeti.HTools.Instance
as
Instance
-- | Serialize a single node
serializeNode
::
Node
.
Node
->
String
serializeNode
node
=
printf
"%s|%.0f|%d|%d|%.0f|%d|%.0f|%c"
(
Node
.
name
node
)
(
Node
.
tMem
node
)
(
Node
.
nMem
node
)
(
Node
.
fMem
node
)
(
Node
.
tDsk
node
)
(
Node
.
fDsk
node
)
(
Node
.
tCpu
node
)
(
if
Node
.
offline
node
then
'Y'
else
'N'
)
-- | Generate node file data from node objects
serializeNodes
::
Node
.
List
->
String
serializeNodes
=
unlines
.
map
serializeNode
.
Container
.
elems
-- | Serialize a single instance
serializeInstance
::
Node
.
List
->
Instance
.
Instance
->
String
serializeInstance
nl
inst
=
let
iname
=
Instance
.
name
inst
pnode
=
Container
.
nameOf
nl
(
Instance
.
pNode
inst
)
sidx
=
Instance
.
sNode
inst
snode
=
(
if
sidx
==
Node
.
noSecondary
then
""
else
Container
.
nameOf
nl
sidx
)
in
printf
"%s|%d|%d|%d|%s|%s|%s|%s"
iname
(
Instance
.
mem
inst
)
(
Instance
.
dsk
inst
)
(
Instance
.
vcpus
inst
)
(
Instance
.
runSt
inst
)
pnode
snode
(
intercalate
","
(
Instance
.
tags
inst
))
-- | Generate instance file data from instance objects
serializeInstances
::
Node
.
List
->
Instance
.
List
->
String
serializeInstances
nl
=
unlines
.
map
(
serializeInstance
nl
)
.
Container
.
elems
-- | Load a node from a field list.
loadNode
::
(
Monad
m
)
=>
[
String
]
->
m
(
String
,
Node
.
Node
)
loadNode
[
name
,
tm
,
nm
,
fm
,
td
,
fd
,
tc
,
fo
]
=
do
...
...
This diff is collapsed.
Click to expand it.
hscan.hs
+
2
−
35
View file @
3bf75b7d
...
...
@@ -6,7 +6,7 @@
{-
Copyright (C) 2009 Google Inc.
Copyright (C) 2009
, 2010
Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
...
...
@@ -27,7 +27,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module
Main
(
main
)
where
import
Data.List
import
Data.Maybe
(
isJust
,
fromJust
,
fromMaybe
)
import
Monad
import
System
(
exitWith
,
ExitCode
(
..
))
...
...
@@ -46,6 +45,7 @@ import qualified Ganeti.HTools.Rapi as Rapi
#
endif
import
qualified
Ganeti.HTools.Luxi
as
Luxi
import
qualified
Ganeti.HTools.Loader
as
Loader
import
Ganeti.HTools.Text
(
serializeNodes
,
serializeInstances
)
import
Ganeti.HTools.CLI
import
Ganeti.HTools.Types
...
...
@@ -62,39 +62,6 @@ options =
,
oShowHelp
]
-- | Serialize a single node
serializeNode
::
Node
.
Node
->
String
serializeNode
node
=
printf
"%s|%.0f|%d|%d|%.0f|%d|%.0f|%c"
(
Node
.
name
node
)
(
Node
.
tMem
node
)
(
Node
.
nMem
node
)
(
Node
.
fMem
node
)
(
Node
.
tDsk
node
)
(
Node
.
fDsk
node
)
(
Node
.
tCpu
node
)
(
if
Node
.
offline
node
then
'Y'
else
'N'
)
-- | Generate node file data from node objects
serializeNodes
::
Node
.
List
->
String
serializeNodes
=
unlines
.
map
serializeNode
.
Container
.
elems
-- | Serialize a single instance
serializeInstance
::
Node
.
List
->
Instance
.
Instance
->
String
serializeInstance
nl
inst
=
let
iname
=
Instance
.
name
inst
pnode
=
Container
.
nameOf
nl
(
Instance
.
pNode
inst
)
sidx
=
Instance
.
sNode
inst
snode
=
(
if
sidx
==
Node
.
noSecondary
then
""
else
Container
.
nameOf
nl
sidx
)
in
printf
"%s|%d|%d|%d|%s|%s|%s|%s"
iname
(
Instance
.
mem
inst
)
(
Instance
.
dsk
inst
)
(
Instance
.
vcpus
inst
)
(
Instance
.
runSt
inst
)
pnode
snode
(
intercalate
","
(
Instance
.
tags
inst
))
-- | Generate instance file data from instance objects
serializeInstances
::
Node
.
List
->
Instance
.
List
->
String
serializeInstances
nl
=
unlines
.
map
(
serializeInstance
nl
)
.
Container
.
elems
-- | Return a one-line summary of cluster state
printCluster
::
Node
.
List
->
Instance
.
List
->
String
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment