Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qbar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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
Jens Nolte
qbar
Commits
82c6ac15
Commit
82c6ac15
authored
4 years ago
by
Mr. Snow Ball / projects
Browse files
Options
Downloads
Patches
Plain Diff
Add block qubesCount
parent
893ca6c1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/QBar/Blocks.hs
+1
-0
1 addition, 0 deletions
src/QBar/Blocks.hs
src/QBar/Blocks/Qubes.hs
+9
-1
9 additions, 1 deletion
src/QBar/Blocks/Qubes.hs
src/QBar/Cli.hs
+2
-1
2 additions, 1 deletion
src/QBar/Cli.hs
src/QBar/Qubes/AdminAPI.hs
+4
-0
4 additions, 0 deletions
src/QBar/Qubes/AdminAPI.hs
with
16 additions
and
2 deletions
src/QBar/Blocks.hs
+
1
−
0
View file @
82c6ac15
...
...
@@ -6,6 +6,7 @@ module QBar.Blocks
QBar
.
Blocks
.
NetworkManager
.
networkManagerBlock
,
QBar
.
Blocks
.
Qubes
.
diskUsageQubesBlock
,
QBar
.
Blocks
.
Qubes
.
qubesMonitorPropertyBlock
,
QBar
.
Blocks
.
Qubes
.
qubesVMCountBlock
,
QBar
.
Blocks
.
Script
.
scriptBlock
,
QBar
.
Blocks
.
Script
.
pollScriptBlock
,
)
...
...
This diff is collapsed.
Click to expand it.
src/QBar/Blocks/Qubes.hs
+
9
−
1
View file @
82c6ac15
...
...
@@ -3,11 +3,12 @@ module QBar.Blocks.Qubes where
import
QBar.BlockHelper
import
QBar.BlockOutput
import
QBar.Core
import
QBar.Qubes.AdminAPI
(
qubesUsageOfDefaultPool
,
qubesMonitorProperty
,
qubesGetProperty
,
qubesEvents
,
QubesPropertyInfo
(
..
))
import
QBar.Qubes.AdminAPI
(
qubesUsageOfDefaultPool
,
qubesMonitorProperty
,
qubesGetProperty
,
qubesEvents
,
QubesPropertyInfo
(
..
)
,
qubesListVMsP
,
QubesVMState
(
..
),
vmState
)
import
Control.Concurrent.Async
import
Control.Monad.Reader
(
runReaderT
)
import
qualified
Data.ByteString.Lazy
as
BL
import
qualified
Data.Map
as
M
import
qualified
Data.Text.Lazy
as
T
import
Data.Text.Lazy.Encoding
(
decodeUtf8With
)
import
Data.Text.Encoding.Error
(
lenientDecode
)
...
...
@@ -81,3 +82,10 @@ qubesMonitorPropertyBlock name = pipeBlockWithEvents (qubesMonitorProperty qubes
handle
=
handle'
<=<
either
(
const
$
liftIO
$
qubesGetProperty
name
)
return
handle'
QubesPropertyInfo
{
propValue
,
propIsDefault
}
=
return
$
Just
$
mkBlockOutput
$
normalText
$
decode
propValue
<>
(
if
propIsDefault
then
" (D)"
else
""
)
decode
=
decodeUtf8With
lenientDecode
qubesVMCountBlock
::
Block
qubesVMCountBlock
=
qubesListVMsP
>->
P
.
map
countVMs
>>
exitBlock
where
countVMs
=
wrap
.
format
.
M
.
size
.
M
.
filterWithKey
isRunningVM
isRunningVM
name
x
=
vmState
x
==
VMRunning
&&
name
/=
"dom0"
format
n
=
mkBlockOutput
$
normalText
$
T
.
pack
(
show
n
)
<>
" Qube"
<>
(
if
n
/=
1
then
"s"
else
""
)
wrap
x
=
(
Just
(
x
,
Nothing
),
DefaultUpdate
)
This diff is collapsed.
Click to expand it.
src/QBar/Cli.hs
+
2
−
1
View file @
82c6ac15
...
...
@@ -95,7 +95,8 @@ blockParser =
command
"networkmanager"
(
info
(
pure
$
addBlock
networkManagerBlock
)
(
progDesc
"Load the network-manager block."
))
<>
command
"script"
(
info
scriptBlockParser
(
progDesc
"Display the output of an external script as a block."
))
<>
command
"diskQubesPool"
(
info
(
pure
$
addBlock
diskUsageQubesBlock
)
(
progDesc
"Load a block that shows free space in Qubes' default pool."
))
<>
command
"qubesProperty"
(
info
qubesPropertyBlockParser
(
progDesc
"Display the current value of a Qubes property."
))
command
"qubesProperty"
(
info
qubesPropertyBlockParser
(
progDesc
"Display the current value of a Qubes property."
))
<>
command
"qubesCount"
(
info
(
pure
$
addBlock
qubesVMCountBlock
)
(
progDesc
"Display the number of running Qubes (VMs)."
))
)
diskUsageBlockParser
::
Parser
(
BarIO
()
)
...
...
This diff is collapsed.
Click to expand it.
src/QBar/Qubes/AdminAPI.hs
+
4
−
0
View file @
82c6ac15
...
...
@@ -257,6 +257,10 @@ qubesListVMs = parse <$> qubesAdminCallLines "admin.vm.List" []
tryReadProp
::
Read
a
=>
BL
.
ByteString
->
Maybe
a
tryReadProp
name
=
readMaybe
.
BLC
.
unpack
=<<
getProp
name
qubesListVMsP
::
forall
m
.
(
P
.
MonadSafe
m
,
MonadIO
m
,
MonadFail
m
)
=>
Producer
(
Map
.
Map
BL
.
ByteString
QubesVMInfo
)
m
()
qubesListVMsP
=
liftIO
qubesListVMs
>>=
yield
>>
qubesEvents
>->
P
.
mapM
(
const
$
liftIO
qubesListVMs
)
data
QubesPropertyInfo
=
QubesPropertyInfo
{
propIsDefault
::
Bool
,
propType
::
BL
.
ByteString
,
propValue
::
BL
.
ByteString
}
deriving
(
Eq
,
Ord
,
Show
,
Read
)
...
...
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