...
1 package gcp
2
3 import (
4 "context"
5
6 compute "google.golang.org/api/compute/v1"
7 container "google.golang.org/api/container/v1"
8
9 "edge-infra.dev/pkg/edge/api/types"
10 )
11
12 type computeService struct {
13 Client *compute.Service
14 ProjectID string
15 }
16
17 type containerService struct {
18 Client *container.Service
19 ProjectID string
20 }
21
22
23 func NewCompute(ctx context.Context, projectID string) (types.ComputeService, error) {
24 computeClient, err := compute.NewService(ctx)
25 if err != nil {
26 return nil, err
27 }
28
29 return &computeService{
30 Client: computeClient,
31 ProjectID: projectID,
32 }, nil
33 }
34
35
36 func NewContainer(ctx context.Context, projectID string) (types.ContainerService, error) {
37 containerClient, err := container.NewService(ctx)
38 if err != nil {
39 return nil, err
40 }
41
42 return &containerService{
43 Client: containerClient,
44 ProjectID: projectID,
45 }, nil
46 }
47
48
49 func (s *computeService) GetZones(ctx context.Context) (*compute.ZoneList, error) {
50 zoneList, err := s.Client.Zones.List(s.ProjectID).Filter("name:us-*").Context(ctx).Do()
51 return zoneList, err
52 }
53
54
55 func (s *computeService) GetMachineTypes(ctx context.Context, zone string) (*compute.MachineTypeList, error) {
56 return s.Client.MachineTypes.List(s.ProjectID, zone).Context(ctx).Do()
57 }
58
59
60 func (s *computeService) GetMachineType(ctx context.Context, zone, machineType string) (*compute.MachineType, error) {
61 return s.Client.MachineTypes.Get(s.ProjectID, zone, machineType).Context(ctx).Do()
62 }
63
64
65 func (s *containerService) GetServerConfig(ctx context.Context, zone string) (*container.ServerConfig, error) {
66 return s.Client.Projects.Zones.GetServerconfig(s.ProjectID, zone).Context(ctx).Do()
67 }
68
View as plain text