-
Notifications
You must be signed in to change notification settings - Fork 286
/
cloudstackdatacenterconfig.go
70 lines (60 loc) · 1.84 KB
/
cloudstackdatacenterconfig.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
package v1alpha1
import (
"fmt"
"net/url"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const CloudStackDatacenterKind = "CloudStackDatacenterConfig"
// Used for generating yaml for generate clusterconfig command.
func NewCloudStackDatacenterConfigGenerate(clusterName string) *CloudStackDatacenterConfigGenerate {
return &CloudStackDatacenterConfigGenerate{
TypeMeta: metav1.TypeMeta{
Kind: CloudStackDatacenterKind,
APIVersion: SchemeBuilder.GroupVersion.String(),
},
ObjectMeta: ObjectMeta{
Name: clusterName,
},
Spec: CloudStackDatacenterConfigSpec{
AvailabilityZones: []CloudStackAvailabilityZone{
{
Name: "az-1",
Zone: CloudStackZone{
Network: CloudStackResourceIdentifier{},
},
CredentialsRef: "global",
Account: "admin",
Domain: "domain1",
},
},
},
}
}
func (c *CloudStackDatacenterConfigGenerate) APIVersion() string {
return c.TypeMeta.APIVersion
}
func (c *CloudStackDatacenterConfigGenerate) Kind() string {
return c.TypeMeta.Kind
}
func (c *CloudStackDatacenterConfigGenerate) Name() string {
return c.ObjectMeta.Name
}
func GetCloudStackDatacenterConfig(fileName string) (*CloudStackDatacenterConfig, error) {
var clusterConfig CloudStackDatacenterConfig
err := ParseClusterConfig(fileName, &clusterConfig)
if err != nil {
return nil, err
}
return &clusterConfig, nil
}
// GetCloudStackManagementAPIEndpointHostname parses the CloudStackAvailabilityZone's ManagementApiEndpoint URL and returns the hostname.
func GetCloudStackManagementAPIEndpointHostname(az CloudStackAvailabilityZone) (string, error) {
return getHostnameFromURL(az.ManagementApiEndpoint)
}
func getHostnameFromURL(rawurl string) (string, error) {
url, err := url.Parse(rawurl)
if err != nil {
return "", fmt.Errorf("%s is not a valid url", rawurl)
}
return url.Hostname(), nil
}