now we talkin, updates to db now get reflected in cluster!

This commit is contained in:
Sivert V. Sæther 2021-09-13 16:52:50 +02:00
parent 6c41ae2fd5
commit 9943d3e025
13 changed files with 389 additions and 50 deletions

View File

@ -13,11 +13,21 @@ Everything is optional!
```json ```json
{ {
"LibVirtHosts": [ "LibVirtHosts": [
"qemu:///system" "qemu:///system",
"qemu+ssh://userwithlibvirtgroup@othernode/system"
],
"LibVirtReadOnlyHosts": [
"qemu+ssh://user@privatenode/system"
], ],
"MongoDbStr": "mongodb://localhost:27017", "MongoDbStr": "mongodb://localhost:27017",
"MongoDbName": "overlord",
"LogLevel": 0, "LogLevel": 0,
"LogFilePath": "lord.log" "LogFilePath": "lord.log",
"MatrixCreds": {
"Homeserver": "https://matrix.org",
"Username": "@changme:matrix.org",
"Password": "yourpassword!"
}
} }
``` ```
No log file means stdout only! No log file means stdout only!

View File

@ -1,4 +1,9 @@
# TODO # TODO
## Now
* Do something with State.Stats!
## Future
* Add support for libvirt connection auth. * Add support for libvirt connection auth.
* Fix docker development environment. * Fix docker development environment.
* Matrix client with access token and user id?

3
go.mod
View File

@ -5,9 +5,11 @@ go 1.17
require ( require (
go.mongodb.org/mongo-driver v1.7.2 go.mongodb.org/mongo-driver v1.7.2
libvirt.org/go/libvirt v1.7007.0 libvirt.org/go/libvirt v1.7007.0
maunium.net/go/mautrix v0.9.24
) )
require ( require (
github.com/btcsuite/btcutil v1.0.2 // indirect
github.com/go-stack/stack v1.8.0 // indirect github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/snappy v0.0.3 // indirect github.com/golang/snappy v0.0.3 // indirect
github.com/klauspost/compress v1.13.4 // indirect github.com/klauspost/compress v1.13.4 // indirect
@ -17,6 +19,7 @@ require (
github.com/xdg-go/stringprep v1.0.2 // indirect github.com/xdg-go/stringprep v1.0.2 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/text v0.3.6 // indirect golang.org/x/text v0.3.6 // indirect
) )

49
go.sum
View File

@ -1,7 +1,20 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/btcutil v1.0.2 h1:9iZ1Terx9fMIOtq1VrwdqfsATL9MC2l8ZrUY6YZ2uts=
github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0=
@ -28,15 +41,22 @@ github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWe
github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ=
github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s= github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s=
github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
@ -45,9 +65,14 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxv
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.9.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@ -58,6 +83,7 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
@ -69,8 +95,12 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/sjson v1.1.5/go.mod h1:VuJzsZnTowhSxWdOgsAnb886i4AjEyTkk7tNtsL7EYE=
github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w= github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w=
@ -81,28 +111,38 @@ github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
go.mongodb.org/mongo-driver v1.7.2 h1:pFttQyIiJUHEn50YfZgC9ECjITMT44oiN36uArf/OFg= go.mongodb.org/mongo-driver v1.7.2 h1:pFttQyIiJUHEn50YfZgC9ECjITMT44oiN36uArf/OFg=
go.mongodb.org/mongo-driver v1.7.2/go.mod h1:Q4oFMbo1+MSNqICAdYMlC/zSTrwCogR4R8NzkI+yfU8= go.mongodb.org/mongo-driver v1.7.2/go.mod h1:Q4oFMbo1+MSNqICAdYMlC/zSTrwCogR4R8NzkI+yfU8=
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
@ -119,8 +159,15 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
libvirt.org/go/libvirt v1.7007.0 h1:pTe6uRhxDpWzGS06SXvgeQXqWcG1aTKRfL+gS5xI9Kw= libvirt.org/go/libvirt v1.7007.0 h1:pTe6uRhxDpWzGS06SXvgeQXqWcG1aTKRfL+gS5xI9Kw=
libvirt.org/go/libvirt v1.7007.0/go.mod h1:1WiFE8EjZfq+FCVog+rvr1yatKbKZ9FaFMZgEqxEJqQ= libvirt.org/go/libvirt v1.7007.0/go.mod h1:1WiFE8EjZfq+FCVog+rvr1yatKbKZ9FaFMZgEqxEJqQ=
maunium.net/go/maulogger/v2 v2.2.4/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
maunium.net/go/mautrix v0.9.24 h1:NEwWLHcJ/hPF0TBppdezfbVaxwWY9E9f2KDkG4Q6GC0=
maunium.net/go/mautrix v0.9.24/go.mod h1:7IzKfWvpQtN+W2Lzxc0rLvIxFM3ryKX6Ys3S/ZoWbg8=

View File

@ -9,7 +9,7 @@ func main() {
log.PrintLog(log.INFO, "Starting Overlord.") log.PrintLog(log.INFO, "Starting Overlord.")
state := overlord.NewState() state := overlord.NewState()
state.Setup() state.Setup()
//state.MainLoop() state.MainLoop()
state.Stop() state.Stop()
log.PrintLog(log.TRACE, "Done.") log.PrintLog(log.TRACE, "Done.")
} }

70
src/libvirt/dbhandlers.go Normal file
View File

@ -0,0 +1,70 @@
package libvirt
import (
"context"
"bitsnthings.dev/overlord/src/log"
"go.mongodb.org/mongo-driver/mongo"
"libvirt.org/go/libvirt"
)
type domainDocument struct {
Active bool
Uuid string
Uri string
Xml string
}
func domainError(
err error,
str string,
domain domainDocument,
a ...interface{},
) bool {
if err != nil {
log.PrintLog(
log.ERROR,
str+" domain with uuid: \"%s\" on node with uri: \"%s\"!",
a, domain.Uuid, domain.Uri,
)
return true
} else {
return false
}
}
func (virt *Libvirt) DomainChangeHandler(stream *mongo.ChangeStream) {
for stream.Next(context.TODO()) {
go func() {
updatedDomain := struct {
FullDocument domainDocument `bson:"fullDocument"`
}{}
if err := stream.Decode(&updatedDomain); err != nil {
log.PrintLog(log.ERROR, "Error decoding mongodb change stream! %s", err)
}
domain := updatedDomain.FullDocument
dom, err := virt.Hosts[domain.Uri].DomainDefineXML(domain.Xml)
if domainError(err, "Error updating", domain) {
return
}
setDomainActive(dom, domain)
log.PrintLog(
log.INFO,
"Updated domain with uuid: \"%s\" on node with uri: \"%s\"!",
domain.Uuid, domain.Uri)
}()
}
}
func setDomainActive(dom *libvirt.Domain, domain domainDocument) {
active, err := dom.IsActive()
if domainError(err, "Error getting active status of", domain) {
return
}
if !active && domain.Active {
domainError(dom.Resume(), "Error resuming", domain)
}
if active && !domain.Active {
domainError(dom.Suspend(), "Error suspending", domain)
}
}

View File

@ -6,28 +6,33 @@ import (
) )
func (virt *Libvirt) getAllDomains() { func (virt *Libvirt) getAllDomains() {
virt.getDomainsByFlag(libvirt.CONNECT_LIST_DOMAINS_ACTIVE) virt.Domains.Active = make(map[string]map[string]libvirt.Domain)
virt.getDomainsByFlag(libvirt.CONNECT_LIST_DOMAINS_INACTIVE) virt.Domains.Inactive = make(map[string]map[string]libvirt.Domain)
for uri, conn := range virt.Hosts {
virt.Domains.Active[uri] = getDomainsByFlag(uri, conn, libvirt.CONNECT_LIST_DOMAINS_ACTIVE)
virt.Domains.Inactive[uri] = getDomainsByFlag(uri, conn, libvirt.CONNECT_LIST_DOMAINS_INACTIVE)
}
} }
func (virt *Libvirt) getDomainsByFlag(flag libvirt.ConnectListAllDomainsFlags) { func getDomainsByFlag(uri string, conn *libvirt.Connect, flag libvirt.ConnectListAllDomainsFlags) map[string]libvirt.Domain {
for _, conn := range virt.Hosts { domMap := make(map[string]libvirt.Domain)
doms, err := conn.ListAllDomains(flag) doms, err := conn.ListAllDomains(flag)
uri, _ := conn.GetURI() if err != nil {
log.PrintLog(
log.ERROR,
"Error fetching domain list from node with connection uri: \"%s\"! %s",
uri, err)
}
for _, dom := range doms {
uuid, err := dom.GetUUIDString()
if err != nil { if err != nil {
log.PrintLog( log.PrintLog(
log.ERROR, log.ERROR,
"Error fetching domain list from node with connection uri: \"%s\"! %s", "Error getting id of domain on node with uri: \"%s\"! %s",
uri, err) uri, err)
} } else {
virt.Guests[uri] = make(map[string]libvirt.Domain) domMap[uuid] = dom
for _, dom := range doms {
name, err := dom.GetName()
if err != nil {
log.PrintLog(log.ERROR, "Error getting name of domain on node with connection string \"%s\"! %s",
uri, err)
}
virt.Guests[uri][name] = dom
} }
} }
return domMap
} }

View File

@ -5,35 +5,49 @@ import (
libvirt "libvirt.org/go/libvirt" libvirt "libvirt.org/go/libvirt"
) )
type libvirtConnectFunc func(string) (*libvirt.Connect, error)
type Domains struct {
Active map[string]map[string]libvirt.Domain
Inactive map[string]map[string]libvirt.Domain
}
type Stats struct {
}
type Libvirt struct { type Libvirt struct {
Hosts map[string]*libvirt.Connect Hosts map[string]*libvirt.Connect
Guests map[string]map[string]libvirt.Domain ROHosts map[string]*libvirt.Connect
Domains Domains
// Auth libvirt.ConnectAuth // Auth libvirt.ConnectAuth
// Flags libvirt.ConnectFlags // Flags libvirt.ConnectFlags
Stats Stats
} }
func New() Libvirt { func New() Libvirt {
return Libvirt{ return Libvirt{
map[string]*libvirt.Connect{}, map[string]*libvirt.Connect{},
map[string]map[string]libvirt.Domain{}, map[string]*libvirt.Connect{},
Domains{},
Stats{},
} }
} }
func (virt *Libvirt) GetStatus() { func (virt *Libvirt) GetStatus() {
log.PrintLog(log.TRACE, "Getting libvirt cluster status.")
virt.getAllDomains() virt.getAllDomains()
log.PrintLog(log.INFO, "All domains in the cluster:") log.PrintLog(log.TRACE, "Fetched libvirt cluster status.")
for uri, doms := range virt.Guests { }
log.PrintLog(log.INFO, "With uri: %s", uri)
for name, dom := range doms { func (virt *Libvirt) IsReadOnly(uri string) bool {
os, _ := dom.GetOSType() if _, ok := virt.ROHosts[uri]; ok {
log.PrintLog(log.INFO, "%s (%s)", name, os) return true
} } else {
return false
} }
} }
func (virt *Libvirt) Connect(cstr string) (*libvirt.Connect, error) { func (virt *Libvirt) Connect(cstr string, connFn libvirtConnectFunc) (*libvirt.Connect, error) {
conn, err := libvirt.NewConnect(cstr) //, &virt.Auth, virt.Flags) conn, err := connFn(cstr) //, &virt.Auth, virt.Flags)
if err != nil { if err != nil {
log.PrintLog(log.WARN, "Error connecting to libvirt host with uri: \"%s\"! %s", log.PrintLog(log.WARN, "Error connecting to libvirt host with uri: \"%s\"! %s",
cstr, err) cstr, err)
@ -43,8 +57,8 @@ func (virt *Libvirt) Connect(cstr string) (*libvirt.Connect, error) {
return conn, err return conn, err
} }
func (virt *Libvirt) ConnectMany(cstrs []string) { func (virt *Libvirt) ConnectMany(cstrs []string, connFn libvirtConnectFunc) {
for _, cstr := range cstrs { for _, cstr := range cstrs {
virt.Connect(cstr) virt.Connect(cstr, connFn)
} }
} }

35
src/matrix/matrix.go Normal file
View File

@ -0,0 +1,35 @@
package matrix
import (
"bitsnthings.dev/overlord/src/log"
"bitsnthings.dev/overlord/src/state/conf"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
)
func parseMatrixMessage(src mautrix.EventSource, evt *event.Event) {
log.PrintLog(log.INFO, "<%s> %s", evt.Sender, evt.Content.AsMessage().Body)
}
func Setup(conf conf.Config) {
client, err := mautrix.NewClient(conf.MatrixCreds.Homeserver, "", "")
if err != nil {
log.PrintLog(log.ERROR, "Could not connect to matrix server! %s", err)
conf.EnableMatrix = false
return
}
_, err = client.Login(&mautrix.ReqLogin{
Type: "m.login.password",
Identifier: mautrix.UserIdentifier{
Type: mautrix.IdentifierTypeUser, User: conf.MatrixCreds.Username},
Password: conf.MatrixCreds.Password,
StoreCredentials: false,
})
if err != nil {
log.PrintLog(log.ERROR, "Could not login to matrix server! %s", err)
return
}
conf.MatrixCleint = *client
syncer := client.Syncer.(*mautrix.DefaultSyncer)
syncer.OnEventType(event.EventMessage, parseMatrixMessage)
}

View File

@ -1,4 +1,4 @@
package state package conf
import ( import (
"encoding/json" "encoding/json"
@ -6,14 +6,28 @@ import (
"os" "os"
log "bitsnthings.dev/overlord/src/log" log "bitsnthings.dev/overlord/src/log"
"maunium.net/go/mautrix"
) )
type Config struct { type Config struct {
LibvirtHosts []string LibvirtHosts []string
MongoDbStr string LibvirtReadOnlyHosts []string
ConfFilePath string MongoDbStr string
LogLevel log.LogLevel MongoDbName string
LogFilePath string ConfFilePath string
LogLevel log.LogLevel
LogFilePath string
EnableMatrix bool
MatrixCreds MatrixCreds
MatrixCleint mautrix.Client
}
type MatrixCreds struct {
Homeserver string
// AccessToken string
// UserID mautrix.UserIdentifier
Username string
Password string
} }
func (conf *Config) ReadConfig() { func (conf *Config) ReadConfig() {

89
src/state/db.go Normal file
View File

@ -0,0 +1,89 @@
package state
import (
"context"
log "bitsnthings.dev/overlord/src/log"
"libvirt.org/go/libvirt"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func (state *State) setDBWatchers() {
state.startWatchStreamHandler(
*state.MongoDB.Collection("domains"),
mongo.Pipeline{},
state.Libvirt.DomainChangeHandler)
}
func (state *State) startWatchStreamHandler(
collection mongo.Collection,
pipeline mongo.Pipeline,
handler func(*mongo.ChangeStream),
) {
stream, err := collection.Watch(
context.TODO(),
pipeline,
state.streamOpts)
if err != nil {
log.PrintLog(
log.ERROR,
"Error starting mongodb watch stream! %s",
err)
stream.Close(context.TODO())
return
}
state.changeStreams = append(state.changeStreams, stream)
go handler(stream)
}
func (state *State) fetchDBState() {
}
func (state *State) pushDBState() {
for uri, domMap := range state.Libvirt.Domains.Active {
setDomainStatesInDB(
domMap, state, true, uri, state.upsertOpts)
}
for uri, domMap := range state.Libvirt.Domains.Inactive {
setDomainStatesInDB(
domMap, state, false, uri, state.upsertOpts)
}
}
func setDomainStatesInDB(
domMap map[string]libvirt.Domain,
state *State,
domainState bool,
uri string,
opts *options.UpdateOptions,
) {
var flags libvirt.DomainXMLFlags
if !state.Libvirt.IsReadOnly(uri) {
flags = libvirt.DOMAIN_XML_INACTIVE + libvirt.DOMAIN_XML_INACTIVE
}
for uuid, dom := range domMap {
xml, err := dom.GetXMLDesc(flags)
if err != nil {
log.PrintLog(
log.ERROR,
"Error getting XML of domain with uuid: \"%s\" on node with uri: \"%s\"! %s",
uuid, uri, err)
}
state.MongoDB.Collection("domains").UpdateOne(
context.TODO(),
bson.D{
{Key: "uri", Value: uri},
{Key: "uuid", Value: uuid}},
bson.D{
{Key: "$set", Value: bson.M{
"active": domainState,
"xml": xml,
}}},
opts,
)
}
}

View File

@ -9,8 +9,10 @@ import (
"syscall" "syscall"
log "bitsnthings.dev/overlord/src/log" log "bitsnthings.dev/overlord/src/log"
matrix "bitsnthings.dev/overlord/src/matrix"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"
"libvirt.org/go/libvirt"
) )
func (state *State) Setup() { func (state *State) Setup() {
@ -21,13 +23,25 @@ func (state *State) Setup() {
log.PrintLog(log.TRACE, "Config and logfile ready.") log.PrintLog(log.TRACE, "Config and logfile ready.")
state.setupDB() state.setupDB()
log.PrintLog(log.TRACE, "Connected to database.") log.PrintLog(log.TRACE, "Connected to database.")
state.Libvirt.ConnectMany(state.Config.LibvirtHosts) state.Libvirt.ConnectMany(state.Config.LibvirtHosts, libvirt.NewConnect)
state.Libvirt.ConnectMany(state.Config.LibvirtReadOnlyHosts, libvirt.NewConnectReadOnly)
log.PrintLog(log.TRACE, "Done with inital connections.") log.PrintLog(log.TRACE, "Done with inital connections.")
state.fetchDBState()
log.PrintLog(log.TRACE, "Loaded state from DB.")
state.Libvirt.GetStatus() state.Libvirt.GetStatus()
log.PrintLog(log.TRACE, "Fetched cluster status and prepared internal state.") log.PrintLog(log.TRACE, "Fetched cluster status and updated internal state.")
state.pushDBState()
log.PrintLog(log.TRACE, "Pushed updated state to DB.")
if state.Config.EnableMatrix {
matrix.Setup(state.Config)
log.PrintLog(log.INFO, "Connected to matrix.")
}
} }
func (state *State) setupDB() { func (state *State) setupDB() {
state.upsertOpts.SetUpsert(true)
state.streamOpts.SetBatchSize(8)
state.streamOpts.SetFullDocument("updateLookup")
clientOptions := options.Client().ApplyURI(state.Config.MongoDbStr) clientOptions := options.Client().ApplyURI(state.Config.MongoDbStr)
client, _ := mongo.Connect(context.TODO(), clientOptions) client, _ := mongo.Connect(context.TODO(), clientOptions)
err := client.Ping(context.TODO(), nil) err := client.Ping(context.TODO(), nil)
@ -37,7 +51,12 @@ func (state *State) setupDB() {
log.PrintLog(log.FATAL, "Error connecting to database wtih connection string \"%s\"! %s", log.PrintLog(log.FATAL, "Error connecting to database wtih connection string \"%s\"! %s",
state.Config.MongoDbStr, err) state.Config.MongoDbStr, err)
} }
state.Mongo = client dbName := state.Config.MongoDbName
if dbName == "" {
dbName = "overlord"
}
state.MongoDB = client.Database(dbName)
state.setDBWatchers()
} }
func (state *State) setupCloseSignalHandlers() { func (state *State) setupCloseSignalHandlers() {

View File

@ -1,33 +1,61 @@
package state package state
import ( import (
"context"
"time"
virt "bitsnthings.dev/overlord/src/libvirt" virt "bitsnthings.dev/overlord/src/libvirt"
log "bitsnthings.dev/overlord/src/log" log "bitsnthings.dev/overlord/src/log"
"bitsnthings.dev/overlord/src/state/conf"
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
) )
const Version = "0.0.69" const Version = "0.0.69"
type State struct { type State struct {
Libvirt virt.Libvirt Libvirt virt.Libvirt
Config Config Config conf.Config
Mongo *mongo.Client MongoDB *mongo.Database
upsertOpts *options.UpdateOptions
streamOpts *options.ChangeStreamOptions
changeStreams []*mongo.ChangeStream
} }
func NewState() State { func NewState() State {
return State{ return State{
virt.New(), virt.New(),
Config{}, conf.Config{},
&mongo.Client{}, &mongo.Database{},
&options.UpdateOptions{},
&options.ChangeStreamOptions{},
[]*mongo.ChangeStream{},
} }
} }
func (state *State) MainLoop() { func (state *State) MainLoop() {
state.Libvirt.GetStatus() for {
time.Sleep(time.Second * 10)
}
// state.Libvirt.GetStatus()
// state.Config.MatrixCleint.Sync()
} }
func (state *State) Stop() { func (state *State) Stop() {
log.PrintLog(log.INFO, "Stopping Overlord.") log.PrintLog(log.INFO, "Stopping Overlord.")
for _, stream := range state.changeStreams {
stream.Close(context.TODO())
}
log.PrintLog(log.TRACE, "Closed mongodb change streams.")
for uri, domMap := range state.Libvirt.Domains.Active {
log.PrintLog(
log.TRACE,
"Freeing internal domain structures for libvirt domain with uri: %s.",
uri)
for _, dom := range domMap {
dom.Free()
}
}
for _, conn := range state.Libvirt.Hosts { for _, conn := range state.Libvirt.Hosts {
conn.Close() conn.Close()
} }