Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
8b6b81c7
Commit
8b6b81c7
authored
Aug 27, 2018
by
Yang Guo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GCE: Add ListLocations to Cloud TPU API
parent
3da79f5c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
9 deletions
+22
-9
gce_tpu.go
pkg/cloudprovider/providers/gce/gce_tpu.go
+22
-9
No files found.
pkg/cloudprovider/providers/gce/gce_tpu.go
View file @
8b6b81c7
...
...
@@ -38,16 +38,14 @@ func newTPUService(client *http.Client) (*tpuService, error) {
return
nil
,
err
}
return
&
tpuService
{
nodesService
:
tpuapi
.
NewProjectsLocationsNodesService
(
s
),
operationsService
:
tpuapi
.
NewProjectsLocationsOperationsService
(
s
),
projects
:
tpuapi
.
NewProjectsService
(
s
),
},
nil
}
// tpuService encapsulates the TPU services on nodes and the operations on the
// nodes.
type
tpuService
struct
{
nodesService
*
tpuapi
.
ProjectsLocationsNodesService
operationsService
*
tpuapi
.
ProjectsLocationsOperationsService
projects
*
tpuapi
.
ProjectsService
}
// CreateTPU creates the Cloud TPU node with the specified name in the
...
...
@@ -59,7 +57,7 @@ func (gce *GCECloud) CreateTPU(ctx context.Context, name, zone string, node *tpu
var
op
*
tpuapi
.
Operation
parent
:=
getTPUParentName
(
gce
.
projectID
,
zone
)
op
,
err
=
gce
.
tpuService
.
nodesService
.
Create
(
parent
,
node
)
.
NodeId
(
name
)
.
Do
()
op
,
err
=
gce
.
tpuService
.
projects
.
Locations
.
Nodes
.
Create
(
parent
,
node
)
.
NodeId
(
name
)
.
Do
()
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -92,7 +90,7 @@ func (gce *GCECloud) DeleteTPU(ctx context.Context, name, zone string) error {
var
op
*
tpuapi
.
Operation
name
=
getTPUName
(
gce
.
projectID
,
zone
,
name
)
op
,
err
=
gce
.
tpuService
.
nodesService
.
Delete
(
name
)
.
Do
()
op
,
err
=
gce
.
tpuService
.
projects
.
Locations
.
Nodes
.
Delete
(
name
)
.
Do
()
if
err
!=
nil
{
return
err
}
...
...
@@ -114,7 +112,7 @@ func (gce *GCECloud) GetTPU(ctx context.Context, name, zone string) (*tpuapi.Nod
mc
:=
newTPUMetricContext
(
"get"
,
zone
)
name
=
getTPUName
(
gce
.
projectID
,
zone
,
name
)
node
,
err
:=
gce
.
tpuService
.
nodesService
.
Get
(
name
)
.
Do
()
node
,
err
:=
gce
.
tpuService
.
projects
.
Locations
.
Nodes
.
Get
(
name
)
.
Do
()
if
err
!=
nil
{
return
nil
,
mc
.
Observe
(
err
)
}
...
...
@@ -126,13 +124,24 @@ func (gce *GCECloud) ListTPUs(ctx context.Context, zone string) ([]*tpuapi.Node,
mc
:=
newTPUMetricContext
(
"list"
,
zone
)
parent
:=
getTPUParentName
(
gce
.
projectID
,
zone
)
response
,
err
:=
gce
.
tpuService
.
nodesService
.
List
(
parent
)
.
Do
()
response
,
err
:=
gce
.
tpuService
.
projects
.
Locations
.
Nodes
.
List
(
parent
)
.
Do
()
if
err
!=
nil
{
return
nil
,
mc
.
Observe
(
err
)
}
return
response
.
Nodes
,
mc
.
Observe
(
nil
)
}
// ListLocations returns the zones where Cloud TPUs are available.
func
(
gce
*
GCECloud
)
ListLocations
(
ctx
context
.
Context
)
([]
*
tpuapi
.
Location
,
error
)
{
mc
:=
newTPUMetricContext
(
"list_locations"
,
""
)
parent
:=
getTPUProjectURL
(
gce
.
projectID
)
response
,
err
:=
gce
.
tpuService
.
projects
.
Locations
.
List
(
parent
)
.
Do
()
if
err
!=
nil
{
return
nil
,
mc
.
Observe
(
err
)
}
return
response
.
Locations
,
mc
.
Observe
(
nil
)
}
// waitForTPUOp checks whether the op is done every 30 seconds before the ctx
// is cancelled.
func
(
gce
*
GCECloud
)
waitForTPUOp
(
ctx
context
.
Context
,
op
*
tpuapi
.
Operation
)
(
*
tpuapi
.
Operation
,
error
)
{
...
...
@@ -155,7 +164,7 @@ func (gce *GCECloud) waitForTPUOp(ctx context.Context, op *tpuapi.Operation) (*t
}
var
err
error
op
,
err
=
gce
.
tpuService
.
operationsService
.
Get
(
op
.
Name
)
.
Do
()
op
,
err
=
gce
.
tpuService
.
projects
.
Locations
.
Operations
.
Get
(
op
.
Name
)
.
Do
()
if
err
!=
nil
{
return
true
,
err
}
...
...
@@ -188,6 +197,10 @@ func getErrorFromTPUOp(op *tpuapi.Operation) error {
return
nil
}
func
getTPUProjectURL
(
project
string
)
string
{
return
fmt
.
Sprintf
(
"projects/%s"
,
project
)
}
func
getTPUParentName
(
project
,
zone
string
)
string
{
return
fmt
.
Sprintf
(
"projects/%s/locations/%s"
,
project
,
zone
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment