forked from rancher/rke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws.go
53 lines (44 loc) · 1.05 KB
/
aws.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
package aws
import (
"bytes"
"fmt"
"github.com/go-ini/ini"
"github.com/rancher/types/apis/management.cattle.io/v3"
)
const (
AWSCloudProviderName = "aws"
AWSConfig = "AWSConfig"
)
type CloudProvider struct {
Config *v3.AWSCloudProvider
Name string
}
func GetInstance() *CloudProvider {
return &CloudProvider{}
}
func (p *CloudProvider) Init(cloudProviderConfig v3.CloudProvider) error {
p.Name = AWSCloudProviderName
if cloudProviderConfig.AWSCloudProvider == nil {
return nil
}
p.Config = cloudProviderConfig.AWSCloudProvider
return nil
}
func (p *CloudProvider) GetName() string {
return p.Name
}
func (p *CloudProvider) GenerateCloudConfigFile() (string, error) {
if p.Config == nil {
return "", nil
}
// Generate INI style configuration
buf := new(bytes.Buffer)
cloudConfig := ini.Empty()
if err := ini.ReflectFrom(cloudConfig, p.Config); err != nil {
return "", fmt.Errorf("Failed to parse Openstack cloud config")
}
if _, err := cloudConfig.WriteTo(buf); err != nil {
return "", err
}
return buf.String(), nil
}