Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

355: yang type instance-identifier implemented with YANGInstanceIden… #360

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions pyangbind/lib/yangtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1445,3 +1445,71 @@ def __str__(self, encoding="ascii", errors="replace"):
return " ".join(sorted(self, key=sort_key))

return YANGBits
def YANGInstanceIdentifier(*args, **kwargs):

path_helper = kwargs.pop("path_helper", None)
caller = kwargs.pop("caller", False)
require_instance = kwargs.pop("require_instance", False)

class YANGInstanceIdentifier:

__slots__ = (
"_path_helper",
"_caller",
"_referenced_object",
"_ptr",
"_require_instance",
"_type",
"_utype",
)

_pybind_generated_by = "YANGInstanceIdentifier"

def __init__(self, *args, **kwargs):
self._referenced_path = ref_path
self._path_helper = path_helper
self._caller = caller
self._require_instance = require_instance

if len(args):
value = args[0]
if hasattr(self, "_set"):
self._set()
else:
value = None

if self._path_helper and value is not None:
path_chk = self._path_helper.get(value, caller=self._caller)

# THis lookup must return an instance object. If it does not, then we should atleast
# check for the leaf object. If this is a leaf object then allow setting the value else don't.
if self._require_instance:

if len(path_chk) < 1:

raise ValueError("If require-instance is set to true, the xpath needs to exist. In other words
it must exist.")

self.set(value=value)


def _get_ptr(self):
if self._ptr:
ptr = self._path_helper.get(self.value, caller=self._caller)
if len(ptr) == 1:
return ptr[0]
raise ValueError("Invalid pointer specified")


def _get(self):
return self.value

def __str__(self):
return str(self.value)


def set(self, value):
self.value = value


return type(YANGInstanceIdentifier(*args, **kwargs))
9 changes: 9 additions & 0 deletions pyangbind/plugin/pybind.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import pyangbind.helpers.misc as misc_help
from pyangbind.helpers.identity import IdentityStore
from pyangbind.lib.yangtypes import RestrictedClassType, YANGBool, safe_name, YANGBinary, YANGBitsType
from pyangbind.lib.yangtypes import (RestrictedClassType, YANGBinary, YANGBitsType, YANGBool, YANGInstanceIdentifier,
safe_name)

long = int

Expand Down Expand Up @@ -177,6 +179,12 @@
base_type=long, restriction_dict={"range": ["-9223372036854775808..9223372036854775807"]}, int_size=64
),
},
"instance-identifier": {
"native_type": "YANGInstanceIdentifier",
"base_type": True,
"quote_arg": True,
"pytype": YANGInstanceIdentifier
}
}

# We have a set of types which support "range" statements in RFC6020. This
Expand Down Expand Up @@ -320,6 +328,7 @@ def build_pybind(ctx, modules, fd):
"ReferenceType",
"YANGBinary",
"YANGBitsType",
"YANGInstanceIdentifier"
]
for library in yangtypes_imports:
ctx.pybind_common_hdr += "from pyangbind.lib.yangtypes import {}\n".format(library)
Expand Down