diff options
Diffstat (limited to 'libs/utils/hostutils.py')
-rw-r--r-- | libs/utils/hostutils.py | 73 |
1 files changed, 57 insertions, 16 deletions
diff --git a/libs/utils/hostutils.py b/libs/utils/hostutils.py index e6f7189..bb4ca29 100644 --- a/libs/utils/hostutils.py +++ b/libs/utils/hostutils.py @@ -13,7 +13,7 @@ import re from collections import namedtuple import atfutils from atfglobals import GlobalObj -import pdb +import os system_dirs = re.compile('(/bin|/boot|/dev|/etc|/lib|/mnt|/net|/opt|/root|/sbin|/usr|/var|/sys)\/?$') @@ -27,15 +27,15 @@ def cd(hostkey, dirpath): if not host_connection: logger.error("SSH Connection Not established to host '%s' " % hostkey) return 1 - + command = ' '.join([base_command, dirpath]) logger.debug('%s: Executing Command: %s' % (hostkey, command)) output = host_connection.executecommand(command) return_status = atfutils.assert_success(output['exitstatus']) atfutils.print_stdout(output['stdoutdata']) atfutils.print_stderr(output['stderrdata']) - return return_status - + return return_status + def rmdir(hostkey, dirpath): """ """ @@ -45,7 +45,7 @@ def rmdir(hostkey, dirpath): if system_dirs.match(dirpath): logger.error("System Directiories cannot be deleted") return 1 - + else: host_connection = cm.getConnection(hostkey) if not host_connection: @@ -60,7 +60,7 @@ def rmdir(hostkey, dirpath): atfutils.print_stdout(output['stdoutdata']) atfutils.print_stderr(output['stderrdata']) return return_status - + def mkdir(hostkey, dirpath): """ """ @@ -92,7 +92,7 @@ def mkfs(hostkey, device, fstype=None): """ logger = GlobalObj.getLoggerObj() base_command = "mkfs" - cm = GlobalObj.getConnectionsManagerObj() + cm = GlobalObj.getConnectionsManagerObj() host_connection = cm.getConnection(hostkey) command = [base_command] options = [] @@ -103,9 +103,9 @@ def mkfs(hostkey, device, fstype=None): if fstype is None: fstype = "xfs" - + options.extend(["-t", fstype, "-f", device]) - + command.extend(options) command = ' '.join(command) logger.debug('%s: Executing Command: %s' % (hostkey, command)) @@ -115,13 +115,48 @@ def mkfs(hostkey, device, fstype=None): atfutils.print_stderr(output['stderrdata']) return return_status +def md5sum(hostkey, path): + """ + """ + output = {} + output["exitstatus"] = None + output["stdoutdata"] = None + output["stderrdata"] = None + + base_command1 = "rm -rf" + base_command2 = "arequal-checksum" + landfill_dir = os.path.join(path, ".landfill") + + cm = GlobalObj.getConnectionsManagerObj() + host_connection = cm.getConnection(hostkey) + if not host_connection: + logger.error("SSH connection to host '%s' has not been established" + % hostkey) + output["exitstatus"] = 1 + return output + + command1 = ' '.join([base_command1, landfill_dir]) + command2 = ' '.join([base_command2, path]) + command = ';'.join([command1, command2]) + output = host_connection.executecommand(command) + atfutils.print_stdout(output['stdoutdata']) + atfutils.print_stderr(output['stderrdata']) + + if output['stdoutdata'] is None or (not output['stdoutdata']): + output['stdoutdata'] = "" + + else: + output['stdoutdata'] = str(output['stdoutdata']) + + return output + def find_mountpoints(hostkey, device): """ """ logger = GlobalObj.getLoggerObj() - base_command = "mount | grep " + base_command = "mount | grep " cm = GlobalObj.getConnectionsManagerObj() - + host_connection = cm.getConnection(hostkey) if not host_connection: logger.error("SSH connection to host '%s' has not been established" @@ -141,13 +176,18 @@ def find_mountpoints(hostkey, device): def execute_command(hostkey, command, commandInput=None): """ """ + output = {} + output["exitstatus"] = None + output["stdoutdata"] = None + output["stderrdata"] = None logger = GlobalObj.getLoggerObj() cm = GlobalObj.getConnectionsManagerObj() host_connection = cm.getConnection(hostkey) if not host_connection: logger.error("SSH Connection Not established to host '%s' " % hostkey) - return 1 + output["exitstatus"] = 1 + return output new_command = _substitute_value_for_variables(command) logger.debug('%s: Executing Command: %s' % (hostkey, command)) @@ -178,14 +218,14 @@ def _substitute_value_for_variables(command): "name", "option"]) variables_to_replace = [] - + variables = pattern_for_variables.findall(command) - if not variables: + if not variables: return new_command - + else: active_volume = env.getActiveVolume() - + for variable in variables: if variable not in variables_to_replace: name, option = (variable.strip("<>")).split(".") @@ -230,5 +270,6 @@ __all__ = ['cd', 'rmdir', 'mkdir', 'mkfs', + 'md5sum', 'find_mountpoints', 'execute_command'] |