def resize_fs(device_path): """Resize the filesystem on the specified device""" VolumeHelper._check_device_exists(device_path) try: utils.execute("sudo", "resize2fs", device_path) except ProcessExecutionError as err: LOG.error(err) raise GuestError("Error resizing the filesystem: %s" % device_path)
def resize_fs(self): """Resize the filesystem on the specified device""" self._check_device_exists() try: utils.execute("sudo", "resize2fs", self.device_path) except ProcessExecutionError as err: LOG.error(err) raise GuestError("Error resizing the filesystem: %s" % self.device_path)
def migrate_data(device_path, mysql_base): """ Synchronize the data from the mysql directory to the new volume """ utils.execute("sudo", "mkdir", "-p", TMP_MOUNT_POINT) VolumeHelper.mount(device_path, TMP_MOUNT_POINT) if not mysql_base[-1] == '/': mysql_base = "%s/" % mysql_base utils.execute("sudo", "rsync", "--safe-links", "--perms", "--recursive", "--owner", "--group", "--xattrs", "--sparse", mysql_base, TMP_MOUNT_POINT) VolumeHelper.unmount(device_path)
def migrate_data(self, mysql_base): """ Synchronize the data from the mysql directory to the new volume """ # Use sudo to have access to this spot. utils.execute("sudo", "mkdir", "-p", TMP_MOUNT_POINT) self._tmp_mount(TMP_MOUNT_POINT) if not mysql_base[-1] == '/': mysql_base = "%s/" % mysql_base utils.execute("sudo", "rsync", "--safe-links", "--perms", "--recursive", "--owner", "--group", "--xattrs", "--sparse", mysql_base, TMP_MOUNT_POINT) self.unmount()
def write_to_fstab(self): fstab_line = ("%s\t%s\t%s\t%s\t0\t0" % (self.device_path, self.mount_point, self.volume_fstype, self.mount_options)) LOG.debug("Writing new line to fstab:%s" % fstab_line) utils.execute("sudo", "cp", "/etc/fstab", "/etc/fstab.orig") utils.execute("sudo", "cp", "/etc/fstab", "/tmp/newfstab") utils.execute("sudo", "chmod", "666", "/tmp/newfstab") with open("/tmp/newfstab", 'a') as new_fstab: new_fstab.write("\n" + fstab_line) utils.execute("sudo", "chmod", "640", "/tmp/newfstab") utils.execute("sudo", "mv", "/tmp/newfstab", "/etc/fstab")
def _check_device_exists(device_path): """Check that the device path exists. Verify that the device path has actually been created and can report it's size, only then can it be available for formatting, retry num_tries to account for the time lag. """ try: num_tries = CONFIG.get('num_tries', 3) utils.execute('sudo', 'blockdev', '--getsize64', device_path, attempts=num_tries) except ProcessExecutionError: raise GuestError("InvalidDevicePath(path=%s)" % device_path)
def pkg_install(self, package_name, time_out): """Installs a package.""" try: utils.execute("apt-get", "update", run_as_root=True, root_helper="sudo") except ProcessExecutionError as e: LOG.error(_("Error updating the apt sources")) result = self._install(package_name, time_out) if result != OK: if result == RUN_DPKG_FIRST: self._fix(time_out) result = self._install(package_name, time_out) if result != OK: raise PkgPackageStateError("Package %s is in a bad state." % package_name)
def _check_device_exists(self): """Check that the device path exists. Verify that the device path has actually been created and can report it's size, only then can it be available for formatting, retry num_tries to account for the time lag. """ try: num_tries = CONFIG.get('num_tries', 3) utils.execute('sudo', 'blockdev', '--getsize64', self.device_path, attempts=num_tries) except ProcessExecutionError: raise GuestError("InvalidDevicePath(path=%s)" % self.device_path)
def pkg_install(package_name, time_out): """Installs a package.""" try: utils.execute("apt-get", "update", run_as_root=True, root_helper="sudo") except ProcessExecutionError as e: LOG.error(_("Error updating the apt sources")) result = _install(package_name, time_out) if result != OK: if result == RUN_DPKG_FIRST: _fix(time_out) result = _install(package_name, time_out) if result != OK: raise PkgPackageStateError("Package %s is in a bad state." % package_name)
def load_mysqld_options(): try: out, err = utils.execute("/usr/sbin/mysqld", "--print-defaults", run_as_root=True) arglist = re.split("\n", out)[1].split() args = {} for item in arglist: if "=" in item: key, value = item.split("=") args[key.lstrip("--")] = value else: args[item.lstrip("--")] = None return args except ProcessExecutionError as e: return None
def _run_prepare(self): if hasattr(self, 'prepare_cmd'): LOG.info("Running innobackupex prepare...") self.prep_retcode = utils.execute(self.prepare_cmd, shell=True) LOG.info("Innobackupex prepare finished successfully")