Skip to content

HuaweiDatacomm/mdk

 
 

Repository files navigation

MDK

Overview

MDK: Model Driven Kit.MDK is easy for User to get started and use that provides a way to simplify the process of generating configuration files for network devices using YANG models.User can quickly develop complex network configuration applications by using Python code (not Yang files). User can use the Python language to gracefully handle data structures without thinking about infrastructure and architecture. MDK makes operational network configuration more intuitive and easy to maintain and manage.

Installation

Prerequisites

OS: Ubuntu, CentOS, Suse
Python: 2.7, 3.4, 3.5, 3.6, 3.7
Required Python package:pyang, bitarray, lxml, regex, six, enum34, ncclient, pyangbind

Build From Source

1.Clone the mdk repository:

git clone https://github.com/HuaweiDatacomm/mdk.git

2.Install required Python package:

 pip3 install -r requirments.txt
 python3 setup.py install

Generate Yang modules to Python Class

put Yang Files in dir yang,then run generate_py.sh,you can get all python classes generated by yang files.

cd mdk/yang
chmod +x generate_py.sh
./generate_py.sh

Introduction of MDK API

get: operation queries all or specified configuration data sets.
merge: modifies or creates data in the database. This is the default operation.
create: adds configuration data to the configuration database only if such data does not exist. If the configuration data already exists, is returned, in which the value is data-exists.
delete: deletes a specified configuration data record from the configuration database. If the data exists, it is deleted. If the data does not exist, is returned, in which the value is data-missing.
replace: replaces existing data or creates data that does not exist in the database.

Use Python Class to get configuration and deliver packets to huawei's device

1.modify the mdk.json
2.import mdk.py and python class
3.create mdk and python class instance object
4.get configuration by MDK
5.new objects are added by calling .add() and passing unique key as an argument.
6.update python class
7.deliver packets

Example

huawei_debug.py is used as an example.
1.modify the netconf.json file and configure netconf connection

cd mdk/conf
vim netconf.json

2.import huawei_debug and mdk.

from yang import huawei_debug
from yang import mdk

3.create instance object.

obj = huawei_debug.huawei_debug() 
kit = mdk.MDK()

4.get configuration by MDK.

config_obj = kit.get(python_obj=obj.debug, binding=huawei_debug, entrance_name='huawei-debug')
print(config_obj.get())
result: {'debug':
{'cpu-infos':
{'cpu-info':
OrderedDict([
('3', {'position': '3', 'overload-threshold': 90, 'unoverload-threshold': 75, 'interval': 8, 'index': 0, 'system-cpu-usage': 0, 'monitor-number': 0, 'monitor-cycle': 0, 'overload-state-change-time': '', 'current-overload-state': ''}),
('4', {'position': '4', 'overload-threshold': 90, 'unoverload-threshold': 75, 'interval': 8, 'index': 0, 'system-cpu-usage': 0, 'monitor-number': 0, 'monitor-cycle': 0, 'overload-state-change-time': '', 'current-overload-state': ''}),
('17', {'position': '17', 'overload-threshold': 90, 'unoverload-threshold': 75, 'interval': 8, 'index': 0, 'system-cpu-usage': 0, 'monitor-number': 0, 'monitor-cycle': 0, 'overload-state-change-time': '', 'current-overload-state': ''}),
('18', {'position': '18', 'overload-threshold': 90, 'unoverload-threshold': 75, 'interval': 8, 'index': 0, 'system-cpu-usage': 0, 'monitor-number': 0, 'monitor-cycle': 0, 'overload-state-change-time': '', 'current-overload-state': ''})])},
'memory-infos':
{'memory-info':
OrderedDict([
('3', {'position': '3', 'overload-threshold': 95, 'unoverload-threshold': 75, 'memreli-notice-threshold': 85, 'memreli-overload-threshold': 95, 'index': 0, 'os-memory-total': 0, 'os-memory-use': 0, 'os-memory-free': 0, 'os-memory-usage': 0, 'do-memory-total': 0, 'do-memory-use': 0, 'do-memory-free': 0, 'do-memory-usage': 0, 'simple-memory-total': 0, 'simple-memory-use': 0, 'simple-memory-free': 0, 'simple-memory-usage': 0, 'overload-state-change-time': '', 'current-overload-state': ''}),
('4', {'position': '4', 'overload-threshold': 95, 'unoverload-threshold': 75, 'memreli-notice-threshold': 85, 'memreli-overload-threshold': 95, 'index': 0, 'os-memory-total': 0, 'os-memory-use': 0, 'os-memory-free': 0, 'os-memory-usage': 0, 'do-memory-total': 0, 'do-memory-use': 0, 'do-memory-free': 0, 'do-memory-usage': 0, 'simple-memory-total': 0, 'simple-memory-use': 0, 'simple-memory-free': 0, 'simple-memory-usage': 0, 'overload-state-change-time': '', 'current-overload-state': ''}),
('17', {'position': '17', 'overload-threshold': 95, 'unoverload-threshold': 75, 'memreli-notice-threshold': 85, 'memreli-overload-threshold': 95, 'index': 0, 'os-memory-total': 0, 'os-memory-use': 0, 'os-memory-free': 0, 'os-memory-usage': 0, 'do-memory-total': 0, 'do-memory-use': 0, 'do-memory-free': 0, 'do-memory-usage': 0, 'simple-memory-total': 0, 'simple-memory-use': 0, 'simple-memory-free': 0, 'simple-memory-usage': 0, 'overload-state-change-time': '', 'current-overload-state': ''}),
('18', {'position': '18', 'overload-threshold': 95, 'unoverload-threshold': 75, 'memreli-notice-threshold': 85, 'memreli-overload-threshold': 95, 'index': 0, 'os-memory-total': 0, 'os-memory-use': 0, 'os-memory-free': 0, 'os-memory-usage': 0, 'do-memory-total': 0, 'do-memory-use': 0, 'do-memory-free': 0, 'do-memory-usage': 0, 'simple-memory-total': 0, 'simple-memory-use': 0, 'simple-memory-free': 0, 'simple-memory-usage': 0, 'overload-state-change-time': '', 'current-overload-state': ''})])},
'resouce-reliability': {'memory-reliability': {'enable': False}, 'memory-reliability-switchover-threshold': {'threshold': 70}, 'flow-control-message-reliability': {'enable': True}},
'service-cpu-infos': {'service-cpu-info': OrderedDict()}, 'board-resouce-states': {'board-resouce-state': OrderedDict()}}}

Note: unique key is '3','4','17','18'

5.get details.New objects are added by calling .add() and passing unique key as an argument.

memory_info_position3 = obj.debug.memory_infos.memory_info.add('3')
position3 = kit.get(python_obj=obj.debug, binding=huawei_debug, entrance_name='huawei-debug')
print(position3.get())
result: {'debug':
{'cpu-infos':
{'cpu-info': OrderedDict()},
'memory-infos':
{'memory-info':
OrderedDict([
('3', {'position': '3', 'overload-threshold': 95, 'unoverload-threshold': 75, 'memreli-notice-threshold': 85, 'memreli-overload-threshold': 95, 'index': 0, 'os-memory-total': 0, 'os-memory-use': 0, 'os-memory-free': 0, 'os-memory-usage': 0, 'do-memory-total': 0, 'do-memory-use': 0, 'do-memory-free': 0, 'do-memory-usage': 0, 'simple-memory-total': 0, 'simple-memory-use': 0, 'simple-memory-free': 0, 'simple-memory-usage': 0, 'overload-state-change-time': '', 'current-overload-state': ''})])}, 'resouce-reliability': {'memory-reliability': {'enable': False}, 'memory-reliability-switchover-threshold': {'threshold': 0}, 'flow-control-message-reliability': {'enable': True}}, 'service-cpu-infos': {'service-cpu-info': OrderedDict()}, 'board-resouce-states': {'board-resouce-state': OrderedDict()}}}

6.update python class

position3.debug.memory_infos.memory_info['3'].overload_threshold = 80

7.deliver packets. If the change was applied successfully should return ok

xpath = "/ns:debug/ns:memory-infos/ns:memory-info[ns:position='3']"
ns = {'ns': 'urn:huawei:yang:huawei-debug'}
kit.merge(python_obj=obj.debug, xpath=xpath, namespace=ns)

Note: the xpath is similar to the file path in the file management system. Users can update xpath based on Python objects.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.8%
  • Shell 0.2%