[sonic-cfggen]: Move get_machine_info function to sonic_platform.py (#489)
* Move get_machine_info to lib * Add get platform info API * Create sonic_platform.py Signed-off-by: Sihui Han <sihan@microsoft.com>
This commit is contained in:
parent
4c81204eaf
commit
ec73735d21
@ -47,7 +47,6 @@ class minigraph_encoder(json.JSONEncoder):
|
||||
return str(obj)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
def parse_png(png, hname):
|
||||
neighbors = {}
|
||||
devices = {}
|
||||
|
@ -15,7 +15,7 @@ setup(name='sonic-config-engine',
|
||||
author='Taoyu Li',
|
||||
author_email='taoyl@microsoft.com',
|
||||
url='https://github.com/Azure/sonic-buildimage',
|
||||
py_modules=['minigraph', 'openconfig_acl'],
|
||||
py_modules=['minigraph', 'openconfig_acl', 'sonic_platform'],
|
||||
scripts=['sonic-cfggen', 'translate_acl'],
|
||||
install_requires=['lxml', 'jinja2', 'netaddr', 'ipaddr', 'pyyaml', 'pyangbind'],
|
||||
test_suite='setup.get_test_suite',
|
||||
|
@ -7,9 +7,10 @@ import yaml
|
||||
import jinja2
|
||||
import netaddr
|
||||
import json
|
||||
from minigraph import parse_xml
|
||||
from minigraph import minigraph_encoder
|
||||
|
||||
from minigraph import parse_xml
|
||||
from sonic_platform import get_machine_info
|
||||
from sonic_platform import get_platform_info
|
||||
|
||||
def is_ipv4(value):
|
||||
if not value:
|
||||
@ -44,19 +45,6 @@ def unique_name(l):
|
||||
new_list.append(item)
|
||||
return new_list
|
||||
|
||||
def get_machine_info():
|
||||
if not os.path.isfile('/host/machine.conf'):
|
||||
return None
|
||||
machine_vars = {}
|
||||
with open('/host/machine.conf') as machine_file:
|
||||
for line in machine_file:
|
||||
tokens = line.split('=')
|
||||
if len(tokens) < 2:
|
||||
continue
|
||||
machine_vars[tokens[0]] = tokens[1].strip()
|
||||
return machine_vars
|
||||
|
||||
|
||||
def main():
|
||||
parser=argparse.ArgumentParser(description="Render configuration file from minigraph data and jinja2 template.")
|
||||
parser.add_argument("-m", "--minigraph", help="minigraph xml file")
|
||||
@ -74,10 +62,9 @@ def main():
|
||||
machine_info = get_machine_info()
|
||||
if machine_info != None:
|
||||
data.update(machine_info)
|
||||
if machine_info.has_key('onie_platform'):
|
||||
data['platform'] = machine_info['onie_platform']
|
||||
elif machine_info.has_key('aboot_platform'):
|
||||
data['platform'] = machine_info['aboot_platform']
|
||||
platform_info = get_platform_info(machine_info)
|
||||
if platform_info != None:
|
||||
data['platform'] = platform_info
|
||||
|
||||
if args.minigraph != None:
|
||||
minigraph = args.minigraph
|
||||
|
32
src/sonic-config-engine/sonic_platform.py
Normal file
32
src/sonic-config-engine/sonic_platform.py
Normal file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: sonic_platform
|
||||
version_added: "1.9"
|
||||
short_description: Retrive platform related facts for a device.
|
||||
description:
|
||||
- Retrieve platform related facts from config files.
|
||||
'''
|
||||
|
||||
def get_machine_info():
|
||||
if not os.path.isfile('/host/machine.conf'):
|
||||
return None
|
||||
machine_vars = {}
|
||||
with open('/host/machine.conf') as machine_file:
|
||||
for line in machine_file:
|
||||
tokens = line.split('=')
|
||||
if len(tokens) < 2:
|
||||
continue
|
||||
machine_vars[tokens[0]] = tokens[1].strip()
|
||||
return machine_vars
|
||||
|
||||
def get_platform_info(machine_info):
|
||||
if machine_info != None:
|
||||
if machine_info.has_key('onie_platform'):
|
||||
return machine_info['onie_platform']
|
||||
elif machine_info.has_key('aboot_platform'):
|
||||
return machine_info['aboot_platform']
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user