/
api_ready.go
63 lines (51 loc) · 1.36 KB
/
api_ready.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package apstra
import (
"context"
"fmt"
)
// ready tests whether an Apstra server is ready to handle client requests.
// It's based on a code sample shared by JP Senior
// https://apstra-eng.slack.com/archives/C2DFCFHJR/p1674246878325579?thread_ts=1674244723.467159&cid=C2DFCFHJR
func (o *Client) ready(ctx context.Context) error {
var err error
_, err = o.getVersion(ctx)
if err != nil {
return fmt.Errorf("error getting Version - %w", err)
}
_, err = o.listSystems(ctx)
if err != nil {
return fmt.Errorf("error listing Systems - %w", err)
}
_, err = o.getAllBlueprintStatus(ctx)
if err != nil {
return fmt.Errorf("error listing Blueprints - %w", err)
}
_, err = o.getAllSystemAgents(ctx)
if err != nil {
return fmt.Errorf("error getting System Agents - %w", err)
}
_, err = o.getAuditConfig(ctx)
if err != nil {
return fmt.Errorf("error getting Audit Config- %w", err)
}
_, err = o.getAsnPools(ctx)
if err != nil {
return fmt.Errorf("error getting ASN Pools - %w", err)
}
_, err = o.getTelemetryQuery(ctx)
if err != nil {
return fmt.Errorf("error getting Telemetry Query - %w", err)
}
return nil
}
// waitUntilReady calls ready() until it returns without error or the supplied
// context is cancelled.
func (o *Client) waitUntilReady(ctx context.Context) error {
for {
err := o.ready(ctx)
if err != nil {
break
}
}
return nil
}