forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
78 lines (69 loc) · 2.04 KB
/
client.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package caasapplication
import (
"github.com/juju/names/v4"
"github.com/DavinZhang/juju/api/base"
"github.com/DavinZhang/juju/apiserver/params"
)
// Client allows access to the CAAS operator API endpoint.
type Client struct {
base.ClientFacade
facade base.FacadeCaller
}
// NewClient returns a client used to access the CAAS Operator API.
func NewClient(caller base.APICallCloser) *Client {
frontend, backend := base.NewClientFacade(caller, "CAASApplication")
return &Client{
ClientFacade: frontend,
facade: backend,
}
}
type UnitConfig struct {
UnitTag names.UnitTag
AgentConf []byte
}
// UnitIntroduction introduces the unit and returns an agent config.
func (c *Client) UnitIntroduction(podName string, podUUID string) (*UnitConfig, error) {
var result params.CAASUnitIntroductionResult
args := params.CAASUnitIntroductionArgs{
PodName: podName,
PodUUID: podUUID,
}
err := c.facade.FacadeCall("UnitIntroduction", args, &result)
if err != nil {
return nil, err
}
if err := result.Error; err != nil {
return nil, err
}
return &UnitConfig{
UnitTag: names.NewUnitTag(result.Result.UnitName),
AgentConf: result.Result.AgentConf,
}, nil
}
// UnitTermination holds the result from calling UnitTerminating.
type UnitTermination struct {
// WillRestart is true when the unit agent should restart.
// It will be false when the unit is dying and should shutdown normally.
WillRestart bool
}
// UnitTerminating is to be called by the CAASUnitTerminationWorker when the uniter is
// shutting down.
func (c *Client) UnitTerminating(unit names.UnitTag) (UnitTermination, error) {
var result params.CAASUnitTerminationResult
args := params.Entity{
Tag: unit.String(),
}
err := c.facade.FacadeCall("UnitTerminating", args, &result)
if err != nil {
return UnitTermination{}, err
}
if err := result.Error; err != nil {
return UnitTermination{}, err
}
term := UnitTermination{
WillRestart: result.WillRestart,
}
return term, nil
}