API Reference
ttp_templates.parse_output(data: str, platform: Optional[str] = None, command: Optional[str] = None, path: Optional[str] = None, yang: Optional[str] = None, misc: Optional[str] = None, get: Optional[str] = None, structure: Optional[str] = 'list', template_vars: Optional[Dict] = None) -> Union[Dict, List]
¶
Load a template and parse the provided data string with TTP.
path argument is always preferred over other arguments.
Valid combinations of template location arguments:
path="./misc/foo/bar.txt"platform="cisco_ios", command="show version"yang="ietf-interfaces", platform="cisco_ios"misc="foo_folder/bar_template.txt"get="inventory", platform="cisco_xr"
Parameters:
-
data
(
str) –Raw text data to parse.
-
path
(
Optional[str]) –OS path or
ttp://URI to the template file to load. -
platform
(
Optional[str]) –Platform name to load the template for, e.g.
cisco_ios. Required whengetis used — it selects the platform-specific input inside the getter template (e.g."cisco_xr","arista_eos"). -
command
(
Optional[str]) –CLI command to load the template for, e.g.
show ip arp. -
yang
(
Optional[str]) –YANG module name to load the template for, e.g.
ietf-interfaces. -
misc
(
Optional[str]) –Path to the template relative to the repository
miscfolder. -
get
(
Optional[str]) –Name of the getter template, e.g.
"inventory". Works similarly to NAPALM getters — a single getter bundles platform-specific parsing logic and returns a normalized, platform-agnostic structure.platformmust also be supplied so the correct input section is selected. -
structure
(
Optional[str]) –Output structure format -
list,dictionary, orflat_list. -
template_vars
(
Optional[Dict]) –Additional variables to pass into the TTP template object.
Returns:
-
Union[Dict, List]–Parsed results as a dict or list, depending on the
structureargument.
Raises:
-
ValueError–If no valid template-locating argument combination is provided, or if
getis used withoutplatform. -
RuntimeError–If
getis used and none of the getter's inputs support the specifiedplatform.
Source code in ttp_templates\ttp_templates.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
ttp_templates.get_template(path: Optional[str] = None, platform: Optional[str] = None, command: Optional[str] = None, yang: Optional[str] = None, misc: Optional[str] = None, get: Optional[str] = None) -> Optional[str]
¶
Locate a template file and return its content.
path argument is always preferred over other arguments.
Valid combinations of template location arguments:
path="./misc/foo/bar.txt"platform="cisco_ios", command="show version"yang="ietf-interfaces", platform="cisco_ios"misc="foo_folder/bar_template.txt"get="foo_folder/bar_template.txt"
Parameters:
-
path
(
Optional[str]) –OS path or
ttp://URI to the template file to load. -
platform
(
Optional[str]) –Platform name to load the template for, e.g.
cisco_ios. -
command
(
Optional[str]) –CLI command to load the template for, e.g.
show ip arp. -
yang
(
Optional[str]) –YANG module name to load the template for, e.g.
ietf-interfaces. -
misc
(
Optional[str]) –Path to the template relative to the repository
miscfolder. -
get
(
Optional[str]) –Name of the getter template e.g. "inventory"
Returns:
-
Optional[str]–Template file content as a string, or
Noneif no valid argument -
Optional[str]–combination was provided.
Source code in ttp_templates\ttp_templates.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
ttp_templates.list_templates(pattern: str = '*') -> Dict
¶
List available templates whose filenames match the given glob pattern.
The primary use case for this function is to simplify integration with other applications by providing a programmatic API to enumerate all available TTP templates.
Parameters:
-
pattern
(
str) –Glob pattern used to filter template filenames. Defaults to
"*"which matches all templates.
Returns:
-
Dict–Dictionary with three top-level keys:
-
Dict–platform- list of matching platform template filenames.
-
Dict–yang- list of matching YANG template filenames.
-
Dict–misc- nested dict mirroring themisc/directory hierarchy, with leaf values being lists of matching filenames.
Source code in ttp_templates\ttp_templates.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |