mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
XML file: add support for HDM format
This commit is contained in:
parent
d9daf63337
commit
20548f2301
2 changed files with 140 additions and 6 deletions
13
README.md
13
README.md
|
|
@ -626,7 +626,7 @@ The application should bring its JSON file under **'/etc/bbfdm/json/'** path wit
|
||||||
|
|
||||||
### XML generator
|
### XML generator
|
||||||
|
|
||||||
It is a generator of Data Model tree in XML format which conforms to Broadband Forum schema.
|
It is a generator of Data Model tree in XML with two format: **Broadband Forum schema** and **HDM**.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ python generate_dm_xml.py -h
|
$ python generate_dm_xml.py -h
|
||||||
|
|
@ -635,6 +635,13 @@ Options:
|
||||||
-r, --remote-dm Check OBJ/PARAM under these repositories if it is not found under bbf repo
|
-r, --remote-dm Check OBJ/PARAM under these repositories if it is not found under bbf repo
|
||||||
-v, --vendor-list Generate data model tree with vendor extension OBJ/PARAM
|
-v, --vendor-list Generate data model tree with vendor extension OBJ/PARAM
|
||||||
-p, --vendor-prefix Generate data model tree using this vendor prefix. Default vendor prefix: X_IOPSYS_EU_
|
-p, --vendor-prefix Generate data model tree using this vendor prefix. Default vendor prefix: X_IOPSYS_EU_
|
||||||
|
-f, --format Generate data model tree with HDM format. Default format: BBF
|
||||||
|
-d, --device-protocol Generate data model tree using this device protocol. Default device protocol: DEVICE_PROTOCOL_DSLFTR069v1
|
||||||
|
-m, --manufacturer Generate data model tree using this manufacturer. Default manufacturer: iopsys
|
||||||
|
-o, --manufacturer-oui Generate data model tree using this manufacturer oui. Default manufacturer oui: 002207
|
||||||
|
-c, --product-class Generate data model tree using this product class. Default product class: DG400PRIME
|
||||||
|
-n, --model-name Generate data model tree using this model name. Default model name: DG400PRIME-A
|
||||||
|
-s, --software-version Generate data model tree using this software version. Default software version: 1.2.3.4
|
||||||
-h, --help This help text
|
-h, --help This help text
|
||||||
Urls:
|
Urls:
|
||||||
url^(branch,hash,tag) The url with branch, hash or tag to be used
|
url^(branch,hash,tag) The url with branch, hash or tag to be used
|
||||||
|
|
@ -642,8 +649,10 @@ Urls:
|
||||||
Examples:
|
Examples:
|
||||||
- python generate_dm_xml.py
|
- python generate_dm_xml.py
|
||||||
==> Generate xml file in datamodel.xml
|
==> Generate xml file in datamodel.xml
|
||||||
|
- python generate_dm_xml.py -f HDM
|
||||||
|
==> Generate xml file with HDM format in datamodel.xml
|
||||||
- python generate_dm_xml.py -v iopsys
|
- python generate_dm_xml.py -v iopsys
|
||||||
==> Generate xml file in datamodel.xml
|
==> Generate xml file using iopsys extension in datamodel.xml
|
||||||
- python generate_dm_xml.py -r https://dev.iopsys.eu/feed/iopsys.git^devel,https://dev.iopsys.eu/iopsys/mydatamodel.git^5c8e7cb740dc5e425adf53ea574fb529d2823f88
|
- python generate_dm_xml.py -r https://dev.iopsys.eu/feed/iopsys.git^devel,https://dev.iopsys.eu/iopsys/mydatamodel.git^5c8e7cb740dc5e425adf53ea574fb529d2823f88
|
||||||
==> Generate xml file in datamodel.xml
|
==> Generate xml file in datamodel.xml
|
||||||
- python generate_dm_xml.py -v iopsys,openwrt,test -r https://dev.iopsys.eu/feed/iopsys.git^6.0.0ALPHA1 -p X_TEST_COM_
|
- python generate_dm_xml.py -v iopsys,openwrt,test -r https://dev.iopsys.eu/feed/iopsys.git^6.0.0ALPHA1 -p X_TEST_COM_
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,19 @@ import getopt
|
||||||
import bbf_common as bbf
|
import bbf_common as bbf
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import xml.dom.minidom as MD
|
import xml.dom.minidom as MD
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
BBF_REMOTE_DM = None
|
BBF_REMOTE_DM = None
|
||||||
BBF_VENDOR_LIST = None
|
BBF_VENDOR_LIST = None
|
||||||
DM_OBJ_COUNT = 0
|
DM_OBJ_COUNT = 0
|
||||||
DM_PARAM_COUNT = 0
|
DM_PARAM_COUNT = 0
|
||||||
|
DEVICE_PROTOCOL = "DEVICE_PROTOCOL_DSLFTR069v1"
|
||||||
|
MANUFACTURER = "iopsys"
|
||||||
|
MANUFACTURER_OUI = "002207"
|
||||||
|
PRODUCT_CLASS = "DG400PRIME"
|
||||||
|
MODEL_NAME = "DG400PRIME-A"
|
||||||
|
SOFTWARE_VERSION = "1.2.3.4"
|
||||||
|
XML_FORMAT = "BBF"
|
||||||
XML_FILE = "datamodel.xml"
|
XML_FILE = "datamodel.xml"
|
||||||
|
|
||||||
ARRAY_TYPES = { "DMT_STRING" : "string",
|
ARRAY_TYPES = { "DMT_STRING" : "string",
|
||||||
|
|
@ -32,6 +40,15 @@ def print_dmxml_usage():
|
||||||
print(" -r, --remote-dm Check OBJ/PARAM under these repositories if it is not found under bbf repo")
|
print(" -r, --remote-dm Check OBJ/PARAM under these repositories if it is not found under bbf repo")
|
||||||
print(" -v, --vendor-list Generate data model tree with vendor extension OBJ/PARAM")
|
print(" -v, --vendor-list Generate data model tree with vendor extension OBJ/PARAM")
|
||||||
print(" -p, --vendor-prefix Generate data model tree using this vendor prefix. Default vendor prefix: %s" % bbf.BBF_VENDOR_PREFIX)
|
print(" -p, --vendor-prefix Generate data model tree using this vendor prefix. Default vendor prefix: %s" % bbf.BBF_VENDOR_PREFIX)
|
||||||
|
print(" -f, --format Generate data model tree with HDM format. Default format: %s" % XML_FORMAT)
|
||||||
|
print(" -d, --device-protocol Generate data model tree using this device protocol. Default device protocol: %s" % DEVICE_PROTOCOL)
|
||||||
|
print(" -m, --manufacturer Generate data model tree using this manufacturer. Default manufacturer: %s" % MANUFACTURER)
|
||||||
|
print(" -o, --manufacturer-oui Generate data model tree using this manufacturer oui. Default manufacturer oui: %s" % MANUFACTURER_OUI)
|
||||||
|
print(" -c, --product-class Generate data model tree using this product class. Default product class: %s" % PRODUCT_CLASS)
|
||||||
|
print(" -n, --model-name Generate data model tree using this model name. Default model name: %s" % MODEL_NAME)
|
||||||
|
print(" -s, --software-version Generate data model tree using this software version. Default software version: %s" % SOFTWARE_VERSION)
|
||||||
|
|
||||||
|
|
||||||
print(" -h, --help This help text")
|
print(" -h, --help This help text")
|
||||||
print("Urls: ")
|
print("Urls: ")
|
||||||
print(" url^(branch,hash,tag) The url with branch, hash or tag to be used")
|
print(" url^(branch,hash,tag) The url with branch, hash or tag to be used")
|
||||||
|
|
@ -39,8 +56,10 @@ def print_dmxml_usage():
|
||||||
print("Examples: ")
|
print("Examples: ")
|
||||||
print(" - python " + sys.argv[0])
|
print(" - python " + sys.argv[0])
|
||||||
print(" ==> Generate xml file in %s" % XML_FILE)
|
print(" ==> Generate xml file in %s" % XML_FILE)
|
||||||
|
print(" - python " + sys.argv[0] + " -f HDM")
|
||||||
|
print(" ==> Generate xml file with HDM format in %s" % XML_FILE)
|
||||||
print(" - python " + sys.argv[0] + " -v iopsys")
|
print(" - python " + sys.argv[0] + " -v iopsys")
|
||||||
print(" ==> Generate xml file in %s" % XML_FILE)
|
print(" ==> Generate xml file using iopsys extension in %s" % XML_FILE)
|
||||||
print(" - python " + sys.argv[0] + " -r https://dev.iopsys.eu/feed/iopsys.git^devel,https://dev.iopsys.eu/iopsys/mydatamodel.git^5c8e7cb740dc5e425adf53ea574fb529d2823f88")
|
print(" - python " + sys.argv[0] + " -r https://dev.iopsys.eu/feed/iopsys.git^devel,https://dev.iopsys.eu/iopsys/mydatamodel.git^5c8e7cb740dc5e425adf53ea574fb529d2823f88")
|
||||||
print(" ==> Generate xml file in %s" % XML_FILE)
|
print(" ==> Generate xml file in %s" % XML_FILE)
|
||||||
print(" - python " + sys.argv[0] + " -v iopsys,openwrt,test -r https://dev.iopsys.eu/feed/iopsys.git^6.0.0ALPHA1 -p X_TEST_COM_")
|
print(" - python " + sys.argv[0] + " -v iopsys,openwrt,test -r https://dev.iopsys.eu/feed/iopsys.git^6.0.0ALPHA1 -p X_TEST_COM_")
|
||||||
|
|
@ -51,7 +70,7 @@ def pretty_format( elem ):
|
||||||
reparsed = MD.parseString(elem_string)
|
reparsed = MD.parseString(elem_string)
|
||||||
return reparsed.toprettyxml(indent=" ")
|
return reparsed.toprettyxml(indent=" ")
|
||||||
|
|
||||||
def generate_xml_file():
|
def generate_bbf_xml_file():
|
||||||
global DM_OBJ_COUNT
|
global DM_OBJ_COUNT
|
||||||
global DM_PARAM_COUNT
|
global DM_PARAM_COUNT
|
||||||
|
|
||||||
|
|
@ -95,8 +114,97 @@ def generate_xml_file():
|
||||||
xml_file.write(pretty_format(root))
|
xml_file.write(pretty_format(root))
|
||||||
xml_file.close()
|
xml_file.close()
|
||||||
|
|
||||||
|
def generate_hdm_xml_file():
|
||||||
|
global DM_OBJ_COUNT
|
||||||
|
global DM_PARAM_COUNT
|
||||||
|
|
||||||
|
bbf.remove_file(XML_FILE)
|
||||||
|
root = ET.Element("deviceType")
|
||||||
|
root.set("xmlns", "urn:dslforum-org:hdm-0-0")
|
||||||
|
root.set("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
|
||||||
|
root.set("xsi:schemaLocation", "urn:dslforum-org:hdm-0-0 deviceType.xsd")
|
||||||
|
|
||||||
|
protocol = ET.SubElement(root, "protocol")
|
||||||
|
protocol.text = str(DEVICE_PROTOCOL)
|
||||||
|
manufacturer = ET.SubElement(root, "manufacturer")
|
||||||
|
manufacturer.text = str(MANUFACTURER)
|
||||||
|
manufacturerOUI = ET.SubElement(root, "manufacturerOUI")
|
||||||
|
manufacturerOUI.text = str(MANUFACTURER_OUI)
|
||||||
|
productClass = ET.SubElement(root, "productClass")
|
||||||
|
productClass.text = str(PRODUCT_CLASS)
|
||||||
|
modelName = ET.SubElement(root, "modelName")
|
||||||
|
modelName.text = str(MODEL_NAME)
|
||||||
|
softwareVersion = ET.SubElement(root, "softwareVersion")
|
||||||
|
softwareVersion.text = str(SOFTWARE_VERSION)
|
||||||
|
|
||||||
|
dataModel = ET.SubElement(root, "dataModel")
|
||||||
|
attributes = ET.SubElement(dataModel, "attributes")
|
||||||
|
parameters = ET.SubElement(dataModel, "parameters")
|
||||||
|
|
||||||
|
attribute_notification = ET.SubElement(attributes, "attribute")
|
||||||
|
attributeName = ET.SubElement(attribute_notification, "attributeName")
|
||||||
|
attributeName.text = str("notification")
|
||||||
|
attributeType = ET.SubElement(attribute_notification, "attributeType")
|
||||||
|
attributeType.text = str("int")
|
||||||
|
minValue = ET.SubElement(attribute_notification, "minValue")
|
||||||
|
minValue.text = str("0")
|
||||||
|
maxValue = ET.SubElement(attribute_notification, "maxValue")
|
||||||
|
maxValue.text = str("2")
|
||||||
|
|
||||||
|
attribute_access_list = ET.SubElement(attributes, "attribute")
|
||||||
|
attributeName = ET.SubElement(attribute_access_list, "attributeName")
|
||||||
|
attributeName.text = str("accessList")
|
||||||
|
attributeType = ET.SubElement(attribute_access_list, "attributeType")
|
||||||
|
attributeType.text = str("string")
|
||||||
|
array = ET.SubElement(attribute_access_list, "array")
|
||||||
|
array.text = str("true")
|
||||||
|
attributeLength = ET.SubElement(attribute_access_list, "attributeLength")
|
||||||
|
attributeLength.text = str("64")
|
||||||
|
|
||||||
|
attribute_visibility = ET.SubElement(attributes, "attribute")
|
||||||
|
attributeName = ET.SubElement(attribute_visibility, "attributeName")
|
||||||
|
attributeName.text = str("visibility")
|
||||||
|
attributeType = ET.SubElement(attribute_visibility, "attributeType")
|
||||||
|
attributeType.text = str("string")
|
||||||
|
array = ET.SubElement(attribute_visibility, "array")
|
||||||
|
array.text = str("true")
|
||||||
|
attributeLength = ET.SubElement(attribute_visibility, "attributeLength")
|
||||||
|
attributeLength.text = str("64")
|
||||||
|
|
||||||
|
param_array = np.empty(15, dtype=ET.Element)
|
||||||
|
param_array[0] = parameters
|
||||||
|
|
||||||
|
for value in bbf.LIST_SUPPORTED_DM:
|
||||||
|
|
||||||
|
obj = value.split(",")
|
||||||
|
|
||||||
|
if obj[2] == "DMT_OBJ":
|
||||||
|
## Object
|
||||||
|
obj_tag = ET.SubElement(param_array[obj[0].replace(".{i}", "").count('.')-1], "parameter")
|
||||||
|
obj_name = ET.SubElement(obj_tag, "parameterName")
|
||||||
|
obj_name.text = str(obj[0].replace(".{i}", "").split('.')[-2])
|
||||||
|
obj_type = ET.SubElement(obj_tag, "parameterType")
|
||||||
|
obj_type.text = str("object")
|
||||||
|
obj_array = ET.SubElement(obj_tag, "array")
|
||||||
|
obj_array.text = str("true" if obj[0].endswith(".{i}.") else "false")
|
||||||
|
parameters = ET.SubElement(obj_tag, "parameters")
|
||||||
|
param_array[obj[0].replace(".{i}", "").count('.')] = parameters
|
||||||
|
DM_OBJ_COUNT += 1
|
||||||
|
else:
|
||||||
|
## Parameter
|
||||||
|
param_tag = ET.SubElement(param_array[obj[0].replace(".{i}", "").count('.')], "parameter")
|
||||||
|
param_name = ET.SubElement(param_tag, "parameterName")
|
||||||
|
param_name.text = str(obj[0][obj[0].rindex('.')+1:])
|
||||||
|
param_type = ET.SubElement(param_tag, "parameterType")
|
||||||
|
param_type.text = str(ARRAY_TYPES.get(obj[2], None))
|
||||||
|
DM_PARAM_COUNT += 1
|
||||||
|
|
||||||
|
xml_file = open(XML_FILE, "w")
|
||||||
|
xml_file.write(pretty_format(root))
|
||||||
|
xml_file.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "hr:v:p:", ["remote-dm=", "vendor-list=", "vendor-prefix="])
|
opts, args = getopt.getopt(sys.argv[1:], "hr:v:p:d:m:o:c:n:s:f:", ["remote-dm=", "vendor-list=", "vendor-prefix=", "device-protocol=", "manufacturer=", "manufacturer-oui=", "product-class=", "model-name=", "software-version=", "format="])
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
print_dmxml_usage()
|
print_dmxml_usage()
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
@ -111,10 +219,27 @@ for opt, arg in opts:
|
||||||
BBF_VENDOR_LIST = arg
|
BBF_VENDOR_LIST = arg
|
||||||
elif opt in ("-p", "--vendor-prefix"):
|
elif opt in ("-p", "--vendor-prefix"):
|
||||||
bbf.BBF_VENDOR_PREFIX = arg
|
bbf.BBF_VENDOR_PREFIX = arg
|
||||||
|
elif opt in ("-d", "--device-protocol"):
|
||||||
|
DEVICE_PROTOCOL = arg
|
||||||
|
elif opt in ("-m", "--manufacturer"):
|
||||||
|
MANUFACTURER = arg
|
||||||
|
elif opt in ("-o", "--manufacturer-oui"):
|
||||||
|
MANUFACTURER_OUI = arg
|
||||||
|
elif opt in ("-c", "--product-class"):
|
||||||
|
PRODUCT_CLASS = arg
|
||||||
|
elif opt in ("-n", "--model-name"):
|
||||||
|
MODEL_NAME = arg
|
||||||
|
elif opt in ("-s", "--software-version"):
|
||||||
|
SOFTWARE_VERSION = arg
|
||||||
|
elif opt in ("-f", "--format"):
|
||||||
|
XML_FORMAT = arg
|
||||||
|
|
||||||
bbf.generate_supported_dm(BBF_REMOTE_DM, BBF_VENDOR_LIST)
|
bbf.generate_supported_dm(BBF_REMOTE_DM, BBF_VENDOR_LIST)
|
||||||
|
|
||||||
generate_xml_file()
|
if XML_FORMAT == "HDM":
|
||||||
|
generate_hdm_xml_file()
|
||||||
|
else:
|
||||||
|
generate_bbf_xml_file()
|
||||||
|
|
||||||
print("Number of BBF Data Models objects is %d" % DM_OBJ_COUNT)
|
print("Number of BBF Data Models objects is %d" % DM_OBJ_COUNT)
|
||||||
print("Number of BBF Data Models parameters is %d" % DM_PARAM_COUNT)
|
print("Number of BBF Data Models parameters is %d" % DM_PARAM_COUNT)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue