Beispiel #1
0
 def back(self, savePath, parentPath, needBack):
     '''
         savePath:备份文件保存的路径
         parentPath:需要备份的父路径
         needBack:需要备份的父目录
     '''
     tr = ExecUtil.execCommand(" tar czvf " + savePath + " -C " + parentPath + " " + needBack)
Beispiel #2
0
 def back(self, savePath, parentPath, needBack):
     '''
         savePath:备份文件保存的路径
         parentPath:需要备份的父路径
         needBack:需要备份的父目录
     '''
     tr = ExecUtil.execCommand(" tar czvf " + savePath + " -C " +
                               parentPath + " " + needBack)
Beispiel #3
0
 def yumInstall(self):
     child = pexpect.spawnu('yum groupinstall " NFS file server"')
     child.expect('(?i)Is this ok [y/N]:')
     child.sendline('y')
     child.expect('Complete!')
     child.close()
     self.writeConfig()
     ExecUtil.execCommand("/etc/init.d/rpcbind start  ")
     ExecUtil.execCommand("/etc/init.d/nfs start")
     ExecUtil.execCommand("chkconfig nfs on")
     ExecUtil.execCommand("chkconfig rpcbind on")
Beispiel #4
0
 def initSSHKey(self):
     home = ExecUtil.execCommand("echo ~")[1]
     if not os.path.exists(home + "/.ssh/id_rsa"):
         child = pexpect.spawnu('ssh-keygen')
         child.expect('(?i)(/root/.ssh/id_rsa):')
         child.sendline('\r')
         child.expect('(?i)Enter passphrase (empty for no passphrase):')
         child.sendline('\r')
         child.expect('(?i)Enter same passphrase again:')
         child.sendline('\r')
         child.expect('(?i)+-----------------+')
         child.close()
 def openByPort(self, port):
     return ExecUtil.execCommandList(["iptables -A INPUT -p tcp --dport " + port + " -j ACCEPT",
                                      "iptables -A OUTPUT -p tcp --sport " + port + " -j ACCEPT"])
 def openWeb(self):
     return ExecUtil.execCommandList(["iptables -A INPUT -p tcp --dport 80 -j ACCEPT",
                                      "iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT"])
 def dropAll(self):
     ExecUtil.execCommandList(
         ["iptables -P INPUT DROP", "iptables -P FORWARD DROP", "iptables -P OUTPUT DROP", "service iptables save "])
 def limitIp(self, ip, port):
     return ExecUtil.execCommandList([
         "iptables -A INPUT -s " + ip + " -p tcp --dport " + port +
         " -j DROP"
     ])
 def openByPort(self, port):
     return ExecUtil.execCommandList([
         "iptables -A INPUT -p tcp --dport " + port + " -j ACCEPT",
         "iptables -A OUTPUT -p tcp --sport " + port + " -j ACCEPT"
     ])
Beispiel #10
0
 def downloadFile(self, downloadPath):
     filename = os.path.basename(downloadPath)
     return ExecUtil.execCommand("wget -O " + downloadPath + " " +
                                 Config.softServer + filename)
Beispiel #11
0
 def back(self, user, pwd, db, savePath):
     ExecUtil.execCommand(" mysqldump -u" + user + " -p" + pwd +
                          " -B --skip-lock-tables  " + db + " |gzip  > " +
                          savePath + "/" + db + "`/bin/date +%F`.back.gz")
Beispiel #12
0
 def downloadTar(self):
     down_rt = ExecUtil.execCommand("wget -O " + self.downloadSavePath + " " + self.downloadPath)
Beispiel #13
0
 def execCmd(self, cmd):
     return ExecUtil.execCommand(cmd)
Beispiel #14
0
            info.append(install)
        except Exception , e:
            install=self.getInfo("yum install mysql*",False,"yum install mysql* false")
            info.append(install)
            return info
        try:
            self.writeConfig()
            install=self.getInfo("write config",True,"write config ok")
            info.append(install)
        except Exception , e:
            install=self.getInfo("write config",False,"write config false")
            info.append(install)
            return info


        rt=ExecUtil.execCommand("service mysqld restart")
        if rt[0]==0:
            install=self.getInfo("service mysqld restart",True,rt[1])
            info.append(install)
        else:
            install=self.getInfo("service mysqld restart",False,rt[1])
            info.append(install)
            return info

        rt=ExecUtil.execCommand("mysqladmin -u root password " + Config.mysqlRoot)
        if rt[0]==0:
            install=self.getInfo("mysqladmin -u root password "+Config.mysqlRoot,True,rt[1])
            info.append(install)
        else:
            install=self.getInfo("mysqladmin -u root password "+Config.mysqlRoot,False,rt[1])
            info.append(install)
Beispiel #15
0
            info.append(install)
        except Exception, e:
            install = self.getInfo("yum install mysql*", False,
                                   "yum install mysql* false")
            info.append(install)
            return info
        try:
            self.writeConfig()
            install = self.getInfo("write config", True, "write config ok")
            info.append(install)
        except Exception, e:
            install = self.getInfo("write config", False, "write config false")
            info.append(install)
            return info

        rt = ExecUtil.execCommand("service mysqld restart")
        if rt[0] == 0:
            install = self.getInfo("service mysqld restart", True, rt[1])
            info.append(install)
        else:
            install = self.getInfo("service mysqld restart", False, rt[1])
            info.append(install)
            return info

        rt = ExecUtil.execCommand("mysqladmin -u root password " +
                                  Config.mysqlRoot)
        if rt[0] == 0:
            install = self.getInfo(
                "mysqladmin -u root password " + Config.mysqlRoot, True, rt[1])
            info.append(install)
        else:
Beispiel #16
0
 def limitIp(self, ip, port):
     return ExecUtil.execCommandList(["iptables -A INPUT -s " + ip + " -p tcp --dport " + port + " -j DROP"])
Beispiel #17
0
 def make(self):
     tar_rt = ExecUtil.execCommand("tar zxvf " + self.downloadSavePath + " -C " + self.installPath)
Beispiel #18
0
 def dropAll(self):
     ExecUtil.execCommandList([
         "iptables -P INPUT DROP", "iptables -P FORWARD DROP",
         "iptables -P OUTPUT DROP", "service iptables save "
     ])
Beispiel #19
0
 def back(self, user, pwd, db, savePath):
     ExecUtil.execCommand(
         " mysqldump -u" + user + " -p" + pwd + " -B --skip-lock-tables  " + db + " |gzip  > " + savePath + "/" + db + "`/bin/date +%F`.back.gz")
Beispiel #20
0
 def writeConfig(self):
     f = open("/etc/profile", 'a')
     f.write('export MAVEN_HOME=' + self.installPath + "/maven")
     f.write("export PATH=$MAVEN_HOME/bin:$PATH")
     f.close()
     source_rt = ExecUtil.execCommand("source /etc/profile")
Beispiel #21
0
 def openWeb(self):
     return ExecUtil.execCommandList([
         "iptables -A INPUT -p tcp --dport 80 -j ACCEPT",
         "iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT"
     ])
Beispiel #22
0
 def downloadFile(self,downloadPath):
     filename=os.path.basename(downloadPath)
     return ExecUtil.execCommand("wget -O " + downloadPath + " " + Config.softServer+filename)
Beispiel #23
0
 def updateYumToAli(self):
     return ExecUtil.execCommandList(
         ["mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup",
          "wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo",
          "yum makecache"])