Python ENM Scripting Access Tips
Python ENM Scripting Access Tips
• The Python scripts are stored on and executed from the General Scripting VM on the
ENM system
• Any ENM user who has the 'Scripting_Operator' role can logon to the General Scripting
VM and run Python scripts to execute CLI commands
• Users need only logon to the General Scripting VM, no further authentication is required to
run their Python scripts.
python Page 1
This can be accomplished by calling the open() function. No Parameters are required when
starting a session on the ENM System via the General Scripting VM.
import enmscripting
session = enmscripting.open()
• Users have access to their own home area and a common shared storage area on the
General Scripting VM.
[bfisha@scp-2-scripting(syl1launcher) ~]$ls
0404 Ericsson
[bfisha@scp-2-scripting(syl1launcher) ~]$
[bfisha@scp-2-scripting(syl1launcher) ~]$pwd
/home/shared/bfisha
• Users scripts can be uploaded to these storage areas( we can upload script to our home
directory or create using Cat > xxx.py)
[bfisha@scp-2-scripting(syl1launcher) 0404]$ls
log nhc_scrip.py sites test.py
Once we are here we can type to python and will go directly to com mode to run python scripts.
[bfisha@scp-2-scripting(syl1launcher) 0404]$python
Python 2.6.6 (r266:84292, Nov 21 2013, 10:50:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Example script :
python Page 2
FDN : NetworkElement=LNJ05017A
neProductVersion : [{revision=R24HA, identity=CXP102051/26}]
networkElementId : LNJ05017A
neType : ERBS
nodeModelIdentity : 1659-743-117
ossModelIdentity : 17A-H.1.160
ossPrefix : SubNetwork=ONRM_ROOT_MO,SubNetwork=Wayne,MeContext=LNJ05017A
platformType : CPP
release : H.1.167
technologyDomain : [EPS]
utcOffset : -04:00
2 instance(s)
>>enmscripting.close(session)
One more if we want to run script uploaded on our drive.( health check command)
Note: if you run python in COM mode '>>>' to get out we can type 'exit()'
[bfisha@scp-2-scripting(syl1launcher) ~]$python
Python 2.6.6 (r266:84292, Nov 21 2013, 10:50:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[bfisha@scp-2-scripting(syl1launcher) ~]$
python Page 3
• Client Scripting via Client workstation:
• Prerequisites
Ericsson recommend 2.6.6 but I down load latest 3.6 and works so far but we can find version
2.6.6. down load exe file and installed.
When we install we can use C:\Pythonxx (xx is version we used) to get access folder easy
○ A Python module installation tool that can install modules from Python wheel archives
must be installed on the client workstation. Some Python versions has already included
Python installation package so first check on Script directory under C: \PythonXX if file
PIP.exe is existing if not
Down load get-pip.py script from https address below( which helps to down load PIP and load it
on C:\Pythonxx\Scripts folder
https://pip.pypa.io/en/stable/installing/#do-i-need-to-install-pip
Note: Internet access is required to download the requests module and to run get -pip.py
python Page 4
CMD:
C:\Python36>python get-pip.py
Requirement already up-to-date: pip in c:\python36\lib\site-packages
Collecting wheel
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
100% |████████████████████████████████| 71kB 227kB/s
Installing collected packages: wheel
Successfully installed wheel-0.29.0
○ The user downloads the library to their local machine and imports the modules into their
local Python scripts
1. Download (from ENM) and save the wheel archive to the client workstation. The file name
will be of the form enm_client_scripting-x.x.x-py2-none-any.whl where enm-client-scripting
is the name of the package and x.x.x is the version
2. Install the required modules from the wheel archive. This and subsequent examples, use
the Python Package management tool (PIP) for installation and upgrade of the client
scripting module .
First go to directory:C:\Python36\Scripts
C:\Python36\Scripts>dir
Volume in drive C is OS
Volume Serial Number is C057-8912
Directory of C:\Python36\Scripts
python Page 5
04/12/2017 04:03 PM 98,132 wheel.exe
7 File(s) 588,872 bytes
2 Dir(s) 232,440,737,792 bytes free
C:\Python36\Scripts>
C:\Python36\Scripts>
C:\Python36\Scripts>
C:\Python36\Scripts>pip.exe install C:\Python36\enm_client_scripting-1.13.1-py2.py3-none-
any.whl
• Note: I will upload wheel file on Team Microssoft with procedure so we can access there too
3. Verify enm-client-scripting module and requests module are installed from the wheel
archive using the available Python Package management tool on the client workstation
pip list
enm-client-scripting (x.x.x)
requests (2.6.0)
C:\Python36\Scripts>pip list
enm-client-scripting (1.13.1)
pip (9.0.1)
requests (2.6.0)
setuptools (28.8.0)
wheel (0.29.0)
4. The Client Scripting Library is ready to be used. But when we import ' enmscripting' we will
see error
>>> import enmscripting
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python36\lib\site-packages\enmscripting\__init__.py", line 1, in <module>
from .enmscripting import (open, close)
File "C:\Python36\lib\site-packages\enmscripting\enmscripting.py", line 4, in <module>
from .private import session
File "C:\Python36\lib\site-packages\enmscripting\private\session.py", line 15, in <module>
from .retry import (retry, on_fail_sleep)
File "C:\Python36\lib\site-packages\enmscripting\private\retry.py", line 120
raise self._result[0], self._result[1], self._result[2]
On last page Line 120: Red highlight is the one complain so we have to replace based on note " # The
above is incompatible with Python 3, install six and replace raise with this:)
def return_raise_result(self):
if self._is_exception:
# raise like this is required to keep the original call's stack trace
raise self._result[0], self._result[1], self._result[2]
python Page 6
raise self._result[0], self._result[1], self._result[2]
# The above is incompatible with Python 3, install six and replace raise with this:
# six.reraise(self._result[0], self._result[1], self._result[2])
else:
return self._result
Corrected File will be: after change same it and try import
def return_raise_result(self):
if self._is_exception:
# raise like this is required to keep the original call's stack trace
raise six.reraise(self._result[0], self._result[1], self._result[2])
# The above is incompatible with Python 3, install six and replace raise with this:
# six.reraise(self._result[0], self._result[1], self._result[2]) else:
return self._result
○ Valid credentials must be available to allow logon to ENM from within the scripts
○ Any ENM user specified within the scripts must have correct authorization to execute ENM
CLI commands used in a script
How we can run script is we can use file or we can run command same as using
Client VM.
import enmscripting
Example:
python Page 7
>>> session = enmscripting.open('https://syl1launcher.syl1enm1.mgmt' , 'Username' , 'password')
>>> command = 'config list'
>>> cmd = session.command()
>>> response = cmd.execute(command)
>>> print('The command was successfully sent and a response received: ' +
str(response.is_command_result_available()))
The command was successfully sent and a response received: True
>>> enmscripting.close(session)
>>> for line in response.get_output():
... print(line)
...
HCAcceptanceCriteriaBucket
HCReportBucket
HCCompareBucket
CmGatConfiguration
l2l_test
jeff_test
tmo_demo
TESTGERAN
test_l2l
OD_Test
• The user writes the scripts, using the API to execute whatever CLI commands are required
• The user executes the scripts locally, and the responses are received from the ENM
system to the clients workstation for review/further processing
python Page 8