forked from rancher/external-dns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cattle.go
44 lines (37 loc) · 1.04 KB
/
cattle.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
package main
import (
"github.com/rancher/external-dns/utils"
rancher "github.com/rancher/go-rancher/v2"
)
type CattleClient struct {
rancherClient *rancher.RancherClient
}
func NewCattleClient(cattleUrl string, accessKey string, secretKey string) (*CattleClient, error) {
client, err := rancher.NewRancherClient(&rancher.ClientOpts{
Url: cattleUrl,
AccessKey: accessKey,
SecretKey: secretKey,
})
if err != nil {
return nil, err
}
return &CattleClient{
rancherClient: client,
}, nil
}
func (c *CattleClient) UpdateServiceDomainName(serviceDnsRecord utils.ServiceDnsRecord) error {
event := &rancher.ExternalDnsEvent{
EventType: "dns.update",
ExternalId: serviceDnsRecord.Fqdn,
ServiceName: serviceDnsRecord.ServiceName,
StackName: serviceDnsRecord.StackName,
Fqdn: serviceDnsRecord.Fqdn,
}
_, err := c.rancherClient.ExternalDnsEvent.Create(event)
return err
}
func (c *CattleClient) TestConnect() error {
opts := &rancher.ListOpts{}
_, err := c.rancherClient.ExternalDnsEvent.List(opts)
return err
}