-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed ssd_base -> storage_base, added class for common calls, modif…
…ied child class implementation accordingly
- Loading branch information
1 parent
4e5e79d
commit 2ebc2c1
Showing
5 changed files
with
138 additions
and
36 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,85 @@ | ||
# | ||
# storage_common.py | ||
# | ||
# Class for common implementation functions, | ||
# i.e. functions that are storage device type agnostic. | ||
# | ||
|
||
try: | ||
import os | ||
import sys | ||
except ImportError as e: | ||
raise ImportError (str(e) + "- required module not found") | ||
|
||
try: | ||
import psutil | ||
except ImportError as e: | ||
pass | ||
|
||
class StorageCommon(object): | ||
def __init__(self, diskdev): | ||
""" | ||
Constructor | ||
Args: | ||
Block device path for which we need to get information | ||
""" | ||
self.DISKSTATS_FILE = "/proc/diskstats" | ||
self.MOUNTS_FILE = "/proc/mounts" | ||
self.diskdev = os.path.basename(diskdev) | ||
self.partition = self.__set_host_partition(self.diskdev) | ||
|
||
def __set_host_partition(self, diskdev): | ||
""" | ||
internal function to fetch SONiC partition | ||
Returns: | ||
The partition containing '/host' mount, or 'N/A' if not found | ||
Args: | ||
N/A | ||
""" | ||
if 'psutil' in sys.modules: | ||
for p in psutil.disk_partitions(): | ||
if p.mountpoint == "/host": | ||
return os.path.basename(p.device) | ||
return None | ||
|
||
else: | ||
mounts = "" | ||
with open(self.MOUNTS_FILE) as f: | ||
mounts = f.readlines() | ||
|
||
for mt in mounts: | ||
if '/host' in mt and diskdev in mt: | ||
return os.path.basename(mt.split()[0]) | ||
return None | ||
|
||
def get_fs_io_reads(self): | ||
|
||
searchterm = self.partition | ||
if searchterm == None: searchterm = self.diskdev | ||
|
||
if 'psutil' in sys.modules: | ||
return psutil.disk_io_counters(perdisk=True, nowrap=True)[searchterm].read_count | ||
else: | ||
with open(self.DISKSTATS_FILE) as f: | ||
statsfile = f.readlines() | ||
for line in statsfile: | ||
if searchterm in line: | ||
return line.split()[3] | ||
return 'N/A' | ||
|
||
def get_fs_io_writes(self): | ||
|
||
searchterm = self.partition | ||
if searchterm == None: searchterm = self.diskdev | ||
|
||
if 'psutil' in sys.modules: | ||
return psutil.disk_io_counters(perdisk=True, nowrap=True)[searchterm].write_count | ||
else: | ||
with open(self.DISKSTATS_FILE) as f: | ||
statsfile = f.readlines() | ||
for line in statsfile: | ||
if searchterm in line: | ||
return line.split()[7] | ||
return 'N/A' |
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