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) {
...
@@ -38,16 +38,14 @@ func newTPUService(client *http.Client) (*tpuService, error) {
return
nil
,
err
return
nil
,
err
}
}
return
&
tpuService
{
return
&
tpuService
{
nodesService
:
tpuapi
.
NewProjectsLocationsNodesService
(
s
),
projects
:
tpuapi
.
NewProjectsService
(
s
),
operationsService
:
tpuapi
.
NewProjectsLocationsOperationsService
(
s
),
},
nil
},
nil
}
}
// tpuService encapsulates the TPU services on nodes and the operations on the
// tpuService encapsulates the TPU services on nodes and the operations on the
// nodes.
// nodes.
type
tpuService
struct
{
type
tpuService
struct
{
nodesService
*
tpuapi
.
ProjectsLocationsNodesService
projects
*
tpuapi
.
ProjectsService
operationsService
*
tpuapi
.
ProjectsLocationsOperationsService
}
}
// CreateTPU creates the Cloud TPU node with the specified name in the
// 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
...
@@ -59,7 +57,7 @@ func (gce *GCECloud) CreateTPU(ctx context.Context, name, zone string, node *tpu
var
op
*
tpuapi
.
Operation
var
op
*
tpuapi
.
Operation
parent
:=
getTPUParentName
(
gce
.
projectID
,
zone
)
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
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -92,7 +90,7 @@ func (gce *GCECloud) DeleteTPU(ctx context.Context, name, zone string) error {
...
@@ -92,7 +90,7 @@ func (gce *GCECloud) DeleteTPU(ctx context.Context, name, zone string) error {
var
op
*
tpuapi
.
Operation
var
op
*
tpuapi
.
Operation
name
=
getTPUName
(
gce
.
projectID
,
zone
,
name
)
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
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -114,7 +112,7 @@ func (gce *GCECloud) GetTPU(ctx context.Context, name, zone string) (*tpuapi.Nod
...
@@ -114,7 +112,7 @@ func (gce *GCECloud) GetTPU(ctx context.Context, name, zone string) (*tpuapi.Nod
mc
:=
newTPUMetricContext
(
"get"
,
zone
)
mc
:=
newTPUMetricContext
(
"get"
,
zone
)
name
=
getTPUName
(
gce
.
projectID
,
zone
,
name
)
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
{
if
err
!=
nil
{
return
nil
,
mc
.
Observe
(
err
)
return
nil
,
mc
.
Observe
(
err
)
}
}
...
@@ -126,13 +124,24 @@ func (gce *GCECloud) ListTPUs(ctx context.Context, zone string) ([]*tpuapi.Node,
...
@@ -126,13 +124,24 @@ func (gce *GCECloud) ListTPUs(ctx context.Context, zone string) ([]*tpuapi.Node,
mc
:=
newTPUMetricContext
(
"list"
,
zone
)
mc
:=
newTPUMetricContext
(
"list"
,
zone
)
parent
:=
getTPUParentName
(
gce
.
projectID
,
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
{
if
err
!=
nil
{
return
nil
,
mc
.
Observe
(
err
)
return
nil
,
mc
.
Observe
(
err
)
}
}
return
response
.
Nodes
,
mc
.
Observe
(
nil
)
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
// waitForTPUOp checks whether the op is done every 30 seconds before the ctx
// is cancelled.
// is cancelled.
func
(
gce
*
GCECloud
)
waitForTPUOp
(
ctx
context
.
Context
,
op
*
tpuapi
.
Operation
)
(
*
tpuapi
.
Operation
,
error
)
{
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
...
@@ -155,7 +164,7 @@ func (gce *GCECloud) waitForTPUOp(ctx context.Context, op *tpuapi.Operation) (*t
}
}
var
err
error
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
{
if
err
!=
nil
{
return
true
,
err
return
true
,
err
}
}
...
@@ -188,6 +197,10 @@ func getErrorFromTPUOp(op *tpuapi.Operation) error {
...
@@ -188,6 +197,10 @@ func getErrorFromTPUOp(op *tpuapi.Operation) error {
return
nil
return
nil
}
}
func
getTPUProjectURL
(
project
string
)
string
{
return
fmt
.
Sprintf
(
"projects/%s"
,
project
)
}
func
getTPUParentName
(
project
,
zone
string
)
string
{
func
getTPUParentName
(
project
,
zone
string
)
string
{
return
fmt
.
Sprintf
(
"projects/%s/locations/%s"
,
project
,
zone
)
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