Merge ~cgrabowski/maas:rpc_client_server into maas:rack_region_exploration
- Git
- lp:~cgrabowski/maas
- rpc_client_server
- Merge into rack_region_exploration
Status: | Merged |
---|---|
Approved by: | Christian Grabowski |
Approved revision: | e4105e0c6bf7c8b11fa71629d67385c20b5a2cad |
Merge reported by: | MAAS Lander |
Merged at revision: | not available |
Proposed branch: | ~cgrabowski/maas:rpc_client_server |
Merge into: | maas:rack_region_exploration |
Diff against target: |
3110 lines (+2887/-3) 21 files modified
src/rackd_spike/Makefile (+21/-1) src/rackd_spike/cmd/rackd.go (+21/-0) src/rackd_spike/go.mod (+4/-0) src/rackd_spike/go.sum (+15/-2) src/rackd_spike/internal/machine_helpers/env.go (+67/-0) src/rackd_spike/internal/machine_helpers/info.go (+24/-0) src/rackd_spike/internal/machine_helpers/interfaces.go (+498/-0) src/rackd_spike/internal/machine_helpers/interfaces_capnp.go (+65/-0) src/rackd_spike/internal/machine_helpers/interfaces_test.go (+81/-0) src/rackd_spike/internal/machine_helpers/ps.go (+81/-0) src/rackd_spike/internal/machine_helpers/refresh.go (+29/-0) src/rackd_spike/internal/machine_helpers/snap.go (+30/-0) src/rackd_spike/internal/transport/rpc.go (+127/-0) src/rackd_spike/pkg/authenticate/authenticator.go (+93/-0) src/rackd_spike/pkg/region/handshake.go (+91/-0) src/rackd_spike/pkg/register/registerer.go (+125/-0) src/rackd_spike/pkg/rpc/handshake.capnp.go (+933/-0) src/rackd_spike/pkg/rpc/network.capnp.go (+489/-0) src/rpc/go.capnp (+27/-0) src/rpc/handshake.capnp (+36/-0) src/rpc/network.capnp (+30/-0) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexsander de Souza | Approve | ||
MAAS Lander | Approve | ||
Review via email: mp+405247@code.launchpad.net |
Commit message
add rpc handshake
add machine helper functions
Description of the change
Alexsander de Souza (alexsander-souza) : | # |
Christian Grabowski (cgrabowski) : | # |
MAAS Lander (maas-lander) wrote : | # |
UNIT TESTS
-b rpc_client_server lp:~cgrabowski/maas/+git/maas into -b rack_region_
STATUS: SUCCESS
COMMIT: 55db9bddb0a716d
MAAS Lander (maas-lander) wrote : | # |
UNIT TESTS
-b rpc_client_server lp:~cgrabowski/maas/+git/maas into -b rack_region_
STATUS: FAILED
LOG: http://
COMMIT: 6b7bb3239a1fa16
Alexsander de Souza (alexsander-souza) : | # |
Christian Grabowski (cgrabowski) : | # |
MAAS Lander (maas-lander) wrote : | # |
UNIT TESTS
-b rpc_client_server lp:~cgrabowski/maas/+git/maas into -b rack_region_
STATUS: SUCCESS
COMMIT: efa4abdd774328b
MAAS Lander (maas-lander) wrote : | # |
UNIT TESTS
-b rpc_client_server lp:~cgrabowski/maas/+git/maas into -b rack_region_
STATUS: SUCCESS
COMMIT: bd874202dee2eee
MAAS Lander (maas-lander) wrote : | # |
UNIT TESTS
-b rpc_client_server lp:~cgrabowski/maas/+git/maas into -b rack_region_
STATUS: FAILED
LOG: http://
COMMIT: a350ebb73dc98f9
MAAS Lander (maas-lander) wrote : | # |
UNIT TESTS
-b rpc_client_server lp:~cgrabowski/maas/+git/maas into -b rack_region_
STATUS: SUCCESS
COMMIT: e4105e0c6bf7c8b
Alexsander de Souza (alexsander-souza) wrote : | # |
LGTM
MAAS Lander (maas-lander) wrote : | # |
LANDING
-b rpc_client_server lp:~cgrabowski/maas/+git/maas into -b rack_region_
STATUS: FAILED BUILD
LOG: http://
Preview Diff
1 | diff --git a/src/rackd_spike/Makefile b/src/rackd_spike/Makefile | |||
2 | index 81278c8..df50bdd 100644 | |||
3 | --- a/src/rackd_spike/Makefile | |||
4 | +++ b/src/rackd_spike/Makefile | |||
5 | @@ -1,3 +1,6 @@ | |||
6 | 1 | PWD:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) | ||
7 | 2 | ROOT_DIR:=$(shell dirname $(PWD)) | ||
8 | 3 | RPC_DIR:=$(PWD)/pkg/rpc | ||
9 | 1 | VERSION:=develop-$(shell git rev-list -1 HEAD) | 4 | VERSION:=develop-$(shell git rev-list -1 HEAD) |
10 | 2 | 5 | ||
11 | 3 | PATH:=$(shell go env GOPATH)/bin:${PATH} | 6 | PATH:=$(shell go env GOPATH)/bin:${PATH} |
12 | @@ -5,24 +8,41 @@ export PATH | |||
13 | 5 | 8 | ||
14 | 6 | LDFLAGS="-X main.Version=$(VERSION) -s -w" | 9 | LDFLAGS="-X main.Version=$(VERSION) -s -w" |
15 | 7 | 10 | ||
16 | 11 | .PHONY: all | ||
17 | 8 | all: version test build | 12 | all: version test build |
18 | 9 | 13 | ||
19 | 10 | version: | 14 | version: |
20 | 11 | @go version | 15 | @go version |
21 | 12 | 16 | ||
22 | 17 | .PHONY: build | ||
23 | 13 | build: rackd | 18 | build: rackd |
24 | 14 | 19 | ||
25 | 20 | .PHONY: build-dir | ||
26 | 15 | build-dir: | 21 | build-dir: |
27 | 16 | mkdir -p ./build | 22 | mkdir -p ./build |
28 | 17 | 23 | ||
30 | 18 | rackd: build-dir | 24 | .PHONY: rackd |
31 | 25 | rackd: build-dir gen-capnp | ||
32 | 19 | go build -ldflags $(LDFLAGS) -o ./build/rackd ./cmd/rackd.go | 26 | go build -ldflags $(LDFLAGS) -o ./build/rackd ./cmd/rackd.go |
33 | 20 | 27 | ||
34 | 28 | .PHONY: test | ||
35 | 21 | test: | 29 | test: |
36 | 22 | go test ./... | 30 | go test ./... |
37 | 23 | 31 | ||
38 | 32 | .PHONY: lint | ||
39 | 24 | lint: | 33 | lint: |
40 | 25 | go vet ./... | 34 | go vet ./... |
41 | 26 | 35 | ||
42 | 36 | .PHONY: format | ||
43 | 27 | format: | 37 | format: |
44 | 28 | gofmt -s -d ./cmd ./internal ./pkg | 38 | gofmt -s -d ./cmd ./internal ./pkg |
45 | 39 | |||
46 | 40 | .PHONY: capnp-dir | ||
47 | 41 | capnp-dir: | ||
48 | 42 | mkdir -p ./pkg/rpc | ||
49 | 43 | |||
50 | 44 | %.capnp: capnp-dir | ||
51 | 45 | capnp compile -ogo:$(PWD)/pkg/rpc $(ROOT_DIR)/rpc/$@ --src-prefix $(ROOT_DIR)/rpc | ||
52 | 46 | |||
53 | 47 | .PHONY: gen-capnp | ||
54 | 48 | gen-capnp: handshake.capnp network.capnp | ||
55 | diff --git a/src/rackd_spike/cmd/rackd.go b/src/rackd_spike/cmd/rackd.go | |||
56 | index fd7dac5..8ca5188 100644 | |||
57 | --- a/src/rackd_spike/cmd/rackd.go | |||
58 | +++ b/src/rackd_spike/cmd/rackd.go | |||
59 | @@ -14,6 +14,10 @@ import ( | |||
60 | 14 | "rackd/cmd/subcommands" | 14 | "rackd/cmd/subcommands" |
61 | 15 | "rackd/internal/config" | 15 | "rackd/internal/config" |
62 | 16 | "rackd/internal/metrics" | 16 | "rackd/internal/metrics" |
63 | 17 | "rackd/internal/transport" | ||
64 | 18 | "rackd/pkg/authenticate" | ||
65 | 19 | "rackd/pkg/region" | ||
66 | 20 | "rackd/pkg/register" | ||
67 | 17 | ) | 21 | ) |
68 | 18 | 22 | ||
69 | 19 | type opts struct { | 23 | type opts struct { |
70 | @@ -76,6 +80,23 @@ var ( | |||
71 | 76 | } | 80 | } |
72 | 77 | defer metricsSrvr.Close() | 81 | defer metricsSrvr.Close() |
73 | 78 | 82 | ||
74 | 83 | initRegion := os.Getenv("REGION_URL") | ||
75 | 84 | rpcMgr := transport.NewRPCManager(initRegion, true) // TODO use the register command to provide info to connect instead and make TLS skip verify configurable | ||
76 | 85 | err = rpcMgr.Init(ctx) | ||
77 | 86 | if err != nil { | ||
78 | 87 | return err | ||
79 | 88 | } | ||
80 | 89 | rpcMgr.AddClient(ctx, authenticate.NewCapnpAuthenticator()) | ||
81 | 90 | rpcMgr.AddClient(ctx, register.NewCapnpRegisterer()) | ||
82 | 91 | err = rpcMgr.Init(ctx) | ||
83 | 92 | if err != nil { | ||
84 | 93 | return err | ||
85 | 94 | } | ||
86 | 95 | err = region.Handshake(ctx, initRegion, Version, rpcMgr) | ||
87 | 96 | if err != nil { | ||
88 | 97 | return err | ||
89 | 98 | } | ||
90 | 99 | |||
91 | 79 | log.Info().Msgf("rackd %v started successfully", Version) | 100 | log.Info().Msgf("rackd %v started successfully", Version) |
92 | 80 | 101 | ||
93 | 81 | sigChan := make(chan os.Signal, 4) | 102 | sigChan := make(chan os.Signal, 4) |
94 | diff --git a/src/rackd_spike/go.mod b/src/rackd_spike/go.mod | |||
95 | index 3339fb7..73edbc6 100644 | |||
96 | --- a/src/rackd_spike/go.mod | |||
97 | +++ b/src/rackd_spike/go.mod | |||
98 | @@ -3,11 +3,15 @@ module rackd | |||
99 | 3 | go 1.16 | 3 | go 1.16 |
100 | 4 | 4 | ||
101 | 5 | require ( | 5 | require ( |
102 | 6 | capnproto.org/go/capnp/v3 v3.0.0-alpha.1 | ||
103 | 6 | github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d | 7 | github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d |
104 | 7 | github.com/coreos/go-systemd/v22 v22.3.2 | 8 | github.com/coreos/go-systemd/v22 v22.3.2 |
105 | 8 | github.com/kolo/xmlrpc v0.0.0-20201022064351-38db28db192b | 9 | github.com/kolo/xmlrpc v0.0.0-20201022064351-38db28db192b |
106 | 10 | github.com/lxc/lxd v0.0.0-20210705204343-3596a3bcba59 | ||
107 | 11 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect | ||
108 | 9 | github.com/prometheus/client_golang v0.9.3 | 12 | github.com/prometheus/client_golang v0.9.3 |
109 | 10 | github.com/rs/zerolog v1.23.0 | 13 | github.com/rs/zerolog v1.23.0 |
110 | 11 | github.com/spf13/cobra v1.1.3 | 14 | github.com/spf13/cobra v1.1.3 |
111 | 15 | gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect | ||
112 | 12 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b | 16 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b |
113 | 13 | ) | 17 | ) |
114 | diff --git a/src/rackd_spike/go.sum b/src/rackd_spike/go.sum | |||
115 | index 4c08b8b..b61ac4f 100644 | |||
116 | --- a/src/rackd_spike/go.sum | |||
117 | +++ b/src/rackd_spike/go.sum | |||
118 | @@ -1,3 +1,5 @@ | |||
119 | 1 | capnproto.org/go/capnp/v3 v3.0.0-alpha.1 h1:lA/zWC1XgaFez/UdqcWi5Bz1grsqPQDY5Ki4lgYrQ1o= | ||
120 | 2 | capnproto.org/go/capnp/v3 v3.0.0-alpha.1/go.mod h1:izbWjXlvObqHwvhxwDBFLpY9lXSXIxDKRtnuktKHVsU= | ||
121 | 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= | 3 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= |
122 | 2 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= | 4 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= |
123 | 3 | cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= | 5 | cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= |
124 | @@ -110,11 +112,13 @@ github.com/kolo/xmlrpc v0.0.0-20201022064351-38db28db192b h1:iNjcivnc6lhbvJA3LD6 | |||
125 | 110 | github.com/kolo/xmlrpc v0.0.0-20201022064351-38db28db192b/go.mod h1:pcaDhQK0/NJZEvtCO0qQPPropqV0sJOJ6YW7X+9kRwM= | 112 | github.com/kolo/xmlrpc v0.0.0-20201022064351-38db28db192b/go.mod h1:pcaDhQK0/NJZEvtCO0qQPPropqV0sJOJ6YW7X+9kRwM= |
126 | 111 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= | 113 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= |
127 | 112 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= | 114 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= |
128 | 113 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= | ||
129 | 114 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= | 115 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= |
130 | 115 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | 116 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= |
131 | 116 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= | 117 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= |
132 | 117 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | 118 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= |
133 | 119 | github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= | ||
134 | 120 | github.com/lxc/lxd v0.0.0-20210705204343-3596a3bcba59 h1:FvuAx1MSuzz2gC5fqGG1tL99SNm1JacG3kDWqL3vILo= | ||
135 | 121 | github.com/lxc/lxd v0.0.0-20210705204343-3596a3bcba59/go.mod h1:2BaZflfwsv8a3uy3/Vw+de4Avn4DSrAiqaHJjCIXMV4= | ||
136 | 118 | github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= | 122 | github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= |
137 | 119 | github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= | 123 | github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= |
138 | 120 | github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= | 124 | github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= |
139 | @@ -132,9 +136,13 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh | |||
140 | 132 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= | 136 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= |
141 | 133 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= | 137 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= |
142 | 134 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= | 138 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= |
143 | 139 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= | ||
144 | 140 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= | ||
145 | 135 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= | 141 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= |
146 | 136 | github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= | 142 | github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= |
147 | 137 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= | 143 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= |
148 | 144 | github.com/philhofer/fwd v1.1.1 h1:GdGcTjf5RNAxwS4QLsiMzJYj5KEvPJD3Abr261yRQXQ= | ||
149 | 145 | github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= | ||
150 | 138 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | 146 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= |
151 | 139 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | 147 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= |
152 | 140 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | 148 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= |
153 | @@ -181,7 +189,10 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ | |||
154 | 181 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | 189 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= |
155 | 182 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | 190 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= |
156 | 183 | github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= | 191 | github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= |
157 | 192 | github.com/tinylib/msgp v1.1.5 h1:2gXmtWueD2HefZHQe1QOy9HVzmFrLOVvsXwXBQ0ayy0= | ||
158 | 193 | github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg= | ||
159 | 184 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= | 194 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= |
160 | 195 | github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= | ||
161 | 185 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= | 196 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= |
162 | 186 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= | 197 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= |
163 | 187 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= | 198 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= |
164 | @@ -280,6 +291,7 @@ golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtn | |||
165 | 280 | golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | 291 | golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= |
166 | 281 | golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | 292 | golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= |
167 | 282 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | 293 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= |
168 | 294 | golang.org/x/tools v0.0.0-20201022035929-9cf592e881e9/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= | ||
169 | 283 | golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= | 295 | golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= |
170 | 284 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | 296 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
171 | 285 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | 297 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
172 | @@ -307,8 +319,9 @@ google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiq | |||
173 | 307 | google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= | 319 | google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= |
174 | 308 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= | 320 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= |
175 | 309 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | 321 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
176 | 310 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= | ||
177 | 311 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | 322 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
178 | 323 | gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U= | ||
179 | 324 | gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
180 | 312 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= | 325 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= |
181 | 313 | gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= | 326 | gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= |
182 | 314 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= | 327 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= |
183 | diff --git a/src/rackd_spike/internal/machine_helpers/env.go b/src/rackd_spike/internal/machine_helpers/env.go | |||
184 | 315 | new file mode 100644 | 328 | new file mode 100644 |
185 | index 0000000..351d53c | |||
186 | --- /dev/null | |||
187 | +++ b/src/rackd_spike/internal/machine_helpers/env.go | |||
188 | @@ -0,0 +1,67 @@ | |||
189 | 1 | package machinehelpers | ||
190 | 2 | |||
191 | 3 | import ( | ||
192 | 4 | "fmt" | ||
193 | 5 | "io" | ||
194 | 6 | "os" | ||
195 | 7 | "path/filepath" | ||
196 | 8 | "strings" | ||
197 | 9 | "sync" | ||
198 | 10 | ) | ||
199 | 11 | |||
200 | 12 | var ( | ||
201 | 13 | maasId string | ||
202 | 14 | ) | ||
203 | 15 | |||
204 | 16 | var ( | ||
205 | 17 | maasIdLock = &sync.RWMutex{} | ||
206 | 18 | ) | ||
207 | 19 | |||
208 | 20 | func GetMAASDataPath(path string) string { | ||
209 | 21 | basePath, ok := os.LookupEnv(path) | ||
210 | 22 | if !ok { | ||
211 | 23 | basePath = "/var/lib/maas" | ||
212 | 24 | } | ||
213 | 25 | return filepath.Join(basePath, path) | ||
214 | 26 | } | ||
215 | 27 | |||
216 | 28 | func GetMAASID() (string, error) { | ||
217 | 29 | maasIdLock.RLock() | ||
218 | 30 | defer maasIdLock.RUnlock() | ||
219 | 31 | |||
220 | 32 | if len(maasId) == 0 { | ||
221 | 33 | path := GetMAASDataPath("maas_id") | ||
222 | 34 | f, err := os.Open(path) | ||
223 | 35 | if err != nil { | ||
224 | 36 | if os.IsNotExist(err) { | ||
225 | 37 | return "", nil | ||
226 | 38 | } | ||
227 | 39 | return "", err | ||
228 | 40 | } | ||
229 | 41 | contents, err := io.ReadAll(f) | ||
230 | 42 | if err != nil { | ||
231 | 43 | return "", err | ||
232 | 44 | } | ||
233 | 45 | maasIdLock.Lock() | ||
234 | 46 | defer maasIdLock.Unlock() | ||
235 | 47 | maasId = strings.TrimSpace(string(contents)) | ||
236 | 48 | } | ||
237 | 49 | return maasId, nil | ||
238 | 50 | } | ||
239 | 51 | |||
240 | 52 | func SetMAASId(id string) error { | ||
241 | 53 | path := GetMAASDataPath("maas_id") | ||
242 | 54 | maasIdLock.Lock() | ||
243 | 55 | defer maasIdLock.Unlock() | ||
244 | 56 | maasId = id | ||
245 | 57 | f, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0644) | ||
246 | 58 | if err != nil { | ||
247 | 59 | return err | ||
248 | 60 | } | ||
249 | 61 | defer f.Close() | ||
250 | 62 | _, err = fmt.Fprint(f, id) | ||
251 | 63 | if err != nil { | ||
252 | 64 | return err | ||
253 | 65 | } | ||
254 | 66 | return nil | ||
255 | 67 | } | ||
256 | diff --git a/src/rackd_spike/internal/machine_helpers/info.go b/src/rackd_spike/internal/machine_helpers/info.go | |||
257 | 0 | new file mode 100644 | 68 | new file mode 100644 |
258 | index 0000000..1517fc6 | |||
259 | --- /dev/null | |||
260 | +++ b/src/rackd_spike/internal/machine_helpers/info.go | |||
261 | @@ -0,0 +1,24 @@ | |||
262 | 1 | package machinehelpers | ||
263 | 2 | |||
264 | 3 | import ( | ||
265 | 4 | lxdresources "github.com/lxc/lxd/shared/api" | ||
266 | 5 | ) | ||
267 | 6 | |||
268 | 7 | type EnvInfo struct { | ||
269 | 8 | Kernel string `json:"kernel"` | ||
270 | 9 | KernelArchitecture string `json:"kernel_architecture"` | ||
271 | 10 | KernelVersion string `json:"kernel_version"` | ||
272 | 11 | OSName string `json:"os_name"` | ||
273 | 12 | OSVersion string `json:"os_version"` | ||
274 | 13 | Server string `json:"server"` | ||
275 | 14 | ServerName string `json:"server_name"` | ||
276 | 15 | ServerVersion string `json:"server_version"` | ||
277 | 16 | } | ||
278 | 17 | |||
279 | 18 | type MachineInfo struct { | ||
280 | 19 | APIExtensions []string `json:"api_extension"` | ||
281 | 20 | APIVersion string `json:"api_version"` | ||
282 | 21 | Environment EnvInfo `json:"environment"` | ||
283 | 22 | Resources lxdresources.Resources `json:"resources"` | ||
284 | 23 | Networks map[string]lxdresources.NetworkState `json:"networks"` | ||
285 | 24 | } | ||
286 | diff --git a/src/rackd_spike/internal/machine_helpers/interfaces.go b/src/rackd_spike/internal/machine_helpers/interfaces.go | |||
287 | 0 | new file mode 100644 | 25 | new file mode 100644 |
288 | index 0000000..cbf58e6 | |||
289 | --- /dev/null | |||
290 | +++ b/src/rackd_spike/internal/machine_helpers/interfaces.go | |||
291 | @@ -0,0 +1,498 @@ | |||
292 | 1 | package machinehelpers | ||
293 | 2 | |||
294 | 3 | import ( | ||
295 | 4 | "bufio" | ||
296 | 5 | "context" | ||
297 | 6 | "encoding/json" | ||
298 | 7 | "fmt" | ||
299 | 8 | "io" | ||
300 | 9 | "net" | ||
301 | 10 | "os" | ||
302 | 11 | "os/exec" | ||
303 | 12 | "path/filepath" | ||
304 | 13 | "regexp" | ||
305 | 14 | "sort" | ||
306 | 15 | "strconv" | ||
307 | 16 | "strings" | ||
308 | 17 | |||
309 | 18 | lxdresources "github.com/lxc/lxd/shared/api" | ||
310 | 19 | ) | ||
311 | 20 | |||
312 | 21 | var ( | ||
313 | 22 | excludedInterfaceTypes = map[string]struct{}{ | ||
314 | 23 | "loopback": {}, | ||
315 | 24 | "ipip": {}, | ||
316 | 25 | "tunnel": {}, | ||
317 | 26 | } | ||
318 | 27 | |||
319 | 28 | leaseRx = regexp.MustCompile(`(?m)(^\s*lease\s+{([^}]+)})`) | ||
320 | 29 | ) | ||
321 | 30 | |||
322 | 31 | func isExcludedType(ctx context.Context, t string) (bool, error) { | ||
323 | 32 | if _, ok := excludedInterfaceTypes[t]; ok { | ||
324 | 33 | return true, nil | ||
325 | 34 | } | ||
326 | 35 | runningContainer, err := RunningInContainer(ctx) | ||
327 | 36 | if err != nil { | ||
328 | 37 | return false, err | ||
329 | 38 | } | ||
330 | 39 | if runningContainer && t == "ethernet" { | ||
331 | 40 | return true, nil | ||
332 | 41 | } | ||
333 | 42 | if strings.HasPrefix("unknown-", t) { | ||
334 | 43 | return true, nil | ||
335 | 44 | } | ||
336 | 45 | return false, nil | ||
337 | 46 | } | ||
338 | 47 | |||
339 | 48 | func GetIPAddr(ctx context.Context) (map[string]lxdresources.NetworkState, error) { | ||
340 | 49 | cmdPath, err := GetResourcesBinPath() | ||
341 | 50 | if err != nil { | ||
342 | 51 | return nil, err | ||
343 | 52 | } | ||
344 | 53 | var args []string | ||
345 | 54 | if IsRunningInSnap() { | ||
346 | 55 | args = append(args, cmdPath) | ||
347 | 56 | cmdPath = "/usr/bin/sudo" | ||
348 | 57 | } | ||
349 | 58 | cmd := exec.CommandContext(ctx, cmdPath, args...) | ||
350 | 59 | out, err := cmd.Output() | ||
351 | 60 | if err != nil { | ||
352 | 61 | return nil, err | ||
353 | 62 | } | ||
354 | 63 | var info MachineInfo | ||
355 | 64 | err = json.Unmarshal(out, &info) | ||
356 | 65 | if err != nil { | ||
357 | 66 | return nil, err | ||
358 | 67 | } | ||
359 | 68 | return info.Networks, nil | ||
360 | 69 | } | ||
361 | 70 | |||
362 | 71 | func splitDhclientCmdlineFile(data []byte, atEOF bool) (advance int, token []byte, err error) { | ||
363 | 72 | for i := 0; i < len(data); i++ { | ||
364 | 73 | if data[i] == '\x00' { | ||
365 | 74 | return i + 1, data[:i], nil | ||
366 | 75 | } | ||
367 | 76 | if !atEOF { | ||
368 | 77 | return 0, nil, nil | ||
369 | 78 | } | ||
370 | 79 | } | ||
371 | 80 | return 0, data, bufio.ErrFinalToken | ||
372 | 81 | } | ||
373 | 82 | |||
374 | 83 | func GetLatestFixedAddress(leasePath string) (string, error) { | ||
375 | 84 | f, err := os.Open(leasePath) | ||
376 | 85 | if err != nil { | ||
377 | 86 | return "", err | ||
378 | 87 | } | ||
379 | 88 | defer f.Close() | ||
380 | 89 | return getLatestFixedAddress(f) | ||
381 | 90 | } | ||
382 | 91 | |||
383 | 92 | func getLatestFixedAddress(leaseFile io.Reader) (string, error) { | ||
384 | 93 | leaseBytes, err := io.ReadAll(leaseFile) | ||
385 | 94 | if err != nil { | ||
386 | 95 | return "", err | ||
387 | 96 | } | ||
388 | 97 | submatches := leaseRx.FindAllSubmatch(leaseBytes, -1) | ||
389 | 98 | if len(submatches) > 0 { | ||
390 | 99 | matches := submatches[len(submatches)-1] | ||
391 | 100 | if len(matches) > 0 { | ||
392 | 101 | lastLease := matches[len(matches)-1] | ||
393 | 102 | for _, line := range strings.Split(string(lastLease), "\n") { | ||
394 | 103 | line = strings.TrimSpace(line) | ||
395 | 104 | if len(line) > 0 { | ||
396 | 105 | lineList := strings.SplitN(line, " ", 2) | ||
397 | 106 | if len(lineList) < 2 { | ||
398 | 107 | continue | ||
399 | 108 | } | ||
400 | 109 | statement, value := lineList[0], lineList[1] | ||
401 | 110 | if statement == "fixed-address" || statement == "fixed-address6" { | ||
402 | 111 | return strings.TrimSpace(strings.SplitN(value, ";", 2)[0]), nil | ||
403 | 112 | } | ||
404 | 113 | } | ||
405 | 114 | } | ||
406 | 115 | } | ||
407 | 116 | } | ||
408 | 117 | return "", nil | ||
409 | 118 | } | ||
410 | 119 | |||
411 | 120 | func GetDhclientInfo(ctx context.Context, procPath string) (map[string]string, error) { | ||
412 | 121 | if len(procPath) == 0 { | ||
413 | 122 | procPath = "/proc" | ||
414 | 123 | } | ||
415 | 124 | pids, err := GetRunningPIDsWithCMD(ctx, "dhclient", "", false) | ||
416 | 125 | if err != nil { | ||
417 | 126 | return nil, err | ||
418 | 127 | } | ||
419 | 128 | info := make(map[string]string) | ||
420 | 129 | for _, pid := range pids { | ||
421 | 130 | cmdlinePath := filepath.Join(procPath, strconv.Itoa(pid), "cmdline") | ||
422 | 131 | err = func() error { | ||
423 | 132 | f, err := os.Open(cmdlinePath) | ||
424 | 133 | if err != nil { | ||
425 | 134 | return err | ||
426 | 135 | } | ||
427 | 136 | defer f.Close() | ||
428 | 137 | scanner := bufio.NewScanner(f) | ||
429 | 138 | scanner.Split(splitDhclientCmdlineFile) | ||
430 | 139 | var ( | ||
431 | 140 | cmd []string | ||
432 | 141 | leasePath string | ||
433 | 142 | ) | ||
434 | 143 | lfIdx := -1 | ||
435 | 144 | for scanner.Scan() { | ||
436 | 145 | cmd = append(cmd, scanner.Text()) | ||
437 | 146 | if cmd[len(cmd)-1] == "-lf" { | ||
438 | 147 | lfIdx = len(cmd) - 1 | ||
439 | 148 | } | ||
440 | 149 | if lfIdx > -1 && len(cmd)-2 == lfIdx { | ||
441 | 150 | leasePath = cmd[len(cmd)-1] | ||
442 | 151 | } | ||
443 | 152 | } | ||
444 | 153 | ifaceName := cmd[len(cmd)-1] | ||
445 | 154 | ipAddr, err := GetLatestFixedAddress(leasePath) | ||
446 | 155 | if err != nil { | ||
447 | 156 | return err | ||
448 | 157 | } | ||
449 | 158 | if len(ipAddr) > 0 && ipAddr != " " { | ||
450 | 159 | info[ifaceName] = ipAddr | ||
451 | 160 | } | ||
452 | 161 | return nil | ||
453 | 162 | }() | ||
454 | 163 | if err != nil { | ||
455 | 164 | return nil, err | ||
456 | 165 | } | ||
457 | 166 | } | ||
458 | 167 | return info, nil | ||
459 | 168 | } | ||
460 | 169 | |||
461 | 170 | type IPLink struct { | ||
462 | 171 | Netmask int | ||
463 | 172 | Mode string | ||
464 | 173 | Address string | ||
465 | 174 | Gateway string | ||
466 | 175 | } | ||
467 | 176 | |||
468 | 177 | type Vlan struct { | ||
469 | 178 | LowerDev string | ||
470 | 179 | Vid uint64 | ||
471 | 180 | } | ||
472 | 181 | |||
473 | 182 | type Interface struct { | ||
474 | 183 | Type string | ||
475 | 184 | Mac string | ||
476 | 185 | Links []IPLink | ||
477 | 186 | Enabled bool | ||
478 | 187 | Vlan *Vlan | ||
479 | 188 | Source string | ||
480 | 189 | Parents []string | ||
481 | 190 | Monitored bool | ||
482 | 191 | } | ||
483 | 192 | |||
484 | 193 | type sortableSubnets []*net.IPNet | ||
485 | 194 | |||
486 | 195 | func (s sortableSubnets) Len() int { | ||
487 | 196 | return len(s) | ||
488 | 197 | } | ||
489 | 198 | |||
490 | 199 | func (s sortableSubnets) Less(i, j int) bool { | ||
491 | 200 | iPrefixlen, _ := s[i].Mask.Size() | ||
492 | 201 | jPrefixlen, _ := s[j].Mask.Size() | ||
493 | 202 | return iPrefixlen < jPrefixlen | ||
494 | 203 | } | ||
495 | 204 | |||
496 | 205 | func (s sortableSubnets) Swap(i, j int) { | ||
497 | 206 | tmp := s[j] | ||
498 | 207 | s[j] = s[i] | ||
499 | 208 | s[i] = tmp | ||
500 | 209 | } | ||
501 | 210 | |||
502 | 211 | func fixLinkAddresses(links []IPLink) ([]IPLink, error) { | ||
503 | 212 | var ( | ||
504 | 213 | subnetsV4 []*net.IPNet | ||
505 | 214 | linksV4 []struct { | ||
506 | 215 | Link IPLink | ||
507 | 216 | Idx int | ||
508 | 217 | } | ||
509 | 218 | subnetsV6 []*net.IPNet | ||
510 | 219 | linksV6 []struct { | ||
511 | 220 | Link IPLink | ||
512 | 221 | Idx int | ||
513 | 222 | } | ||
514 | 223 | ) | ||
515 | 224 | for i, link := range links { | ||
516 | 225 | var ( | ||
517 | 226 | ipAddr net.IP | ||
518 | 227 | ipNet *net.IPNet | ||
519 | 228 | err error | ||
520 | 229 | ) | ||
521 | 230 | if link.Netmask != 0 { | ||
522 | 231 | ipAddr, ipNet, err = net.ParseCIDR(fmt.Sprintf("%s/%d", link.Address, link.Netmask)) | ||
523 | 232 | if err != nil { | ||
524 | 233 | return nil, err | ||
525 | 234 | } | ||
526 | 235 | } else { | ||
527 | 236 | ipAddr, ipNet, err = net.ParseCIDR(link.Address) | ||
528 | 237 | if err != nil { | ||
529 | 238 | return nil, err | ||
530 | 239 | } | ||
531 | 240 | } | ||
532 | 241 | prefixLen, _ := ipNet.Mask.Size() | ||
533 | 242 | if ipAddr.To4() != nil { | ||
534 | 243 | if prefixLen == 32 { | ||
535 | 244 | linksV4 = append(linksV4, struct { | ||
536 | 245 | Link IPLink | ||
537 | 246 | Idx int | ||
538 | 247 | }{ | ||
539 | 248 | Link: link, | ||
540 | 249 | Idx: i, | ||
541 | 250 | }) | ||
542 | 251 | } else { | ||
543 | 252 | subnetsV4 = append(subnetsV4, ipNet) | ||
544 | 253 | } | ||
545 | 254 | } else { | ||
546 | 255 | if prefixLen == 128 { | ||
547 | 256 | linksV6 = append(linksV6, struct { | ||
548 | 257 | Link IPLink | ||
549 | 258 | Idx int | ||
550 | 259 | }{ | ||
551 | 260 | Link: link, | ||
552 | 261 | Idx: i, | ||
553 | 262 | }) | ||
554 | 263 | } else { | ||
555 | 264 | subnetsV6 = append(subnetsV6, ipNet) | ||
556 | 265 | } | ||
557 | 266 | } | ||
558 | 267 | } | ||
559 | 268 | newLinks := [][]struct { | ||
560 | 269 | Link IPLink | ||
561 | 270 | Idx int | ||
562 | 271 | }{linksV4, linksV6} | ||
563 | 272 | newSubnets := [][]*net.IPNet{subnetsV4, subnetsV6} | ||
564 | 273 | for i, currLinks := range newLinks { | ||
565 | 274 | currSubnets := sortableSubnets(newSubnets[i]) | ||
566 | 275 | var ok bool | ||
567 | 276 | currSubnets, ok = sort.Reverse(currSubnets).(sortableSubnets) | ||
568 | 277 | if !ok { | ||
569 | 278 | return nil, fmt.Errorf("sort.Reverse() returned a type other than sortableSubnets, %T", currSubnets) | ||
570 | 279 | } | ||
571 | 280 | for _, link := range currLinks { | ||
572 | 281 | var ( | ||
573 | 282 | ip net.IP | ||
574 | 283 | err error | ||
575 | 284 | ) | ||
576 | 285 | if link.Link.Netmask != 0 { | ||
577 | 286 | ip, _, err = net.ParseCIDR( | ||
578 | 287 | fmt.Sprintf("%s:%d", link.Link.Address, link.Link.Netmask), | ||
579 | 288 | ) | ||
580 | 289 | } else { | ||
581 | 290 | ip, _, err = net.ParseCIDR(link.Link.Address) | ||
582 | 291 | } | ||
583 | 292 | if err != nil { | ||
584 | 293 | return nil, err | ||
585 | 294 | } | ||
586 | 295 | for _, subnet := range currSubnets { | ||
587 | 296 | if subnet.Contains(ip) { | ||
588 | 297 | prefixlen, _ := subnet.Mask.Size() | ||
589 | 298 | if link.Link.Netmask != 0 { | ||
590 | 299 | link.Link.Netmask = prefixlen | ||
591 | 300 | } else { | ||
592 | 301 | link.Link.Address = fmt.Sprintf("%s/%d", ip, prefixlen) | ||
593 | 302 | } | ||
594 | 303 | } | ||
595 | 304 | } | ||
596 | 305 | links[link.Idx] = link.Link | ||
597 | 306 | } | ||
598 | 307 | } | ||
599 | 308 | return links, nil | ||
600 | 309 | } | ||
601 | 310 | |||
602 | 311 | type IPRoute struct { | ||
603 | 312 | Gateway string `json:"gateway"` | ||
604 | 313 | GatewayIP net.IP `json:"-"` | ||
605 | 314 | Dev string `json:"dev"` | ||
606 | 315 | Protocol string `json:"protocol"` | ||
607 | 316 | Metric int `json:"metric"` | ||
608 | 317 | Flags []int `json:"flags"` | ||
609 | 318 | } | ||
610 | 319 | |||
611 | 320 | func GetIPRoute(ctx context.Context) (map[string]IPRoute, error) { | ||
612 | 321 | cmd := exec.CommandContext(ctx, "ip", "-json", "route", "list", "scope", "global") | ||
613 | 322 | routes := make(map[string]IPRoute) | ||
614 | 323 | var routeList []struct { | ||
615 | 324 | Name string `json:"dst"` | ||
616 | 325 | IPRoute | ||
617 | 326 | } | ||
618 | 327 | out, err := cmd.Output() | ||
619 | 328 | if err != nil { | ||
620 | 329 | return nil, err | ||
621 | 330 | } | ||
622 | 331 | err = json.Unmarshal(out, &routeList) | ||
623 | 332 | if err != nil { | ||
624 | 333 | return nil, err | ||
625 | 334 | } | ||
626 | 335 | for _, route := range routeList { | ||
627 | 336 | route.IPRoute.GatewayIP = net.ParseIP(route.Gateway) | ||
628 | 337 | routes[route.Name] = route.IPRoute | ||
629 | 338 | } | ||
630 | 339 | return routes, nil | ||
631 | 340 | } | ||
632 | 341 | |||
633 | 342 | func fixGateways(links []IPLink, ipRouteInfo map[string]IPRoute) ([]IPLink, error) { | ||
634 | 343 | for i, link := range links { | ||
635 | 344 | _, subnet, err := net.ParseCIDR(link.Address) | ||
636 | 345 | if err != nil { | ||
637 | 346 | return nil, err | ||
638 | 347 | } | ||
639 | 348 | if routeInfo, ok := ipRouteInfo[subnet.String()]; ok { | ||
640 | 349 | link.Gateway = routeInfo.Gateway | ||
641 | 350 | } else if defaultInfo, ok := ipRouteInfo["default"]; ok && subnet.Contains(defaultInfo.GatewayIP) { | ||
642 | 351 | link.Gateway = defaultInfo.Gateway | ||
643 | 352 | } | ||
644 | 353 | links[i] = link | ||
645 | 354 | } | ||
646 | 355 | return links, nil | ||
647 | 356 | } | ||
648 | 357 | |||
649 | 358 | func GetInterfaceChildren(interfaces map[string]Interface) map[string][]string { | ||
650 | 359 | children := make(map[string][]string) | ||
651 | 360 | for name, iface := range interfaces { | ||
652 | 361 | for _, parent := range iface.Parents { | ||
653 | 362 | if node, ok := children[parent]; ok { | ||
654 | 363 | node = append(node, name) | ||
655 | 364 | } else { | ||
656 | 365 | children[parent] = []string{name} | ||
657 | 366 | } | ||
658 | 367 | } | ||
659 | 368 | } | ||
660 | 369 | return children | ||
661 | 370 | } | ||
662 | 371 | |||
663 | 372 | type InterfaceChild struct { | ||
664 | 373 | Name string | ||
665 | 374 | Iface Interface | ||
666 | 375 | } | ||
667 | 376 | |||
668 | 377 | func InterfaceChildren(ifname string, interfaces map[string]Interface, children map[string][]string) (res []InterfaceChild) { | ||
669 | 378 | if node, ok := children[ifname]; ok { | ||
670 | 379 | for _, child := range node { | ||
671 | 380 | res = append(res, InterfaceChild{Name: child, Iface: interfaces[child]}) | ||
672 | 381 | } | ||
673 | 382 | } | ||
674 | 383 | return res | ||
675 | 384 | } | ||
676 | 385 | |||
677 | 386 | func GetDefaultMonitoredInterfaces(interfaces map[string]Interface) (res map[string]struct{}) { | ||
678 | 387 | res = make(map[string]struct{}) | ||
679 | 388 | childrenMap := GetInterfaceChildren(interfaces) | ||
680 | 389 | for name, iface := range interfaces { | ||
681 | 390 | if !iface.Enabled { | ||
682 | 391 | continue | ||
683 | 392 | } | ||
684 | 393 | switch iface.Type { | ||
685 | 394 | case "physical": | ||
686 | 395 | shouldMonitor := true | ||
687 | 396 | for _, child := range InterfaceChildren(name, interfaces, childrenMap) { | ||
688 | 397 | if child.Iface.Type == "bond" { | ||
689 | 398 | shouldMonitor = false | ||
690 | 399 | break | ||
691 | 400 | } | ||
692 | 401 | } | ||
693 | 402 | if shouldMonitor { | ||
694 | 403 | res[name] = struct{}{} | ||
695 | 404 | } | ||
696 | 405 | case "bond": | ||
697 | 406 | res[name] = struct{}{} | ||
698 | 407 | case "bridge": | ||
699 | 408 | if len(iface.Parents) == 0 { | ||
700 | 409 | res[name] = struct{}{} | ||
701 | 410 | } | ||
702 | 411 | } | ||
703 | 412 | } | ||
704 | 413 | return res | ||
705 | 414 | } | ||
706 | 415 | |||
707 | 416 | func GetAllInterfacesDefinition(ctx context.Context, annotateWithMonitored bool) (map[string]Interface, error) { | ||
708 | 417 | dhclientInfo, err := GetDhclientInfo(ctx, "") | ||
709 | 418 | if err != nil { | ||
710 | 419 | return nil, err | ||
711 | 420 | } | ||
712 | 421 | netIfaces, err := GetIPAddr(ctx) | ||
713 | 422 | if err != nil { | ||
714 | 423 | return nil, err | ||
715 | 424 | } | ||
716 | 425 | iprouteInfo, err := GetIPRoute(ctx) | ||
717 | 426 | if err != nil { | ||
718 | 427 | return nil, err | ||
719 | 428 | } | ||
720 | 429 | res := make(map[string]Interface) | ||
721 | 430 | for name, iface := range netIfaces { | ||
722 | 431 | excludeType, err := isExcludedType(ctx, iface.Type) | ||
723 | 432 | if err != nil { | ||
724 | 433 | return nil, err | ||
725 | 434 | } | ||
726 | 435 | if excludeType { | ||
727 | 436 | continue | ||
728 | 437 | } | ||
729 | 438 | i := Interface{ | ||
730 | 439 | Mac: iface.Hwaddr, | ||
731 | 440 | Enabled: iface.State == "up", | ||
732 | 441 | } | ||
733 | 442 | if !(iface.Type == "vlan" || iface.Type == "bridge" || iface.Type == "bond") { | ||
734 | 443 | i.Type = "physical" | ||
735 | 444 | } else { | ||
736 | 445 | i.Type = iface.Type | ||
737 | 446 | if iface.Bond != nil && len(iface.Bond.LowerDevices) > 0 { | ||
738 | 447 | i.Parents = append(i.Parents, iface.Bond.LowerDevices...) | ||
739 | 448 | } | ||
740 | 449 | if iface.Bridge != nil && len(iface.Bridge.UpperDevices) > 0 { | ||
741 | 450 | i.Parents = append(i.Parents, iface.Bridge.UpperDevices...) | ||
742 | 451 | } | ||
743 | 452 | } | ||
744 | 453 | if iface.VLAN != nil { | ||
745 | 454 | i.Vlan = &Vlan{ | ||
746 | 455 | LowerDev: iface.VLAN.LowerDevice, | ||
747 | 456 | Vid: iface.VLAN.VID, | ||
748 | 457 | } | ||
749 | 458 | i.Parents = append(i.Parents, iface.VLAN.LowerDevice) | ||
750 | 459 | } | ||
751 | 460 | dhcpAddr := dhclientInfo[name] | ||
752 | 461 | for _, addr := range iface.Addresses { | ||
753 | 462 | mode := "static" | ||
754 | 463 | if net.ParseIP(addr.Address).String() == dhcpAddr { | ||
755 | 464 | mode = "dhcp" | ||
756 | 465 | } | ||
757 | 466 | |||
758 | 467 | link := IPLink{Mode: mode, Address: addr.Address} | ||
759 | 468 | if len(addr.Netmask) > 0 { | ||
760 | 469 | link.Netmask, err = strconv.Atoi(addr.Netmask) | ||
761 | 470 | if err != nil { | ||
762 | 471 | return nil, err | ||
763 | 472 | } | ||
764 | 473 | } | ||
765 | 474 | i.Links = append(i.Links, link) | ||
766 | 475 | } | ||
767 | 476 | i.Links, err = fixLinkAddresses(i.Links) | ||
768 | 477 | if err != nil { | ||
769 | 478 | return nil, err | ||
770 | 479 | } | ||
771 | 480 | i.Links, err = fixGateways(i.Links, iprouteInfo) | ||
772 | 481 | if err != nil { | ||
773 | 482 | return nil, err | ||
774 | 483 | } | ||
775 | 484 | res[name] = i | ||
776 | 485 | } | ||
777 | 486 | if annotateWithMonitored { | ||
778 | 487 | monitoredIfaces := GetDefaultMonitoredInterfaces(res) | ||
779 | 488 | for name, iface := range res { | ||
780 | 489 | if _, ok := monitoredIfaces[name]; ok { | ||
781 | 490 | iface.Monitored = true | ||
782 | 491 | } else { | ||
783 | 492 | iface.Monitored = false | ||
784 | 493 | } | ||
785 | 494 | res[name] = iface | ||
786 | 495 | } | ||
787 | 496 | } | ||
788 | 497 | return res, nil | ||
789 | 498 | } | ||
790 | diff --git a/src/rackd_spike/internal/machine_helpers/interfaces_capnp.go b/src/rackd_spike/internal/machine_helpers/interfaces_capnp.go | |||
791 | 0 | new file mode 100644 | 499 | new file mode 100644 |
792 | index 0000000..777f0b4 | |||
793 | --- /dev/null | |||
794 | +++ b/src/rackd_spike/internal/machine_helpers/interfaces_capnp.go | |||
795 | @@ -0,0 +1,65 @@ | |||
796 | 1 | package machinehelpers | ||
797 | 2 | |||
798 | 3 | import ( | ||
799 | 4 | "rackd/pkg/rpc" | ||
800 | 5 | ) | ||
801 | 6 | |||
802 | 7 | type CapnpInterfaces map[string]Interface | ||
803 | 8 | |||
804 | 9 | func (c CapnpInterfaces) SetProto(ifacePayload rpc.Interfaces) error { | ||
805 | 10 | ifaces, err := ifacePayload.NewIfaces(int32(len(c))) | ||
806 | 11 | if err != nil { | ||
807 | 12 | return err | ||
808 | 13 | } | ||
809 | 14 | var idx int | ||
810 | 15 | for name, iface := range c { | ||
811 | 16 | protoIface := ifaces.At(idx) | ||
812 | 17 | err = protoIface.SetName(name) | ||
813 | 18 | if err != nil { | ||
814 | 19 | return err | ||
815 | 20 | } | ||
816 | 21 | details, err := protoIface.NewIface() | ||
817 | 22 | if err != nil { | ||
818 | 23 | return err | ||
819 | 24 | } | ||
820 | 25 | details.SetMacAddress(iface.Mac) | ||
821 | 26 | details.SetType(iface.Type) | ||
822 | 27 | protoLinks, err := details.NewLinks(int32(len(iface.Links))) | ||
823 | 28 | if err != nil { | ||
824 | 29 | return err | ||
825 | 30 | } | ||
826 | 31 | for i, link := range iface.Links { | ||
827 | 32 | protoLink := protoLinks.At(i) | ||
828 | 33 | err = protoLink.SetMode(link.Mode) | ||
829 | 34 | if err != nil { | ||
830 | 35 | return err | ||
831 | 36 | } | ||
832 | 37 | err = protoLink.SetAddress(link.Address) | ||
833 | 38 | if err != nil { | ||
834 | 39 | return err | ||
835 | 40 | } | ||
836 | 41 | err = protoLink.SetGateway(link.Gateway) | ||
837 | 42 | if err != nil { | ||
838 | 43 | return err | ||
839 | 44 | } | ||
840 | 45 | protoLink.SetNetmask(int32(link.Netmask)) | ||
841 | 46 | } | ||
842 | 47 | if iface.Vlan != nil { | ||
843 | 48 | details.SetVid(iface.Vlan.Vid) | ||
844 | 49 | } | ||
845 | 50 | if len(iface.Parents) > 0 { | ||
846 | 51 | protoParents, err := details.NewParents(int32(len(iface.Parents))) | ||
847 | 52 | if err != nil { | ||
848 | 53 | return err | ||
849 | 54 | } | ||
850 | 55 | for i, parent := range iface.Parents { | ||
851 | 56 | err = protoParents.Set(i, parent) | ||
852 | 57 | if err != nil { | ||
853 | 58 | return err | ||
854 | 59 | } | ||
855 | 60 | } | ||
856 | 61 | } | ||
857 | 62 | idx++ | ||
858 | 63 | } | ||
859 | 64 | return nil | ||
860 | 65 | } | ||
861 | diff --git a/src/rackd_spike/internal/machine_helpers/interfaces_test.go b/src/rackd_spike/internal/machine_helpers/interfaces_test.go | |||
862 | 0 | new file mode 100644 | 66 | new file mode 100644 |
863 | index 0000000..a7d2b3c | |||
864 | --- /dev/null | |||
865 | +++ b/src/rackd_spike/internal/machine_helpers/interfaces_test.go | |||
866 | @@ -0,0 +1,81 @@ | |||
867 | 1 | package machinehelpers | ||
868 | 2 | |||
869 | 3 | import ( | ||
870 | 4 | "errors" | ||
871 | 5 | "io" | ||
872 | 6 | "testing" | ||
873 | 7 | ) | ||
874 | 8 | |||
875 | 9 | type mockLeaseFile struct { | ||
876 | 10 | Data []byte | ||
877 | 11 | } | ||
878 | 12 | |||
879 | 13 | func (m mockLeaseFile) Read(b []byte) (n int, err error) { | ||
880 | 14 | n = copy(b, m.Data) | ||
881 | 15 | if n > 0 { | ||
882 | 16 | m.Data = m.Data[n:] | ||
883 | 17 | } | ||
884 | 18 | if len(m.Data) == 0 { | ||
885 | 19 | return n, io.EOF | ||
886 | 20 | } | ||
887 | 21 | return n, nil | ||
888 | 22 | } | ||
889 | 23 | |||
890 | 24 | func TestGetLatestFixedAddress(t *testing.T) { | ||
891 | 25 | table := []struct { | ||
892 | 26 | Name string | ||
893 | 27 | In mockLeaseFile | ||
894 | 28 | Out string | ||
895 | 29 | Err error | ||
896 | 30 | }{ | ||
897 | 31 | { | ||
898 | 32 | Name: "basic-v4-lease-file", | ||
899 | 33 | In: mockLeaseFile{ | ||
900 | 34 | Data: []byte(` | ||
901 | 35 | lease { | ||
902 | 36 | fixed-address 10.0.0.2; | ||
903 | 37 | } | ||
904 | 38 | `), | ||
905 | 39 | }, | ||
906 | 40 | Out: "10.0.0.2", | ||
907 | 41 | }, { | ||
908 | 42 | Name: "basic-v6-lease-file", | ||
909 | 43 | In: mockLeaseFile{ | ||
910 | 44 | Data: []byte(` | ||
911 | 45 | lease { | ||
912 | 46 | fixed-address6 fe80::ca56:eed8:1344:1aa2; | ||
913 | 47 | } | ||
914 | 48 | `), | ||
915 | 49 | }, | ||
916 | 50 | Out: "fe80::ca56:eed8:1344:1aa2", | ||
917 | 51 | }, { | ||
918 | 52 | Name: "no-data-lease-file", | ||
919 | 53 | In: mockLeaseFile{}, | ||
920 | 54 | }, { | ||
921 | 55 | Name: "multi-lease-lease-file", | ||
922 | 56 | In: mockLeaseFile{ | ||
923 | 57 | Data: []byte(` | ||
924 | 58 | lease { | ||
925 | 59 | fixed-address 10.0.0.9; | ||
926 | 60 | } | ||
927 | 61 | |||
928 | 62 | lease { | ||
929 | 63 | fixed-address 10.0.0.2; | ||
930 | 64 | } | ||
931 | 65 | `), | ||
932 | 66 | }, | ||
933 | 67 | Out: "10.0.0.2", | ||
934 | 68 | }, | ||
935 | 69 | } | ||
936 | 70 | for _, tcase := range table { | ||
937 | 71 | t.Run(tcase.Name, func(tt *testing.T) { | ||
938 | 72 | out, err := getLatestFixedAddress(tcase.In) | ||
939 | 73 | if !errors.Is(err, tcase.Err) { | ||
940 | 74 | tt.Fatalf("expected %v to equal %v", err, tcase.Err) | ||
941 | 75 | } | ||
942 | 76 | if out != tcase.Out { | ||
943 | 77 | tt.Fatalf("expected '%s' to equal '%s'", out, tcase.Out) | ||
944 | 78 | } | ||
945 | 79 | }) | ||
946 | 80 | } | ||
947 | 81 | } | ||
948 | diff --git a/src/rackd_spike/internal/machine_helpers/ps.go b/src/rackd_spike/internal/machine_helpers/ps.go | |||
949 | 0 | new file mode 100644 | 82 | new file mode 100644 |
950 | index 0000000..016564b | |||
951 | --- /dev/null | |||
952 | +++ b/src/rackd_spike/internal/machine_helpers/ps.go | |||
953 | @@ -0,0 +1,81 @@ | |||
954 | 1 | package machinehelpers | ||
955 | 2 | |||
956 | 3 | import ( | ||
957 | 4 | "bufio" | ||
958 | 5 | "context" | ||
959 | 6 | "os" | ||
960 | 7 | "os/exec" | ||
961 | 8 | "path/filepath" | ||
962 | 9 | "strconv" | ||
963 | 10 | "strings" | ||
964 | 11 | ) | ||
965 | 12 | |||
966 | 13 | const ( | ||
967 | 14 | vertCheckExec = "systemd-detect-virt" | ||
968 | 15 | ) | ||
969 | 16 | |||
970 | 17 | var ( | ||
971 | 18 | vertCheckArgs = []string{"-c"} | ||
972 | 19 | ) | ||
973 | 20 | |||
974 | 21 | func RunningInContainer(ctx context.Context) (bool, error) { | ||
975 | 22 | cmd := exec.CommandContext(ctx, vertCheckExec, vertCheckArgs...) | ||
976 | 23 | if err := cmd.Run(); err != nil { | ||
977 | 24 | if cmd.ProcessState.ExitCode() == 1 { | ||
978 | 25 | return false, nil | ||
979 | 26 | } | ||
980 | 27 | return false, err | ||
981 | 28 | } | ||
982 | 29 | return true, nil | ||
983 | 30 | } | ||
984 | 31 | |||
985 | 32 | func PIDInContainer(pid int, procPath string) (bool, error) { | ||
986 | 33 | if len(procPath) == 0 { | ||
987 | 34 | procPath = "/proc" | ||
988 | 35 | } | ||
989 | 36 | cgroupPath := filepath.Join(procPath, strconv.Itoa(pid), "cgroup") | ||
990 | 37 | f, err := os.Open(cgroupPath) | ||
991 | 38 | if err != nil { | ||
992 | 39 | return false, err | ||
993 | 40 | } | ||
994 | 41 | defer f.Close() | ||
995 | 42 | scanner := bufio.NewScanner(f) | ||
996 | 43 | for scanner.Scan() { | ||
997 | 44 | line := scanner.Text() | ||
998 | 45 | cgroup := strings.SplitN(line, ":", 2) | ||
999 | 46 | // cgroup[2] will be the cgroup heirarchy | ||
1000 | 47 | if strings.HasPrefix(cgroup[2], "/lxc") || strings.Contains(cgroup[2], "docker") { | ||
1001 | 48 | return true, nil | ||
1002 | 49 | } | ||
1003 | 50 | } | ||
1004 | 51 | return false, nil | ||
1005 | 52 | } | ||
1006 | 53 | |||
1007 | 54 | func GetRunningPIDsWithCMD(ctx context.Context, command, procPath string, excludeContainerProcesses bool) ([]int, error) { | ||
1008 | 55 | if len(procPath) == 0 { | ||
1009 | 56 | procPath = "/proc" | ||
1010 | 57 | } | ||
1011 | 58 | dirs, err := os.ReadDir(procPath) | ||
1012 | 59 | if err != nil { | ||
1013 | 60 | return nil, err | ||
1014 | 61 | } | ||
1015 | 62 | var runningPIDs []int | ||
1016 | 63 | runningInContainer, err := RunningInContainer(ctx) | ||
1017 | 64 | if err != nil { | ||
1018 | 65 | return nil, err | ||
1019 | 66 | } | ||
1020 | 67 | for _, dir := range dirs { | ||
1021 | 68 | pid, parseErr := strconv.Atoi(dir.Name()) | ||
1022 | 69 | if parseErr == nil { | ||
1023 | 70 | pidInContainer, err := PIDInContainer(pid, procPath) | ||
1024 | 71 | if err != nil { | ||
1025 | 72 | return nil, err | ||
1026 | 73 | } | ||
1027 | 74 | if excludeContainerProcesses && !runningInContainer && pidInContainer { | ||
1028 | 75 | continue | ||
1029 | 76 | } | ||
1030 | 77 | runningPIDs = append(runningPIDs, pid) | ||
1031 | 78 | } | ||
1032 | 79 | } | ||
1033 | 80 | return runningPIDs, nil | ||
1034 | 81 | } | ||
1035 | diff --git a/src/rackd_spike/internal/machine_helpers/refresh.go b/src/rackd_spike/internal/machine_helpers/refresh.go | |||
1036 | 0 | new file mode 100644 | 82 | new file mode 100644 |
1037 | index 0000000..685460b | |||
1038 | --- /dev/null | |||
1039 | +++ b/src/rackd_spike/internal/machine_helpers/refresh.go | |||
1040 | @@ -0,0 +1,29 @@ | |||
1041 | 1 | package machinehelpers | ||
1042 | 2 | |||
1043 | 3 | import ( | ||
1044 | 4 | "path/filepath" | ||
1045 | 5 | "runtime" | ||
1046 | 6 | ) | ||
1047 | 7 | |||
1048 | 8 | func isDevEnv() bool { | ||
1049 | 9 | // TODO grab this value from config | ||
1050 | 10 | return true | ||
1051 | 11 | } | ||
1052 | 12 | |||
1053 | 13 | func GetResourcesBinPath() (string, error) { | ||
1054 | 14 | var path string | ||
1055 | 15 | if isDevEnv() { | ||
1056 | 16 | path = "src/machine-resources/bin" | ||
1057 | 17 | } else { | ||
1058 | 18 | prefix, ok := SnapPaths{}.FromEnv()["snap"] | ||
1059 | 19 | path = "/usr/share/maas/machine-resources" | ||
1060 | 20 | if ok { | ||
1061 | 21 | path = prefix + path | ||
1062 | 22 | } | ||
1063 | 23 | } | ||
1064 | 24 | absPath, err := filepath.Abs(path) | ||
1065 | 25 | if err != nil { | ||
1066 | 26 | return "", err | ||
1067 | 27 | } | ||
1068 | 28 | return filepath.Join(absPath, runtime.GOARCH), nil | ||
1069 | 29 | } | ||
1070 | diff --git a/src/rackd_spike/internal/machine_helpers/snap.go b/src/rackd_spike/internal/machine_helpers/snap.go | |||
1071 | 0 | new file mode 100644 | 30 | new file mode 100644 |
1072 | index 0000000..0956377 | |||
1073 | --- /dev/null | |||
1074 | +++ b/src/rackd_spike/internal/machine_helpers/snap.go | |||
1075 | @@ -0,0 +1,30 @@ | |||
1076 | 1 | package machinehelpers | ||
1077 | 2 | |||
1078 | 3 | import ( | ||
1079 | 4 | "os" | ||
1080 | 5 | ) | ||
1081 | 6 | |||
1082 | 7 | var ( | ||
1083 | 8 | pathVars = map[string]string{ | ||
1084 | 9 | "snap": "SNAP", | ||
1085 | 10 | "common": "SNAP_COMMON", | ||
1086 | 11 | "data": "SNAP_DATA", | ||
1087 | 12 | } | ||
1088 | 13 | ) | ||
1089 | 14 | |||
1090 | 15 | func IsRunningInSnap() bool { | ||
1091 | 16 | _, ok := os.LookupEnv("SNAP") | ||
1092 | 17 | return ok | ||
1093 | 18 | } | ||
1094 | 19 | |||
1095 | 20 | type SnapPaths map[string]string | ||
1096 | 21 | |||
1097 | 22 | func (s SnapPaths) FromEnv() SnapPaths { | ||
1098 | 23 | for k, v := range pathVars { | ||
1099 | 24 | path, ok := os.LookupEnv(v) | ||
1100 | 25 | if ok { | ||
1101 | 26 | s[k] = path | ||
1102 | 27 | } | ||
1103 | 28 | } | ||
1104 | 29 | return s | ||
1105 | 30 | } | ||
1106 | diff --git a/src/rackd_spike/internal/transport/rpc.go b/src/rackd_spike/internal/transport/rpc.go | |||
1107 | 0 | new file mode 100644 | 31 | new file mode 100644 |
1108 | index 0000000..c0764d0 | |||
1109 | --- /dev/null | |||
1110 | +++ b/src/rackd_spike/internal/transport/rpc.go | |||
1111 | @@ -0,0 +1,127 @@ | |||
1112 | 1 | package transport | ||
1113 | 2 | |||
1114 | 3 | import ( | ||
1115 | 4 | "context" | ||
1116 | 5 | "crypto/tls" | ||
1117 | 6 | "errors" | ||
1118 | 7 | "net" | ||
1119 | 8 | "net/url" | ||
1120 | 9 | |||
1121 | 10 | capnprpc "capnproto.org/go/capnp/v3/rpc" | ||
1122 | 11 | "github.com/rs/zerolog" | ||
1123 | 12 | |||
1124 | 13 | "rackd/internal/metrics" | ||
1125 | 14 | ) | ||
1126 | 15 | |||
1127 | 16 | var ( | ||
1128 | 17 | ErrRPCClientNotFound = errors.New("error client not found") | ||
1129 | 18 | ) | ||
1130 | 19 | |||
1131 | 20 | type RPCHandler interface { | ||
1132 | 21 | Name() string | ||
1133 | 22 | RegisterMetrics(*metrics.Registry) error | ||
1134 | 23 | SetupServer(context.Context, *ConnWrapper) | ||
1135 | 24 | } | ||
1136 | 25 | |||
1137 | 26 | type RPCClient interface { | ||
1138 | 27 | Name() string | ||
1139 | 28 | RegisterMetrics(*metrics.Registry) error | ||
1140 | 29 | SetupClient(context.Context, *ConnWrapper) | ||
1141 | 30 | } | ||
1142 | 31 | |||
1143 | 32 | type CapnpRPCClient interface { | ||
1144 | 33 | RPCClient | ||
1145 | 34 | Release() | ||
1146 | 35 | } | ||
1147 | 36 | |||
1148 | 37 | type ConnWrapper struct { | ||
1149 | 38 | Conn net.Conn | ||
1150 | 39 | capnpConn *capnprpc.Conn | ||
1151 | 40 | } | ||
1152 | 41 | |||
1153 | 42 | func NewConnWrapper(conn net.Conn) *ConnWrapper { | ||
1154 | 43 | return &ConnWrapper{ | ||
1155 | 44 | Conn: conn, | ||
1156 | 45 | capnpConn: capnprpc.NewConn(capnprpc.NewStreamTransport(conn), nil), | ||
1157 | 46 | } | ||
1158 | 47 | } | ||
1159 | 48 | |||
1160 | 49 | func (c *ConnWrapper) Capnp() *capnprpc.Conn { | ||
1161 | 50 | return c.capnpConn | ||
1162 | 51 | } | ||
1163 | 52 | |||
1164 | 53 | type RPCManager struct { | ||
1165 | 54 | conns map[string]*ConnWrapper | ||
1166 | 55 | handlers map[string]RPCHandler | ||
1167 | 56 | clients map[string]RPCClient | ||
1168 | 57 | initURL string | ||
1169 | 58 | skipHostVerify bool | ||
1170 | 59 | } | ||
1171 | 60 | |||
1172 | 61 | func NewRPCManager(rpcServerURL string, skipHostVerify bool) *RPCManager { | ||
1173 | 62 | return &RPCManager{ | ||
1174 | 63 | conns: make(map[string]*ConnWrapper), | ||
1175 | 64 | handlers: make(map[string]RPCHandler), | ||
1176 | 65 | clients: make(map[string]RPCClient), | ||
1177 | 66 | initURL: rpcServerURL, | ||
1178 | 67 | skipHostVerify: skipHostVerify, | ||
1179 | 68 | } | ||
1180 | 69 | } | ||
1181 | 70 | |||
1182 | 71 | // Init initiates the initial region connection | ||
1183 | 72 | func (r *RPCManager) Init(ctx context.Context) error { | ||
1184 | 73 | parsedURL, err := url.Parse(r.initURL) | ||
1185 | 74 | if err != nil { | ||
1186 | 75 | return err | ||
1187 | 76 | } | ||
1188 | 77 | var conn net.Conn | ||
1189 | 78 | if parsedURL.Scheme == "https" { | ||
1190 | 79 | conn, err = tls.Dial( | ||
1191 | 80 | "tcp", | ||
1192 | 81 | net.JoinHostPort(parsedURL.Hostname(), parsedURL.Port()), | ||
1193 | 82 | &tls.Config{InsecureSkipVerify: r.skipHostVerify}, | ||
1194 | 83 | ) | ||
1195 | 84 | } else { | ||
1196 | 85 | conn, err = net.Dial("tcp", net.JoinHostPort(parsedURL.Hostname(), parsedURL.Port())) | ||
1197 | 86 | } | ||
1198 | 87 | if err != nil { | ||
1199 | 88 | return err | ||
1200 | 89 | } | ||
1201 | 90 | r.AddConn(ctx, conn) | ||
1202 | 91 | log := zerolog.Ctx(ctx) | ||
1203 | 92 | log.Debug().Msg("connected to region server") | ||
1204 | 93 | return nil | ||
1205 | 94 | } | ||
1206 | 95 | |||
1207 | 96 | func (r *RPCManager) AddHandler(ctx context.Context, handler RPCHandler) { | ||
1208 | 97 | r.handlers[handler.Name()] = handler | ||
1209 | 98 | for _, conn := range r.conns { | ||
1210 | 99 | handler.SetupServer(ctx, conn) | ||
1211 | 100 | } | ||
1212 | 101 | } | ||
1213 | 102 | |||
1214 | 103 | func (r *RPCManager) AddClient(ctx context.Context, client RPCClient) { | ||
1215 | 104 | r.clients[client.Name()] = client | ||
1216 | 105 | for _, conn := range r.conns { | ||
1217 | 106 | client.SetupClient(ctx, conn) | ||
1218 | 107 | } | ||
1219 | 108 | } | ||
1220 | 109 | |||
1221 | 110 | func (r *RPCManager) AddConn(ctx context.Context, conn net.Conn) { | ||
1222 | 111 | newConn := NewConnWrapper(conn) | ||
1223 | 112 | r.conns[conn.RemoteAddr().String()] = newConn | ||
1224 | 113 | for _, handler := range r.handlers { | ||
1225 | 114 | handler.SetupServer(ctx, newConn) | ||
1226 | 115 | } | ||
1227 | 116 | for _, client := range r.clients { | ||
1228 | 117 | client.SetupClient(ctx, newConn) | ||
1229 | 118 | } | ||
1230 | 119 | } | ||
1231 | 120 | |||
1232 | 121 | func (r *RPCManager) GetClient(clientName string) (RPCClient, error) { | ||
1233 | 122 | c, ok := r.clients[clientName] | ||
1234 | 123 | if !ok { | ||
1235 | 124 | return nil, ErrRPCClientNotFound | ||
1236 | 125 | } | ||
1237 | 126 | return c, nil | ||
1238 | 127 | } | ||
1239 | diff --git a/src/rackd_spike/pkg/authenticate/authenticator.go b/src/rackd_spike/pkg/authenticate/authenticator.go | |||
1240 | 0 | new file mode 100644 | 128 | new file mode 100644 |
1241 | index 0000000..6a60a86 | |||
1242 | --- /dev/null | |||
1243 | +++ b/src/rackd_spike/pkg/authenticate/authenticator.go | |||
1244 | @@ -0,0 +1,93 @@ | |||
1245 | 1 | package authenticate | ||
1246 | 2 | |||
1247 | 3 | import ( | ||
1248 | 4 | "bytes" | ||
1249 | 5 | "context" | ||
1250 | 6 | "fmt" | ||
1251 | 7 | |||
1252 | 8 | "rackd/internal/metrics" | ||
1253 | 9 | "rackd/internal/transport" | ||
1254 | 10 | "rackd/pkg/rpc" | ||
1255 | 11 | ) | ||
1256 | 12 | |||
1257 | 13 | type AuthCreds struct { | ||
1258 | 14 | Salt []byte | ||
1259 | 15 | Digest []byte | ||
1260 | 16 | } | ||
1261 | 17 | |||
1262 | 18 | func (c *AuthCreds) localDigest(secret, message []byte) []byte { | ||
1263 | 19 | // TODO | ||
1264 | 20 | return nil | ||
1265 | 21 | } | ||
1266 | 22 | |||
1267 | 23 | func (c *AuthCreds) Verify(secret, message []byte) bool { | ||
1268 | 24 | return bytes.Compare(c.Digest, c.localDigest(secret, message)) == 0 | ||
1269 | 25 | } | ||
1270 | 26 | |||
1271 | 27 | type Authenticator interface { | ||
1272 | 28 | transport.RPCClient | ||
1273 | 29 | Authenticate(context.Context, string, []byte, []byte) (*AuthCreds, error) | ||
1274 | 30 | } | ||
1275 | 31 | |||
1276 | 32 | type CapnpAuthenticator struct { | ||
1277 | 33 | clients map[string]*rpc.Authenticator | ||
1278 | 34 | } | ||
1279 | 35 | |||
1280 | 36 | func NewCapnpAuthenticator() Authenticator { | ||
1281 | 37 | // Perhaps we should initialize this with the shared secret already loaded either | ||
1282 | 38 | // from the config manager or load from the FS on instantiation? | ||
1283 | 39 | return &CapnpAuthenticator{ | ||
1284 | 40 | clients: make(map[string]*rpc.Authenticator), | ||
1285 | 41 | } | ||
1286 | 42 | } | ||
1287 | 43 | |||
1288 | 44 | func (c *CapnpAuthenticator) Name() string { | ||
1289 | 45 | return "authenticator" | ||
1290 | 46 | } | ||
1291 | 47 | |||
1292 | 48 | func (c *CapnpAuthenticator) RegisterMetrics(registry *metrics.Registry) error { | ||
1293 | 49 | // TODO | ||
1294 | 50 | return nil | ||
1295 | 51 | } | ||
1296 | 52 | |||
1297 | 53 | func (c *CapnpAuthenticator) SetupClient(ctx context.Context, conn *transport.ConnWrapper) { | ||
1298 | 54 | c.clients[conn.Conn.RemoteAddr().String()] = &rpc.Authenticator{Client: conn.Capnp().Bootstrap(ctx)} | ||
1299 | 55 | } | ||
1300 | 56 | |||
1301 | 57 | func (c *CapnpAuthenticator) Authenticate(ctx context.Context, region string, secret, message []byte) (*AuthCreds, error) { | ||
1302 | 58 | regionClient, ok := c.clients[region] | ||
1303 | 59 | if !ok { | ||
1304 | 60 | return nil, fmt.Errorf("%w: %s", transport.ErrRPCClientNotFound, region) | ||
1305 | 61 | } | ||
1306 | 62 | result, release := regionClient.Authenticate(ctx, func(params rpc.Authenticator_authenticate_Params) error { | ||
1307 | 63 | return params.SetMsg(message) | ||
1308 | 64 | }) | ||
1309 | 65 | defer release() | ||
1310 | 66 | resp, err := result.Struct() | ||
1311 | 67 | if err != nil { | ||
1312 | 68 | return nil, err | ||
1313 | 69 | } | ||
1314 | 70 | creds, err := resp.Resp() | ||
1315 | 71 | if err != nil { | ||
1316 | 72 | return nil, err | ||
1317 | 73 | } | ||
1318 | 74 | salt, err := creds.Salt() | ||
1319 | 75 | if err != nil { | ||
1320 | 76 | return nil, err | ||
1321 | 77 | } | ||
1322 | 78 | digest, err := creds.Digest() | ||
1323 | 79 | if err != nil { | ||
1324 | 80 | return nil, err | ||
1325 | 81 | } | ||
1326 | 82 | return &AuthCreds{ | ||
1327 | 83 | Salt: salt, | ||
1328 | 84 | Digest: digest, | ||
1329 | 85 | }, nil | ||
1330 | 86 | } | ||
1331 | 87 | |||
1332 | 88 | func (c *CapnpAuthenticator) Release() { | ||
1333 | 89 | for k, client := range c.clients { | ||
1334 | 90 | client.Release() | ||
1335 | 91 | delete(c.clients, k) | ||
1336 | 92 | } | ||
1337 | 93 | } | ||
1338 | diff --git a/src/rackd_spike/pkg/region/handshake.go b/src/rackd_spike/pkg/region/handshake.go | |||
1339 | 0 | new file mode 100644 | 94 | new file mode 100644 |
1340 | index 0000000..4d1a090 | |||
1341 | --- /dev/null | |||
1342 | +++ b/src/rackd_spike/pkg/region/handshake.go | |||
1343 | @@ -0,0 +1,91 @@ | |||
1344 | 1 | package region | ||
1345 | 2 | |||
1346 | 3 | import ( | ||
1347 | 4 | "context" | ||
1348 | 5 | "crypto/rand" | ||
1349 | 6 | "errors" | ||
1350 | 7 | "fmt" | ||
1351 | 8 | "os" | ||
1352 | 9 | |||
1353 | 10 | machinehelpers "rackd/internal/machine_helpers" | ||
1354 | 11 | "rackd/internal/transport" | ||
1355 | 12 | auth "rackd/pkg/authenticate" | ||
1356 | 13 | reg "rackd/pkg/register" | ||
1357 | 14 | ) | ||
1358 | 15 | |||
1359 | 16 | var ( | ||
1360 | 17 | ErrNoAuthenticatorProvided = errors.New("error no authenticator was provided") | ||
1361 | 18 | ErrNoRegistererProvided = errors.New("error no registerer was provided") | ||
1362 | 19 | ErrRegionNotAuthed = errors.New("error unable to authenticate with region") | ||
1363 | 20 | ) | ||
1364 | 21 | |||
1365 | 22 | func authenticate(ctx context.Context, region string, rpcMgr *transport.RPCManager) error { | ||
1366 | 23 | authenticatorIface, err := rpcMgr.GetClient("authenticator") | ||
1367 | 24 | if err != nil { | ||
1368 | 25 | return err | ||
1369 | 26 | } | ||
1370 | 27 | authenticator, ok := authenticatorIface.(auth.Authenticator) | ||
1371 | 28 | if !ok { | ||
1372 | 29 | return ErrNoAuthenticatorProvided | ||
1373 | 30 | } | ||
1374 | 31 | secret := []byte{} // TODO get this from filesystem | ||
1375 | 32 | message := make([]byte, 16) | ||
1376 | 33 | _, err = rand.Read(message) | ||
1377 | 34 | if err != nil { | ||
1378 | 35 | return err | ||
1379 | 36 | } | ||
1380 | 37 | creds, err := authenticator.Authenticate(ctx, region, secret, message) | ||
1381 | 38 | if err != nil { | ||
1382 | 39 | return err | ||
1383 | 40 | } | ||
1384 | 41 | if !creds.Verify(secret, message) { | ||
1385 | 42 | return fmt.Errorf("%w: credential verification failed", ErrRegionNotAuthed) | ||
1386 | 43 | } | ||
1387 | 44 | return nil | ||
1388 | 45 | } | ||
1389 | 46 | |||
1390 | 47 | func register(ctx context.Context, region, localVersion string, rpcMgr *transport.RPCManager) error { | ||
1391 | 48 | registererIface, err := rpcMgr.GetClient("registerer") | ||
1392 | 49 | if err != nil { | ||
1393 | 50 | return err | ||
1394 | 51 | } | ||
1395 | 52 | registerer, ok := registererIface.(reg.Registerer) | ||
1396 | 53 | if !ok { | ||
1397 | 54 | return ErrNoRegistererProvided | ||
1398 | 55 | } | ||
1399 | 56 | // TODO get cluster UUID from config | ||
1400 | 57 | clusterUUID := "123456" | ||
1401 | 58 | systemId, err := machinehelpers.GetMAASID() | ||
1402 | 59 | if err != nil { | ||
1403 | 60 | return err | ||
1404 | 61 | } | ||
1405 | 62 | interfaces, err := machinehelpers.GetAllInterfacesDefinition(ctx, false) | ||
1406 | 63 | if err != nil { | ||
1407 | 64 | return err | ||
1408 | 65 | } | ||
1409 | 66 | hostname, err := os.Hostname() | ||
1410 | 67 | if err != nil { | ||
1411 | 68 | return err | ||
1412 | 69 | } | ||
1413 | 70 | err = registerer.Register( | ||
1414 | 71 | ctx, | ||
1415 | 72 | region, | ||
1416 | 73 | clusterUUID, | ||
1417 | 74 | systemId, | ||
1418 | 75 | hostname, | ||
1419 | 76 | localVersion, | ||
1420 | 77 | interfaces, | ||
1421 | 78 | ) | ||
1422 | 79 | if err != nil { | ||
1423 | 80 | return err | ||
1424 | 81 | } | ||
1425 | 82 | return nil | ||
1426 | 83 | } | ||
1427 | 84 | |||
1428 | 85 | func Handshake(ctx context.Context, region, localVersion string, rpcMgr *transport.RPCManager) error { | ||
1429 | 86 | err := authenticate(ctx, region, rpcMgr) | ||
1430 | 87 | if err != nil { | ||
1431 | 88 | return err | ||
1432 | 89 | } | ||
1433 | 90 | return register(ctx, region, localVersion, rpcMgr) | ||
1434 | 91 | } | ||
1435 | diff --git a/src/rackd_spike/pkg/register/registerer.go b/src/rackd_spike/pkg/register/registerer.go | |||
1436 | 0 | new file mode 100644 | 92 | new file mode 100644 |
1437 | index 0000000..b6562e7 | |||
1438 | --- /dev/null | |||
1439 | +++ b/src/rackd_spike/pkg/register/registerer.go | |||
1440 | @@ -0,0 +1,125 @@ | |||
1441 | 1 | package register | ||
1442 | 2 | |||
1443 | 3 | import ( | ||
1444 | 4 | "context" | ||
1445 | 5 | |||
1446 | 6 | "github.com/rs/zerolog" | ||
1447 | 7 | |||
1448 | 8 | machinehelpers "rackd/internal/machine_helpers" | ||
1449 | 9 | "rackd/internal/metrics" | ||
1450 | 10 | "rackd/internal/transport" | ||
1451 | 11 | "rackd/pkg/rpc" | ||
1452 | 12 | ) | ||
1453 | 13 | |||
1454 | 14 | type Registerer interface { | ||
1455 | 15 | transport.RPCClient | ||
1456 | 16 | Register( | ||
1457 | 17 | ctx context.Context, | ||
1458 | 18 | region, clusterUUID, systemId, hostname, version string, | ||
1459 | 19 | interfaces map[string]machinehelpers.Interface, | ||
1460 | 20 | ) error | ||
1461 | 21 | } | ||
1462 | 22 | |||
1463 | 23 | type CapnpRegisterer struct { | ||
1464 | 24 | clients map[string]*rpc.Registerer | ||
1465 | 25 | } | ||
1466 | 26 | |||
1467 | 27 | func NewCapnpRegisterer() Registerer { | ||
1468 | 28 | return &CapnpRegisterer{} | ||
1469 | 29 | } | ||
1470 | 30 | |||
1471 | 31 | func (c *CapnpRegisterer) Name() string { | ||
1472 | 32 | return "Registerer" | ||
1473 | 33 | } | ||
1474 | 34 | |||
1475 | 35 | func (c *CapnpRegisterer) RegisterMetrics(registry *metrics.Registry) error { | ||
1476 | 36 | // TODO | ||
1477 | 37 | return nil | ||
1478 | 38 | } | ||
1479 | 39 | |||
1480 | 40 | func (c *CapnpRegisterer) SetupClient(ctx context.Context, client *transport.ConnWrapper) { | ||
1481 | 41 | c.clients[client.Conn.RemoteAddr().String()] = &rpc.Registerer{Client: client.Capnp().Bootstrap(ctx)} | ||
1482 | 42 | } | ||
1483 | 43 | |||
1484 | 44 | func (c *CapnpRegisterer) Register( | ||
1485 | 45 | ctx context.Context, | ||
1486 | 46 | region, clusterUUID, systemId, hostname, version string, | ||
1487 | 47 | interfaces map[string]machinehelpers.Interface, | ||
1488 | 48 | ) error { | ||
1489 | 49 | client, ok := c.clients[region] | ||
1490 | 50 | if !ok { | ||
1491 | 51 | return transport.ErrRPCClientNotFound | ||
1492 | 52 | } | ||
1493 | 53 | result, release := client.Register(ctx, func(params rpc.Registerer_register_Params) error { | ||
1494 | 54 | req, err := params.NewReq() | ||
1495 | 55 | if err != nil { | ||
1496 | 56 | return err | ||
1497 | 57 | } | ||
1498 | 58 | err = req.SetSystemId(systemId) | ||
1499 | 59 | if err != nil { | ||
1500 | 60 | return err | ||
1501 | 61 | } | ||
1502 | 62 | err = req.SetHostname(hostname) | ||
1503 | 63 | if err != nil { | ||
1504 | 64 | return err | ||
1505 | 65 | } | ||
1506 | 66 | ifaces, err := req.NewInterfaces() | ||
1507 | 67 | if err != nil { | ||
1508 | 68 | return err | ||
1509 | 69 | } | ||
1510 | 70 | capnpIfaces := machinehelpers.CapnpInterfaces(interfaces) | ||
1511 | 71 | err = capnpIfaces.SetProto(ifaces) | ||
1512 | 72 | if err != nil { | ||
1513 | 73 | return err | ||
1514 | 74 | } | ||
1515 | 75 | err = req.SetUrl(region) | ||
1516 | 76 | if err != nil { | ||
1517 | 77 | return err | ||
1518 | 78 | } | ||
1519 | 79 | err = req.SetNodegroup(clusterUUID) | ||
1520 | 80 | if err != nil { | ||
1521 | 81 | return err | ||
1522 | 82 | } | ||
1523 | 83 | req.SetBeaconSupport(true) | ||
1524 | 84 | err = req.SetVersion(version) | ||
1525 | 85 | if err != nil { | ||
1526 | 86 | return err | ||
1527 | 87 | } | ||
1528 | 88 | return nil | ||
1529 | 89 | }) | ||
1530 | 90 | defer release() | ||
1531 | 91 | resp, err := result.Struct() | ||
1532 | 92 | if err != nil { | ||
1533 | 93 | return err | ||
1534 | 94 | } | ||
1535 | 95 | res, err := resp.Resp() | ||
1536 | 96 | if err != nil { | ||
1537 | 97 | return err | ||
1538 | 98 | } | ||
1539 | 99 | localId, err := res.SystemId() | ||
1540 | 100 | if err != nil { | ||
1541 | 101 | return err | ||
1542 | 102 | } | ||
1543 | 103 | // TODO set global metrics labels | ||
1544 | 104 | err = machinehelpers.SetMAASId(localId) | ||
1545 | 105 | if err != nil { | ||
1546 | 106 | return err | ||
1547 | 107 | } | ||
1548 | 108 | respVersion, err := res.Version() | ||
1549 | 109 | if err != nil { | ||
1550 | 110 | return err | ||
1551 | 111 | } | ||
1552 | 112 | if len(respVersion) == 0 { | ||
1553 | 113 | respVersion = "unknown MAAS version" | ||
1554 | 114 | } | ||
1555 | 115 | log := zerolog.Ctx(ctx) | ||
1556 | 116 | log.Log().Msgf("Rack controller '%s' registered (via %s) with %s.", localId, region, respVersion) | ||
1557 | 117 | return nil | ||
1558 | 118 | } | ||
1559 | 119 | |||
1560 | 120 | func (c *CapnpRegisterer) Release() { | ||
1561 | 121 | for k, client := range c.clients { | ||
1562 | 122 | client.Release() | ||
1563 | 123 | delete(c.clients, k) | ||
1564 | 124 | } | ||
1565 | 125 | } | ||
1566 | diff --git a/src/rackd_spike/pkg/rpc/handshake.capnp.go b/src/rackd_spike/pkg/rpc/handshake.capnp.go | |||
1567 | 0 | new file mode 100644 | 126 | new file mode 100644 |
1568 | index 0000000..94955c9 | |||
1569 | --- /dev/null | |||
1570 | +++ b/src/rackd_spike/pkg/rpc/handshake.capnp.go | |||
1571 | @@ -0,0 +1,933 @@ | |||
1572 | 1 | // Code generated by capnpc-go. DO NOT EDIT. | ||
1573 | 2 | |||
1574 | 3 | package rpc | ||
1575 | 4 | |||
1576 | 5 | import ( | ||
1577 | 6 | capnp "capnproto.org/go/capnp/v3" | ||
1578 | 7 | text "capnproto.org/go/capnp/v3/encoding/text" | ||
1579 | 8 | schemas "capnproto.org/go/capnp/v3/schemas" | ||
1580 | 9 | server "capnproto.org/go/capnp/v3/server" | ||
1581 | 10 | context "context" | ||
1582 | 11 | ) | ||
1583 | 12 | |||
1584 | 13 | type AuthResponse struct{ capnp.Struct } | ||
1585 | 14 | |||
1586 | 15 | // AuthResponse_TypeID is the unique identifier for the type AuthResponse. | ||
1587 | 16 | const AuthResponse_TypeID = 0x98b03f82d720e4e1 | ||
1588 | 17 | |||
1589 | 18 | func NewAuthResponse(s *capnp.Segment) (AuthResponse, error) { | ||
1590 | 19 | st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 2}) | ||
1591 | 20 | return AuthResponse{st}, err | ||
1592 | 21 | } | ||
1593 | 22 | |||
1594 | 23 | func NewRootAuthResponse(s *capnp.Segment) (AuthResponse, error) { | ||
1595 | 24 | st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 2}) | ||
1596 | 25 | return AuthResponse{st}, err | ||
1597 | 26 | } | ||
1598 | 27 | |||
1599 | 28 | func ReadRootAuthResponse(msg *capnp.Message) (AuthResponse, error) { | ||
1600 | 29 | root, err := msg.Root() | ||
1601 | 30 | return AuthResponse{root.Struct()}, err | ||
1602 | 31 | } | ||
1603 | 32 | |||
1604 | 33 | func (s AuthResponse) String() string { | ||
1605 | 34 | str, _ := text.Marshal(0x98b03f82d720e4e1, s.Struct) | ||
1606 | 35 | return str | ||
1607 | 36 | } | ||
1608 | 37 | |||
1609 | 38 | func (s AuthResponse) Salt() ([]byte, error) { | ||
1610 | 39 | p, err := s.Struct.Ptr(0) | ||
1611 | 40 | return []byte(p.Data()), err | ||
1612 | 41 | } | ||
1613 | 42 | |||
1614 | 43 | func (s AuthResponse) HasSalt() bool { | ||
1615 | 44 | return s.Struct.HasPtr(0) | ||
1616 | 45 | } | ||
1617 | 46 | |||
1618 | 47 | func (s AuthResponse) SetSalt(v []byte) error { | ||
1619 | 48 | return s.Struct.SetData(0, v) | ||
1620 | 49 | } | ||
1621 | 50 | |||
1622 | 51 | func (s AuthResponse) Digest() ([]byte, error) { | ||
1623 | 52 | p, err := s.Struct.Ptr(1) | ||
1624 | 53 | return []byte(p.Data()), err | ||
1625 | 54 | } | ||
1626 | 55 | |||
1627 | 56 | func (s AuthResponse) HasDigest() bool { | ||
1628 | 57 | return s.Struct.HasPtr(1) | ||
1629 | 58 | } | ||
1630 | 59 | |||
1631 | 60 | func (s AuthResponse) SetDigest(v []byte) error { | ||
1632 | 61 | return s.Struct.SetData(1, v) | ||
1633 | 62 | } | ||
1634 | 63 | |||
1635 | 64 | // AuthResponse_List is a list of AuthResponse. | ||
1636 | 65 | type AuthResponse_List struct{ capnp.List } | ||
1637 | 66 | |||
1638 | 67 | // NewAuthResponse creates a new list of AuthResponse. | ||
1639 | 68 | func NewAuthResponse_List(s *capnp.Segment, sz int32) (AuthResponse_List, error) { | ||
1640 | 69 | l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 2}, sz) | ||
1641 | 70 | return AuthResponse_List{l}, err | ||
1642 | 71 | } | ||
1643 | 72 | |||
1644 | 73 | func (s AuthResponse_List) At(i int) AuthResponse { return AuthResponse{s.List.Struct(i)} } | ||
1645 | 74 | |||
1646 | 75 | func (s AuthResponse_List) Set(i int, v AuthResponse) error { return s.List.SetStruct(i, v.Struct) } | ||
1647 | 76 | |||
1648 | 77 | func (s AuthResponse_List) String() string { | ||
1649 | 78 | str, _ := text.MarshalList(0x98b03f82d720e4e1, s.List) | ||
1650 | 79 | return str | ||
1651 | 80 | } | ||
1652 | 81 | |||
1653 | 82 | // AuthResponse_Future is a wrapper for a AuthResponse promised by a client call. | ||
1654 | 83 | type AuthResponse_Future struct{ *capnp.Future } | ||
1655 | 84 | |||
1656 | 85 | func (p AuthResponse_Future) Struct() (AuthResponse, error) { | ||
1657 | 86 | s, err := p.Future.Struct() | ||
1658 | 87 | return AuthResponse{s}, err | ||
1659 | 88 | } | ||
1660 | 89 | |||
1661 | 90 | type Authenticator struct{ Client *capnp.Client } | ||
1662 | 91 | |||
1663 | 92 | // Authenticator_TypeID is the unique identifier for the type Authenticator. | ||
1664 | 93 | const Authenticator_TypeID = 0x800ae3a77a7bc18e | ||
1665 | 94 | |||
1666 | 95 | func (c Authenticator) Authenticate(ctx context.Context, params func(Authenticator_authenticate_Params) error) (Authenticator_authenticate_Results_Future, capnp.ReleaseFunc) { | ||
1667 | 96 | s := capnp.Send{ | ||
1668 | 97 | Method: capnp.Method{ | ||
1669 | 98 | InterfaceID: 0x800ae3a77a7bc18e, | ||
1670 | 99 | MethodID: 0, | ||
1671 | 100 | InterfaceName: "handshake.capnp:Authenticator", | ||
1672 | 101 | MethodName: "authenticate", | ||
1673 | 102 | }, | ||
1674 | 103 | } | ||
1675 | 104 | if params != nil { | ||
1676 | 105 | s.ArgsSize = capnp.ObjectSize{DataSize: 0, PointerCount: 1} | ||
1677 | 106 | s.PlaceArgs = func(s capnp.Struct) error { return params(Authenticator_authenticate_Params{Struct: s}) } | ||
1678 | 107 | } | ||
1679 | 108 | ans, release := c.Client.SendCall(ctx, s) | ||
1680 | 109 | return Authenticator_authenticate_Results_Future{Future: ans.Future()}, release | ||
1681 | 110 | } | ||
1682 | 111 | |||
1683 | 112 | func (c Authenticator) AddRef() Authenticator { | ||
1684 | 113 | return Authenticator{ | ||
1685 | 114 | Client: c.Client.AddRef(), | ||
1686 | 115 | } | ||
1687 | 116 | } | ||
1688 | 117 | |||
1689 | 118 | func (c Authenticator) Release() { | ||
1690 | 119 | c.Client.Release() | ||
1691 | 120 | } | ||
1692 | 121 | |||
1693 | 122 | // A Authenticator_Server is a Authenticator with a local implementation. | ||
1694 | 123 | type Authenticator_Server interface { | ||
1695 | 124 | Authenticate(context.Context, Authenticator_authenticate) error | ||
1696 | 125 | } | ||
1697 | 126 | |||
1698 | 127 | // Authenticator_NewServer creates a new Server from an implementation of Authenticator_Server. | ||
1699 | 128 | func Authenticator_NewServer(s Authenticator_Server, policy *server.Policy) *server.Server { | ||
1700 | 129 | c, _ := s.(server.Shutdowner) | ||
1701 | 130 | return server.New(Authenticator_Methods(nil, s), s, c, policy) | ||
1702 | 131 | } | ||
1703 | 132 | |||
1704 | 133 | // Authenticator_ServerToClient creates a new Client from an implementation of Authenticator_Server. | ||
1705 | 134 | // The caller is responsible for calling Release on the returned Client. | ||
1706 | 135 | func Authenticator_ServerToClient(s Authenticator_Server, policy *server.Policy) Authenticator { | ||
1707 | 136 | return Authenticator{Client: capnp.NewClient(Authenticator_NewServer(s, policy))} | ||
1708 | 137 | } | ||
1709 | 138 | |||
1710 | 139 | // Authenticator_Methods appends Methods to a slice that invoke the methods on s. | ||
1711 | 140 | // This can be used to create a more complicated Server. | ||
1712 | 141 | func Authenticator_Methods(methods []server.Method, s Authenticator_Server) []server.Method { | ||
1713 | 142 | if cap(methods) == 0 { | ||
1714 | 143 | methods = make([]server.Method, 0, 1) | ||
1715 | 144 | } | ||
1716 | 145 | |||
1717 | 146 | methods = append(methods, server.Method{ | ||
1718 | 147 | Method: capnp.Method{ | ||
1719 | 148 | InterfaceID: 0x800ae3a77a7bc18e, | ||
1720 | 149 | MethodID: 0, | ||
1721 | 150 | InterfaceName: "handshake.capnp:Authenticator", | ||
1722 | 151 | MethodName: "authenticate", | ||
1723 | 152 | }, | ||
1724 | 153 | Impl: func(ctx context.Context, call *server.Call) error { | ||
1725 | 154 | return s.Authenticate(ctx, Authenticator_authenticate{call}) | ||
1726 | 155 | }, | ||
1727 | 156 | }) | ||
1728 | 157 | |||
1729 | 158 | return methods | ||
1730 | 159 | } | ||
1731 | 160 | |||
1732 | 161 | // Authenticator_authenticate holds the state for a server call to Authenticator.authenticate. | ||
1733 | 162 | // See server.Call for documentation. | ||
1734 | 163 | type Authenticator_authenticate struct { | ||
1735 | 164 | *server.Call | ||
1736 | 165 | } | ||
1737 | 166 | |||
1738 | 167 | // Args returns the call's arguments. | ||
1739 | 168 | func (c Authenticator_authenticate) Args() Authenticator_authenticate_Params { | ||
1740 | 169 | return Authenticator_authenticate_Params{Struct: c.Call.Args()} | ||
1741 | 170 | } | ||
1742 | 171 | |||
1743 | 172 | // AllocResults allocates the results struct. | ||
1744 | 173 | func (c Authenticator_authenticate) AllocResults() (Authenticator_authenticate_Results, error) { | ||
1745 | 174 | r, err := c.Call.AllocResults(capnp.ObjectSize{DataSize: 0, PointerCount: 1}) | ||
1746 | 175 | return Authenticator_authenticate_Results{Struct: r}, err | ||
1747 | 176 | } | ||
1748 | 177 | |||
1749 | 178 | type Authenticator_authenticate_Params struct{ capnp.Struct } | ||
1750 | 179 | |||
1751 | 180 | // Authenticator_authenticate_Params_TypeID is the unique identifier for the type Authenticator_authenticate_Params. | ||
1752 | 181 | const Authenticator_authenticate_Params_TypeID = 0xdbaca3bedaffa653 | ||
1753 | 182 | |||
1754 | 183 | func NewAuthenticator_authenticate_Params(s *capnp.Segment) (Authenticator_authenticate_Params, error) { | ||
1755 | 184 | st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) | ||
1756 | 185 | return Authenticator_authenticate_Params{st}, err | ||
1757 | 186 | } | ||
1758 | 187 | |||
1759 | 188 | func NewRootAuthenticator_authenticate_Params(s *capnp.Segment) (Authenticator_authenticate_Params, error) { | ||
1760 | 189 | st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) | ||
1761 | 190 | return Authenticator_authenticate_Params{st}, err | ||
1762 | 191 | } | ||
1763 | 192 | |||
1764 | 193 | func ReadRootAuthenticator_authenticate_Params(msg *capnp.Message) (Authenticator_authenticate_Params, error) { | ||
1765 | 194 | root, err := msg.Root() | ||
1766 | 195 | return Authenticator_authenticate_Params{root.Struct()}, err | ||
1767 | 196 | } | ||
1768 | 197 | |||
1769 | 198 | func (s Authenticator_authenticate_Params) String() string { | ||
1770 | 199 | str, _ := text.Marshal(0xdbaca3bedaffa653, s.Struct) | ||
1771 | 200 | return str | ||
1772 | 201 | } | ||
1773 | 202 | |||
1774 | 203 | func (s Authenticator_authenticate_Params) Msg() ([]byte, error) { | ||
1775 | 204 | p, err := s.Struct.Ptr(0) | ||
1776 | 205 | return []byte(p.Data()), err | ||
1777 | 206 | } | ||
1778 | 207 | |||
1779 | 208 | func (s Authenticator_authenticate_Params) HasMsg() bool { | ||
1780 | 209 | return s.Struct.HasPtr(0) | ||
1781 | 210 | } | ||
1782 | 211 | |||
1783 | 212 | func (s Authenticator_authenticate_Params) SetMsg(v []byte) error { | ||
1784 | 213 | return s.Struct.SetData(0, v) | ||
1785 | 214 | } | ||
1786 | 215 | |||
1787 | 216 | // Authenticator_authenticate_Params_List is a list of Authenticator_authenticate_Params. | ||
1788 | 217 | type Authenticator_authenticate_Params_List struct{ capnp.List } | ||
1789 | 218 | |||
1790 | 219 | // NewAuthenticator_authenticate_Params creates a new list of Authenticator_authenticate_Params. | ||
1791 | 220 | func NewAuthenticator_authenticate_Params_List(s *capnp.Segment, sz int32) (Authenticator_authenticate_Params_List, error) { | ||
1792 | 221 | l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz) | ||
1793 | 222 | return Authenticator_authenticate_Params_List{l}, err | ||
1794 | 223 | } | ||
1795 | 224 | |||
1796 | 225 | func (s Authenticator_authenticate_Params_List) At(i int) Authenticator_authenticate_Params { | ||
1797 | 226 | return Authenticator_authenticate_Params{s.List.Struct(i)} | ||
1798 | 227 | } | ||
1799 | 228 | |||
1800 | 229 | func (s Authenticator_authenticate_Params_List) Set(i int, v Authenticator_authenticate_Params) error { | ||
1801 | 230 | return s.List.SetStruct(i, v.Struct) | ||
1802 | 231 | } | ||
1803 | 232 | |||
1804 | 233 | func (s Authenticator_authenticate_Params_List) String() string { | ||
1805 | 234 | str, _ := text.MarshalList(0xdbaca3bedaffa653, s.List) | ||
1806 | 235 | return str | ||
1807 | 236 | } | ||
1808 | 237 | |||
1809 | 238 | // Authenticator_authenticate_Params_Future is a wrapper for a Authenticator_authenticate_Params promised by a client call. | ||
1810 | 239 | type Authenticator_authenticate_Params_Future struct{ *capnp.Future } | ||
1811 | 240 | |||
1812 | 241 | func (p Authenticator_authenticate_Params_Future) Struct() (Authenticator_authenticate_Params, error) { | ||
1813 | 242 | s, err := p.Future.Struct() | ||
1814 | 243 | return Authenticator_authenticate_Params{s}, err | ||
1815 | 244 | } | ||
1816 | 245 | |||
1817 | 246 | type Authenticator_authenticate_Results struct{ capnp.Struct } | ||
1818 | 247 | |||
1819 | 248 | // Authenticator_authenticate_Results_TypeID is the unique identifier for the type Authenticator_authenticate_Results. | ||
1820 | 249 | const Authenticator_authenticate_Results_TypeID = 0x96c07ce683897942 | ||
1821 | 250 | |||
1822 | 251 | func NewAuthenticator_authenticate_Results(s *capnp.Segment) (Authenticator_authenticate_Results, error) { | ||
1823 | 252 | st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) | ||
1824 | 253 | return Authenticator_authenticate_Results{st}, err | ||
1825 | 254 | } | ||
1826 | 255 | |||
1827 | 256 | func NewRootAuthenticator_authenticate_Results(s *capnp.Segment) (Authenticator_authenticate_Results, error) { | ||
1828 | 257 | st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) | ||
1829 | 258 | return Authenticator_authenticate_Results{st}, err | ||
1830 | 259 | } | ||
1831 | 260 | |||
1832 | 261 | func ReadRootAuthenticator_authenticate_Results(msg *capnp.Message) (Authenticator_authenticate_Results, error) { | ||
1833 | 262 | root, err := msg.Root() | ||
1834 | 263 | return Authenticator_authenticate_Results{root.Struct()}, err | ||
1835 | 264 | } | ||
1836 | 265 | |||
1837 | 266 | func (s Authenticator_authenticate_Results) String() string { | ||
1838 | 267 | str, _ := text.Marshal(0x96c07ce683897942, s.Struct) | ||
1839 | 268 | return str | ||
1840 | 269 | } | ||
1841 | 270 | |||
1842 | 271 | func (s Authenticator_authenticate_Results) Resp() (AuthResponse, error) { | ||
1843 | 272 | p, err := s.Struct.Ptr(0) | ||
1844 | 273 | return AuthResponse{Struct: p.Struct()}, err | ||
1845 | 274 | } | ||
1846 | 275 | |||
1847 | 276 | func (s Authenticator_authenticate_Results) HasResp() bool { | ||
1848 | 277 | return s.Struct.HasPtr(0) | ||
1849 | 278 | } | ||
1850 | 279 | |||
1851 | 280 | func (s Authenticator_authenticate_Results) SetResp(v AuthResponse) error { | ||
1852 | 281 | return s.Struct.SetPtr(0, v.Struct.ToPtr()) | ||
1853 | 282 | } | ||
1854 | 283 | |||
1855 | 284 | // NewResp sets the resp field to a newly | ||
1856 | 285 | // allocated AuthResponse struct, preferring placement in s's segment. | ||
1857 | 286 | func (s Authenticator_authenticate_Results) NewResp() (AuthResponse, error) { | ||
1858 | 287 | ss, err := NewAuthResponse(s.Struct.Segment()) | ||
1859 | 288 | if err != nil { | ||
1860 | 289 | return AuthResponse{}, err | ||
1861 | 290 | } | ||
1862 | 291 | err = s.Struct.SetPtr(0, ss.Struct.ToPtr()) | ||
1863 | 292 | return ss, err | ||
1864 | 293 | } | ||
1865 | 294 | |||
1866 | 295 | // Authenticator_authenticate_Results_List is a list of Authenticator_authenticate_Results. | ||
1867 | 296 | type Authenticator_authenticate_Results_List struct{ capnp.List } | ||
1868 | 297 | |||
1869 | 298 | // NewAuthenticator_authenticate_Results creates a new list of Authenticator_authenticate_Results. | ||
1870 | 299 | func NewAuthenticator_authenticate_Results_List(s *capnp.Segment, sz int32) (Authenticator_authenticate_Results_List, error) { | ||
1871 | 300 | l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz) | ||
1872 | 301 | return Authenticator_authenticate_Results_List{l}, err | ||
1873 | 302 | } | ||
1874 | 303 | |||
1875 | 304 | func (s Authenticator_authenticate_Results_List) At(i int) Authenticator_authenticate_Results { | ||
1876 | 305 | return Authenticator_authenticate_Results{s.List.Struct(i)} | ||
1877 | 306 | } | ||
1878 | 307 | |||
1879 | 308 | func (s Authenticator_authenticate_Results_List) Set(i int, v Authenticator_authenticate_Results) error { | ||
1880 | 309 | return s.List.SetStruct(i, v.Struct) | ||
1881 | 310 | } | ||
1882 | 311 | |||
1883 | 312 | func (s Authenticator_authenticate_Results_List) String() string { | ||
1884 | 313 | str, _ := text.MarshalList(0x96c07ce683897942, s.List) | ||
1885 | 314 | return str | ||
1886 | 315 | } | ||
1887 | 316 | |||
1888 | 317 | // Authenticator_authenticate_Results_Future is a wrapper for a Authenticator_authenticate_Results promised by a client call. | ||
1889 | 318 | type Authenticator_authenticate_Results_Future struct{ *capnp.Future } | ||
1890 | 319 | |||
1891 | 320 | func (p Authenticator_authenticate_Results_Future) Struct() (Authenticator_authenticate_Results, error) { | ||
1892 | 321 | s, err := p.Future.Struct() | ||
1893 | 322 | return Authenticator_authenticate_Results{s}, err | ||
1894 | 323 | } | ||
1895 | 324 | |||
1896 | 325 | func (p Authenticator_authenticate_Results_Future) Resp() AuthResponse_Future { | ||
1897 | 326 | return AuthResponse_Future{Future: p.Future.Field(0, nil)} | ||
1898 | 327 | } | ||
1899 | 328 | |||
1900 | 329 | type RegisterRequest struct{ capnp.Struct } | ||
1901 | 330 | |||
1902 | 331 | // RegisterRequest_TypeID is the unique identifier for the type RegisterRequest. | ||
1903 | 332 | const RegisterRequest_TypeID = 0x8a21a43d866e69f4 | ||
1904 | 333 | |||
1905 | 334 | func NewRegisterRequest(s *capnp.Segment) (RegisterRequest, error) { | ||
1906 | 335 | st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 6}) | ||
1907 | 336 | return RegisterRequest{st}, err | ||
1908 | 337 | } | ||
1909 | 338 | |||
1910 | 339 | func NewRootRegisterRequest(s *capnp.Segment) (RegisterRequest, error) { | ||
1911 | 340 | st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 6}) | ||
1912 | 341 | return RegisterRequest{st}, err | ||
1913 | 342 | } | ||
1914 | 343 | |||
1915 | 344 | func ReadRootRegisterRequest(msg *capnp.Message) (RegisterRequest, error) { | ||
1916 | 345 | root, err := msg.Root() | ||
1917 | 346 | return RegisterRequest{root.Struct()}, err | ||
1918 | 347 | } | ||
1919 | 348 | |||
1920 | 349 | func (s RegisterRequest) String() string { | ||
1921 | 350 | str, _ := text.Marshal(0x8a21a43d866e69f4, s.Struct) | ||
1922 | 351 | return str | ||
1923 | 352 | } | ||
1924 | 353 | |||
1925 | 354 | func (s RegisterRequest) SystemId() (string, error) { | ||
1926 | 355 | p, err := s.Struct.Ptr(0) | ||
1927 | 356 | return p.Text(), err | ||
1928 | 357 | } | ||
1929 | 358 | |||
1930 | 359 | func (s RegisterRequest) HasSystemId() bool { | ||
1931 | 360 | return s.Struct.HasPtr(0) | ||
1932 | 361 | } | ||
1933 | 362 | |||
1934 | 363 | func (s RegisterRequest) SystemIdBytes() ([]byte, error) { | ||
1935 | 364 | p, err := s.Struct.Ptr(0) | ||
1936 | 365 | return p.TextBytes(), err | ||
1937 | 366 | } | ||
1938 | 367 | |||
1939 | 368 | func (s RegisterRequest) SetSystemId(v string) error { | ||
1940 | 369 | return s.Struct.SetText(0, v) | ||
1941 | 370 | } | ||
1942 | 371 | |||
1943 | 372 | func (s RegisterRequest) Hostname() (string, error) { | ||
1944 | 373 | p, err := s.Struct.Ptr(1) | ||
1945 | 374 | return p.Text(), err | ||
1946 | 375 | } | ||
1947 | 376 | |||
1948 | 377 | func (s RegisterRequest) HasHostname() bool { | ||
1949 | 378 | return s.Struct.HasPtr(1) | ||
1950 | 379 | } | ||
1951 | 380 | |||
1952 | 381 | func (s RegisterRequest) HostnameBytes() ([]byte, error) { | ||
1953 | 382 | p, err := s.Struct.Ptr(1) | ||
1954 | 383 | return p.TextBytes(), err | ||
1955 | 384 | } | ||
1956 | 385 | |||
1957 | 386 | func (s RegisterRequest) SetHostname(v string) error { | ||
1958 | 387 | return s.Struct.SetText(1, v) | ||
1959 | 388 | } | ||
1960 | 389 | |||
1961 | 390 | func (s RegisterRequest) Interfaces() (Interfaces, error) { | ||
1962 | 391 | p, err := s.Struct.Ptr(2) | ||
1963 | 392 | return Interfaces{Struct: p.Struct()}, err | ||
1964 | 393 | } | ||
1965 | 394 | |||
1966 | 395 | func (s RegisterRequest) HasInterfaces() bool { | ||
1967 | 396 | return s.Struct.HasPtr(2) | ||
1968 | 397 | } | ||
1969 | 398 | |||
1970 | 399 | func (s RegisterRequest) SetInterfaces(v Interfaces) error { | ||
1971 | 400 | return s.Struct.SetPtr(2, v.Struct.ToPtr()) | ||
1972 | 401 | } | ||
1973 | 402 | |||
1974 | 403 | // NewInterfaces sets the interfaces field to a newly | ||
1975 | 404 | // allocated Interfaces struct, preferring placement in s's segment. | ||
1976 | 405 | func (s RegisterRequest) NewInterfaces() (Interfaces, error) { | ||
1977 | 406 | ss, err := NewInterfaces(s.Struct.Segment()) | ||
1978 | 407 | if err != nil { | ||
1979 | 408 | return Interfaces{}, err | ||
1980 | 409 | } | ||
1981 | 410 | err = s.Struct.SetPtr(2, ss.Struct.ToPtr()) | ||
1982 | 411 | return ss, err | ||
1983 | 412 | } | ||
1984 | 413 | |||
1985 | 414 | func (s RegisterRequest) Url() (string, error) { | ||
1986 | 415 | p, err := s.Struct.Ptr(3) | ||
1987 | 416 | return p.Text(), err | ||
1988 | 417 | } | ||
1989 | 418 | |||
1990 | 419 | func (s RegisterRequest) HasUrl() bool { | ||
1991 | 420 | return s.Struct.HasPtr(3) | ||
1992 | 421 | } | ||
1993 | 422 | |||
1994 | 423 | func (s RegisterRequest) UrlBytes() ([]byte, error) { | ||
1995 | 424 | p, err := s.Struct.Ptr(3) | ||
1996 | 425 | return p.TextBytes(), err | ||
1997 | 426 | } | ||
1998 | 427 | |||
1999 | 428 | func (s RegisterRequest) SetUrl(v string) error { | ||
2000 | 429 | return s.Struct.SetText(3, v) | ||
2001 | 430 | } | ||
2002 | 431 | |||
2003 | 432 | func (s RegisterRequest) Nodegroup() (string, error) { | ||
2004 | 433 | p, err := s.Struct.Ptr(4) | ||
2005 | 434 | return p.Text(), err | ||
2006 | 435 | } | ||
2007 | 436 | |||
2008 | 437 | func (s RegisterRequest) HasNodegroup() bool { | ||
2009 | 438 | return s.Struct.HasPtr(4) | ||
2010 | 439 | } | ||
2011 | 440 | |||
2012 | 441 | func (s RegisterRequest) NodegroupBytes() ([]byte, error) { | ||
2013 | 442 | p, err := s.Struct.Ptr(4) | ||
2014 | 443 | return p.TextBytes(), err | ||
2015 | 444 | } | ||
2016 | 445 | |||
2017 | 446 | func (s RegisterRequest) SetNodegroup(v string) error { | ||
2018 | 447 | return s.Struct.SetText(4, v) | ||
2019 | 448 | } | ||
2020 | 449 | |||
2021 | 450 | func (s RegisterRequest) BeaconSupport() bool { | ||
2022 | 451 | return s.Struct.Bit(0) | ||
2023 | 452 | } | ||
2024 | 453 | |||
2025 | 454 | func (s RegisterRequest) SetBeaconSupport(v bool) { | ||
2026 | 455 | s.Struct.SetBit(0, v) | ||
2027 | 456 | } | ||
2028 | 457 | |||
2029 | 458 | func (s RegisterRequest) Version() (string, error) { | ||
2030 | 459 | p, err := s.Struct.Ptr(5) | ||
2031 | 460 | return p.Text(), err | ||
2032 | 461 | } | ||
2033 | 462 | |||
2034 | 463 | func (s RegisterRequest) HasVersion() bool { | ||
2035 | 464 | return s.Struct.HasPtr(5) | ||
2036 | 465 | } | ||
2037 | 466 | |||
2038 | 467 | func (s RegisterRequest) VersionBytes() ([]byte, error) { | ||
2039 | 468 | p, err := s.Struct.Ptr(5) | ||
2040 | 469 | return p.TextBytes(), err | ||
2041 | 470 | } | ||
2042 | 471 | |||
2043 | 472 | func (s RegisterRequest) SetVersion(v string) error { | ||
2044 | 473 | return s.Struct.SetText(5, v) | ||
2045 | 474 | } | ||
2046 | 475 | |||
2047 | 476 | // RegisterRequest_List is a list of RegisterRequest. | ||
2048 | 477 | type RegisterRequest_List struct{ capnp.List } | ||
2049 | 478 | |||
2050 | 479 | // NewRegisterRequest creates a new list of RegisterRequest. | ||
2051 | 480 | func NewRegisterRequest_List(s *capnp.Segment, sz int32) (RegisterRequest_List, error) { | ||
2052 | 481 | l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 8, PointerCount: 6}, sz) | ||
2053 | 482 | return RegisterRequest_List{l}, err | ||
2054 | 483 | } | ||
2055 | 484 | |||
2056 | 485 | func (s RegisterRequest_List) At(i int) RegisterRequest { return RegisterRequest{s.List.Struct(i)} } | ||
2057 | 486 | |||
2058 | 487 | func (s RegisterRequest_List) Set(i int, v RegisterRequest) error { | ||
2059 | 488 | return s.List.SetStruct(i, v.Struct) | ||
2060 | 489 | } | ||
2061 | 490 | |||
2062 | 491 | func (s RegisterRequest_List) String() string { | ||
2063 | 492 | str, _ := text.MarshalList(0x8a21a43d866e69f4, s.List) | ||
2064 | 493 | return str | ||
2065 | 494 | } | ||
2066 | 495 | |||
2067 | 496 | // RegisterRequest_Future is a wrapper for a RegisterRequest promised by a client call. | ||
2068 | 497 | type RegisterRequest_Future struct{ *capnp.Future } | ||
2069 | 498 | |||
2070 | 499 | func (p RegisterRequest_Future) Struct() (RegisterRequest, error) { | ||
2071 | 500 | s, err := p.Future.Struct() | ||
2072 | 501 | return RegisterRequest{s}, err | ||
2073 | 502 | } | ||
2074 | 503 | |||
2075 | 504 | func (p RegisterRequest_Future) Interfaces() Interfaces_Future { | ||
2076 | 505 | return Interfaces_Future{Future: p.Future.Field(2, nil)} | ||
2077 | 506 | } | ||
2078 | 507 | |||
2079 | 508 | type RegisterResponse struct{ capnp.Struct } | ||
2080 | 509 | |||
2081 | 510 | // RegisterResponse_TypeID is the unique identifier for the type RegisterResponse. | ||
2082 | 511 | const RegisterResponse_TypeID = 0x971fe28893233a11 | ||
2083 | 512 | |||
2084 | 513 | func NewRegisterResponse(s *capnp.Segment) (RegisterResponse, error) { | ||
2085 | 514 | st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 3}) | ||
2086 | 515 | return RegisterResponse{st}, err | ||
2087 | 516 | } | ||
2088 | 517 | |||
2089 | 518 | func NewRootRegisterResponse(s *capnp.Segment) (RegisterResponse, error) { | ||
2090 | 519 | st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 3}) | ||
2091 | 520 | return RegisterResponse{st}, err | ||
2092 | 521 | } | ||
2093 | 522 | |||
2094 | 523 | func ReadRootRegisterResponse(msg *capnp.Message) (RegisterResponse, error) { | ||
2095 | 524 | root, err := msg.Root() | ||
2096 | 525 | return RegisterResponse{root.Struct()}, err | ||
2097 | 526 | } | ||
2098 | 527 | |||
2099 | 528 | func (s RegisterResponse) String() string { | ||
2100 | 529 | str, _ := text.Marshal(0x971fe28893233a11, s.Struct) | ||
2101 | 530 | return str | ||
2102 | 531 | } | ||
2103 | 532 | |||
2104 | 533 | func (s RegisterResponse) SystemId() (string, error) { | ||
2105 | 534 | p, err := s.Struct.Ptr(0) | ||
2106 | 535 | return p.Text(), err | ||
2107 | 536 | } | ||
2108 | 537 | |||
2109 | 538 | func (s RegisterResponse) HasSystemId() bool { | ||
2110 | 539 | return s.Struct.HasPtr(0) | ||
2111 | 540 | } | ||
2112 | 541 | |||
2113 | 542 | func (s RegisterResponse) SystemIdBytes() ([]byte, error) { | ||
2114 | 543 | p, err := s.Struct.Ptr(0) | ||
2115 | 544 | return p.TextBytes(), err | ||
2116 | 545 | } | ||
2117 | 546 | |||
2118 | 547 | func (s RegisterResponse) SetSystemId(v string) error { | ||
2119 | 548 | return s.Struct.SetText(0, v) | ||
2120 | 549 | } | ||
2121 | 550 | |||
2122 | 551 | func (s RegisterResponse) Uuid() (string, error) { | ||
2123 | 552 | p, err := s.Struct.Ptr(1) | ||
2124 | 553 | return p.Text(), err | ||
2125 | 554 | } | ||
2126 | 555 | |||
2127 | 556 | func (s RegisterResponse) HasUuid() bool { | ||
2128 | 557 | return s.Struct.HasPtr(1) | ||
2129 | 558 | } | ||
2130 | 559 | |||
2131 | 560 | func (s RegisterResponse) UuidBytes() ([]byte, error) { | ||
2132 | 561 | p, err := s.Struct.Ptr(1) | ||
2133 | 562 | return p.TextBytes(), err | ||
2134 | 563 | } | ||
2135 | 564 | |||
2136 | 565 | func (s RegisterResponse) SetUuid(v string) error { | ||
2137 | 566 | return s.Struct.SetText(1, v) | ||
2138 | 567 | } | ||
2139 | 568 | |||
2140 | 569 | func (s RegisterResponse) Version() (string, error) { | ||
2141 | 570 | p, err := s.Struct.Ptr(2) | ||
2142 | 571 | return p.Text(), err | ||
2143 | 572 | } | ||
2144 | 573 | |||
2145 | 574 | func (s RegisterResponse) HasVersion() bool { | ||
2146 | 575 | return s.Struct.HasPtr(2) | ||
2147 | 576 | } | ||
2148 | 577 | |||
2149 | 578 | func (s RegisterResponse) VersionBytes() ([]byte, error) { | ||
2150 | 579 | p, err := s.Struct.Ptr(2) | ||
2151 | 580 | return p.TextBytes(), err | ||
2152 | 581 | } | ||
2153 | 582 | |||
2154 | 583 | func (s RegisterResponse) SetVersion(v string) error { | ||
2155 | 584 | return s.Struct.SetText(2, v) | ||
2156 | 585 | } | ||
2157 | 586 | |||
2158 | 587 | // RegisterResponse_List is a list of RegisterResponse. | ||
2159 | 588 | type RegisterResponse_List struct{ capnp.List } | ||
2160 | 589 | |||
2161 | 590 | // NewRegisterResponse creates a new list of RegisterResponse. | ||
2162 | 591 | func NewRegisterResponse_List(s *capnp.Segment, sz int32) (RegisterResponse_List, error) { | ||
2163 | 592 | l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 3}, sz) | ||
2164 | 593 | return RegisterResponse_List{l}, err | ||
2165 | 594 | } | ||
2166 | 595 | |||
2167 | 596 | func (s RegisterResponse_List) At(i int) RegisterResponse { return RegisterResponse{s.List.Struct(i)} } | ||
2168 | 597 | |||
2169 | 598 | func (s RegisterResponse_List) Set(i int, v RegisterResponse) error { | ||
2170 | 599 | return s.List.SetStruct(i, v.Struct) | ||
2171 | 600 | } | ||
2172 | 601 | |||
2173 | 602 | func (s RegisterResponse_List) String() string { | ||
2174 | 603 | str, _ := text.MarshalList(0x971fe28893233a11, s.List) | ||
2175 | 604 | return str | ||
2176 | 605 | } | ||
2177 | 606 | |||
2178 | 607 | // RegisterResponse_Future is a wrapper for a RegisterResponse promised by a client call. | ||
2179 | 608 | type RegisterResponse_Future struct{ *capnp.Future } | ||
2180 | 609 | |||
2181 | 610 | func (p RegisterResponse_Future) Struct() (RegisterResponse, error) { | ||
2182 | 611 | s, err := p.Future.Struct() | ||
2183 | 612 | return RegisterResponse{s}, err | ||
2184 | 613 | } | ||
2185 | 614 | |||
2186 | 615 | type Registerer struct{ Client *capnp.Client } | ||
2187 | 616 | |||
2188 | 617 | // Registerer_TypeID is the unique identifier for the type Registerer. | ||
2189 | 618 | const Registerer_TypeID = 0xe75723043cae2d20 | ||
2190 | 619 | |||
2191 | 620 | func (c Registerer) Register(ctx context.Context, params func(Registerer_register_Params) error) (Registerer_register_Results_Future, capnp.ReleaseFunc) { | ||
2192 | 621 | s := capnp.Send{ | ||
2193 | 622 | Method: capnp.Method{ | ||
2194 | 623 | InterfaceID: 0xe75723043cae2d20, | ||
2195 | 624 | MethodID: 0, | ||
2196 | 625 | InterfaceName: "handshake.capnp:Registerer", | ||
2197 | 626 | MethodName: "register", | ||
2198 | 627 | }, | ||
2199 | 628 | } | ||
2200 | 629 | if params != nil { | ||
2201 | 630 | s.ArgsSize = capnp.ObjectSize{DataSize: 0, PointerCount: 1} | ||
2202 | 631 | s.PlaceArgs = func(s capnp.Struct) error { return params(Registerer_register_Params{Struct: s}) } | ||
2203 | 632 | } | ||
2204 | 633 | ans, release := c.Client.SendCall(ctx, s) | ||
2205 | 634 | return Registerer_register_Results_Future{Future: ans.Future()}, release | ||
2206 | 635 | } | ||
2207 | 636 | |||
2208 | 637 | func (c Registerer) AddRef() Registerer { | ||
2209 | 638 | return Registerer{ | ||
2210 | 639 | Client: c.Client.AddRef(), | ||
2211 | 640 | } | ||
2212 | 641 | } | ||
2213 | 642 | |||
2214 | 643 | func (c Registerer) Release() { | ||
2215 | 644 | c.Client.Release() | ||
2216 | 645 | } | ||
2217 | 646 | |||
2218 | 647 | // A Registerer_Server is a Registerer with a local implementation. | ||
2219 | 648 | type Registerer_Server interface { | ||
2220 | 649 | Register(context.Context, Registerer_register) error | ||
2221 | 650 | } | ||
2222 | 651 | |||
2223 | 652 | // Registerer_NewServer creates a new Server from an implementation of Registerer_Server. | ||
2224 | 653 | func Registerer_NewServer(s Registerer_Server, policy *server.Policy) *server.Server { | ||
2225 | 654 | c, _ := s.(server.Shutdowner) | ||
2226 | 655 | return server.New(Registerer_Methods(nil, s), s, c, policy) | ||
2227 | 656 | } | ||
2228 | 657 | |||
2229 | 658 | // Registerer_ServerToClient creates a new Client from an implementation of Registerer_Server. | ||
2230 | 659 | // The caller is responsible for calling Release on the returned Client. | ||
2231 | 660 | func Registerer_ServerToClient(s Registerer_Server, policy *server.Policy) Registerer { | ||
2232 | 661 | return Registerer{Client: capnp.NewClient(Registerer_NewServer(s, policy))} | ||
2233 | 662 | } | ||
2234 | 663 | |||
2235 | 664 | // Registerer_Methods appends Methods to a slice that invoke the methods on s. | ||
2236 | 665 | // This can be used to create a more complicated Server. | ||
2237 | 666 | func Registerer_Methods(methods []server.Method, s Registerer_Server) []server.Method { | ||
2238 | 667 | if cap(methods) == 0 { | ||
2239 | 668 | methods = make([]server.Method, 0, 1) | ||
2240 | 669 | } | ||
2241 | 670 | |||
2242 | 671 | methods = append(methods, server.Method{ | ||
2243 | 672 | Method: capnp.Method{ | ||
2244 | 673 | InterfaceID: 0xe75723043cae2d20, | ||
2245 | 674 | MethodID: 0, | ||
2246 | 675 | InterfaceName: "handshake.capnp:Registerer", | ||
2247 | 676 | MethodName: "register", | ||
2248 | 677 | }, | ||
2249 | 678 | Impl: func(ctx context.Context, call *server.Call) error { | ||
2250 | 679 | return s.Register(ctx, Registerer_register{call}) | ||
2251 | 680 | }, | ||
2252 | 681 | }) | ||
2253 | 682 | |||
2254 | 683 | return methods | ||
2255 | 684 | } | ||
2256 | 685 | |||
2257 | 686 | // Registerer_register holds the state for a server call to Registerer.register. | ||
2258 | 687 | // See server.Call for documentation. | ||
2259 | 688 | type Registerer_register struct { | ||
2260 | 689 | *server.Call | ||
2261 | 690 | } | ||
2262 | 691 | |||
2263 | 692 | // Args returns the call's arguments. | ||
2264 | 693 | func (c Registerer_register) Args() Registerer_register_Params { | ||
2265 | 694 | return Registerer_register_Params{Struct: c.Call.Args()} | ||
2266 | 695 | } | ||
2267 | 696 | |||
2268 | 697 | // AllocResults allocates the results struct. | ||
2269 | 698 | func (c Registerer_register) AllocResults() (Registerer_register_Results, error) { | ||
2270 | 699 | r, err := c.Call.AllocResults(capnp.ObjectSize{DataSize: 0, PointerCount: 1}) | ||
2271 | 700 | return Registerer_register_Results{Struct: r}, err | ||
2272 | 701 | } | ||
2273 | 702 | |||
2274 | 703 | type Registerer_register_Params struct{ capnp.Struct } | ||
2275 | 704 | |||
2276 | 705 | // Registerer_register_Params_TypeID is the unique identifier for the type Registerer_register_Params. | ||
2277 | 706 | const Registerer_register_Params_TypeID = 0x80a0e6cbaa396ef4 | ||
2278 | 707 | |||
2279 | 708 | func NewRegisterer_register_Params(s *capnp.Segment) (Registerer_register_Params, error) { | ||
2280 | 709 | st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) | ||
2281 | 710 | return Registerer_register_Params{st}, err | ||
2282 | 711 | } | ||
2283 | 712 | |||
2284 | 713 | func NewRootRegisterer_register_Params(s *capnp.Segment) (Registerer_register_Params, error) { | ||
2285 | 714 | st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) | ||
2286 | 715 | return Registerer_register_Params{st}, err | ||
2287 | 716 | } | ||
2288 | 717 | |||
2289 | 718 | func ReadRootRegisterer_register_Params(msg *capnp.Message) (Registerer_register_Params, error) { | ||
2290 | 719 | root, err := msg.Root() | ||
2291 | 720 | return Registerer_register_Params{root.Struct()}, err | ||
2292 | 721 | } | ||
2293 | 722 | |||
2294 | 723 | func (s Registerer_register_Params) String() string { | ||
2295 | 724 | str, _ := text.Marshal(0x80a0e6cbaa396ef4, s.Struct) | ||
2296 | 725 | return str | ||
2297 | 726 | } | ||
2298 | 727 | |||
2299 | 728 | func (s Registerer_register_Params) Req() (RegisterRequest, error) { | ||
2300 | 729 | p, err := s.Struct.Ptr(0) | ||
2301 | 730 | return RegisterRequest{Struct: p.Struct()}, err | ||
2302 | 731 | } | ||
2303 | 732 | |||
2304 | 733 | func (s Registerer_register_Params) HasReq() bool { | ||
2305 | 734 | return s.Struct.HasPtr(0) | ||
2306 | 735 | } | ||
2307 | 736 | |||
2308 | 737 | func (s Registerer_register_Params) SetReq(v RegisterRequest) error { | ||
2309 | 738 | return s.Struct.SetPtr(0, v.Struct.ToPtr()) | ||
2310 | 739 | } | ||
2311 | 740 | |||
2312 | 741 | // NewReq sets the req field to a newly | ||
2313 | 742 | // allocated RegisterRequest struct, preferring placement in s's segment. | ||
2314 | 743 | func (s Registerer_register_Params) NewReq() (RegisterRequest, error) { | ||
2315 | 744 | ss, err := NewRegisterRequest(s.Struct.Segment()) | ||
2316 | 745 | if err != nil { | ||
2317 | 746 | return RegisterRequest{}, err | ||
2318 | 747 | } | ||
2319 | 748 | err = s.Struct.SetPtr(0, ss.Struct.ToPtr()) | ||
2320 | 749 | return ss, err | ||
2321 | 750 | } | ||
2322 | 751 | |||
2323 | 752 | // Registerer_register_Params_List is a list of Registerer_register_Params. | ||
2324 | 753 | type Registerer_register_Params_List struct{ capnp.List } | ||
2325 | 754 | |||
2326 | 755 | // NewRegisterer_register_Params creates a new list of Registerer_register_Params. | ||
2327 | 756 | func NewRegisterer_register_Params_List(s *capnp.Segment, sz int32) (Registerer_register_Params_List, error) { | ||
2328 | 757 | l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz) | ||
2329 | 758 | return Registerer_register_Params_List{l}, err | ||
2330 | 759 | } | ||
2331 | 760 | |||
2332 | 761 | func (s Registerer_register_Params_List) At(i int) Registerer_register_Params { | ||
2333 | 762 | return Registerer_register_Params{s.List.Struct(i)} | ||
2334 | 763 | } | ||
2335 | 764 | |||
2336 | 765 | func (s Registerer_register_Params_List) Set(i int, v Registerer_register_Params) error { | ||
2337 | 766 | return s.List.SetStruct(i, v.Struct) | ||
2338 | 767 | } | ||
2339 | 768 | |||
2340 | 769 | func (s Registerer_register_Params_List) String() string { | ||
2341 | 770 | str, _ := text.MarshalList(0x80a0e6cbaa396ef4, s.List) | ||
2342 | 771 | return str | ||
2343 | 772 | } | ||
2344 | 773 | |||
2345 | 774 | // Registerer_register_Params_Future is a wrapper for a Registerer_register_Params promised by a client call. | ||
2346 | 775 | type Registerer_register_Params_Future struct{ *capnp.Future } | ||
2347 | 776 | |||
2348 | 777 | func (p Registerer_register_Params_Future) Struct() (Registerer_register_Params, error) { | ||
2349 | 778 | s, err := p.Future.Struct() | ||
2350 | 779 | return Registerer_register_Params{s}, err | ||
2351 | 780 | } | ||
2352 | 781 | |||
2353 | 782 | func (p Registerer_register_Params_Future) Req() RegisterRequest_Future { | ||
2354 | 783 | return RegisterRequest_Future{Future: p.Future.Field(0, nil)} | ||
2355 | 784 | } | ||
2356 | 785 | |||
2357 | 786 | type Registerer_register_Results struct{ capnp.Struct } | ||
2358 | 787 | |||
2359 | 788 | // Registerer_register_Results_TypeID is the unique identifier for the type Registerer_register_Results. | ||
2360 | 789 | const Registerer_register_Results_TypeID = 0xb5c83b347e16691c | ||
2361 | 790 | |||
2362 | 791 | func NewRegisterer_register_Results(s *capnp.Segment) (Registerer_register_Results, error) { | ||
2363 | 792 | st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) | ||
2364 | 793 | return Registerer_register_Results{st}, err | ||
2365 | 794 | } | ||
2366 | 795 | |||
2367 | 796 | func NewRootRegisterer_register_Results(s *capnp.Segment) (Registerer_register_Results, error) { | ||
2368 | 797 | st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) | ||
2369 | 798 | return Registerer_register_Results{st}, err | ||
2370 | 799 | } | ||
2371 | 800 | |||
2372 | 801 | func ReadRootRegisterer_register_Results(msg *capnp.Message) (Registerer_register_Results, error) { | ||
2373 | 802 | root, err := msg.Root() | ||
2374 | 803 | return Registerer_register_Results{root.Struct()}, err | ||
2375 | 804 | } | ||
2376 | 805 | |||
2377 | 806 | func (s Registerer_register_Results) String() string { | ||
2378 | 807 | str, _ := text.Marshal(0xb5c83b347e16691c, s.Struct) | ||
2379 | 808 | return str | ||
2380 | 809 | } | ||
2381 | 810 | |||
2382 | 811 | func (s Registerer_register_Results) Resp() (RegisterResponse, error) { | ||
2383 | 812 | p, err := s.Struct.Ptr(0) | ||
2384 | 813 | return RegisterResponse{Struct: p.Struct()}, err | ||
2385 | 814 | } | ||
2386 | 815 | |||
2387 | 816 | func (s Registerer_register_Results) HasResp() bool { | ||
2388 | 817 | return s.Struct.HasPtr(0) | ||
2389 | 818 | } | ||
2390 | 819 | |||
2391 | 820 | func (s Registerer_register_Results) SetResp(v RegisterResponse) error { | ||
2392 | 821 | return s.Struct.SetPtr(0, v.Struct.ToPtr()) | ||
2393 | 822 | } | ||
2394 | 823 | |||
2395 | 824 | // NewResp sets the resp field to a newly | ||
2396 | 825 | // allocated RegisterResponse struct, preferring placement in s's segment. | ||
2397 | 826 | func (s Registerer_register_Results) NewResp() (RegisterResponse, error) { | ||
2398 | 827 | ss, err := NewRegisterResponse(s.Struct.Segment()) | ||
2399 | 828 | if err != nil { | ||
2400 | 829 | return RegisterResponse{}, err | ||
2401 | 830 | } | ||
2402 | 831 | err = s.Struct.SetPtr(0, ss.Struct.ToPtr()) | ||
2403 | 832 | return ss, err | ||
2404 | 833 | } | ||
2405 | 834 | |||
2406 | 835 | // Registerer_register_Results_List is a list of Registerer_register_Results. | ||
2407 | 836 | type Registerer_register_Results_List struct{ capnp.List } | ||
2408 | 837 | |||
2409 | 838 | // NewRegisterer_register_Results creates a new list of Registerer_register_Results. | ||
2410 | 839 | func NewRegisterer_register_Results_List(s *capnp.Segment, sz int32) (Registerer_register_Results_List, error) { | ||
2411 | 840 | l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz) | ||
2412 | 841 | return Registerer_register_Results_List{l}, err | ||
2413 | 842 | } | ||
2414 | 843 | |||
2415 | 844 | func (s Registerer_register_Results_List) At(i int) Registerer_register_Results { | ||
2416 | 845 | return Registerer_register_Results{s.List.Struct(i)} | ||
2417 | 846 | } | ||
2418 | 847 | |||
2419 | 848 | func (s Registerer_register_Results_List) Set(i int, v Registerer_register_Results) error { | ||
2420 | 849 | return s.List.SetStruct(i, v.Struct) | ||
2421 | 850 | } | ||
2422 | 851 | |||
2423 | 852 | func (s Registerer_register_Results_List) String() string { | ||
2424 | 853 | str, _ := text.MarshalList(0xb5c83b347e16691c, s.List) | ||
2425 | 854 | return str | ||
2426 | 855 | } | ||
2427 | 856 | |||
2428 | 857 | // Registerer_register_Results_Future is a wrapper for a Registerer_register_Results promised by a client call. | ||
2429 | 858 | type Registerer_register_Results_Future struct{ *capnp.Future } | ||
2430 | 859 | |||
2431 | 860 | func (p Registerer_register_Results_Future) Struct() (Registerer_register_Results, error) { | ||
2432 | 861 | s, err := p.Future.Struct() | ||
2433 | 862 | return Registerer_register_Results{s}, err | ||
2434 | 863 | } | ||
2435 | 864 | |||
2436 | 865 | func (p Registerer_register_Results_Future) Resp() RegisterResponse_Future { | ||
2437 | 866 | return RegisterResponse_Future{Future: p.Future.Field(0, nil)} | ||
2438 | 867 | } | ||
2439 | 868 | |||
2440 | 869 | const schema_dceab81b996ed67b = "x\xda\x8cTM\x88\x1cE\x18}\xaf\xaa\xbb'\x09\xbb" + | ||
2441 | 870 | "\xcc\x14=zI\xe2F\xb3\x07W\xd8%\x92\x04qU" + | ||
2442 | 871 | "6F%\xc9\xa2\xb8\xb51(\xb9uf\xca\xdd1;" + | ||
2443 | 872 | "=\x93\xae\x1e%\xc6\x9f\x10QTPQ\xc1?<\x08" + | ||
2444 | 873 | "\x8a\x82\x88z0\xa0\xa0\x12\xc1\xc0\x82\x04\x12\x10\x7f\xe2" + | ||
2445 | 874 | "^\xa2!J\xc0\x8b\xe4\xe2AZj\xdc\xe9\xe9L\x0c" + | ||
2446 | 875 | "\xd9[\xd7\xc7\xeb\xf7\xbd\xef\xbd\xaao\xd3Ub\x9b\xb8" + | ||
2447 | 876 | "\xd1\xbf)\x00\xf4N?\xc8^\xfc\xe6\xd0\xa3\x1f\xfc\xb6" + | ||
2448 | 877 | "\xe60TEf\x87~\x88\xdf\\\xfb\xf9\xf9%\x80!" + | ||
2449 | 878 | "\xe5_\xe1\xb0,\x01\xe1j\xb9#\xdc\xea\xbe\xb2\x0b\xf1" + | ||
2450 | 879 | "\xcd\x1f~w\xee\x9d\xc3Pk\x09\xf8,\x01\x9b\xd7\xcb" + | ||
2451 | 880 | "\xbd\x04\xc319\x05f\x17\x1a\xf13\xb7\xbdw\xed\xf3" + | ||
2452 | 881 | "\xd0\x15\xb2O\xe7\x07\x0e\xb9K\x0a\x86{\x1c\xd1f-" + | ||
2453 | 882 | "_\"\x98m?\xf8\xdcS\xe7\x1e;\xf6\x1a\xd459" + | ||
2454 | 883 | "\xdf\x9f\xde[\x8e\xef\x1f\xcf\xf1\xa9\xc9\x8d\xaf>\xfb\xeb" + | ||
2455 | 884 | "\xc8\xebP\x95\"]\x97c\xbd\xbf\x86\xe1\xb8\xef\x14\x8e" + | ||
2456 | 885 | "\xf9\x9f\x80\xd9\x99\xb3\x1b~<2\xf5\xe9\x1b\x03`\xe1" + | ||
2457 | 886 | "\x10\xc7\xfd\xf3\xe1\xa9.\xf6\x84\xff\x08\x98\xadk\\\xfd" + | ||
2458 | 887 | "\xc4\x96[\x16\x8f\x16'\x19\x0b\xf6\xb9\xce[\x03\xd7y" + | ||
2459 | 888 | "\xf7\xfb\xd9\xe9\xaf\xdf\xfd\xe8\x97\xa2\xb4=\xc1+\x0e`" + | ||
2460 | 889 | "\xba\x80\x0d\xe3\x1f\xdf\xeam\xbc\xff\xf7K\x8c{:8" + | ||
2461 | 890 | "\x1d\xbe\xec\x06\x0e_\x08v\x84_\x04%\xd4\xb2\xf9(" + | ||
2462 | 891 | "\xae\xdb\xf9h\xbf0\x13\xb5\xa8\x1d\xb7'o\xef\xa4\xf3" + | ||
2463 | 892 | "&N\x1b#\xb5(m%3\xa4\xf6\xa4\x0f\xe4m\xd9" + | ||
2464 | 893 | "\xb3F\xa9\x87 \xd4\xeaR\x16-\xff\x81r-J\xcd" + | ||
2465 | 894 | "6\xce\x909\xad\xd7\xa3\x9d5s\x0d\x9b\x9a\xc4$\x13" + | ||
2466 | 895 | "\xc9\xf2\xe7\xe8L\x94D\xb2i\xb5'=\xc0#\xa0\x86" + | ||
2467 | 896 | "\xaf\x03\xf4*I]\x15,%\xe6\x00+\xfd\xe0@V" + | ||
2468 | 897 | "\xd0g\x96\x83\xcc\xb3\xe6@\xc7\xd8\x14N\xf2\xba\x9c\xf1" + | ||
2469 | 898 | "\xe84\xa0?\x93\xd4\xc7\x04\x15Y\xa5+~\xe5\x8a_" + | ||
2470 | 899 | "J\xeaEA%D\x95\x02P\xc7\xf7\x02\xfa[I}" + | ||
2471 | 900 | "RPIY\xa5\x04\xd4\x09'hQR\x7f/\xa8<" + | ||
2472 | 901 | "\xafJ\x0fP\xa7f\x01}RR/\x09\xd2\xaf\xd2\x07" + | ||
2473 | 902 | "\xd4\xcf\x09\xa0\x7f\x92\xd4g\x05U\xe0W\x19\x00\xea\xcc" + | ||
2474 | 903 | "v@/I\xea?\x043{\xd0\xa6\xa6\xb9\xab\x0e\x80" + | ||
2475 | 904 | "C\x10\x1cr\xc3\xb4l\x1aGMS\xac5\xe2\xd4$" + | ||
2476 | 905 | "\x0fF5HcY\xc9\xee\x98~\xfc\xef{\xdf\xde\x7f" + | ||
2477 | 906 | "dy\xfeR'Y\xc8\xa1q\xabn\xe6\x92V\x07l" + | ||
2478 | 907 | "\xe7\xb5}&\xaa\xb5\xe2\xdd\x1d\x8c\xb4\xdb\xad$%!" + | ||
2479 | 908 | "H\xf0\xc9\x87Mb\x1b\xad\xb8\xdfz\xd9G\x7f0\xf8" + | ||
2480 | 909 | "n\xee\x13Q\xffdFg\x8d\xed,\xc8\xf4\xa2\xa4n" + | ||
2481 | 910 | "\xe8'UN\x8cm\xb3\xd2\xbf\xe6W\x8e\xca\xb6[\xb1" + | ||
2482 | 911 | "5\xe8\x865\x94\x93\xde\xe5r\xb9SR\xcf\x14\xc2\xba" + | ||
2483 | 912 | "\xc7u\xda)\xa9\xef+\x84\xa5\x9d\xb3wK\xea\x07\xfe" + | ||
2484 | 913 | "\xdf\xd9r\xa7\xd3\xa8\xf7\x0e\x97\x9d\xfd\xa2K\xefD\x95" + | ||
2485 | 914 | "\x9d*\xa7iU\xaei\xcc\xb5\x1f\x95\xd4\x9b\x0a\x9a\xc6" + | ||
2486 | 915 | "'\x01}\xbd\xa4\xde\"X\xb6\xd1B\xcaa\x08\x0e\x83" + | ||
2487 | 916 | "S\xf5\xc6\x9c\xb1\xf9qe\xef\xc0\xd9[Z\xb8\xa2\xbd" + | ||
2488 | 917 | "\xf9\xca\x19\xb0w%\x09\xba\xa7\xd6\xe4e\x9fZ\xd3\xce" + | ||
2489 | 918 | "]\"Y\x0cJ\x96\xa6\xb0\x0ez\x0b\x97\xbd}\xa5\xd4" + | ||
2490 | 919 | "\xf4\x7f\xeb\xa07\x16\x80\xee.\xf87\x00\x00\xff\xff\x86" + | ||
2491 | 920 | "\xdc\x84m" | ||
2492 | 921 | |||
2493 | 922 | func init() { | ||
2494 | 923 | schemas.Register(schema_dceab81b996ed67b, | ||
2495 | 924 | 0x800ae3a77a7bc18e, | ||
2496 | 925 | 0x80a0e6cbaa396ef4, | ||
2497 | 926 | 0x8a21a43d866e69f4, | ||
2498 | 927 | 0x96c07ce683897942, | ||
2499 | 928 | 0x971fe28893233a11, | ||
2500 | 929 | 0x98b03f82d720e4e1, | ||
2501 | 930 | 0xb5c83b347e16691c, | ||
2502 | 931 | 0xdbaca3bedaffa653, | ||
2503 | 932 | 0xe75723043cae2d20) | ||
2504 | 933 | } | ||
2505 | diff --git a/src/rackd_spike/pkg/rpc/network.capnp.go b/src/rackd_spike/pkg/rpc/network.capnp.go | |||
2506 | 0 | new file mode 100644 | 934 | new file mode 100644 |
2507 | index 0000000..4101c19 | |||
2508 | --- /dev/null | |||
2509 | +++ b/src/rackd_spike/pkg/rpc/network.capnp.go | |||
2510 | @@ -0,0 +1,489 @@ | |||
2511 | 1 | // Code generated by capnpc-go. DO NOT EDIT. | ||
2512 | 2 | |||
2513 | 3 | package rpc | ||
2514 | 4 | |||
2515 | 5 | import ( | ||
2516 | 6 | capnp "capnproto.org/go/capnp/v3" | ||
2517 | 7 | text "capnproto.org/go/capnp/v3/encoding/text" | ||
2518 | 8 | schemas "capnproto.org/go/capnp/v3/schemas" | ||
2519 | 9 | ) | ||
2520 | 10 | |||
2521 | 11 | type Link struct{ capnp.Struct } | ||
2522 | 12 | |||
2523 | 13 | // Link_TypeID is the unique identifier for the type Link. | ||
2524 | 14 | const Link_TypeID = 0xc7251b7c2c125e6e | ||
2525 | 15 | |||
2526 | 16 | func NewLink(s *capnp.Segment) (Link, error) { | ||
2527 | 17 | st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 3}) | ||
2528 | 18 | return Link{st}, err | ||
2529 | 19 | } | ||
2530 | 20 | |||
2531 | 21 | func NewRootLink(s *capnp.Segment) (Link, error) { | ||
2532 | 22 | st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 8, PointerCount: 3}) | ||
2533 | 23 | return Link{st}, err | ||
2534 | 24 | } | ||
2535 | 25 | |||
2536 | 26 | func ReadRootLink(msg *capnp.Message) (Link, error) { | ||
2537 | 27 | root, err := msg.Root() | ||
2538 | 28 | return Link{root.Struct()}, err | ||
2539 | 29 | } | ||
2540 | 30 | |||
2541 | 31 | func (s Link) String() string { | ||
2542 | 32 | str, _ := text.Marshal(0xc7251b7c2c125e6e, s.Struct) | ||
2543 | 33 | return str | ||
2544 | 34 | } | ||
2545 | 35 | |||
2546 | 36 | func (s Link) Mode() (string, error) { | ||
2547 | 37 | p, err := s.Struct.Ptr(0) | ||
2548 | 38 | return p.Text(), err | ||
2549 | 39 | } | ||
2550 | 40 | |||
2551 | 41 | func (s Link) HasMode() bool { | ||
2552 | 42 | return s.Struct.HasPtr(0) | ||
2553 | 43 | } | ||
2554 | 44 | |||
2555 | 45 | func (s Link) ModeBytes() ([]byte, error) { | ||
2556 | 46 | p, err := s.Struct.Ptr(0) | ||
2557 | 47 | return p.TextBytes(), err | ||
2558 | 48 | } | ||
2559 | 49 | |||
2560 | 50 | func (s Link) SetMode(v string) error { | ||
2561 | 51 | return s.Struct.SetText(0, v) | ||
2562 | 52 | } | ||
2563 | 53 | |||
2564 | 54 | func (s Link) Address() (string, error) { | ||
2565 | 55 | p, err := s.Struct.Ptr(1) | ||
2566 | 56 | return p.Text(), err | ||
2567 | 57 | } | ||
2568 | 58 | |||
2569 | 59 | func (s Link) HasAddress() bool { | ||
2570 | 60 | return s.Struct.HasPtr(1) | ||
2571 | 61 | } | ||
2572 | 62 | |||
2573 | 63 | func (s Link) AddressBytes() ([]byte, error) { | ||
2574 | 64 | p, err := s.Struct.Ptr(1) | ||
2575 | 65 | return p.TextBytes(), err | ||
2576 | 66 | } | ||
2577 | 67 | |||
2578 | 68 | func (s Link) SetAddress(v string) error { | ||
2579 | 69 | return s.Struct.SetText(1, v) | ||
2580 | 70 | } | ||
2581 | 71 | |||
2582 | 72 | func (s Link) Gateway() (string, error) { | ||
2583 | 73 | p, err := s.Struct.Ptr(2) | ||
2584 | 74 | return p.Text(), err | ||
2585 | 75 | } | ||
2586 | 76 | |||
2587 | 77 | func (s Link) HasGateway() bool { | ||
2588 | 78 | return s.Struct.HasPtr(2) | ||
2589 | 79 | } | ||
2590 | 80 | |||
2591 | 81 | func (s Link) GatewayBytes() ([]byte, error) { | ||
2592 | 82 | p, err := s.Struct.Ptr(2) | ||
2593 | 83 | return p.TextBytes(), err | ||
2594 | 84 | } | ||
2595 | 85 | |||
2596 | 86 | func (s Link) SetGateway(v string) error { | ||
2597 | 87 | return s.Struct.SetText(2, v) | ||
2598 | 88 | } | ||
2599 | 89 | |||
2600 | 90 | func (s Link) Netmask() int32 { | ||
2601 | 91 | return int32(s.Struct.Uint32(0)) | ||
2602 | 92 | } | ||
2603 | 93 | |||
2604 | 94 | func (s Link) SetNetmask(v int32) { | ||
2605 | 95 | s.Struct.SetUint32(0, uint32(v)) | ||
2606 | 96 | } | ||
2607 | 97 | |||
2608 | 98 | // Link_List is a list of Link. | ||
2609 | 99 | type Link_List struct{ capnp.List } | ||
2610 | 100 | |||
2611 | 101 | // NewLink creates a new list of Link. | ||
2612 | 102 | func NewLink_List(s *capnp.Segment, sz int32) (Link_List, error) { | ||
2613 | 103 | l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 8, PointerCount: 3}, sz) | ||
2614 | 104 | return Link_List{l}, err | ||
2615 | 105 | } | ||
2616 | 106 | |||
2617 | 107 | func (s Link_List) At(i int) Link { return Link{s.List.Struct(i)} } | ||
2618 | 108 | |||
2619 | 109 | func (s Link_List) Set(i int, v Link) error { return s.List.SetStruct(i, v.Struct) } | ||
2620 | 110 | |||
2621 | 111 | func (s Link_List) String() string { | ||
2622 | 112 | str, _ := text.MarshalList(0xc7251b7c2c125e6e, s.List) | ||
2623 | 113 | return str | ||
2624 | 114 | } | ||
2625 | 115 | |||
2626 | 116 | // Link_Future is a wrapper for a Link promised by a client call. | ||
2627 | 117 | type Link_Future struct{ *capnp.Future } | ||
2628 | 118 | |||
2629 | 119 | func (p Link_Future) Struct() (Link, error) { | ||
2630 | 120 | s, err := p.Future.Struct() | ||
2631 | 121 | return Link{s}, err | ||
2632 | 122 | } | ||
2633 | 123 | |||
2634 | 124 | type InterfaceDetails struct{ capnp.Struct } | ||
2635 | 125 | |||
2636 | 126 | // InterfaceDetails_TypeID is the unique identifier for the type InterfaceDetails. | ||
2637 | 127 | const InterfaceDetails_TypeID = 0xca5e2a006234f169 | ||
2638 | 128 | |||
2639 | 129 | func NewInterfaceDetails(s *capnp.Segment) (InterfaceDetails, error) { | ||
2640 | 130 | st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 16, PointerCount: 4}) | ||
2641 | 131 | return InterfaceDetails{st}, err | ||
2642 | 132 | } | ||
2643 | 133 | |||
2644 | 134 | func NewRootInterfaceDetails(s *capnp.Segment) (InterfaceDetails, error) { | ||
2645 | 135 | st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 16, PointerCount: 4}) | ||
2646 | 136 | return InterfaceDetails{st}, err | ||
2647 | 137 | } | ||
2648 | 138 | |||
2649 | 139 | func ReadRootInterfaceDetails(msg *capnp.Message) (InterfaceDetails, error) { | ||
2650 | 140 | root, err := msg.Root() | ||
2651 | 141 | return InterfaceDetails{root.Struct()}, err | ||
2652 | 142 | } | ||
2653 | 143 | |||
2654 | 144 | func (s InterfaceDetails) String() string { | ||
2655 | 145 | str, _ := text.Marshal(0xca5e2a006234f169, s.Struct) | ||
2656 | 146 | return str | ||
2657 | 147 | } | ||
2658 | 148 | |||
2659 | 149 | func (s InterfaceDetails) MacAddress() (string, error) { | ||
2660 | 150 | p, err := s.Struct.Ptr(0) | ||
2661 | 151 | return p.Text(), err | ||
2662 | 152 | } | ||
2663 | 153 | |||
2664 | 154 | func (s InterfaceDetails) HasMacAddress() bool { | ||
2665 | 155 | return s.Struct.HasPtr(0) | ||
2666 | 156 | } | ||
2667 | 157 | |||
2668 | 158 | func (s InterfaceDetails) MacAddressBytes() ([]byte, error) { | ||
2669 | 159 | p, err := s.Struct.Ptr(0) | ||
2670 | 160 | return p.TextBytes(), err | ||
2671 | 161 | } | ||
2672 | 162 | |||
2673 | 163 | func (s InterfaceDetails) SetMacAddress(v string) error { | ||
2674 | 164 | return s.Struct.SetText(0, v) | ||
2675 | 165 | } | ||
2676 | 166 | |||
2677 | 167 | func (s InterfaceDetails) Type() (string, error) { | ||
2678 | 168 | p, err := s.Struct.Ptr(1) | ||
2679 | 169 | return p.Text(), err | ||
2680 | 170 | } | ||
2681 | 171 | |||
2682 | 172 | func (s InterfaceDetails) HasType() bool { | ||
2683 | 173 | return s.Struct.HasPtr(1) | ||
2684 | 174 | } | ||
2685 | 175 | |||
2686 | 176 | func (s InterfaceDetails) TypeBytes() ([]byte, error) { | ||
2687 | 177 | p, err := s.Struct.Ptr(1) | ||
2688 | 178 | return p.TextBytes(), err | ||
2689 | 179 | } | ||
2690 | 180 | |||
2691 | 181 | func (s InterfaceDetails) SetType(v string) error { | ||
2692 | 182 | return s.Struct.SetText(1, v) | ||
2693 | 183 | } | ||
2694 | 184 | |||
2695 | 185 | func (s InterfaceDetails) Links() (Link_List, error) { | ||
2696 | 186 | p, err := s.Struct.Ptr(2) | ||
2697 | 187 | return Link_List{List: p.List()}, err | ||
2698 | 188 | } | ||
2699 | 189 | |||
2700 | 190 | func (s InterfaceDetails) HasLinks() bool { | ||
2701 | 191 | return s.Struct.HasPtr(2) | ||
2702 | 192 | } | ||
2703 | 193 | |||
2704 | 194 | func (s InterfaceDetails) SetLinks(v Link_List) error { | ||
2705 | 195 | return s.Struct.SetPtr(2, v.List.ToPtr()) | ||
2706 | 196 | } | ||
2707 | 197 | |||
2708 | 198 | // NewLinks sets the links field to a newly | ||
2709 | 199 | // allocated Link_List, preferring placement in s's segment. | ||
2710 | 200 | func (s InterfaceDetails) NewLinks(n int32) (Link_List, error) { | ||
2711 | 201 | l, err := NewLink_List(s.Struct.Segment(), n) | ||
2712 | 202 | if err != nil { | ||
2713 | 203 | return Link_List{}, err | ||
2714 | 204 | } | ||
2715 | 205 | err = s.Struct.SetPtr(2, l.List.ToPtr()) | ||
2716 | 206 | return l, err | ||
2717 | 207 | } | ||
2718 | 208 | |||
2719 | 209 | func (s InterfaceDetails) Vid() uint64 { | ||
2720 | 210 | return s.Struct.Uint64(0) | ||
2721 | 211 | } | ||
2722 | 212 | |||
2723 | 213 | func (s InterfaceDetails) SetVid(v uint64) { | ||
2724 | 214 | s.Struct.SetUint64(0, v) | ||
2725 | 215 | } | ||
2726 | 216 | |||
2727 | 217 | func (s InterfaceDetails) Enabled() bool { | ||
2728 | 218 | return s.Struct.Bit(64) | ||
2729 | 219 | } | ||
2730 | 220 | |||
2731 | 221 | func (s InterfaceDetails) SetEnabled(v bool) { | ||
2732 | 222 | s.Struct.SetBit(64, v) | ||
2733 | 223 | } | ||
2734 | 224 | |||
2735 | 225 | func (s InterfaceDetails) Parents() (capnp.TextList, error) { | ||
2736 | 226 | p, err := s.Struct.Ptr(3) | ||
2737 | 227 | return capnp.TextList{List: p.List()}, err | ||
2738 | 228 | } | ||
2739 | 229 | |||
2740 | 230 | func (s InterfaceDetails) HasParents() bool { | ||
2741 | 231 | return s.Struct.HasPtr(3) | ||
2742 | 232 | } | ||
2743 | 233 | |||
2744 | 234 | func (s InterfaceDetails) SetParents(v capnp.TextList) error { | ||
2745 | 235 | return s.Struct.SetPtr(3, v.List.ToPtr()) | ||
2746 | 236 | } | ||
2747 | 237 | |||
2748 | 238 | // NewParents sets the parents field to a newly | ||
2749 | 239 | // allocated capnp.TextList, preferring placement in s's segment. | ||
2750 | 240 | func (s InterfaceDetails) NewParents(n int32) (capnp.TextList, error) { | ||
2751 | 241 | l, err := capnp.NewTextList(s.Struct.Segment(), n) | ||
2752 | 242 | if err != nil { | ||
2753 | 243 | return capnp.TextList{}, err | ||
2754 | 244 | } | ||
2755 | 245 | err = s.Struct.SetPtr(3, l.List.ToPtr()) | ||
2756 | 246 | return l, err | ||
2757 | 247 | } | ||
2758 | 248 | |||
2759 | 249 | // InterfaceDetails_List is a list of InterfaceDetails. | ||
2760 | 250 | type InterfaceDetails_List struct{ capnp.List } | ||
2761 | 251 | |||
2762 | 252 | // NewInterfaceDetails creates a new list of InterfaceDetails. | ||
2763 | 253 | func NewInterfaceDetails_List(s *capnp.Segment, sz int32) (InterfaceDetails_List, error) { | ||
2764 | 254 | l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 16, PointerCount: 4}, sz) | ||
2765 | 255 | return InterfaceDetails_List{l}, err | ||
2766 | 256 | } | ||
2767 | 257 | |||
2768 | 258 | func (s InterfaceDetails_List) At(i int) InterfaceDetails { return InterfaceDetails{s.List.Struct(i)} } | ||
2769 | 259 | |||
2770 | 260 | func (s InterfaceDetails_List) Set(i int, v InterfaceDetails) error { | ||
2771 | 261 | return s.List.SetStruct(i, v.Struct) | ||
2772 | 262 | } | ||
2773 | 263 | |||
2774 | 264 | func (s InterfaceDetails_List) String() string { | ||
2775 | 265 | str, _ := text.MarshalList(0xca5e2a006234f169, s.List) | ||
2776 | 266 | return str | ||
2777 | 267 | } | ||
2778 | 268 | |||
2779 | 269 | // InterfaceDetails_Future is a wrapper for a InterfaceDetails promised by a client call. | ||
2780 | 270 | type InterfaceDetails_Future struct{ *capnp.Future } | ||
2781 | 271 | |||
2782 | 272 | func (p InterfaceDetails_Future) Struct() (InterfaceDetails, error) { | ||
2783 | 273 | s, err := p.Future.Struct() | ||
2784 | 274 | return InterfaceDetails{s}, err | ||
2785 | 275 | } | ||
2786 | 276 | |||
2787 | 277 | type Interface struct{ capnp.Struct } | ||
2788 | 278 | |||
2789 | 279 | // Interface_TypeID is the unique identifier for the type Interface. | ||
2790 | 280 | const Interface_TypeID = 0x929a2663d1c662e2 | ||
2791 | 281 | |||
2792 | 282 | func NewInterface(s *capnp.Segment) (Interface, error) { | ||
2793 | 283 | st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 2}) | ||
2794 | 284 | return Interface{st}, err | ||
2795 | 285 | } | ||
2796 | 286 | |||
2797 | 287 | func NewRootInterface(s *capnp.Segment) (Interface, error) { | ||
2798 | 288 | st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 2}) | ||
2799 | 289 | return Interface{st}, err | ||
2800 | 290 | } | ||
2801 | 291 | |||
2802 | 292 | func ReadRootInterface(msg *capnp.Message) (Interface, error) { | ||
2803 | 293 | root, err := msg.Root() | ||
2804 | 294 | return Interface{root.Struct()}, err | ||
2805 | 295 | } | ||
2806 | 296 | |||
2807 | 297 | func (s Interface) String() string { | ||
2808 | 298 | str, _ := text.Marshal(0x929a2663d1c662e2, s.Struct) | ||
2809 | 299 | return str | ||
2810 | 300 | } | ||
2811 | 301 | |||
2812 | 302 | func (s Interface) Name() (string, error) { | ||
2813 | 303 | p, err := s.Struct.Ptr(0) | ||
2814 | 304 | return p.Text(), err | ||
2815 | 305 | } | ||
2816 | 306 | |||
2817 | 307 | func (s Interface) HasName() bool { | ||
2818 | 308 | return s.Struct.HasPtr(0) | ||
2819 | 309 | } | ||
2820 | 310 | |||
2821 | 311 | func (s Interface) NameBytes() ([]byte, error) { | ||
2822 | 312 | p, err := s.Struct.Ptr(0) | ||
2823 | 313 | return p.TextBytes(), err | ||
2824 | 314 | } | ||
2825 | 315 | |||
2826 | 316 | func (s Interface) SetName(v string) error { | ||
2827 | 317 | return s.Struct.SetText(0, v) | ||
2828 | 318 | } | ||
2829 | 319 | |||
2830 | 320 | func (s Interface) Iface() (InterfaceDetails, error) { | ||
2831 | 321 | p, err := s.Struct.Ptr(1) | ||
2832 | 322 | return InterfaceDetails{Struct: p.Struct()}, err | ||
2833 | 323 | } | ||
2834 | 324 | |||
2835 | 325 | func (s Interface) HasIface() bool { | ||
2836 | 326 | return s.Struct.HasPtr(1) | ||
2837 | 327 | } | ||
2838 | 328 | |||
2839 | 329 | func (s Interface) SetIface(v InterfaceDetails) error { | ||
2840 | 330 | return s.Struct.SetPtr(1, v.Struct.ToPtr()) | ||
2841 | 331 | } | ||
2842 | 332 | |||
2843 | 333 | // NewIface sets the iface field to a newly | ||
2844 | 334 | // allocated InterfaceDetails struct, preferring placement in s's segment. | ||
2845 | 335 | func (s Interface) NewIface() (InterfaceDetails, error) { | ||
2846 | 336 | ss, err := NewInterfaceDetails(s.Struct.Segment()) | ||
2847 | 337 | if err != nil { | ||
2848 | 338 | return InterfaceDetails{}, err | ||
2849 | 339 | } | ||
2850 | 340 | err = s.Struct.SetPtr(1, ss.Struct.ToPtr()) | ||
2851 | 341 | return ss, err | ||
2852 | 342 | } | ||
2853 | 343 | |||
2854 | 344 | // Interface_List is a list of Interface. | ||
2855 | 345 | type Interface_List struct{ capnp.List } | ||
2856 | 346 | |||
2857 | 347 | // NewInterface creates a new list of Interface. | ||
2858 | 348 | func NewInterface_List(s *capnp.Segment, sz int32) (Interface_List, error) { | ||
2859 | 349 | l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 2}, sz) | ||
2860 | 350 | return Interface_List{l}, err | ||
2861 | 351 | } | ||
2862 | 352 | |||
2863 | 353 | func (s Interface_List) At(i int) Interface { return Interface{s.List.Struct(i)} } | ||
2864 | 354 | |||
2865 | 355 | func (s Interface_List) Set(i int, v Interface) error { return s.List.SetStruct(i, v.Struct) } | ||
2866 | 356 | |||
2867 | 357 | func (s Interface_List) String() string { | ||
2868 | 358 | str, _ := text.MarshalList(0x929a2663d1c662e2, s.List) | ||
2869 | 359 | return str | ||
2870 | 360 | } | ||
2871 | 361 | |||
2872 | 362 | // Interface_Future is a wrapper for a Interface promised by a client call. | ||
2873 | 363 | type Interface_Future struct{ *capnp.Future } | ||
2874 | 364 | |||
2875 | 365 | func (p Interface_Future) Struct() (Interface, error) { | ||
2876 | 366 | s, err := p.Future.Struct() | ||
2877 | 367 | return Interface{s}, err | ||
2878 | 368 | } | ||
2879 | 369 | |||
2880 | 370 | func (p Interface_Future) Iface() InterfaceDetails_Future { | ||
2881 | 371 | return InterfaceDetails_Future{Future: p.Future.Field(1, nil)} | ||
2882 | 372 | } | ||
2883 | 373 | |||
2884 | 374 | type Interfaces struct{ capnp.Struct } | ||
2885 | 375 | |||
2886 | 376 | // Interfaces_TypeID is the unique identifier for the type Interfaces. | ||
2887 | 377 | const Interfaces_TypeID = 0x826b9c4ff97d4a43 | ||
2888 | 378 | |||
2889 | 379 | func NewInterfaces(s *capnp.Segment) (Interfaces, error) { | ||
2890 | 380 | st, err := capnp.NewStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) | ||
2891 | 381 | return Interfaces{st}, err | ||
2892 | 382 | } | ||
2893 | 383 | |||
2894 | 384 | func NewRootInterfaces(s *capnp.Segment) (Interfaces, error) { | ||
2895 | 385 | st, err := capnp.NewRootStruct(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}) | ||
2896 | 386 | return Interfaces{st}, err | ||
2897 | 387 | } | ||
2898 | 388 | |||
2899 | 389 | func ReadRootInterfaces(msg *capnp.Message) (Interfaces, error) { | ||
2900 | 390 | root, err := msg.Root() | ||
2901 | 391 | return Interfaces{root.Struct()}, err | ||
2902 | 392 | } | ||
2903 | 393 | |||
2904 | 394 | func (s Interfaces) String() string { | ||
2905 | 395 | str, _ := text.Marshal(0x826b9c4ff97d4a43, s.Struct) | ||
2906 | 396 | return str | ||
2907 | 397 | } | ||
2908 | 398 | |||
2909 | 399 | func (s Interfaces) Ifaces() (Interface_List, error) { | ||
2910 | 400 | p, err := s.Struct.Ptr(0) | ||
2911 | 401 | return Interface_List{List: p.List()}, err | ||
2912 | 402 | } | ||
2913 | 403 | |||
2914 | 404 | func (s Interfaces) HasIfaces() bool { | ||
2915 | 405 | return s.Struct.HasPtr(0) | ||
2916 | 406 | } | ||
2917 | 407 | |||
2918 | 408 | func (s Interfaces) SetIfaces(v Interface_List) error { | ||
2919 | 409 | return s.Struct.SetPtr(0, v.List.ToPtr()) | ||
2920 | 410 | } | ||
2921 | 411 | |||
2922 | 412 | // NewIfaces sets the ifaces field to a newly | ||
2923 | 413 | // allocated Interface_List, preferring placement in s's segment. | ||
2924 | 414 | func (s Interfaces) NewIfaces(n int32) (Interface_List, error) { | ||
2925 | 415 | l, err := NewInterface_List(s.Struct.Segment(), n) | ||
2926 | 416 | if err != nil { | ||
2927 | 417 | return Interface_List{}, err | ||
2928 | 418 | } | ||
2929 | 419 | err = s.Struct.SetPtr(0, l.List.ToPtr()) | ||
2930 | 420 | return l, err | ||
2931 | 421 | } | ||
2932 | 422 | |||
2933 | 423 | // Interfaces_List is a list of Interfaces. | ||
2934 | 424 | type Interfaces_List struct{ capnp.List } | ||
2935 | 425 | |||
2936 | 426 | // NewInterfaces creates a new list of Interfaces. | ||
2937 | 427 | func NewInterfaces_List(s *capnp.Segment, sz int32) (Interfaces_List, error) { | ||
2938 | 428 | l, err := capnp.NewCompositeList(s, capnp.ObjectSize{DataSize: 0, PointerCount: 1}, sz) | ||
2939 | 429 | return Interfaces_List{l}, err | ||
2940 | 430 | } | ||
2941 | 431 | |||
2942 | 432 | func (s Interfaces_List) At(i int) Interfaces { return Interfaces{s.List.Struct(i)} } | ||
2943 | 433 | |||
2944 | 434 | func (s Interfaces_List) Set(i int, v Interfaces) error { return s.List.SetStruct(i, v.Struct) } | ||
2945 | 435 | |||
2946 | 436 | func (s Interfaces_List) String() string { | ||
2947 | 437 | str, _ := text.MarshalList(0x826b9c4ff97d4a43, s.List) | ||
2948 | 438 | return str | ||
2949 | 439 | } | ||
2950 | 440 | |||
2951 | 441 | // Interfaces_Future is a wrapper for a Interfaces promised by a client call. | ||
2952 | 442 | type Interfaces_Future struct{ *capnp.Future } | ||
2953 | 443 | |||
2954 | 444 | func (p Interfaces_Future) Struct() (Interfaces, error) { | ||
2955 | 445 | s, err := p.Future.Struct() | ||
2956 | 446 | return Interfaces{s}, err | ||
2957 | 447 | } | ||
2958 | 448 | |||
2959 | 449 | const schema_dae346a935a6f239 = "x\xda|\x921h\x14O\x18\xc5\xdf\x9b\xd9\xfb'\x81" + | ||
2960 | 450 | "\xfc/\xb7\xde\x15\x82\x85\"Q4\x18\x89\x1a\x0b\xd3$" + | ||
2961 | 451 | "F\x11\"\x82\xf9\x0a\x11D\x82\x93\xdb\xd1,w\xb79" + | ||
2962 | 452 | "\xee\x16C@9\x14,l\xad4\xa4PP\xd1\xde\xc2" + | ||
2963 | 453 | "@\x04#j \x9d\x9d\xd8\xa9\x88X\x89v\xda\xac\xcc" + | ||
2964 | 454 | "\x06\xf7\x16A\xbb\x9d\xc7o\xbf\xf7\xde|32\xc9\x09" + | ||
2965 | 455 | "u\xa0\xb0\xae\x00\xd9Q\xf8/9v\xf2\xea\x8f\xd3\xcb" + | ||
2966 | 456 | "\xb5\xeb\xf0\x8bL\x8e|\x7fx\xf8\xf1\x89\x8f\xefP`" + | ||
2967 | 457 | "\x0fP\x9e\xe2F\xf9L\xfa%\x1c\x07\x93\x0f\xb3\xaf\xdf" + | ||
2968 | 458 | "Tw/\xdd\xfa\x83U\x8e\xb8\xc6\x17\xe5\x9b){\x83" + | ||
2969 | 459 | "\x0b`\x12\xcdl\xd9we\xdb\xaeuH\x91yX;" + | ||
2970 | 460 | "\xe4=\x97\xca_R\xf8\x13?\x83_\xc3o\xa3\xb3C" + | ||
2971 | 461 | "3\x1bR\xa4\xca\xa1\x9e\x03V\xd4\xcf\xf2+\xe7ph" + | ||
2972 | 462 | "M\x9d%\x86\x93\xc8\xc6\x0b\xf3\xad\xda~U5\xcd\xa8" + | ||
2973 | 463 | "96\x15\xc5\xb6u\xd1Tm\x1b\x98&\xc5\xd3\x1e\xe0" + | ||
2974 | 464 | "\x11\xf0\xff\x1f\x03\xa4WS\x06\x15\xc7\xc3\x14a\x11\x9c" + | ||
2975 | 465 | "\xd6d\xa9[\x05t\xe2_\xa7\xa63{\xb3\x99{\x87" + | ||
2976 | 466 | "\x00\x19\xd4\x94\x11E\x9f\xac\xd0\x89\xc3\x07\x01\xd9\xa3)" + | ||
2977 | 467 | "\xa3\x8a\x03\x91iX\xf6C\xb1\x1f\xdc\x9e\xba\xb2\xf4\xbb" + | ||
2978 | 468 | "\x1f\xc8R\xce\x8b\x9b^\xa7B\x1d\xd5\x9cM)\xb31" + | ||
2979 | 469 | "\xce\xe6\xbc\xa6\xcc\xe5l\xec$ \x174\xa5\xae\xe8+" + | ||
2980 | 470 | "U\xa1\x02\xfc\xd0\x89\x81\xa64\x15\xa9+\xd4\x80\xdfp" + | ||
2981 | 471 | "\xda\x9c\xa6\xc4\x8a\x03\x8d\xf9 \xcb\xd31A\xd0\xb2\xed" + | ||
2982 | 472 | "vv\xbedb\xbb`\x16\xb3sd\xe3\x86i\xd7\xe8" + | ||
2983 | 473 | "A\xd1\xfb\xc7\xad\x1c\x1f\xb7\xb1\x09\xebm\x97zk\x96" + | ||
2984 | 474 | "\xfa\xce9@nk\xca\xfd\\\xea{\xae\xca\xb2\xa6<" + | ||
2985 | 475 | "\xca\xa5~\xe0n\xec\xae\xa6\xacvS\xaf\xec\x04\xe4\x89" + | ||
2986 | 476 | "\xa6<W\xf4\xbd\x89\x0a=\xc0\x7f\xe6\xaa<\xd5\x94\x97" + | ||
2987 | 477 | "\x8a~AWX\x00\xfc5'\xaej\xca[\xc5\xa4a" + | ||
2988 | 478 | "\xaaG]+\xe8n\xaf\x81x\xb1\xd9]B=\x8cj" + | ||
2989 | 479 | "\xb9\xcdg\x0fss\xf3=\x97\xc3\x80}P\xec\x03;" + | ||
2990 | 480 | "62\xb3u\x1b\x90P$\xd8i\x9a\x96\x8d\xe2\xecg" + | ||
2991 | 481 | "7\xb1\x08\xfe\x0a\x00\x00\xff\xff\x8c{\xba\xe7" | ||
2992 | 482 | |||
2993 | 483 | func init() { | ||
2994 | 484 | schemas.Register(schema_dae346a935a6f239, | ||
2995 | 485 | 0x826b9c4ff97d4a43, | ||
2996 | 486 | 0x929a2663d1c662e2, | ||
2997 | 487 | 0xc7251b7c2c125e6e, | ||
2998 | 488 | 0xca5e2a006234f169) | ||
2999 | 489 | } | ||
3000 | diff --git a/src/rpc/go.capnp b/src/rpc/go.capnp | |||
3001 | 0 | new file mode 100644 | 490 | new file mode 100644 |
3002 | index 0000000..4072b57 | |||
3003 | --- /dev/null | |||
3004 | +++ b/src/rpc/go.capnp | |||
3005 | @@ -0,0 +1,27 @@ | |||
3006 | 1 | @0xd12a1c51fedd6c88; | ||
3007 | 2 | |||
3008 | 3 | annotation package(file) :Text; | ||
3009 | 4 | # The Go package name for the generated file. | ||
3010 | 5 | |||
3011 | 6 | annotation import(file) :Text; | ||
3012 | 7 | # The Go import path that the generated file is accessible from. | ||
3013 | 8 | # Used to generate import statements and check if two types are in the | ||
3014 | 9 | # same package. | ||
3015 | 10 | |||
3016 | 11 | annotation doc(struct, field, enum) :Text; | ||
3017 | 12 | # Adds a doc comment to the generated code. | ||
3018 | 13 | |||
3019 | 14 | annotation tag(enumerant) :Text; | ||
3020 | 15 | # Changes the string representation of the enum in the generated code. | ||
3021 | 16 | |||
3022 | 17 | annotation notag(enumerant) :Void; | ||
3023 | 18 | # Removes the string representation of the enum in the generated code. | ||
3024 | 19 | |||
3025 | 20 | annotation customtype(field) :Text; | ||
3026 | 21 | # OBSOLETE, not used by code generator. | ||
3027 | 22 | |||
3028 | 23 | annotation name(struct, field, union, enum, enumerant, interface, method, param, annotation, const, group) :Text; | ||
3029 | 24 | # Used to rename the element in the generated code. | ||
3030 | 25 | |||
3031 | 26 | $package("gocp"); | ||
3032 | 27 | $import("capnproto.org/go/capnp/v3/std/go"); | ||
3033 | diff --git a/src/rpc/handshake.capnp b/src/rpc/handshake.capnp | |||
3034 | 0 | new file mode 100644 | 28 | new file mode 100644 |
3035 | index 0000000..dc87b67 | |||
3036 | --- /dev/null | |||
3037 | +++ b/src/rpc/handshake.capnp | |||
3038 | @@ -0,0 +1,36 @@ | |||
3039 | 1 | @0xdceab81b996ed67b; | ||
3040 | 2 | |||
3041 | 3 | using Go = import "go.capnp"; | ||
3042 | 4 | $Go.package("rpc"); | ||
3043 | 5 | $Go.import("rpc"); | ||
3044 | 6 | |||
3045 | 7 | using Network = import "network.capnp"; | ||
3046 | 8 | |||
3047 | 9 | struct AuthResponse { | ||
3048 | 10 | salt @0 :Data; | ||
3049 | 11 | digest @1 :Data; | ||
3050 | 12 | } | ||
3051 | 13 | |||
3052 | 14 | interface Authenticator { | ||
3053 | 15 | authenticate @0 (msg :Data) -> (resp :AuthResponse); | ||
3054 | 16 | } | ||
3055 | 17 | |||
3056 | 18 | struct RegisterRequest { | ||
3057 | 19 | systemId @0 :Text; | ||
3058 | 20 | hostname @1 :Text; | ||
3059 | 21 | interfaces @2 :Network.Interfaces; | ||
3060 | 22 | url @3 :Text; | ||
3061 | 23 | nodegroup @4 :Text; | ||
3062 | 24 | beaconSupport @5 :Bool; | ||
3063 | 25 | version @6 :Text; | ||
3064 | 26 | } | ||
3065 | 27 | |||
3066 | 28 | struct RegisterResponse { | ||
3067 | 29 | systemId @0 :Text; | ||
3068 | 30 | uuid @1 :Text; | ||
3069 | 31 | version @2 :Text; | ||
3070 | 32 | } | ||
3071 | 33 | |||
3072 | 34 | interface Registerer { | ||
3073 | 35 | register @0 (req :RegisterRequest) -> (resp :RegisterResponse); | ||
3074 | 36 | } | ||
3075 | diff --git a/src/rpc/network.capnp b/src/rpc/network.capnp | |||
3076 | 0 | new file mode 100644 | 37 | new file mode 100644 |
3077 | index 0000000..5e719c9 | |||
3078 | --- /dev/null | |||
3079 | +++ b/src/rpc/network.capnp | |||
3080 | @@ -0,0 +1,30 @@ | |||
3081 | 1 | @0xdae346a935a6f239; | ||
3082 | 2 | |||
3083 | 3 | using Go = import "go.capnp"; | ||
3084 | 4 | $Go.package("rpc"); | ||
3085 | 5 | $Go.import("rpc"); | ||
3086 | 6 | |||
3087 | 7 | struct Link { | ||
3088 | 8 | mode @0 :Text; | ||
3089 | 9 | address @1 :Text; | ||
3090 | 10 | gateway @2 :Text; | ||
3091 | 11 | netmask @3 :Int32; | ||
3092 | 12 | } | ||
3093 | 13 | |||
3094 | 14 | struct InterfaceDetails { | ||
3095 | 15 | macAddress @0 :Text; | ||
3096 | 16 | type @1 :Text; | ||
3097 | 17 | links @2 :List(Link); | ||
3098 | 18 | vid @3 :UInt64; | ||
3099 | 19 | enabled @4 :Bool; | ||
3100 | 20 | parents @5 :List(Text); | ||
3101 | 21 | } | ||
3102 | 22 | |||
3103 | 23 | struct Interface { | ||
3104 | 24 | name @0 :Text; | ||
3105 | 25 | iface @1 :InterfaceDetails; | ||
3106 | 26 | } | ||
3107 | 27 | |||
3108 | 28 | struct Interfaces { | ||
3109 | 29 | ifaces @0 :List(Interface); | ||
3110 | 30 | } |
UNIT TESTS exploration lp:~maas-committers/maas
-b rpc_client_server lp:~cgrabowski/maas/+git/maas into -b rack_region_
STATUS: SUCCESS 6ac5a4d5130940e 457ccd5ed9
COMMIT: b8a28beb8353fa6