finn pushed to branch finn/separate-services at BuildGrid / buildgrid
Commits:
-
ebb04267
by finnball at 2018-09-11T14:22:05Z
3 changed files:
- buildgrid/_app/commands/cmd_cas.py
- buildgrid/_app/commands/cmd_execute.py
- + buildgrid/_app/commands/cmd_operation.py
Changes:
| ... | ... | @@ -56,8 +56,7 @@ def cli(context, remote, instance_name, client_key, client_cert, server_cert): |
| 56 | 56 |
else:
|
| 57 | 57 |
credentials = context.load_client_credentials(client_key, client_cert, server_cert)
|
| 58 | 58 |
if not credentials:
|
| 59 |
- click.echo("ERROR: no TLS keys were specified and no defaults could be found.\n" +
|
|
| 60 |
- "Use --allow-insecure in order to deactivate TLS encryption.\n", err=True)
|
|
| 59 |
+ click.echo("ERROR: no TLS keys were specified and no defaults could be found.", err=True)
|
|
| 61 | 60 |
sys.exit(-1)
|
| 62 | 61 |
|
| 63 | 62 |
context.channel = grpc.secure_channel(context.remote, credentials)
|
| ... | ... | @@ -60,8 +60,7 @@ def cli(context, remote, instance_name, client_key, client_cert, server_cert): |
| 60 | 60 |
else:
|
| 61 | 61 |
credentials = context.load_client_credentials(client_key, client_cert, server_cert)
|
| 62 | 62 |
if not credentials:
|
| 63 |
- click.echo("ERROR: no TLS keys were specified and no defaults could be found.\n" +
|
|
| 64 |
- "Use `insecure-mode: false` in order to deactivate TLS encryption.\n", err=True)
|
|
| 63 |
+ click.echo("ERROR: no TLS keys were specified and no defaults could be found.", err=True)
|
|
| 65 | 64 |
sys.exit(-1)
|
| 66 | 65 |
|
| 67 | 66 |
context.channel = grpc.secure_channel(context.remote, credentials)
|
| ... | ... | @@ -98,37 +97,6 @@ def request_dummy(context, number, wait_for_completion): |
| 98 | 97 |
context.logger.info(next(response))
|
| 99 | 98 |
|
| 100 | 99 |
|
| 101 |
-@cli.command('status', short_help="Get the status of an operation.")
|
|
| 102 |
-@click.argument('operation-name', nargs=1, type=click.STRING, required=True)
|
|
| 103 |
-@pass_context
|
|
| 104 |
-def operation_status(context, operation_name):
|
|
| 105 |
- context.logger.info("Getting operation status...")
|
|
| 106 |
- stub = operations_pb2_grpc.OperationsStub(context.channel)
|
|
| 107 |
- |
|
| 108 |
- request = operations_pb2.GetOperationRequest(name=operation_name)
|
|
| 109 |
- |
|
| 110 |
- response = stub.GetOperation(request)
|
|
| 111 |
- context.logger.info(response)
|
|
| 112 |
- |
|
| 113 |
- |
|
| 114 |
-@cli.command('list', short_help="List operations.")
|
|
| 115 |
-@pass_context
|
|
| 116 |
-def list_operations(context):
|
|
| 117 |
- context.logger.info("Getting list of operations")
|
|
| 118 |
- stub = operations_pb2_grpc.OperationsStub(context.channel)
|
|
| 119 |
- |
|
| 120 |
- request = operations_pb2.ListOperationsRequest(name=context.instance_name)
|
|
| 121 |
- |
|
| 122 |
- response = stub.ListOperations(request)
|
|
| 123 |
- |
|
| 124 |
- if not response.operations:
|
|
| 125 |
- context.logger.warning("No operations to list")
|
|
| 126 |
- return
|
|
| 127 |
- |
|
| 128 |
- for op in response.operations:
|
|
| 129 |
- context.logger.info(op)
|
|
| 130 |
- |
|
| 131 |
- |
|
| 132 | 100 |
@cli.command('wait', short_help="Streams an operation until it is complete.")
|
| 133 | 101 |
@click.argument('operation-name', nargs=1, type=click.STRING, required=True)
|
| 134 | 102 |
@pass_context
|
| 1 |
+# Copyright (C) 2018 Bloomberg LP
|
|
| 2 |
+#
|
|
| 3 |
+# Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 4 |
+# you may not use this file except in compliance with the License.
|
|
| 5 |
+# You may obtain a copy of the License at
|
|
| 6 |
+#
|
|
| 7 |
+# <http://www.apache.org/licenses/LICENSE-2.0>
|
|
| 8 |
+#
|
|
| 9 |
+# Unless required by applicable law or agreed to in writing, software
|
|
| 10 |
+# distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 11 |
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 12 |
+# See the License for the specific language governing permissions and
|
|
| 13 |
+# limitations under the License.
|
|
| 14 |
+ |
|
| 15 |
+ |
|
| 16 |
+"""
|
|
| 17 |
+Operations command
|
|
| 18 |
+=================
|
|
| 19 |
+ |
|
| 20 |
+Check the status of operations
|
|
| 21 |
+"""
|
|
| 22 |
+ |
|
| 23 |
+import logging
|
|
| 24 |
+from urllib.parse import urlparse
|
|
| 25 |
+import sys
|
|
| 26 |
+ |
|
| 27 |
+import click
|
|
| 28 |
+import grpc
|
|
| 29 |
+ |
|
| 30 |
+from buildgrid._protos.google.longrunning import operations_pb2, operations_pb2_grpc
|
|
| 31 |
+ |
|
| 32 |
+from ..cli import pass_context
|
|
| 33 |
+ |
|
| 34 |
+ |
|
| 35 |
+@click.group(name='operation', short_help="Long running operations commands")
|
|
| 36 |
+@click.option('--remote', type=click.STRING, default='http://localhost:50051', show_default=True,
|
|
| 37 |
+ help="Remote execution server's URL (port defaults to 50051 if no specified).")
|
|
| 38 |
+@click.option('--client-key', type=click.Path(exists=True, dir_okay=False), default=None,
|
|
| 39 |
+ help="Private client key for TLS (PEM-encoded)")
|
|
| 40 |
+@click.option('--client-cert', type=click.Path(exists=True, dir_okay=False), default=None,
|
|
| 41 |
+ help="Public client certificate for TLS (PEM-encoded)")
|
|
| 42 |
+@click.option('--server-cert', type=click.Path(exists=True, dir_okay=False), default=None,
|
|
| 43 |
+ help="Public server certificate for TLS (PEM-encoded)")
|
|
| 44 |
+@click.option('--instance-name', type=click.STRING, default='main', show_default=True,
|
|
| 45 |
+ help="Targeted farm instance name.")
|
|
| 46 |
+@pass_context
|
|
| 47 |
+def cli(context, remote, instance_name, client_key, client_cert, server_cert):
|
|
| 48 |
+ url = urlparse(remote)
|
|
| 49 |
+ |
|
| 50 |
+ context.remote = '{}:{}'.format(url.hostname, url.port or 50051)
|
|
| 51 |
+ context.instance_name = instance_name
|
|
| 52 |
+ |
|
| 53 |
+ if url.scheme == 'http':
|
|
| 54 |
+ context.channel = grpc.insecure_channel(context.remote)
|
|
| 55 |
+ else:
|
|
| 56 |
+ credentials = context.load_client_credentials(client_key, client_cert, server_cert)
|
|
| 57 |
+ if not credentials:
|
|
| 58 |
+ click.echo("ERROR: no TLS keys were specified and no defaults could be found.", err=True)
|
|
| 59 |
+ sys.exit(-1)
|
|
| 60 |
+ |
|
| 61 |
+ context.channel = grpc.secure_channel(context.remote, credentials)
|
|
| 62 |
+ |
|
| 63 |
+ context.logger = logging.getLogger(__name__)
|
|
| 64 |
+ context.logger.debug("Starting for remote {}".format(context.remote))
|
|
| 65 |
+ |
|
| 66 |
+ |
|
| 67 |
+@cli.command('status', short_help="Get the status of an operation.")
|
|
| 68 |
+@click.argument('operation-name', nargs=1, type=click.STRING, required=True)
|
|
| 69 |
+@pass_context
|
|
| 70 |
+def status(context, operation_name):
|
|
| 71 |
+ context.logger.info("Getting operation status...")
|
|
| 72 |
+ stub = operations_pb2_grpc.OperationsStub(context.channel)
|
|
| 73 |
+ |
|
| 74 |
+ request = operations_pb2.GetOperationRequest(name=operation_name)
|
|
| 75 |
+ |
|
| 76 |
+ response = stub.GetOperation(request)
|
|
| 77 |
+ context.logger.info(response)
|
|
| 78 |
+ |
|
| 79 |
+ |
|
| 80 |
+@cli.command('list', short_help="List operations.")
|
|
| 81 |
+@pass_context
|
|
| 82 |
+def lists(context):
|
|
| 83 |
+ context.logger.info("Getting list of operations")
|
|
| 84 |
+ stub = operations_pb2_grpc.OperationsStub(context.channel)
|
|
| 85 |
+ |
|
| 86 |
+ request = operations_pb2.ListOperationsRequest(name=context.instance_name)
|
|
| 87 |
+ |
|
| 88 |
+ response = stub.ListOperations(request)
|
|
| 89 |
+ |
|
| 90 |
+ if not response.operations:
|
|
| 91 |
+ context.logger.warning("No operations to list")
|
|
| 92 |
+ return
|
|
| 93 |
+ |
|
| 94 |
+ for op in response.operations:
|
|
| 95 |
+ context.logger.info(op)
|
