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
748bfcc2
Commit
748bfcc2
authored
14 years ago
by
Iustin Pop
Browse files
Options
Downloads
Patches
Plain Diff
Rapi loader: split parsing from loading
The change is similar to the text loader change.
parent
dadfc261
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Ganeti/HTools/Rapi.hs
+22
-11
22 additions, 11 deletions
Ganeti/HTools/Rapi.hs
with
22 additions
and
11 deletions
Ganeti/HTools/Rapi.hs
+
22
−
11
View file @
748bfcc2
...
...
@@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module
Ganeti.HTools.Rapi
(
loadData
,
parseData
)
where
import
Network.Curl
...
...
@@ -117,18 +118,28 @@ parseNode a = do
dtotal
dfree
ctotal
False
)
return
(
name
,
node
)
-- |
Buil
ds the cluster data from an URL.
lo
adData
::
String
-- ^ Cluster or URL to use as source
->
IO
(
Result
(
Node
.
AssocList
,
Instance
.
AssocList
,
[
String
])
)
lo
adData
master
=
do
-- IO monad
-- |
Loa
ds the
raw
cluster data from an URL.
re
adData
::
String
-- ^ Cluster or URL to use as source
->
IO
(
Result
String
,
Result
String
,
Result
String
)
re
adData
master
=
do
let
url
=
formatHost
master
node_body
<-
getUrl
$
printf
"%s/2/nodes?bulk=1"
url
inst_body
<-
getUrl
$
printf
"%s/2/instances?bulk=1"
url
tags_body
<-
getUrl
$
printf
"%s/2/tags"
url
return
$
do
-- Result monad
node_data
<-
node_body
>>=
getNodes
let
(
node_names
,
node_idx
)
=
assignIndices
node_data
inst_data
<-
inst_body
>>=
getInstances
node_names
let
(
_
,
inst_idx
)
=
assignIndices
inst_data
tags_data
<-
tags_body
>>=
(
fromJResult
"Parsing tags data"
.
decodeStrict
)
return
(
node_idx
,
inst_idx
,
tags_data
)
return
(
node_body
,
inst_body
,
tags_body
)
-- | Builds the cluster data from the raw Rapi content
parseData
::
(
Result
String
,
Result
String
,
Result
String
)
->
Result
(
Node
.
AssocList
,
Instance
.
AssocList
,
[
String
])
parseData
(
node_body
,
inst_body
,
tags_body
)
=
do
node_data
<-
node_body
>>=
getNodes
let
(
node_names
,
node_idx
)
=
assignIndices
node_data
inst_data
<-
inst_body
>>=
getInstances
node_names
let
(
_
,
inst_idx
)
=
assignIndices
inst_data
tags_data
<-
tags_body
>>=
(
fromJResult
"Parsing tags data"
.
decodeStrict
)
return
(
node_idx
,
inst_idx
,
tags_data
)
-- | Top level function for data loading
loadData
::
String
-- ^ Cluster or URL to use as source
->
IO
(
Result
(
Node
.
AssocList
,
Instance
.
AssocList
,
[
String
]))
loadData
master
=
readData
master
>>=
return
.
parseData
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