Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kernel info and timezone info #127

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions rrmngmnt/operatingsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def __init__(self, host):
self._release_str = None
self._release_info = None
self._dist = None
self._kernel = None
self._timezone = None

def _exec_command(self, cmd, err_msg=None):
host_executor = self.host.executor()
Expand Down Expand Up @@ -114,6 +116,58 @@ def distribution(self):
self._dist = self.get_distribution()
return self._dist

def get_kernel_info(self):
"""
Get kernel info (release, version and type)

Returns:
namedtuple Kernel: Results tuple(release, version and type)

Examples:
kernel(
release='4.18.0-135.el8.x86_64',
version='#1 SMP Fri Aug 16 19:31:40 UTC 2019',
type'='x86_64'
)
"""
values = ["release", "version", "type"]
cmd = ["uname", "-r", ";", "uname", "-v", ";", "uname", "-m"]
out = self._exec_command(
cmd=cmd, err_msg="Failed to obta kernel info"
)
Kernel = namedtuple('Kernel', values)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kernel, should be all lowercase

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made it from capital just to be aligned with already existing code (see Distribution in get_distribution method)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, but I guess @lukas-bednar should decide.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is alright. namedtuple returns a class, and then you create instance of that class. And classes in python should be Uppercased.

return Kernel(*[i.strip() for i in out.strip().split("\n")])

@property
def kernel_info(self):
if not self._kernel:
self._kernel = self.get_kernel_info()
return self._kernel

def get_timezone(self):
"""
Get timezone (name and offset)

Returns:
namedtuple Timezone: Results tuple(name and offset)

Examples:
kernel(name='IDT', offset='+0300')
"""
values = ["name", "offset"]
cmd = ["date", "+%Z\\", "%z"]
out = self._exec_command(
cmd=cmd, err_msg="Failed to obtain timezone info"
)
Timezone = namedtuple('Timezone', values)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

return Timezone(*[i.strip() for i in out.split()])

@property
def timezone(self):
if not self._timezone:
self._timezone = self.get_timezone()
return self._timezone

def stat(self, path):
"""
Get file or directory stats
Expand Down