Exemplo n.º 1
0
 def os_type(self,display=True):
     """
     Show OS type ( LFS, RedHat CentOS ... ) [display] True by default
     """
     if util._is_host_up(env.host, int(env.port)) is False:
         return False
     OS = util._run("bash -c 'head -n 1 /etc/{{system,redhat,centos}-release,release} 2>/dev/null' | sort -u | grep -v '^==>'")
     if re.match("LC",OS,flags=re.IGNORECASE):
         if display:
             print env.host + "| LFS"
         return "lfs"
     if re.match("Red Hat",OS,flags=re.IGNORECASE):
         if display:
             print env.host  + "| redhat"
         return "redhat"
     if re.match("Centos",OS,flags=re.IGNORECASE):
         if display:
             print env.host  + "| centos"
         return "centos"
     if re.match("Solaris",OS,flags=re.IGNORECASE):
         if display:
             print env.host  + "| solaris"
         return "solaris"
     else:
         if display:
             print env.host  + "| UNKNOWN_OS"
         return "UNKNOWN_OS"
Exemplo n.º 2
0
 def arch(self):
         """
         Show architecture x86_64, i386 ...
         """
         if not util._is_host_up(env.host, int(env.port)):
             return False
         print env.host + "|" + util._run("uname --hardware-platform")
Exemplo n.º 3
0
 def uptime(self):
         """
         Show uptime of the host
         """
         if not util._is_host_up(env.host, int(env.port)):
             return False
         print env.host + "|" + util._run('uptime')
Exemplo n.º 4
0
 def id(self):
     """
     Get the current id of the user on remote host
     """
     id = util._run("id")
     print env.host+"|"+id
     return id
Exemplo n.º 5
0
 def kernel_version(self):
         """
         Display the kernel version running on the host
         """
         if util._is_host_up(env.host, int(env.port)) is False:
          return False
         k_version =  util._run('uname -r')
         print env.host + "|" + k_version
Exemplo n.º 6
0
 def _fabrun(self,*args):
     puts("FABRUN SUDO ="+str(self.needSudo))
     if self.needSudo:
         puts("Using sudo for "+str(args))
         return util._sudo(*args)
     else:
         puts("Using run for "+str(args))
         return util._run(*args)
Exemplo n.º 7
0
 def hostname(self):
         """
         Return configured hostname
         """
         if not util._is_host_up(env.host, int(env.port)):
             return False
         result = util._run('hostname -f')
         if result.succeeded:
             print env.host + "|" + result
         return result.succeeded
Exemplo n.º 8
0
 def date(self):
         """
         Show date of the host
         """
         if not util._is_host_up(env.host, int(env.port)):
             return False
         result = util._run('date')
         if result.succeeded:
             print env.host + "|" + result
         return result.succeeded
Exemplo n.º 9
0
 def check_tcp(self,rhost,rport,timeout=5):
         """
         Test <rhost> <rport> tcp connectivity from host using python
         with [timeout] (default: 5s)
         """
         if util._is_host_up(env.host, int(env.port)) is False:
                 return False
         HOSTNAME = env.host
         puts("Proxy %s port %s " % (rhost,rport))
         tcp_check = util._run("python -c \"import socket;sock=socket.socket();sock.settimeout("+str(timeout)+");sock.connect(('"+rhost+"',"+rport+"));sock.close()\"")
         if tcp_check.succeeded:
                 print HOSTNAME + "|" + rhost + "|" + rport + "|" + green("Success")
         else:
                 print HOSTNAME + "|" + rhost + "|" + rport + "|" + red("Failed",True)
         return tcp_check.succeeded
Exemplo n.º 10
0
 def version_rpm(self,name):
         """
         Display rpm package <name> version
         """
         if util._is_host_up(env.host, int(env.port)) is False:
             return False
         #rpms =  util._run('rpm -qa | egrep \"'+name+'\"')
         os_version = self.os_release(display=False)
         rpms =  util._run('rpm -q '+name+' --queryformat "%{NAME}|%{VERSION}-%{RELEASE}.%{ARCH}|%{INSTALLTIME:date}\n"')
         rpms_list = rpms.splitlines()
         if not self.first.has_key(util._func_name()):
             self.first[util._func_name()] = True
             util._print_task_header("HOSTNAME|OS_RELEASE|PACKAGE_NAME|VERSION|INSTALL_DATE")
         for rpm in rpms_list:
                 print env.host + "|"  + os_version + "|" + rpm
