github.com/form3tech-oss/cilium@v1.6.3/examples/kubernetes-grpc/cc_door_client.py (about)

     1  # Copyright 2015 gRPC authors.
     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  """The Python implementation of the GRPC cloudcity.DoorManager client."""
    16  
    17  from __future__ import print_function
    18  
    19  import grpc
    20  
    21  import cloudcity_pb2
    22  import cloudcity_pb2_grpc
    23  import sys
    24  
    25  arg1 = 'GetName'
    26  arg2 = '1'
    27  arg3 = '99' 
    28  
    29  def run():
    30    channel = grpc.insecure_channel('cc-door-server:50051')
    31    stub = cloudcity_pb2_grpc.DoorManagerStub(channel)
    32    if arg1 == 'GetName':
    33      response = stub.GetName(cloudcity_pb2.DoorRequest(door_id=int(arg2)))
    34      print("Door name is: " + response.name)
    35    elif arg1 == 'GetLocation':
    36      response = stub.GetLocation(cloudcity_pb2.DoorRequest(door_id=int(arg2)))
    37      print("Door location is lat = %s long = %s" % (response.lat, response.long))
    38    elif arg1 == 'GetStatus':
    39      response = stub.GetStatus(cloudcity_pb2.DoorRequest(door_id=int(arg2)))
    40      if response.state == cloudcity_pb2.OPEN: 
    41          print("Door is open")
    42      else: 
    43          print("Door is closed")
    44    elif arg1 == 'RequestMaintenance':
    45      response = stub.RequestMaintenance(cloudcity_pb2.DoorMaintRequest(
    46              door_id=int(arg2), maint_description=arg3))
    47      if response.success: 
    48          print("Successfully submitted maintenance request")
    49      else: 
    50          print("Failed to submit maintenaince request") 
    51    elif arg1 == 'SetAccessCode':
    52      response = stub.SetAccessCode(cloudcity_pb2.DoorAccessCodeRequest(
    53              door_id=int(arg2), access_code=int(arg3)))
    54      if response.success: 
    55          print("Successfully set AccessCode to " + arg3)
    56      else: 
    57          print("Failed to set AccessCode") 
    58  
    59    else:
    60      print("Invalid call " + arg1)
    61      return
    62  
    63  if __name__ == '__main__':
    64    if len(sys.argv) > 1:
    65      arg1 = sys.argv[1]
    66    if len(sys.argv) > 2:
    67      arg2 = sys.argv[2]
    68    if len(sys.argv) > 3:
    69      arg3 = sys.argv[3]
    70  
    71    run()