cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

How to read Cisco IXM Gateway MAC address from LXC in 2.0.30 Standalone Mode

1446
Views
0
Helpful
7
Comments
jwen2
Cisco Employee

From 2.0.30, the privilege of LXC is downgraded to user level by the request from our SP customer.


The "pcamap show" command in LXC will not show the true value of MAC address.

bash-3.2# pcamap show

MAC_ADDR: 00:00:00:00:00:00

MODEL_NUM:

VERSION_ID:

MB_SERIAL_NUM:

MB_ASSEMBLY_NUM:

MB_REVISION_NUM:

SYSTEM_SERIAL_NUM:

MODEL_REVISION_NUM:

While the IXM gateway is running on the standalone mode, If you still need to read the MAC address from LXC, we suggest to create a python script in LXC to initiate SSH to the host, execute the CLI and return the result.

Steps and Python Scripts

Step 1

From host CLI, firstly you need to create secret, username, password and generate SSH crypto key

1) (config)#enable secret cisco

2) (config)#username cisco password cisco

3) (config)#crypto key generate rsa


Step 2

Create a python script (such as get_mac.py) in LXC


examples

bash-3.2# more get_mac.py

#!/usr/bin/python

##################################################################

#Name of script : get_mac.py

#usage : to get the device MAC address

#args : ssh-username , ssh-password and privileg-epassword

#usage example : python get_mac.py cisco cisco cisco

####################################################################

#!/usr/bin/python

import re

import pexpect

import sys

username=sys.argv[1]

password=sys.argv[2]

adminsecpassword=sys.argv[3]

cmd ='ssh '+username+'@10.0.3.1'

p=pexpect.spawn(cmd)

p.expect('password:')

p.sendline(password)

p.sendline("\n")

p.sendline("\n")

p.sendline("\n")

p.sendline("\n")

p.sendline("\n")

p.expect('>')

p.sendline("enable\n")

p.expect('Password:')

p.sendline(adminsecpassword)

p.expect('#')

p.sendline("show interfaces")

p.expect('#')

config=p.before

#print("Config Output ----\n %s" %config)

#host_ip = re.search(r'ip address (\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)', config)

mac_addr = re.search(r'address is (([\dA-F]{2})[-:]([\dA-F]{2})[-:]([\dA-F]{2})[-:]([\dA-F]{2})[-:]([\dA-F]{2})[-:]([\dA-F]{2}))', config)

print mac_addr.group(1)

p.sendline("request shell exit")


Step 3

Run this script in LXC and get the return value of MAC


bash-3.2# python get_mac.py cisco cisco cisco

00:5F:86:5C:46:00

7 Comments
Create
Recognize Your Peers
Content for Community-Ad