Exemplo n.º 11
0
 def os_short(self):
         """
         Show truncated OS version ( LFS, RedHat CentOS ... )
         """
         if util._is_host_up(env.host, int(env.port)) is False:
             return False
         OS = util._run("bash -c 'head -n 1 /etc/{{system,redhat,centos}-release,release} 2>/dev/null' | sort -u | grep -v '^==>'")
         if re.match("LC",OS,flags=re.IGNORECASE):
             print env.host + "|LFS " + OS
         if re.match("Red Hat",OS,flags=re.IGNORECASE):
             print env.host  + "|" + OS
         if re.match("Centos",OS,flags=re.IGNORECASE):
             print env.host  + "|" + OS
         if re.match("Solaris",OS,flags=re.IGNORECASE):
             print env.host  + "|" + OS
         else:
             print env.host  + "|UNKNOW_OS" + OS
Exemplo n.º 12
0
 def os_release(self,display=True):
         """
         Show complete OS release ( LFS, RedHat ... )
         """
         if util._is_host_up(env.host, int(env.port)) is False:
             return False
         OS = util._run("bash -c 'head -n 1 /etc/{{system,redhat,centos}-release,release} 2>/dev/null' | sort -u | grep -v '^==>'")
         OS_list = OS.splitlines()
         OS_hash = {}
         for entry in OS_list:
             OS_hash[entry]=1
         OS = ""
         for os in OS_hash.iterkeys():
             OS+=os+' '
         if display:
             print env.host + "|" + OS
         else:
             return OS
Exemplo n.º 13
0
 def check_tcp(self, rhost, rport, timeout=5):
     """
             Test <rhost> <rport> tcp connectivity from host using python
             with [timeout] (default: 5s)
             """
     if util._is_host_up(env.host, int(env.port)) is False:
         return False
     HOSTNAME = env.host
     puts("Proxy %s port %s " % (rhost, rport))
     tcp_check = util._run(
         "python -c \"import socket;sock=socket.socket();sock.settimeout(" +
         str(timeout) + ");sock.connect(('" + rhost + "'," + rport +
         "));sock.close()\"")
     if tcp_check.succeeded:
         print HOSTNAME + "|" + rhost + "|" + rport + "|" + green("Success")
     else:
         print HOSTNAME + "|" + rhost + "|" + rport + "|" + red(
             "Failed", True)
     return tcp_check.succeeded
Exemplo n.º 14
0
def run(image, cmd=None, daemon=False, exposeports=True):
    '''
    Equivalent to `docker run` but a bit simplified
    '''
    basecmd = ['docker', 'run', image]
    if cmd is None:
        # TODO add default args to `docker run`
        pass
    else:
        basecmd.extend(cmd)

    if exposeports:
        basecmd.insert(2, '-P')

    if daemon:
        basecmd.insert(2, '-d')

    # TODO add expose ports functionality

    if _run(basecmd) != 0:
        raise Exception('Failed `%s`' % str(basecmd))
Exemplo n.º 15
0
 def _fabrun(self, *args):
     if self.needSudo:
         return util._sudo(*args)
     else:
         return util._run(*args)
Exemplo n.º 16
0
 def init_repo(self):
     if not self.is_repo():
         cmd = ['git', 'init']
         if _run(cmd, cwd=self.localpath) != 0:
             raise Exception('Failed to init repo @ %s' % self.localpath)
Exemplo n.º 17
0
 def is_repo(self):
     cmd = ['git', 'status']
     return 0 == _run(cmd, cwd=self.localpath)
Exemplo n.º 18
0
 def clone(self, url, cwd=None):
     cmd = ['git', 'clone', url]
     if cwd is not None:
         cmd.append(cwd)
     if _run(cmd, cwd=self.localpath) != 0:
         raise Exception(''.join(['Failed to clone repo ', url]))
Exemplo n.º 19
0
 def delete_branch(self, branchname):
     if branchname == self.current_branch():
         raise Exception('Cannot delete branch %s because you are currently on that branch' % branchname)
     cmd = ['git', 'branch', '-D', branchname]
     if _run(cmd, cwd=self.localpath) != 0:
         raise Exception(''.join(['Failed to delete branch ', branchname, '@', self.localpath]))
Exemplo n.º 20
0
 def fetch(self, url, ref):
     cmd = ['git', 'fetch', url, ref]
     if _run(cmd, cwd=self.localpath) != 0:
         raise Exception(''.join(['Failed to fetch ref ', ref, '@', url]))
Exemplo n.º 21
0
 def new_branch(self, name):
     cmd = ['git', 'checkout', '-b', name]
     if _run(cmd, cwd=self.localpath) != 0:
         raise Exception(''.join(['Failed to checkout branch ', name, '@', self.localpath]))
Exemplo n.º 22
0
 def checkout(self, branch):
     cmd = ['git', 'checkout', branch]
     if _run(cmd, cwd=self.localpath) != 0:
         raise Exception(''.join(['Failed to checkout branch ', branch, '@', self.localpath]))
Exemplo n.º 23
0
 def _fabrun(self,*args):
     if self.needSudo:
         return util._sudo(*args)
     else:
         return util._run(*args)