mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-25 17:27:01 +00:00
Onl Utility Classes.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import subprocess
|
||||
|
||||
class OnlServiceMixin(object):
|
||||
def _execute(self, cmd, root=False, ex=True):
|
||||
self.logger.debug("Executing: %s" % cmd)
|
||||
if root is True and os.getuid() != 0:
|
||||
cmd = "sudo " + cmd
|
||||
try:
|
||||
subprocess.check_call(cmd, shell=True)
|
||||
except Exception, e:
|
||||
if ex:
|
||||
self.logger.error("Command failed: %s" % e)
|
||||
raise
|
||||
else:
|
||||
return e.returncode
|
||||
|
||||
def _raise(self, msg, klass):
|
||||
self.logger.critical(msg)
|
||||
raise klass(msg)
|
||||
|
||||
Reference in New Issue
Block a user