package gcp import ( "context" compute "google.golang.org/api/compute/v1" container "google.golang.org/api/container/v1" "edge-infra.dev/pkg/edge/api/types" ) type computeService struct { Client *compute.Service ProjectID string } type containerService struct { Client *container.Service ProjectID string } // NewCompute returns a new gcp compute client func NewCompute(ctx context.Context, projectID string) (types.ComputeService, error) { computeClient, err := compute.NewService(ctx) if err != nil { return nil, err } return &computeService{ Client: computeClient, ProjectID: projectID, }, nil } // NewContainer returns a new gcp container client func NewContainer(ctx context.Context, projectID string) (types.ContainerService, error) { containerClient, err := container.NewService(ctx) if err != nil { return nil, err } return &containerService{ Client: containerClient, ProjectID: projectID, }, nil } // GetZones returns the available zones filtered by US func (s *computeService) GetZones(ctx context.Context) (*compute.ZoneList, error) { zoneList, err := s.Client.Zones.List(s.ProjectID).Filter("name:us-*").Context(ctx).Do() return zoneList, err } // GetMachineTypes returns the available machine types for a given zone func (s *computeService) GetMachineTypes(ctx context.Context, zone string) (*compute.MachineTypeList, error) { return s.Client.MachineTypes.List(s.ProjectID, zone).Context(ctx).Do() } // GetMachineType returns the machine type of a given vm func (s *computeService) GetMachineType(ctx context.Context, zone, machineType string) (*compute.MachineType, error) { return s.Client.MachineTypes.Get(s.ProjectID, zone, machineType).Context(ctx).Do() } // GetServerConfig returns the server config of a given project zone func (s *containerService) GetServerConfig(ctx context.Context, zone string) (*container.ServerConfig, error) { return s.Client.Projects.Zones.GetServerconfig(s.ProjectID, zone).Context(ctx).Do() }