Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
buildgrid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
BuildGrid
buildgrid
Commits
e7ff9b11
Commit
e7ff9b11
authored
6 years ago
by
finnball
Browse files
Options
Downloads
Patches
Plain Diff
Separated out the operations command.
parent
69f8d823
No related branches found
No related tags found
Loading
Pipeline
#29909607
canceled
6 years ago
Stage: test
Stage: post
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
buildgrid/_app/commands/cmd_operation.py
+96
-0
96 additions, 0 deletions
buildgrid/_app/commands/cmd_operation.py
with
96 additions
and
0 deletions
buildgrid/_app/commands/cmd_operation.py
0 → 100644
+
96
−
0
View file @
e7ff9b11
# Copyright (C) 2018 Bloomberg LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# <http://www.apache.org/licenses/LICENSE-2.0>
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Operations command
=================
Check the status of operations
"""
import
logging
from
urllib.parse
import
urlparse
import
sys
import
click
import
grpc
from
buildgrid._protos.google.longrunning
import
operations_pb2
,
operations_pb2_grpc
from
..cli
import
pass_context
@click.group
(
name
=
'
operation
'
,
short_help
=
"
Long running operations commands
"
)
@click.option
(
'
--remote
'
,
type
=
click
.
STRING
,
default
=
'
http://localhost:50051
'
,
show_default
=
True
,
help
=
"
Remote execution server
'
s URL (port defaults to 50051 if no specified).
"
)
@click.option
(
'
--client-key
'
,
type
=
click
.
Path
(
exists
=
True
,
dir_okay
=
False
),
default
=
None
,
help
=
"
Private client key for TLS (PEM-encoded)
"
)
@click.option
(
'
--client-cert
'
,
type
=
click
.
Path
(
exists
=
True
,
dir_okay
=
False
),
default
=
None
,
help
=
"
Public client certificate for TLS (PEM-encoded)
"
)
@click.option
(
'
--server-cert
'
,
type
=
click
.
Path
(
exists
=
True
,
dir_okay
=
False
),
default
=
None
,
help
=
"
Public server certificate for TLS (PEM-encoded)
"
)
@click.option
(
'
--instance-name
'
,
type
=
click
.
STRING
,
default
=
'
main
'
,
show_default
=
True
,
help
=
"
Targeted farm instance name.
"
)
@pass_context
def
cli
(
context
,
remote
,
instance_name
,
client_key
,
client_cert
,
server_cert
):
url
=
urlparse
(
remote
)
context
.
remote
=
'
{}:{}
'
.
format
(
url
.
hostname
,
url
.
port
or
50051
)
context
.
instance_name
=
instance_name
if
url
.
scheme
==
'
http
'
:
context
.
channel
=
grpc
.
insecure_channel
(
context
.
remote
)
else
:
credentials
=
context
.
load_client_credentials
(
client_key
,
client_cert
,
server_cert
)
if
not
credentials
:
click
.
echo
(
"
ERROR: no TLS keys were specified and no defaults could be found.
\n
"
+
"
Use `insecure-mode: false` in order to deactivate TLS encryption.
\n
"
,
err
=
True
)
sys
.
exit
(
-
1
)
context
.
channel
=
grpc
.
secure_channel
(
context
.
remote
,
credentials
)
context
.
logger
=
logging
.
getLogger
(
__name__
)
context
.
logger
.
debug
(
"
Starting for remote {}
"
.
format
(
context
.
remote
))
@cli.command
(
'
status
'
,
short_help
=
"
Get the status of an operation.
"
)
@click.argument
(
'
operation-name
'
,
nargs
=
1
,
type
=
click
.
STRING
,
required
=
True
)
@pass_context
def
status
(
context
,
operation_name
):
context
.
logger
.
info
(
"
Getting operation status...
"
)
stub
=
operations_pb2_grpc
.
OperationsStub
(
context
.
channel
)
request
=
operations_pb2
.
GetOperationRequest
(
name
=
operation_name
)
response
=
stub
.
GetOperation
(
request
)
context
.
logger
.
info
(
response
)
@cli.command
(
'
list
'
,
short_help
=
"
List operations.
"
)
@pass_context
def
lists
(
context
):
context
.
logger
.
info
(
"
Getting list of operations
"
)
stub
=
operations_pb2_grpc
.
OperationsStub
(
context
.
channel
)
request
=
operations_pb2
.
ListOperationsRequest
(
name
=
context
.
instance_name
)
response
=
stub
.
ListOperations
(
request
)
if
not
response
.
operations
:
context
.
logger
.
warning
(
"
No operations to list
"
)
return
for
op
in
response
.
operations
:
context
.
logger
.
info
(
op
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment