2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-06-30 05:14:26 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
|
2022-09-21 07:47:57 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/hack/qemu-metadata-api/server"
|
|
|
|
"github.com/edgelesssys/constellation/v2/hack/qemu-metadata-api/virtwrapper"
|
|
|
|
"github.com/edgelesssys/constellation/v2/internal/logger"
|
2022-06-30 05:14:26 -04:00
|
|
|
"go.uber.org/zap"
|
|
|
|
"go.uber.org/zap/zapcore"
|
|
|
|
"libvirt.org/go/libvirt"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
bindPort := flag.String("port", "8080", "Port to bind to")
|
2022-09-26 09:52:31 -04:00
|
|
|
targetNetwork := flag.String("network", "constellation-network", "Name of the network in QEMU to use")
|
2022-10-05 03:11:30 -04:00
|
|
|
libvirtURI := flag.String("libvirt-uri", "qemu:///system", "URI of the libvirt connection")
|
2022-06-30 05:14:26 -04:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
log := logger.New(logger.JSONLog, zapcore.InfoLevel)
|
|
|
|
|
2022-10-05 03:11:30 -04:00
|
|
|
conn, err := libvirt.NewConnect(*libvirtURI)
|
2022-06-30 05:14:26 -04:00
|
|
|
if err != nil {
|
|
|
|
log.With(zap.Error(err)).Fatalf("Failed to connect to libvirt")
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
2022-09-26 09:52:31 -04:00
|
|
|
serv := server.New(log, *targetNetwork, &virtwrapper.Connect{Conn: conn})
|
2022-06-30 05:14:26 -04:00
|
|
|
if err := serv.ListenAndServe(*bindPort); err != nil {
|
|
|
|
log.With(zap.Error(err)).Fatalf("Failed to serve")
|
|
|
|
}
|
|
|
|
}
|