forked from ungleich-public/cdist
use new logger
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
parent
6cbcd1132e
commit
a692e551c0
1 changed files with 5 additions and 9 deletions
|
@ -25,14 +25,13 @@ import subprocess
|
||||||
|
|
||||||
import cdist
|
import cdist
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class Wrapper(object):
|
class Wrapper(object):
|
||||||
def __init__(self, target_host, remote_exec, remote_copy):
|
def __init__(self, target_host, remote_exec, remote_copy):
|
||||||
self.target_host = target_host
|
self.target_host = target_host
|
||||||
self.remote_exec = remote_exec
|
self.remote_exec = remote_exec
|
||||||
self.remote_copy = remote_copy
|
self.remote_copy = remote_copy
|
||||||
|
self.log = logging.getLogger(self.target_host)
|
||||||
|
|
||||||
def remote_mkdir(self, directory):
|
def remote_mkdir(self, directory):
|
||||||
"""Create directory on remote side"""
|
"""Create directory on remote side"""
|
||||||
|
@ -58,15 +57,15 @@ class Wrapper(object):
|
||||||
remote_prefix.append(self.target_host)
|
remote_prefix.append(self.target_host)
|
||||||
args[0][:0] = remote_prefix
|
args[0][:0] = remote_prefix
|
||||||
|
|
||||||
log.debug("Shell exec cmd: %s", args)
|
self.log.debug("Shell exec cmd: %s", args)
|
||||||
|
|
||||||
if 'env' in kargs:
|
if 'env' in kargs:
|
||||||
log.debug("Shell exec env: %s", kargs['env'])
|
self.log.debug("Shell exec env: %s", kargs['env'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(*args, **kargs)
|
subprocess.check_call(*args, **kargs)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
log.error("Code that raised the error:\n")
|
self.log.error("Code that raised the error:\n")
|
||||||
|
|
||||||
if remote:
|
if remote:
|
||||||
self.run_or_fail(["cat", script], remote=remote)
|
self.run_or_fail(["cat", script], remote=remote)
|
||||||
|
@ -89,13 +88,10 @@ class Wrapper(object):
|
||||||
remote_prefix.append(self.target_host)
|
remote_prefix.append(self.target_host)
|
||||||
args[0][:0] = remote_prefix
|
args[0][:0] = remote_prefix
|
||||||
|
|
||||||
log.debug("Exec: " + " ".join(*args))
|
self.log.debug("Exec: " + " ".join(*args))
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(*args, **kargs)
|
subprocess.check_call(*args, **kargs)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
raise cdist.Error("Command failed: " + " ".join(*args))
|
raise cdist.Error("Command failed: " + " ".join(*args))
|
||||||
except OSError as error:
|
except OSError as error:
|
||||||
raise cdist.Error(" ".join(*args) + ": " + error.args[1])
|
raise cdist.Error(" ".join(*args) + ": " + error.args[1])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue