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
144f190b
Commit
144f190b
authored
15 years ago
by
Iustin Pop
Browse files
Options
Downloads
Patches
Plain Diff
Small changes to the IAlloc module
Adding a small request type data structure.
parent
2cf61508
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Ganeti/HTools/IAlloc.hs
+19
-2
19 additions, 2 deletions
Ganeti/HTools/IAlloc.hs
with
19 additions
and
2 deletions
Ganeti/HTools/IAlloc.hs
+
19
−
2
View file @
144f190b
...
...
@@ -15,6 +15,11 @@ import Text.JSON
import
Text.Printf
(
printf
)
import
Ganeti.HTools.Utils
data
RqType
=
Allocate
|
Relocate
deriving
(
Show
)
parseInstance
::
String
->
JSObject
JSValue
->
Either
String
String
parseInstance
n
a
=
let
name
=
Right
n
...
...
@@ -57,22 +62,34 @@ parseNode n a =
concatEitherElems
(
show
`
applyEither1
`
dtotal
)
(
show
`
applyEither1
`
dfree
)
validateRequest
::
String
->
Either
String
RqType
validateRequest
rq
=
case
rq
of
"allocate"
->
Right
Allocate
"relocate"
->
Right
Relocate
_
->
Left
(
"Invalid request type '"
++
rq
++
"'"
)
parseData
::
String
->
Either
String
(
String
,
String
)
parseData
body
=
let
decoded
=
resultToEither
$
decodeStrict
body
obj
=
decoded
-- decoded `combineEithers` fromJSObject
-- request parser
request
=
obj
`
combineEithers
`
getObjectElement
"request"
rname
=
request
`
combineEithers
`
getStringElement
"name"
rtype
=
request
`
combineEithers
`
getStringElement
"type"
`
combineEithers
`
validateRequest
-- existing intstance parsing
ilist
=
obj
`
combineEithers
`
getObjectElement
"instances"
nlist
=
obj
`
combineEithers
`
getObjectElement
"nodes"
idata
=
applyEither1
fromJSObject
ilist
ndata
=
applyEither1
fromJSObject
nlist
iobj
=
idata
`
combineEithers
`
(
ensureEitherList
.
map
(
\
(
x
,
y
)
->
asJSObject
y
`
combineEithers
`
parseInstance
x
))
ilines
=
iobj
`
combineEithers
`
(
Right
.
unlines
)
-- existing node parsing
nlist
=
obj
`
combineEithers
`
getObjectElement
"nodes"
ndata
=
applyEither1
fromJSObject
nlist
nobj
=
ndata
`
combineEithers
`
(
ensureEitherList
.
map
(
\
(
x
,
y
)
->
asJSObject
y
`
combineEithers
`
...
...
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