2 # Copyright (C) 2019 Bell Canada.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 from google.protobuf.timestamp_pb2 import Timestamp
18 import proto.CommandExecutor_pb2 as CommandExecutor_pb2
22 def get_blueprint_id(request):
23 blueprint_name = request.identifiers.blueprintName
24 blueprint_version = request.identifiers.blueprintVersion
25 return blueprint_name + '/' + blueprint_version
27 # Create a response for grpc. Fills in the timestamp as well as removes cds_is_successful element
28 def build_grpc_response(request, log_results, payload_return, is_success=False):
30 status = CommandExecutor_pb2.SUCCESS
32 status = CommandExecutor_pb2.FAILURE
34 timestamp = Timestamp()
35 timestamp.GetCurrentTime()
37 if "cds_is_successful" in payload_return:
38 payload_return.pop('cds_is_successful')
39 payload_str = json.dumps(payload_return)
40 return CommandExecutor_pb2.ExecutionOutput(requestId=request.requestId,
46 # build a return data structure which may contain an error message
47 def build_ret_data(cds_is_successful, err_msg):
48 ret_data = {"cds_is_successful": cds_is_successful }
50 ret_data["err_msg"] = err_msg