Initial cut of wwapi.

We need an API for Warewulf in order to automate around it. The initial version of the API will look a lot like wwctl. wwctl will call the API so that we do not need to maintain separate code paths. In this preview wwctl calls the API via direct function call, but we can change that to a gprc or REST call to a Warewulf server in the future.

This commit contains:
wwapid WareWulf API Daemon. A grpc server with mTLS auth.
wwapic WareWulf API Client. A grpc client with mTLS auth. It's just a sample that reads the version from the server.
wwapird WareWulf API Rest Daemon. A http REST reverse proxy to wwapid.
There are also sample insecure and secure curls to test with.

Implemented Functionality:
wwctl node add
wwctl node delete
wwctl node list
wwctl node set
wwctl node status
wwctl container build
wwctl container delete
wwctl container import
wwctl container list
wwctl container show

Some notes on the files:

    Logic that was in wwctl has moved to warewulf/internal/pkg/api. wwctl just calls the API. wwctl functionality is unchanged.
    Everything under the /google directory is copied google proto code to stand up wwapird. It's a bit strange to copy in the code, but that is currently how it's done.
    Everything in warewulf/internal/pkg/api/routes/wwapiv1 is generated code.

There are some loose ends here, such as no service installers. I just ran off the command line for development.
The Makefile could use improvement. I'm building by make clean setup proto all build wwapid wwapic wwapird ; echo $?
I copied the configs from warewulf/etc to /usr/local/etc/warewulf manually.
This commit is contained in:
MatthewHink
2022-05-13 15:12:32 -04:00
parent d976e7fc31
commit d8cd6049ac
57 changed files with 8842 additions and 1157 deletions

View File

@@ -95,7 +95,7 @@ export GOPROXY
# built tags needed for wwbuild binary
WW_GO_BUILD_TAGS := containers_image_openpgp containers_image_ostree
all: config vendor wwctl wwclient bash_completion.d man_pages config_defaults
all: config vendor wwctl wwclient bash_completion.d man_pages config_defaults wwapid wwapic wwapird
build: lint test-it vet all
@@ -170,6 +170,9 @@ files: all
install -d -m 0755 $(DESTDIR)$(WWDATADIR)/ipxe
test -f $(DESTDIR)$(WWCONFIGDIR)/warewulf.conf || install -m 644 etc/warewulf.conf $(DESTDIR)$(WWCONFIGDIR)
test -f $(DESTDIR)$(WWCONFIGDIR)/nodes.conf || install -m 644 etc/nodes.conf $(DESTDIR)$(WWCONFIGDIR)
test -f $(DESTDIR)$(SYSCONFDIR)/warewulf/wwapic.conf || install -m 644 etc/wwapic.conf $(DESTDIR)$(SYSCONFDIR)/warewulf/
test -f $(DESTDIR)$(SYSCONFDIR)/warewulf/wwapid.conf || install -m 644 etc/wwapid.conf $(DESTDIR)$(SYSCONFDIR)/warewulf/
test -f $(DESTDIR)$(SYSCONFDIR)/warewulf/wwapird.conf || install -m 644 etc/wwapird.conf $(DESTDIR)$(SYSCONFDIR)/warewulf/
cp -r etc/examples $(DESTDIR)$(WWCONFIGDIR)/
cp -r etc/ipxe $(DESTDIR)$(WWCONFIGDIR)/
cp -r overlays/* $(DESTDIR)$(WWOVERLAYDIR)/
@@ -180,6 +183,9 @@ files: all
chmod 644 $(DESTDIR)$(WWOVERLAYDIR)/wwinit/etc/ssh/ssh*.pub.ww
chmod 750 $(DESTDIR)$(WWOVERLAYDIR)/host
install -m 0755 wwctl $(DESTDIR)$(BINDIR)
install -m 0755 wwapic $(DESTDIR)$(BINDIR)
install -m 0755 wwapid $(DESTDIR)$(BINDIR)
install -m 0755 wwapird $(DESTDIR)$(BINDIR)
install -m 0644 include/firewalld/warewulf.xml $(DESTDIR)$(FIREWALLDDIR)
install -m 0644 include/systemd/warewulfd.service $(DESTDIR)$(SYSTEMDDIR)
install -m 0644 LICENSE.md $(DESTDIR)$(WWDOCDIR)
@@ -243,6 +249,33 @@ dist: vendor config
cd .dist; tar -czf ../$(WAREWULF)-$(VERSION).tar.gz $(WAREWULF)-$(VERSION)
rm -rf .dist
## wwapi generate code from protobuf. Requires protoc and protoc-grpc-gen-gateway to generate code.
## To setup latest protoc:
## Download the protobuf-all-[VERSION].tar.gz from https://github.com/protocolbuffers/protobuf/releases
## Extract the contents and change in the directory
## ./configure
## make
## make check
## sudo make install
## sudo ldconfig # refresh shared library cache.
## To setup protoc-gen-grpc-gateway, see https://github.com/grpc-ecosystem/grpc-gateway
proto:
protoc -I internal/pkg/api/routes/v1 -I=. \
--grpc-gateway_out=. \
--grpc-gateway_opt logtostderr=true \
--go_out=. \
--go-grpc_out=. \
routes.proto
wwapid: ## Build the grpc api server.
go build -o ./wwapid internal/app/api/wwapid/wwapid.go
wwapic: ## Build the sample wwapi client.
go build -o ./wwapic internal/app/api/wwapic/wwapic.go
wwapird: ## Build the rest api server (revese proxy to the grpc api server).
go build -o ./wwapird internal/app/api/wwapird/wwapird.go
clean:
rm -f wwclient
rm -f wwctl