def run(self, cmd, cwd=None, copy=False, interactive=True): command = "psexec.exe \\\\%s -s -u %s -p %s" % (self.__host, self.__user, self.__password) if copy: command += " -c -f" if cwd: command += " -w %s" % cwd if not interactive: command += " -d" command += " -n %s %s" % (self.__timeout, cmd) logger.debug("psexec command: %s", command) return OS.run(command)
def run(self, cmd, cwd=None, copy=False, interactive=True): command = "psexec.exe \\\\%s -s -u %s -p %s" % ( self.__host, self.__user, self.__password) if copy: command += " -c -f" if cwd: command += " -w %s" % cwd if not interactive: command += " -d" command += " -n %s %s" % (self.__timeout, cmd) logger.debug("psexec command: %s", command) return OS.run(command)
def startup(self, instance): nic = self.machines["m%s" % instance]["nic"] self._txt.load(file="/etc/sysconfig/network-scripts/ifcfg-%s" % nic) self._txt.set_param("BOOTPROTO", "static") self._txt.set_param("DHCPCLASS", "") self._txt.set_param("IPADDR", self.machines["m%s" % instance]["linkip"]) self._txt.set_param("NETMASK", "255.255.255.0") self._txt.set_param("ONBOOT", "yes") self._txt.save() logger.debug("restart the network interface") OS.runex("ifdown %s" % nic) OS.runex("ifup %s" % nic) self._svc.start() if not os.path.exists("/proc/drbd"): raise Exception("ERROR: cannot start drbd service.") drbd_status = None logger.debug("*** active resources.") if instance == 0 : drbd_status = ".*Primary.*UpToDate.*" logger.debug("r0, r1 are set as primary.") OS.runex("drbdadm -- --overwrite-data-of-peer primary r0") OS.runex("drbdadm -- --overwrite-data-of-peer primary r1") elif instance == 1: drbd_status = ".*Secondary.*UpToDate/UpToDate.*" logger.debug("r0, r1 are set as secondary.") OS.runex("drbdadm secondary r0") OS.runex("drbdadm secondary r1") step_pass = False logger.debug("*** Waiting for secondary drbd resources to sync") logger.debug("*** It will take half an hour or more depends on the disk size.") while not step_pass: self._txt.load(file="/proc/drbd") proc_drbd = self._txt.read() logger.debug("/proc/drbd: \n%s", proc_drbd) if "sync'ed" not in proc_drbd: step_pass = True time.sleep(30) else: raise Exception("instance must be 0 or 1") logger.debug("*** Waiting for drbd resources ready") drbd_r0_status = 0 drbd_r1_status = 0 while drbd_r0_status != 1 or drbd_r1_status != 1: self._txt.load(file="/proc/drbd") proc_drbd = self._txt.read() logger.debug("/proc/drbd: \n%s", proc_drbd) if re.search("0:%s" % drbd_status, proc_drbd): drbd_r0_status = 1 if re.search("1:%s" % drbd_status, proc_drbd): drbd_r1_status = 1 time.sleep(10) logger.debug("*** Resources are ready.") self._txt.load(file="/proc/drbd") proc_drbd = self._txt.read() logger.debug("/proc/drbd: \n%s", proc_drbd) if instance == 0: logger.debug("*** Format DRBD devices.") OS.runex("mkfs.ext4 %s" % self.resources["r0"]["device"]) OS.runex("mkfs.ext4 %s" % self.resources["r1"]["device"]) OS.linux.mount( self.resources["r0"]["device"], self.resources["r0"]["dir"], "ext4" ) OS.linux.mount( self.resources["r1"]["device"], self.resources["r1"]["dir"], "ext4" ) (retcode, svc_status) = OS.run("service drbd status") if retcode != 0: raise Exception("get drbd service status failed") if re.search("0:r0%s%s" % (drbd_status, self.resources["r0"]["dir"]), svc_status) and re.search("1:r1%s%s" % (drbd_status, self.resources["r1"]["dir"]), svc_status): logger.debug("drbd installation successfully.") else: raise Exception("drbd installation failed.") File.move( "%s.cache" % self.resources["r0"]["dir"], self.resources["r0"]["dir"] ) File.move( "%s.cache" % self.resources["r1"]["dir"], self.resources["r1"]["dir"] ) self._svc.config(autostart=True) self._txt.load(file="/etc/fstab") self._txt.delete(r"%s|%s" % (self.resources["r0"]["disk"], self.resources["r1"]["dir"])) self._txt.save() logger.debug("*** DRBD Setup Finished.")