or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

core-parsing.mdindex.mdinterface-parsing.mdnetwork-objects.mdutilities.md

interface-parsing.mddocs/

0

# Interface Parsing

1

2

Specialized classes for parsing and analyzing network interface configurations with vendor-specific support. Extract interface properties like IP addresses, VLANs, VRFs, and operational states from configuration lines across multiple network operating systems.

3

4

## Capabilities

5

6

### Base Configuration Line Objects

7

8

Foundation classes that represent configuration lines with hierarchical relationships.

9

10

```python { .api }

11

class BaseCfgLine:

12

"""

13

Abstract base class for all configuration line objects.

14

15

Attributes:

16

- text (str): Line text content

17

- linenum (int): Line number in configuration

18

- parent (BaseCfgLine): Parent configuration object

19

- children (list[BaseCfgLine]): Child configuration objects

20

- indent (int): Indentation level

21

"""

22

23

@property

24

def text(self):

25

"""Get the configuration line text."""

26

27

@property

28

def linenum(self):

29

"""Get the line number in configuration."""

30

31

@property

32

def parent(self):

33

"""Get the parent configuration object."""

34

35

@property

36

def children(self):

37

"""Get list of child configuration objects."""

38

39

@property

40

def indent(self):

41

"""Get the indentation level."""

42

```

43

44

### Cisco IOS Interface Objects

45

46

Parse Cisco IOS interface configurations with comprehensive property extraction.

47

48

```python { .api }

49

class IOSCfgLine(BaseCfgLine):

50

"""Cisco IOS configuration line object."""

51

52

class IOSIntfLine(IOSCfgLine):

53

"""

54

Cisco IOS interface configuration line with advanced property parsing.

55

"""

56

57

@property

58

def name(self):

59

"""

60

Get the interface name.

61

62

Returns:

63

str: Full interface name (e.g., 'GigabitEthernet0/1')

64

"""

65

66

@property

67

def port(self):

68

"""

69

Get the port identifier.

70

71

Returns:

72

str: Port number/identifier (e.g., '0/1')

73

"""

74

75

@property

76

def port_type(self):

77

"""

78

Get the interface type.

79

80

Returns:

81

str: Interface type (e.g., 'GigabitEthernet')

82

"""

83

84

def abbreviate_interface_name(self):

85

"""

86

Get abbreviated interface name.

87

88

Returns:

89

str: Abbreviated interface name (e.g., 'Gi0/1')

90

"""

91

92

@property

93

def manual_arp_timeout(self):

94

"""

95

Get manual ARP timeout value.

96

97

Returns:

98

int: ARP timeout in seconds or None

99

"""

100

101

@property

102

def ip_addr(self):

103

"""

104

Get the interface IP address.

105

106

Returns:

107

str: IPv4 address or None if not configured

108

"""

109

110

@property

111

def ip_netmask(self):

112

"""

113

Get the interface netmask.

114

115

Returns:

116

str: Netmask string or None

117

"""

118

119

@property

120

def ip_network_object(self):

121

"""

122

Get IPv4Obj for the interface network.

123

124

Returns:

125

IPv4Obj: Network object or None

126

"""

127

128

@property

129

def ipv6_addr(self):

130

"""

131

Get the interface IPv6 address.

132

133

Returns:

134

str: IPv6 address or None if not configured

135

"""

136

137

@property

138

def ipv6_network_object(self):

139

"""

140

Get IPv6Obj for the interface network.

141

142

Returns:

143

IPv6Obj: IPv6 network object or None

144

"""

145

146

@property

147

def is_shutdown(self):

148

"""

149

Check if interface is administratively shutdown.

150

151

Returns:

152

bool: True if shutdown, False if no shutdown

153

"""

154

155

@property

156

def vrf(self):

157

"""

158

Get the VRF assignment.

159

160

Returns:

161

str: VRF name or None if not assigned

162

"""

163

164

@property

165

def switchport(self):

166

"""

167

Check if interface is configured as switchport.

168

169

Returns:

170

bool: True if switchport, False otherwise

171

"""

172

173

@property

174

def switchport_access_vlan(self):

175

"""

176

Get the access VLAN number.

177

178

Returns:

179

int: Access VLAN ID or None

180

"""

181

182

@property

183

def switchport_trunk_vlans(self):

184

"""

185

Get the trunk VLAN list.

186

187

Returns:

188

CiscoRange: Range object containing trunk VLANs

189

"""

190

191

@property

192

def switchport_trunk_native_vlan(self):

193

"""

194

Get the trunk native VLAN.

195

196

Returns:

197

int: Native VLAN ID or None

198

"""

199

```

200

201

### Cisco NX-OS Interface Objects

202

203

Parse Cisco NX-OS interface configurations with NX-OS specific features.

204

205

```python { .api }

206

class NXOSCfgLine(BaseCfgLine):

207

"""Cisco NX-OS configuration line object."""

208

209

class NXOSIntfLine(NXOSCfgLine):

210

"""

211

Cisco NX-OS interface configuration line with NX-OS specific parsing.

212

Inherits base interface properties with NX-OS extensions.

213

"""

214

```

215

216

### Cisco ASA Interface Objects

217

218

Parse Cisco ASA interface configurations with security appliance specific features.

219

220

```python { .api }

221

class ASACfgLine(BaseCfgLine):

222

"""Cisco ASA configuration line object."""

223

224

class ASAIntfLine(ASACfgLine):

225

"""

226

Cisco ASA interface configuration line with security appliance features.

227

Handles nameif, security-level, and zone configurations.

228

"""

229

```

230

231

### Cisco IOS-XR Interface Objects

232

233

Parse Cisco IOS-XR interface configurations with XR-specific syntax support.

234

235

```python { .api }

236

class IOSXRCfgLine(BaseCfgLine):

237

"""Cisco IOS-XR configuration line object."""

238

239

class IOSXRIntfLine(IOSXRCfgLine):

240

"""

241

Cisco IOS-XR interface configuration line with XR syntax support.

242

Handles hierarchical XR configuration format.

243

"""

244

```

245

246

### Juniper Junos Interface Objects

247

248

Parse Juniper Junos interface configurations with Junos-specific syntax.

249

250

```python { .api }

251

class JunosCfgLine(BaseCfgLine):

252

"""Juniper Junos configuration line object."""

253

254

class JunosIntfLine(JunosCfgLine):

255

"""

256

Juniper Junos interface configuration line with Junos syntax support.

257

Handles set-based configuration format.

258

"""

259

```

260

261

### Vendor-Specific Global Interface Classes

262

263

Handle global interface configurations for different platforms.

264

265

```python { .api }

266

class IOSIntfGlobal:

267

"""IOS interface global configuration settings."""

268

269

class NXOSIntfGlobal:

270

"""NX-OS interface global configuration settings."""

271

272

class ASAIntfGlobal:

273

"""ASA interface global configuration settings."""

274

```

275

276

## Advanced Interface Features

277

278

### IOS-Specific Configuration Classes

279

280

Specialized classes for IOS-specific configuration elements.

281

282

```python { .api }

283

class IOSHostnameLine:

284

"""IOS hostname configuration line."""

285

286

class IOSAccessLine:

287

"""IOS access-class configuration line."""

288

289

class IOSRouteLine:

290

"""IOS routing configuration line."""

291

292

# AAA Configuration Classes

293

class IOSAaaGroupServerLine:

294

"""AAA group server configuration."""

295

296

class IOSAaaLoginAuthenticationLine:

297

"""AAA login authentication configuration."""

298

299

class IOSAaaEnableAuthenticationLine:

300

"""AAA enable authentication configuration."""

301

302

class IOSAaaCommandsAuthorizationLine:

303

"""AAA commands authorization configuration."""

304

305

class IOSAaaConsoleAuthorizationLine:

306

"""AAA console authorization configuration."""

307

308

class IOSAaaCommandsAccountingLine:

309

"""AAA commands accounting configuration."""

310

311

class IOSAaaExecAccountingLine:

312

"""AAA exec accounting configuration."""

313

```

