-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
72 lines (60 loc) · 1.87 KB
/
metadata.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
package cloud
import (
"k8s.io/klog/v2"
"sync"
)
var (
metadataInsOnce sync.Once
metadataIns MetadataService
)
type (
Metadata struct {
UUID string `json:"uuid"`
Name string `json:"name"`
ProjectID string `json:"project_id"`
AvailabilityZone string `json:"availability_zone"`
Devices []DeviceMetadata `json:"devices,omitempty"`
}
VServerMetadata struct {
UUID string `json:"uuid"`
Name string `json:"name"`
AvailabilityZone string `json:"availability_zone"`
ProjectID string `json:"project_id"`
Devices []DeviceMetadata `json:"devices,omitempty"`
Meta Meta `json:"meta,omitempty"`
// ... and other fields we don't care about. Expand as necessary.
}
DeviceMetadata struct {
Type string `json:"type"`
Bus string `json:"bus,omitempty"`
Serial string `json:"serial,omitempty"`
Address string `json:"address,omitempty"`
// ... and other fields.
}
Meta struct {
Product string `json:"product,omitempty"`
PortalUUID string `json:"portal_uuid,omitempty"`
ProjectID string `json:"project_id,omitempty"`
}
)
func (s *Metadata) GetInstanceID() string {
return s.UUID
}
func (s *Metadata) GetProjectID() string {
return s.ProjectID
}
func (s *Metadata) GetAvailabilityZone() string {
return s.AvailabilityZone
}
func (s *VServerMetadata) GetMetadata() *VServerMetadata {
return s
}
func NewMetadataService(vserverMetadataClient VServerMetadataClient) (MetadataService, error) {
klog.InfoS("[INFO] - NewMetadataService: Retrieving instance data from metadata service")
svc, err := vserverMetadataClient()
if err != nil {
klog.InfoS("error creating vServer metadata client", "err", err)
return nil, err
}
return VServerMetadataInstanceInfo(svc)
}