Skip to content

Commit

Permalink
Merge pull request #48 from netboxlabs/feat-OBS-407-diode-reconciler-…
Browse files Browse the repository at this point in the history
…python-sdk

feat: OBS-407 - netbox plugin: diode reconciler sdk
  • Loading branch information
mfiedorowicz authored Feb 29, 2024
2 parents 43aec3e + 53c641f commit 8173db0
Show file tree
Hide file tree
Showing 43 changed files with 9,711 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python
# Copyright 2024 NetBox Labs Inc
"""Diode Netbox Plugin - Reconciler SDK."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python
# Copyright 2024 NetBox Labs Inc
"""Diode Netbox Plugin - Diode Reconciler SDK."""

import grpc

from netbox_diode_plugin.diode_reconciler_sdk.reconciler.v1 import reconciler_pb2, reconciler_pb2_grpc
from netbox_diode_plugin.diode_reconciler_sdk.version import version_display


class DiodeReconcilerClient:
"""Diode Reconciler client."""

_name = "diode-reconciler-sdk-python"
_version = version_display()
_target = None
_channel = None
_stub = None

def __init__(self, target: str, api_key: str):
"""Initiate a new client configuration."""
self._target = target
# TODO(mfiedorowicz): configure secure channel with auth metatada callback
self._auth_metadata = (("diode-api-key", api_key),)
self._channel = grpc.insecure_channel(target)
self._stub = reconciler_pb2_grpc.ReconcilerServiceStub(self._channel)

@property
def name(self) -> str:
"""Retrieve the name."""
return self._name

@property
def version(self) -> str:
"""Retrieve the version."""
return self._version

@property
def target(self) -> str:
"""Retrieve the target."""
return self._target

@property
def channel(self) -> grpc.Channel:
"""Retrieve the channel."""
return self._channel

def add_object_state(self, object_id: int, object_type: str,
object_change_id: int, object: dict) -> reconciler_pb2.AddObjectStateResponse:
"""Add an object state."""
request = reconciler_pb2.AddObjectStateRequest(object_id=object_id, object_type=object_type,
object_change_id=object_change_id, object=object,
sdk_name=self.name, sdk_version=self.version)

return self._stub.AddObjectState(request, metadata=self._auth_metadata)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python
# Copyright 2024 NetBox Labs Inc
"""Diode Netbox Plugin - Reconciler SDK."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python
# Copyright 2024 NetBox Labs Inc
"""Diode Netbox Plugin - Reconciler SDK - v1."""

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

Loading

0 comments on commit 8173db0

Please sign in to comment.