A collection of Python scripts for interacting with Ericsson NetCloud Manager APIs.
- Python 3.7 or higher
- Git (optional, for cloning the repository)
Using Git (Recommended):
git clone <repository-url>
cd api-samplesDownloading as ZIP:
- Download the repository as a ZIP file
- Extract the ZIP file to your desired location
- Navigate to the extracted
api-samplesfolder
cd path/to/extracted/api-samplesCreating a virtual environment isolates project dependencies from your system Python installation.
Windows:
python -m venv .venv
.venv\Scripts\activatemacOS (zsh):
python3 -m venv .venv
source .venv/bin/activateAfter activation, you should see (.venv) at the beginning of your command prompt, indicating the virtual environment is active.
With your virtual environment activated, install the required packages:
pip install -r requirements.txtThis will install all required dependencies including:
ncm- Ericsson NetCloud Manager Python libraryflask- Web framework (for CSV Script Manager)werkzeug- WSGI utilitiespython-dateutil- Date parsing utilities
You need to set your NCM API credentials as environment variables. The scripts will automatically use these when running.
Windows:
set X_CP_API_ID=your_api_id
set X_CP_API_KEY=your_api_key
set X_ECM_API_ID=your_ecm_api_id
set X_ECM_API_KEY=your_ecm_api_key
set TOKEN=your_ncm_api_v3_tokenTo make these persistent in Windows, go to System Properties > Environment Variables and add them there.
macOS (zsh):
export X_CP_API_ID="your_api_id"
export X_CP_API_KEY="your_api_key"
export X_ECM_API_ID="your_ecm_api_id"
export X_ECM_API_KEY="your_ecm_api_key"
export TOKEN="your_ncm_api_v3_token"To make these persistent, add them to your ~/.zshrc:
echo 'export X_CP_API_ID="your_api_id"' >> ~/.zshrc
echo 'export X_CP_API_KEY="your_api_key"' >> ~/.zshrc
echo 'export X_ECM_API_ID="your_ecm_api_id"' >> ~/.zshrc
echo 'export X_ECM_API_KEY="your_ecm_api_key"' >> ~/.zshrc
echo 'export TOKEN="your_ncm_api_v3_token"' >> ~/.zshrc
source ~/.zshrcThis repository contains many sample scripts in the scripts/ folder that demonstrate various API interactions and use cases. These scripts cover a wide range of functionality including:
- Router management and configuration
- Alert creation and management
- User management
- Location tracking and historical data export
- Device metrics and signal samples
- Configuration backups and restoration
- Subscription management
- Device licensing operations
- And much more
Browse the scripts folder to explore all available sample scripts.
Make sure your virtual environment is activated before running scripts.
Windows:
python script_name.pymacOS:
python3 script_name.pyMany scripts accept command-line arguments. Check the script's docstring or run it with --help (if supported) for usage information.
For a convenient web-based interface to manage CSV files, API keys, and run scripts, check out the CSV Script Manager.
Want just the CSV Script Manager? Get it here!
The CSV Script Manager provides:
- Web-based CSV file editor
- API key management interface
- Script execution interface
- Easy script management and organization
- Displays script instructions from docstrings
-
Navigate to the CSV Script Manager directory:
cd scripts/csv_script_manager -
Make sure your virtual environment is activated
-
Start the web server:
Windows:
python csv_script_manager.py
macOS:
python3 csv_script_manager.py
-
Open your browser to
http://localhost:8000 -
Use the web interface to:
- Load and edit CSV files
- Set API keys (stored in session)
- Select and run scripts
- View script documentation
The CSV Script Manager includes several pre-configured scripts:
- ncm_bulk_configure_devices.py - Bulk configure multiple devices with custom configurations
- ncm_v3_create_users.py - Create and manage users in NCM API v3
- ncm_v3_regrade_subscriptions_by_mac.py - Apply or regrade device subscriptions by MAC address
- ncm_v3_unlicense_devices_by_mac.py - Unlicense devices by MAC address
- ncm_get_router_status.py - Get router status and information using identifiers
- ncm_unregister_routers_batch.py - Unregister routers in batches with logging
Each script includes detailed documentation in its docstring explaining the required CSV format and usage.
For a convenient way to test and explore the Ericsson NetCloud Manager APIs, you can use the Ericsson NCM API Postman Collection. This collection contains pre-configured API requests that you can use to interact with the APIs directly from Postman.
- Open Postman
- Click Import in the top left corner
- Select File or Upload Files
- Navigate to and select the
Ericsson NCM API Postman Collection.jsonfile from this repository - Click Import
The collection will now appear in your Postman workspace. You can use it to explore and test the various API endpoints.
Problem: python or python3 command not found
- Windows: Make sure Python is installed and added to PATH
- macOS: Use
python3explicitly, or install Python via Homebrew
Problem: Virtual environment activation fails
- Make sure you're in the correct directory when creating the virtual environment
Problem: Scripts report missing API keys
- Verify environment variables are set correctly
- Make sure your virtual environment is activated
- Check that variable names match exactly (case-sensitive on macOS)
- For CSV Script Manager, use the API Keys tab in the web interface
Problem: ModuleNotFoundError when running scripts
- Make sure your virtual environment is activated
- Verify dependencies are installed:
pip install -r requirements.txt - Some scripts may require additional dependencies - check the script's docstring
Contributions are welcome! Please feel free to submit a Pull Request.
See the LICENSE file for details.