Debian Codegraph @

lib/jnpr/junos/factory/__init__.py

raw
1 import yaml
2 import os.path
3
4 from jnpr.junos.factory.factory_loader import FactoryLoader
5
6 __all__ = ["loadyaml", "FactoryLoader"]
7
8
9 def loadyaml(path):
10 """
11 Load a YAML file at :path: that contains Table and View definitions.
12 Returns a <dict> of item-name anditem-class definition.
13
14 If you want to import these definitions directly into your namespace,
15 (like a module) you would do the following:
16
17 globals().update( loadyaml( <path-to-yaml-file> ))
18
19 If you did not want to do this, you can access the items as the <dict>.
20 For example, if your YAML file contained a Table called MyTable, then
21 you could do something like:
22
23 catalog = loadyaml( <path-to-yaml-file> )
24 MyTable = catalog['MyTable']
25
26 table = MyTable(dev)
27 table.get()
28 ...
29 """
30 # if no extension is given, default to '.yml'
31 if os.path.splitext(path)[1] == "":
32 path += ".yml"
33 return FactoryLoader().load(yaml.load(open(path, "r"), Loader=yaml.FullLoader))