cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1408
Views
0
Helpful
9
Replies

Building model bundle for Juniper

horseinthesky
Level 1
Level 1

Hello.
I'm trying to create a model bundle for Juniper device using YANG models stored in Juniper Git repo.

I've created a profile:

{
  "name": "junos-19.2",
  "version": "0.1.0",
  "ydk_version": "0.8.4",
  "author": "horseinthesky",
  "copyright": "horseinthesky",
  "description": "JunOS 19.2 Yang Model",
  "models": {
    "git": [
      {
        "url": "https://github.com/Juniper/yang.git",
        "dir": [
          "19.2/19.2R1/junos/conf",
          "19.2/19.2R1/junos/conf-with-extensions"
        ]
      }
    ]
  }
}

But executing generate.py against it runs in exception:

python3 generate.py --python --bundle ~/test/junos-19.2.json
Traceback (most recent call last):
  File "generate.py", line 492, in <module>
    output_directory = (generator.generate(options.bundle))
  File "/home/horseinthesky/ydk-gen/ydkgen/__init__.py", line 93, in generate
    return self._generate_bundle(description_file)
  File "/home/horseinthesky/ydk-gen/ydkgen/__init__.py", line 120, in _generate_bundle
    bundle_translator.translate(profile_file, tmp_file, self.ydk_root)
  File "/home/horseinthesky/ydk-gen/ydkgen/resolver/bundle_translator.py", line 198, in translate
    modules.extend(globals()[get_fun](data['models'][source],ydk_root))
  File "/home/horseinthesky/ydk-gen/ydkgen/resolver/bundle_translator.py", line 151, in get_git_attrs
    for c in g['commits']:
KeyError: 'commits'

 

1 Accepted Solution

Accepted Solutions

yangorelik
Spotlight
Spotlight

There are couple of errors in your profile:

  1. Missing list element 'commits'.
  2. Missing 'common' directory, which leads to pyang failure to parse yang models.

With these changes the profile looks like this:

{
  "name": "junos-19.2",
  "version": "0.1.0",
  "ydk_version": "0.8.4",
  "author": "horseinthesky",
  "copyright": "horseinthesky",
  "description": "JunOS 19.2 Yang Model",
  "models": {
    "git": [
      {
        "url": "https://github.com/Juniper/yang.git",
        "commits": [
          {
            "dir": [
              "19.2/19.2R1/common",
              "19.2/19.2R1/junos/conf",
              "19.2/19.2R1/junos/conf-with-extensions"
            ]
          }
        ]
      }
    ]
  }
}

I tested model bundle generation with this profile and it worked fine. You need to make sure that you have enough RAM and disk space on your system in order to generate API for these models.

Yan Gorelik
YDK Solutions

View solution in original post

9 Replies 9

yangorelik
Spotlight
Spotlight

There are couple of errors in your profile:

  1. Missing list element 'commits'.
  2. Missing 'common' directory, which leads to pyang failure to parse yang models.

With these changes the profile looks like this:

{
  "name": "junos-19.2",
  "version": "0.1.0",
  "ydk_version": "0.8.4",
  "author": "horseinthesky",
  "copyright": "horseinthesky",
  "description": "JunOS 19.2 Yang Model",
  "models": {
    "git": [
      {
        "url": "https://github.com/Juniper/yang.git",
        "commits": [
          {
            "dir": [
              "19.2/19.2R1/common",
              "19.2/19.2R1/junos/conf",
              "19.2/19.2R1/junos/conf-with-extensions"
            ]
          }
        ]
      }
    ]
  }
}

I tested model bundle generation with this profile and it worked fine. You need to make sure that you have enough RAM and disk space on your system in order to generate API for these models.

Yan Gorelik
YDK Solutions

This works. Couldn't find the right structure https://github.com/CiscoDevNet/ydk-gen#build-model-bundle-profile

Thank you.

Could you please open documentation bug on ydk-gen GitHub.
Yan Gorelik
YDK Solutions

How much RAM did you need to install the package with pip? In my case it keeps crushing, the max RAM u could allocate is 32G.

horseinthesky
Level 1
Level 1

Ok. How can I start discovering the package?
It is 14 million lines so it's just undiscoverable. 

Any time i do:

In [1]: from ydk.models.junos_19_2.junos_conf_root import Configuration                                                                                               

In [2]: c = Configuration()  

In [4]: c.

and press <Tab> my interpreter session just freezes forever.

This is obviously not a YDK issue, but rather symptoms of ineffectual architecture of YANG model, where all the components are concentrated in one module (junos_conf_root). For such model architecture I would suggest manually explore components of 'Configuration', define components of your interest in 'import' statements and then try to explore them using the Python interpreter.
Yan Gorelik
YDK Solutions

I mean is there a way to correlate what YANG object turned into while Python module creation?

It really hard to understand how all these YANG things work and the lack of documentation makes it even more difficult. (I'm looking at https://community.cisco.com/t5/yang-development-kit-ydk/sample-apps-for-encoding-acl-using-openconfig/m-p/3880235/highlight/false#M1226)

There is definitive correlation between YANG model and generated API. The rules are multiple and quite complicated; they are implemented in the API generator code. The simple way is just follow YANG model and compare it with generated Python API. You also might consider generating documentation for your core and bundles. You can get example of generated documentation on ydk.cisco.com.

In order to generate documentation for YDK core and bundles, generate the bundles first, then run this command:

    ./generate.py --core --generate-doc

Based on the volume of your model, please be prepared to wait for few hours for this command to finish. It also eats up lots of disk space. I would suggest to run it overnight. Once ready the documentation is located at ./gen-apy/python/ydk/docs_expanded.

Locally you can open documentation by running:

    firefox gen-apy/python/ydk/docs_expanded/index.html &

You also can publish the documentation on the web for your peers access.

The big plus of having documentation is web based, easy to browse and follow API description. 

Yan Gorelik
YDK Solutions

Ok. Thank you for the explanation. I'll try to generate some.
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: