Skip to content
Snippets Groups Projects
Select Git revision
  • ed4665365b4b73009af9c846f696a2b356913e4a
  • master default
  • cnit_ofc26
  • feat/344-implement-a-new-firewall-agent-controllable-through-restconf-openconfig
  • feat/343-integration-of-mimir-deployment-in-production-environment
  • ofc_polimi
  • feat/305-cttc-enhanced-netconf-openconfig-sbi-driver-for-dscm-pluggables
  • feat/306-cttc-enhanced-restconf-based-openconfig-nbi-for-dscm-pluggables
  • feat/301-cttc-dscm-pluggables
  • CTTC-IMPLEMENT-NBI-CONNECTOR-NOS-ZTP
  • CTTC-TEST-SMARTNICS-6GMICROSDN-ZTP
  • develop protected
  • feat/327-tid-new-service-to-ipowdm-controller-to-manage-transceivers-configuration-on-external-agent
  • cnit_tapi
  • feat/330-tid-pcep-component
  • feat/tid-newer-pcep-component
  • feat/116-ubi-updates-in-telemetry-backend-to-support-p4-in-band-network-telemetry
  • feat/292-cttc-implement-integration-test-for-ryu-openflow
  • cnit-p2mp-premerge
  • feat/325-tid-nbi-e2e-to-manage-e2e-path-computation
  • feat/326-tid-external-management-of-devices-telemetry-nbi
  • feat/324-tid-nbi-ietf_l3vpn-deploy-fail
  • v5.0.0 protected
  • v4.0.0 protected
  • demo-dpiab-eucnc2024
  • v3.0.0 protected
  • v2.1.0 protected
  • v2.0.0 protected
  • v1.0.0 protected
29 results

Service_Handler_Methods.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    DeviceClient.py 2.00 KiB
    import grpc, logging
    from common.tools.RetryDecorator import retry, delay_exponential
    from device.proto.context_pb2 import Device, DeviceId, Empty
    from device.proto.device_pb2_grpc import DeviceServiceStub
    
    LOGGER = logging.getLogger(__name__)
    MAX_RETRIES = 15
    DELAY_FUNCTION = delay_exponential(initial=0.01, increment=2.0, maximum=5.0)
    
    class DeviceClient:
        def __init__(self, address, port):
            self.endpoint = '{}:{}'.format(address, port)
            LOGGER.debug('Creating channel to {}...'.format(self.endpoint))
            self.channel = None
            self.stub = None
            self.connect()
            LOGGER.debug('Channel created')
    
        def connect(self):
            self.channel = grpc.insecure_channel(self.endpoint)
            self.stub = DeviceServiceStub(self.channel)
    
        def close(self):
            if(self.channel is not None): self.channel.close()
            self.channel = None
            self.stub = None
    
        @retry(exceptions=set(), max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, prepare_method_name='connect')
        def AddDevice(self, request : Device) -> DeviceId:
            LOGGER.debug('AddDevice request: {}'.format(request))
            response = self.stub.AddDevice(request)
            LOGGER.debug('AddDevice result: {}'.format(response))
            return response
    
        @retry(exceptions=set(), max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, prepare_method_name='connect')
        def ConfigureDevice(self, request : Device) -> DeviceId:
            LOGGER.debug('ConfigureDevice request: {}'.format(request))
            response = self.stub.ConfigureDevice(request)
            LOGGER.debug('ConfigureDevice result: {}'.format(response))
            return response
    
        @retry(exceptions=set(), max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, prepare_method_name='connect')
        def DeleteDevice(self, request : DeviceId) -> Empty:
            LOGGER.debug('DeleteDevice request: {}'.format(request))
            response = self.stub.DeleteDevice(request)
            LOGGER.debug('DeleteDevice result: {}'.format(response))
            return response