-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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>
- Loading branch information
1 parent
4c81204
commit ec73735
Showing
4 changed files
with
39 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|