314

315

### NX-OS Specific Configuration Classes

316

317

Specialized classes for NX-OS-specific features.

318

319

```python { .api }

320

class NXOSIntfGlobal:

321

"""NX-OS interface global configuration."""

322

323

class NXOSvPCLine:

324

"""NX-OS vPC configuration line."""

325

326

class NXOSHostnameLine:

327

"""NX-OS hostname configuration."""

328

329

class NXOSAccessLine:

330

"""NX-OS access configuration."""

331

332

class NXOSRouteLine:

333

"""NX-OS routing configuration."""

334

335

# NX-OS AAA Classes (similar structure to IOS)

336

class NXOSAaaGroupServerLine:

337

"""NX-OS AAA group server configuration."""

338

339

class NXOSAaaLoginAuthenticationLine:

340

"""NX-OS AAA login authentication."""

341

342

class NXOSAaaEnableAuthenticationLine:

343

"""NX-OS AAA enable authentication."""

344

345

class NXOSAaaCommandsAuthorizationLine:

346

"""NX-OS AAA commands authorization."""

347

348

class NXOSAaaConsoleAuthorizationLine:

349

"""NX-OS AAA console authorization."""

350

351

class NXOSAaaCommandsAccountingLine:

352

"""NX-OS AAA commands accounting."""

353

354

class NXOSAaaExecAccountingLine:

355

"""NX-OS AAA exec accounting."""

356

```

357

358

### ASA Security Configuration Classes

359

360

Specialized classes for ASA security appliance configurations.

361

362

```python { .api }

363

class ASAIntfGlobal:

364

"""ASA interface global configuration."""

365

366

class ASAName:

367

"""ASA name object configuration."""

368

369

class ASAObjNetwork:

370

"""ASA network object configuration."""

371

372

class ASAObjService:

373

"""ASA service object configuration."""

374

375

class ASAObjGroupNetwork:

376

"""ASA network object group configuration."""

377

378

class ASAObjGroupService:

379

"""ASA service object group configuration."""

380

381

class ASAHostnameLine:

382

"""ASA hostname configuration."""

383

384

class ASAAclLine:

385

"""ASA access list configuration."""

386

```

387

388

### Junos Configuration Classes

389

390

Classes for handling Junos-specific configuration elements.

391

392

```python { .api }

393

class JunosRouteLine:

394

"""Junos routing configuration line."""

395

```

396

397

## Configuration Factory Functions

398

399

### Line Object Factory

400

401

Automatically create appropriate configuration line objects based on syntax and content.

402

403

```python { .api }

404

def config_line_factory(text, comment_delimiter='!', syntax='ios'):

405

"""

406

Factory function to create appropriate configuration line objects.

407

408

Parameters:

409

- text (str): Configuration line text

410

- comment_delimiter (str): Comment character

411

- syntax (str): Configuration syntax ('ios', 'nxos', 'asa', 'iosxr', 'junos')

412

413

Returns:

414

BaseCfgLine: Appropriate configuration line object

415

"""

416

417

def cfgobj_from_text(text, syntax='ios'):

418

"""

419

Create configuration object from text string.

420

421

Parameters:

422

- text (str): Configuration line text

423

- syntax (str): Configuration syntax

424

425

Returns:

426

BaseCfgLine: Configuration line object

427

"""

428

```

429

430

## Usage Examples

431

432

### Basic Interface Parsing

433

434

```python

435

from ciscoconfparse import CiscoConfParse

436

437

# Parse IOS configuration with factory mode

438

parse = CiscoConfParse('switch_config.txt', syntax='ios', factory=True)

439

440

# Find all interface objects

441

interfaces = parse.find_interface_objects(r'^interface')

442

443

for intf in interfaces:

444

print(f"Interface: {intf.name}")

445

print(f" Type: {intf.port_type}")

446

print(f" Port: {intf.port}")

447

print(f" Shutdown: {intf.is_shutdown}")

448

449

if intf.ip_addr:

450

print(f" IP: {intf.ip_addr}/{intf.ip_network_object.prefixlen}")

451

452

if intf.switchport:

453

print(f" Switchport: True")

454

if intf.switchport_access_vlan:

455

print(f" Access VLAN: {intf.switchport_access_vlan}")

456

if intf.switchport_trunk_vlans:

457

print(f" Trunk VLANs: {intf.switchport_trunk_vlans.compressed_str}")

458

```

