def _setup_vol_groups(self): LOG.info("Attempting to setup volume groups for nova volume management.") mp = dict() backing_file = self.cfg.getdefaulted('nova', 'volume_backing_file', sh.joinpths(self.installer.get_option('app_dir'), 'nova-volumes-backing-file')) vol_group = self.cfg.getdefaulted('nova', 'volume_group', 'nova-volumes') backing_file_size = utils.to_bytes(self.cfg.getdefaulted('nova', 'volume_backing_file_size', '2052M')) mp['VOLUME_GROUP'] = vol_group mp['VOLUME_BACKING_FILE'] = backing_file mp['VOLUME_BACKING_FILE_SIZE'] = backing_file_size try: utils.execute_template(*VG_CHECK_CMD, params=mp) LOG.warn("Volume group already exists: %r" % (vol_group)) except exceptions.ProcessExecutionError as err: # Check that the error from VG_CHECK is an expected error if err.exit_code != 5: raise LOG.info("Need to create volume group: %r" % (vol_group)) sh.touch_file(backing_file, die_if_there=False, file_size=backing_file_size) vg_dev_result = utils.execute_template(*VG_DEV_CMD, params=mp) if vg_dev_result and vg_dev_result[0]: LOG.debug("VG dev result: %s" % (vg_dev_result)) # Strip the newlines out of the stdout (which is in the first # element of the first (and only) tuple in the response (sysout, _) = vg_dev_result[0] mp['DEV'] = sysout.replace('\n', '') utils.execute_template(*VG_CREATE_CMD, params=mp) # One way or another, we should have the volume group, Now check the # logical volumes self._process_lvs(mp) # Finish off by restarting tgt, and ignore any errors cmdrestart = self.distro.get_command('iscsi', 'restart', quiet=True) if cmdrestart: sh.execute(*cmdrestart, run_as_root=True, check_exit_code=False)
def _create_data_location(self): data_dir = sh.joinpths(self.get_option("app_dir"), self.cfg.getdefaulted("swift", "data_location", "data")) fs_image = sh.joinpths(data_dir, SWIFT_IMG) fs_dev = sh.joinpths(data_dir, DEVICE_PATH) loop_size = self.cfg.get("swift", "loopback_disk_size") if not loop_size: loop_size = DEF_LOOP_SIZE else: loop_size = utils.to_bytes(loop_size) sh.create_loopback_file(fname=fs_image, size=loop_size, fs_type=FS_TYPE) self.tracewriter.file_touched(fs_image) sh.mount_loopback_file(fs_image, fs_dev, FS_TYPE) sh.chown_r(fs_dev, sh.geteuid(), sh.getegid())
def _size_cb(option, opt_str, value, parser): try: parser.values.show_amount = utils.to_bytes(value) except (TypeError, ValueError) as e: raise OptionValueError("Invalid value for %s due to %s" % (opt_str, e))