예제 #1
0
    def GetDevice(self, request, context):
        log.info('grpc-request', request=request)

        depth = int(dict(context.invocation_metadata()).get('get-depth', 0))

        if '/' in request.id:
            context.set_details('Malformed device id \'{}\''.format(
                request.id))
            context.set_code(StatusCode.INVALID_ARGUMENT)
            return Device()

        try:
            return self.root.get('/devices/' + request.id, depth=depth)
        except KeyError:
            context.set_details('Device \'{}\' not found'.format(request.id))
            context.set_code(StatusCode.NOT_FOUND)
            return Device()
예제 #2
0
    def GetDevice(self, request, context):
        log.info('grpc-request', request=request)

        try:
            instance_id = self.dispatcher.instance_id_by_device_id(request.id)
        except KeyError:
            context.set_details('Device \'{}\' not found'.format(request.id))
            context.set_code(StatusCode.NOT_FOUND)
            return Device()

        return self.dispatcher.dispatch(instance_id, VolthaLocalServiceStub,
                                        'GetDevice', request, context)
예제 #3
0
    def ActivateDevice(self, request, context):
        log.info('grpc-request', request=request)

        if '/' in request.id:
            context.set_details('Malformed device id \'{}\''.format(
                request.id))
            context.set_code(StatusCode.INVALID_ARGUMENT)
            return Device()

        try:
            path = '/devices/{}'.format(request.id)
            device = self.root.get(path)
            device.admin_state = AdminState.ENABLED
            self.root.update(path, device, strict=True)

        except KeyError:
            context.set_details('Device \'{}\' not found'.format(request.id))
            context.set_code(StatusCode.NOT_FOUND)

        return Empty()
예제 #4
0
    def CreateDevice(self, request, context):
        log.info('grpc-request', request=request)

        known_device_types = dict(
            (dt.id, dt) for dt in self.root.get('/device_types'))

        try:
            assert isinstance(request, Device)
            device = request
            assert device.id == '', 'Device to be created cannot have id yet'
            assert device.type in known_device_types, \
                'Unknown device type \'{}\''.format(device.type)
            assert device.admin_state in (AdminState.UNKNOWN,
                                          AdminState.PREPROVISIONED), \
                'Newly created device cannot be ' \
                'in admin state \'{}\''.format(device.admin_state)

        except AssertionError, e:
            context.set_details(e.message)
            context.set_code(StatusCode.INVALID_ARGUMENT)
            return Device()