459

460

### Interface Property Analysis

461

462

```python

463

# Find routed interfaces with IP addresses

464

routed_intfs = parse.find_objects_w_child(

465

parentspec=r'^interface',

466

childspec=r'ip address'

467

)

468

469

for intf in routed_intfs:

470

if hasattr(intf, 'ip_addr') and intf.ip_addr:

471

network_obj = intf.ip_network_object

472

print(f"{intf.name}: {intf.ip_addr} ({network_obj.network})")

473

print(f" Private: {network_obj.is_private()}")

474

print(f" VRF: {intf.vrf or 'global'}")

475

```

476

477

### Switchport VLAN Analysis

478

479

```python

480

# Analyze switchport configurations

481

switchports = [intf for intf in interfaces if intf.switchport]

482

483

for sp in switchports:

484

print(f"Switchport: {sp.name}")

485

486

if sp.switchport_access_vlan:

487

print(f" Mode: Access, VLAN {sp.switchport_access_vlan}")

488

489

if sp.switchport_trunk_vlans:

490

vlans = sp.switchport_trunk_vlans.as_list()

491

native = sp.switchport_trunk_native_vlan

492

print(f" Mode: Trunk, VLANs: {len(vlans)} configured")

493

if native:

494

print(f" Native VLAN: {native}")

495

```

496

497

### Multi-Vendor Configuration Parsing

498

499

```python

500

# Parse different vendor configurations

501

vendors = {

502

'ios': 'cisco_switch.txt',

503

'nxos': 'nexus_switch.txt',

504

'asa': 'firewall.txt',

505

'iosxr': 'router_xr.txt',

506

'junos': 'juniper_switch.txt'

507

}

508

509

for syntax, config_file in vendors.items():

510

parse = CiscoConfParse(config_file, syntax=syntax, factory=True)

511

interfaces = parse.find_interface_objects(r'^interface')

512

513

print(f"\n{syntax.upper()} - {len(interfaces)} interfaces found")

514

for intf in interfaces[:3]: # Show first 3

515

print(f" {intf.name} ({type(intf).__name__})")

516

```

517

518

### Interface Hierarchy Navigation

519

520

```python

521

# Navigate parent-child relationships

522

interface_obj = parse.find_objects(r'^interface GigabitEthernet0/1')[0]

523

524

print(f"Interface: {interface_obj.text}")

525

print("Child configurations:")

526

for child in interface_obj.children:

527

print(f" {child.text}")

528

529

# Find specific child configurations

530

desc_children = [child for child in interface_obj.children

531

if 'description' in child.text]

532

if desc_children:

533

print(f"Description: {desc_children[0].text.strip().split(' ', 1)[1]}")

534

```

535

536

### Factory vs Non-Factory Parsing

537

538

```python

539

# Without factory - generic objects

540

parse_generic = CiscoConfParse('config.txt', syntax='ios', factory=False)

541

intf_generic = parse_generic.find_objects(r'^interface GigabitEthernet0/1')[0]

542

print(f"Generic type: {type(intf_generic).__name__}") # IOSCfgLine

543

544

# With factory - specialized objects

545

parse_factory = CiscoConfParse('config.txt', syntax='ios', factory=True)

546

intf_factory = parse_factory.find_objects(r'^interface GigabitEthernet0/1')[0]

547

print(f"Factory type: {type(intf_factory).__name__}") # IOSIntfLine

548

549

# Factory objects have additional properties

550

if hasattr(intf_factory, 'ip_addr'):

551

print(f"IP Address: {intf_factory.ip_addr}")

552

```