forked from pachyderm/pachyderm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
google.go
44 lines (39 loc) · 870 Bytes
/
google.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
package provider
import (
"fmt"
"golang.org/x/net/context"
"golang.org/x/oauth2/google"
"google.golang.org/api/compute/v1"
)
type googleProvider struct {
service *compute.Service
project string
zone string
}
func newGoogleProvider(ctx context.Context, project string, zone string) (*googleProvider, error) {
httpClient, err := google.DefaultClient(ctx, compute.ComputeScope)
if err != nil {
return nil, err
}
service, err := compute.New(httpClient)
if err != nil {
return nil, err
}
return &googleProvider{
service: service,
project: project,
zone: zone,
}, nil
}
func (p *googleProvider) CreateDisk(name string, sizeGb int64) error {
_, err := p.service.Disks.Insert(
p.project,
p.zone,
&compute.Disk{
Name: name,
SizeGb: sizeGb,
Type: fmt.Sprintf("zones/%s/diskTypes/pd-ssd", p.zone),
},
).Do()
return err
}