def create_thin_pool(self, name=None, size_str=0): """Creates a thin provisioning pool for this VG. The syntax here is slightly different than the default lvcreate -T, so we'll just write a custom cmd here and do it. :param name: Name to use for pool, default is "<vg-name>-pool" :param size_str: Size to allocate for pool, default is entire VG """ if not self.supports_thin_provisioning(): LOG.error(_('Requested to setup thin provisioning, ' 'however current LVM version does not ' 'support it.')) return None if name is None: name = '%s-pool' % self.vg_name if size_str == 0: self.update_volume_group_info() size_str = self.vg_size # NOTE(jdg): lvcreate will round up extents # to avoid issues, let's chop the size off to an int size_str = re.sub(r'\.\d*', '', size_str) pool_path = '%s/%s' % (self.vg_name, name) cmd = ['lvcreate', '-T', '-L', size_str, pool_path] putils.execute(*cmd, root_helper='sudo', run_as_root=True) self.vg_thin_pool = pool_path
def create_volume(self, name, size_str, lv_type='default', mirror_count=0): """Creates a logical volume on the object's VG. :param name: Name to use when creating Logical Volume :param size_str: Size to use when creating Logical Volume :param lv_type: Type of Volume (default or thin) :param mirror_count: Use LVM mirroring with specified count """ size = self._size_str(size_str) cmd = ['lvcreate', '-n', name, self.vg_name] if lv_type == 'thin': cmd += ['-T', '-V', size] else: cmd += ['-L', size] if mirror_count > 0: cmd += ['-m', mirror_count, '--nosync'] terras = int(size[:-1]) / 1024.0 if terras >= 1.5: rsize = int(2**math.ceil(math.log(terras) / math.log(2))) # NOTE(vish): Next power of two for region size. See: # http://red.ht/U2BPOD cmd += ['-R', str(rsize)] putils.execute(*cmd, root_helper='sudo', run_as_root=True)
def create_volume(self, name, size_str, lv_type='default', mirror_count=0): """Creates a logical volume on the object's VG. :param name: Name to use when creating Logical Volume :param size_str: Size to use when creating Logical Volume :param lv_type: Type of Volume (default or thin) :param mirror_count: Use LVM mirroring with specified count """ size = self._size_str(size_str) cmd = ['lvcreate', '-n', name, self.vg_name] if lv_type == 'thin': cmd += ['-T', '-V', size] else: cmd += ['-L', size] if mirror_count > 0: cmd += ['-m', mirror_count, '--nosync'] terras = int(size[:-1]) / 1024.0 if terras >= 1.5: rsize = int(2 ** math.ceil(math.log(terras) / math.log(2))) # NOTE(vish): Next power of two for region size. See: # http://red.ht/U2BPOD cmd += ['-R', str(rsize)] putils.execute(*cmd, root_helper='sudo', run_as_root=True)
def temporary_chown(self, path, owner_uid=None): """Temporarily chown a path. :params path: The path to chown :params owner_uid: UID of temporary owner (defaults to current user) """ if owner_uid is None: owner_uid = os.getuid() orig_uid = os.stat(path).st_uid if orig_uid != owner_uid: putils.execute('chown', owner_uid, path, root_helper=self._root_helper, run_as_root=True) try: yield finally: if orig_uid != owner_uid: putils.execute('chown', orig_uid, path, root_helper=self._root_helper, run_as_root=True)
def _process_git_status(results_dict): out, err = putils.execute('git', 'status') results_dict['git_status'] = out out, err = putils.execute('git', 'show') results_dict['git_show'] = out out, err = putils.execute('git', 'diff') results_dict['git_diff'] = out
def revert(self, snapshot_name): """Revert an LV from snapshot. :param snapshot_name: Name of snapshot to revert """ putils.execute('lvconvert', '--merge', snapshot_name, root_helper='sudo', run_as_root=True)
def delete(self, name): """Delete logical volume or snapshot. :param name: Name of LV to delete """ putils.execute('lvremove', '-f', '%s/%s' % (self.vg_name, name), root_helper='sudo', run_as_root=True)
def delete_snapshot(self, snapshot_ref): """delete a snapshot""" snapshot = dict(snapshot_ref) snapshot_path = self._get_snapshot_path(snapshot['id']) if os.path.exists(snapshot_path): recycle = self.recycle_path() fileutils.ensure_tree(recycle) cmd = ('mv', snapshot_path, recycle) processutils.execute(*cmd, run_as_root=True) LOG.info("Deleted snapshot %s"%snapshot['id'])
def create_volume_from_snapshot(self, volume, snapshot): """Creates a volume from a snapshot.""" LOG.info('Create volume %s from snapshot %s'%(volume['id'], snapshot['id'])) self.create_volume(volume) volume_size_mb = volume['size'] * 1024 volume_path = self._get_volume_path(volume['id']) snapshot_path = self._get_snapshot_path(snapshot['id']) LOG.info('Copying snapshot %s data to volume %s .'%(snapshot['id'], volume['id'])) cmd = ('dd', 'if=%s'%snapshot_path, 'of=%s'%volume_path, 'bs=1M', 'count=%s'%volume_size_mb) processutils.execute(*cmd, run_as_root=True) LOG.info('Finished data Copy from snapshot %s to volume %s .'%(snapshot['id'], volume['id']))
def get_all_physical_volumes(root_helper, vg_name=None, no_suffix=True): """Static method to get all PVs on a system. :param root_helper: root_helper to use for execute :param vg_name: optional, gathers info for only the specified VG :param no_suffix: optional, reports sizes in g with no suffix :returns: List of Dictionaries with PV info """ cmd = ['pvs', '--noheadings', '--unit=g', '-o', 'vg_name,name,size,free', '--separator', ':'] if no_suffix: cmd.append('--nosuffix') if vg_name is not None: cmd.append(vg_name) (out, err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) pv_list = [] if out is not None: pvs = out.split() for pv in pvs: fields = pv.split(':') pv_list.append({'vg': fields[0], 'name': fields[1], 'size': fields[2], 'available': fields[3]}) return pv_list
def _update_info_from_dpkg(self): LOG.debug('Trying dpkg-query command.') try: _vendor = None out, err = putils.execute("dpkg-query", "-W", "-f='${Version}'", self.PACKAGE_NAME) if not out: LOG.info(_('No dpkg-query info found for %(pkg)s package.') % { 'pkg': self.PACKAGE_NAME}) return False # debian format: [epoch:]upstream_version[-debian_revision] deb_version = out # in case epoch or revision is missing, copy entire string _release = deb_version if ':' in deb_version: deb_epoch, upstream_version = deb_version.split(':') _release = upstream_version if '-' in deb_version: deb_revision = deb_version.split('-')[1] _vendor = deb_revision self._release = _release if _vendor: self._vendor = _vendor return True except Exception as e: LOG.info(_('Could not run dpkg-query command: %(msg)s.') % { 'msg': e}) return False
def get_all_volumes(root_helper, vg_name=None, no_suffix=True): """Static method to get all LV's on a system. :param root_helper: root_helper to use for execute :param vg_name: optional, gathers info for only the specified VG :param no_suffix: optional, reports sizes in g with no suffix :returns: List of Dictionaries with LV info """ cmd = ['lvs', '--noheadings', '--unit=g', '-o', 'vg_name,name,size'] if no_suffix: cmd.append('--nosuffix') if vg_name is not None: cmd.append(vg_name) (out, err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) lv_list = [] if out is not None: volumes = out.split() for vg, name, size in itertools.izip(*[iter(volumes)] * 3): lv_list.append({"vg": vg, "name": name, "size": size}) return lv_list
def get_all_volume_groups(vg_name=None): """Static method to get all VGs on a system. :param vg_name: optional, gathers info for only the specified VG :returns: List of Dictionaries with VG info """ cmd = ['vgs', '--noheadings', '-o', 'name,size,free,lv_count,uuid', '--separator', ':'] if vg_name is not None: cmd += [vg_name] (out, err) = putils.execute(*cmd, root_helper='sudo', run_as_root=True) vg_list = [] if out is not None: vgs = out.split() for vg in vgs: fields = vg.split(':') vg_list.append({'name': fields[0], 'size': fields[1], 'available': fields[2], 'lv_count': fields[3], 'uuid': fields[4]}) return vg_list
def get_all_physical_volumes(vg_name=None): """Static method to get all PVs on a system. :param vg_name: optional, gathers info for only the specified VG :returns: List of Dictionaries with PV info """ cmd = ['pvs', '--noheadings', '-o', 'vg_name,name,size,free', '--separator', ':'] if vg_name is not None: cmd += [vg_name] (out, err) = putils.execute(*cmd, root_helper='sudo', run_as_root=True) pv_list = [] if out is not None: pvs = out.split() for pv in pvs: fields = pv.split(':') pv_list.append({'vg': fields[0], 'name': fields[1], 'size': fields[2], 'available': fields[3]}) return pv_list
def get_all_volume_groups(root_helper, vg_name=None, no_suffix=True): """Static method to get all VGs on a system. :param root_helper: root_helper to use for execute :param vg_name: optional, gathers info for only the specified VG :param no_suffix: optional, reports sizes in g with no suffix :returns: List of Dictionaries with VG info """ cmd = ['env', 'LC_ALL=C', 'LANG=C', 'vgs', '--noheadings', '--unit=g', '-o', 'name,size,free,lv_count,uuid', '--separator', ':'] if no_suffix: cmd.append('--nosuffix') if vg_name is not None: cmd.append(vg_name) (out, err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) vg_list = [] if out is not None: vgs = out.split() for vg in vgs: fields = vg.split(':') vg_list.append({'name': fields[0], 'size': fields[1], 'available': fields[2], 'lv_count': fields[3], 'uuid': fields[4]}) return vg_list
def _update_info_from_dpkg(self): LOG.debug('Trying dpkg-query command.') try: _vendor = None out, err = putils.execute("dpkg-query", "-W", "-f='${Version}'", self.PACKAGE_NAME) if not out: LOG.info( _('No dpkg-query info found for %(pkg)s package.') % {'pkg': self.PACKAGE_NAME}) return False # debian format: [epoch:]upstream_version[-debian_revision] deb_version = out # in case epoch or revision is missing, copy entire string _release = deb_version if ':' in deb_version: deb_epoch, upstream_version = deb_version.split(':') _release = upstream_version if '-' in deb_version: deb_revision = deb_version.split('-')[1] _vendor = deb_revision self._release = _release if _vendor: self._vendor = _vendor return True except Exception as e: LOG.info( _('Could not run dpkg-query command: %(msg)s.') % {'msg': e}) return False
def get_all_physical_volumes(root_helper, vg_name=None): """Static method to get all PVs on a system. :param root_helper: root_helper to use for execute :param vg_name: optional, gathers info for only the specified VG :returns: List of Dictionaries with PV info """ cmd = [ 'env', 'LC_ALL=C', 'pvs', '--noheadings', '--unit=g', '-o', 'vg_name,name,size,free', '--separator', ':', '--nosuffix' ] (out, err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) pvs = out.split() if vg_name is not None: pvs = [pv for pv in pvs if vg_name == pv.split(':')[0]] pv_list = [] for pv in pvs: fields = pv.split(':') pv_list.append({ 'vg': fields[0], 'name': fields[1], 'size': float(fields[2]), 'available': float(fields[3]) }) return pv_list
def get_all_physical_volumes(vg_name=None): """Static method to get all PVs on a system. :param vg_name: optional, gathers info for only the specified VG :returns: List of Dictionaries with PV info """ cmd = [ 'pvs', '--noheadings', '-o', 'vg_name,name,size,free', '--separator', ':' ] if vg_name is not None: cmd += [vg_name] (out, err) = putils.execute(*cmd, root_helper='sudo', run_as_root=True) pv_list = [] if out is not None: pvs = out.split() for pv in pvs: fields = pv.split(':') pv_list.append({ 'vg': fields[0], 'name': fields[1], 'size': fields[2], 'available': fields[3] }) return pv_list
def _get_vg_uuid(self): (out, err) = putils.execute('vgs', '--noheadings', '-o uuid', self.vg_name) if out is not None: return out.split() else: return []
def get_all_physical_volumes(root_helper, vg_name=None): """Static method to get all PVs on a system. :param root_helper: root_helper to use for execute :param vg_name: optional, gathers info for only the specified VG :returns: List of Dictionaries with PV info """ cmd = ['env', 'LC_ALL=C', 'pvs', '--noheadings', '--unit=g', '-o', 'vg_name,name,size,free', '--separator', ':', '--nosuffix'] (out, err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) pvs = out.split() if vg_name is not None: pvs = [pv for pv in pvs if vg_name == pv.split(':')[0]] pv_list = [] for pv in pvs: fields = pv.split(':') pv_list.append({'vg': fields[0], 'name': fields[1], 'size': float(fields[2]), 'available': float(fields[3])}) return pv_list
def supports_thin_provisioning(root_helper): """Static method to check for thin LVM support on a system. :param root_helper: root_helper to use for execute :returns: True if supported, False otherwise """ cmd = ['vgs', '--version'] (out, err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) lines = out.split('\n') for line in lines: if 'LVM version' in line: version_list = line.split() # NOTE(gfidente): version is formatted as follows: # major.minor.patchlevel(library API version)[-customisation] version = version_list[2] version_filter = "(\d+)\.(\d+)\.(\d+).*" r = re.search(version_filter, version) version_tuple = tuple(map(int, r.group(1, 2, 3))) if version_tuple >= (2, 2, 95): return True return False
def get_lv_info(root_helper, vg_name=None, lv_name=None): """Retrieve info about LVs (all, in a VG, or a single LV). :param root_helper: root_helper to use for execute :param vg_name: optional, gathers info for only the specified VG :returns: List of Dictionaries with LV info """ cmd = ['env', 'LC_ALL=C', 'lvs', '--noheadings', '--unit=g', '-o', 'vg_name,name,size', '--nosuffix'] if lv_name is not None and vg_name is not None: cmd.append("%s/%s" % (vg_name, lv_name)) elif vg_name is not None: cmd.append(vg_name) lvs_start = time.time() (out, err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) total_time = time.time() - lvs_start if total_time > 60: LOG.warning(_LW('Took %s seconds to get logical volumes.'), total_time) lv_list = [] if out is not None: volumes = out.split() for vg, name, size in itertools.izip(*[iter(volumes)] * 3): lv_list.append({"vg": vg, "name": name, "size": size}) return lv_list
def get_all_volume_groups(root_helper, vg_name=None): """Static method to get all VGs on a system. :param root_helper: root_helper to use for execute :param vg_name: optional, gathers info for only the specified VG :returns: List of Dictionaries with VG info """ cmd = ['env', 'LC_ALL=C', 'vgs', '--noheadings', '--unit=g', '-o', 'name,size,free,lv_count,uuid', '--separator', ':', '--nosuffix'] if vg_name is not None: cmd.append(vg_name) start_vgs = time.time() (out, err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) total_time = time.time() - start_vgs if total_time > 60: LOG.warning(_('Took %s seconds to get volume groups.'), total_time) vg_list = [] if out is not None: vgs = out.split() for vg in vgs: fields = vg.split(':') vg_list.append({'name': fields[0], 'size': float(fields[1]), 'available': float(fields[2]), 'lv_count': int(fields[3]), 'uuid': fields[4]}) return vg_list
def get_all_volume_groups(vg_name=None): """Static method to get all VGs on a system. :param vg_name: optional, gathers info for only the specified VG :returns: List of Dictionaries with VG info """ cmd = [ 'vgs', '--noheadings', '-o', 'name,size,free,lv_count,uuid', '--separator', ':' ] if vg_name is not None: cmd += [vg_name] (out, err) = putils.execute(*cmd, root_helper='sudo', run_as_root=True) vg_list = [] if out is not None: vgs = out.split() for vg in vgs: fields = vg.split(':') vg_list.append({ 'name': fields[0], 'size': fields[1], 'available': fields[2], 'lv_count': fields[3], 'uuid': fields[4] }) return vg_list
def get_all_physical_volumes(root_helper, vg_name=None): """Static method to get all PVs on a system. :param root_helper: root_helper to use for execute :param vg_name: optional, gathers info for only the specified VG :returns: List of Dictionaries with PV info """ cmd = ['su - padmin -c ioscli lspv'] (out, err) = putils.execute(*cmd, shell=True) pv_list = [] if out is None: LOG.error("No volume groups be found!") return None pvs_array = out.splitlines() for pv in pvs_array: pv = pv.split() if 'active' in pv: cmd = ['su - padmin -c ioscli "lspv ' + pv[0] + ' -field \'VOLUME GROUP\' \'TOTAL PPs\' \'FREE PPs\' -fmt : "'] (out, err) = putils.execute(*cmd, shell=True) params = out.split(":") pv_name = pv[0] vgname = params[0] total_size = re.search(r'\d+', params[1]).group(0) free_size = re.search(r'\d+', params[2]).group(0) #params = out.split("\n") #pv_name = params[0].split()[2] #vgname = params[0].split()[5] #pp_size = float(params[4].split()[2]) #total_size = float(params[5].split()[2]) * pp_size / 1024.0 #free_size = float(params[6].split()[2]) * pp_size / 1024.0 pv_list.append({"vg": vgname, "name": "/dev/" + pv_name, "size": total_size, "available": free_size}) if vg_name is not None: cur_pv = [pv for pv in pv_list if vg_name == pv.get('vg')] return cur_pv else: return pv_list
def temporary_chown(self, path, owner_uid=None): """Temporarily chown a path. :params path: The path to chown :params owner_uid: UID of temporary owner (defaults to current user) """ if owner_uid is None: owner_uid = os.getuid() orig_uid = os.stat(path).st_uid if orig_uid != owner_uid: putils.execute('chown', owner_uid, path, run_as_root=True) try: yield finally: if orig_uid != owner_uid: putils.execute('chown', orig_uid, path, run_as_root=True)
def get_all_volumes(root_helper, vg_name=None): """Static method to get all LV's on a system. :param root_helper: root_helper to use for execute :param vg_name: optional, gathers info for only the specified VG :returns: List of Dictionaries with LV info """ cmd = ['env', 'LC_ALL=C', 'lsvg'] if vg_name is not None: cmd.append(vg_name) (out_vg, err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) cmd = ['env', 'LC_ALL=C', 'lsvg'] if vg_name is not None: cmd.append('-l') cmd.append(vg_name) (out, err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) lv_list = [] if out_vg is not None: pp_size = int(out_vg.split("\n")[1].split()[5]) if out is not None: vg_name = out.split(":")[0] lv_array_tmp = out.split(":")[1].split('\n') lv_array_len = len(lv_array_tmp)-1 lv_array = lv_array_tmp[2:lv_array_len] for volume in lv_array: lv_list.append({"vg": vg_name, "name": volume.split()[0], "size": int(volume.split()[3]) * pp_size / 1024.0}) return lv_list
def _get_cinder_info(cinder_path): cinder_info = {} with _cd(cinder_path): out, err = putils.execute('cat', '/etc/cinder/cinder.conf') cinderconf_list = out.split() cinder_info['cinder_conf'] =\ [_scrub_passwords(item) for item in cinderconf_list] _process_git_status(cinder_info) return cinder_info
def get_all_volume_groups(root_helper, vg_name=None): """Static method to get all VGs on a system. :param root_helper: root_helper to use for execute :param vg_name: optional, gathers info for only the specified VG :returns: List of Dictionaries with VG info """ cmd = ['env', 'LC_ALL=C', 'lsvg'] (out, err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) if out is None: LOG.error("No volume groups be found!") return None list_vgs = out.split("\n") vgs = [] for vgname in list_vgs: if vgname : cmd = ['env', 'LC_ALL=C', 'lsvg'] cmd.append(vgname) (out, err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) params = out.split("\n") pp_size = float(params[1].split()[5]) total_size = float(params[2].split()[5]) * pp_size / 1024.0 free_size = float(params[3].split()[5]) * pp_size / 1024.0 lv_count = int(params[4].split()[1]) vgs.append({"name": vgname, "size": total_size, "available": free_size, "lv_count": lv_count}) if vg_name is not None: list_vg = [vg for vg in vgs if vg_name == vg.get('name')] return list_vg else: return vgs
def create_lv_snapshot(self, name, source_lv_name, lv_type='default'): """Creates a snapshot of a logical volume. :param name: Name to assign to new snapshot :param source_lv_name: Name of Logical Volume to snapshot :param lv_type: Type of LV (default or thin) """ source_lvref = self.get_volume(source_lv_name) if source_lvref is None: LOG.error(_("Unable to find LV: %s") % source_lv_name) return False cmd = ['lvcreate', '--name', name, '--snapshot', '%s/%s' % (self.vg_name, source_lv_name)] if lv_type != 'thin': size = source_lvref['size'] cmd += ['-L', size] putils.execute(*cmd, root_helper='sudo', run_as_root=True)
def create_lv_snapshot(self, name, source_lv_name, lv_type='default'): """Creates a snapshot of a logical volume. :param name: Name to assign to new snapshot :param source_lv_name: Name of Logical Volume to snapshot :param lv_type: Type of LV (default or thin) """ source_lvref = self.get_volume(source_lv_name) if source_lvref is None: LOG.error(_("Unable to find LV: %s") % source_lv_name) return False cmd = [ 'lvcreate', '--name', name, '--snapshot', '%s/%s' % (self.vg_name, source_lv_name) ] if lv_type != 'thin': size = source_lvref['size'] cmd += ['-L', size] putils.execute(*cmd, root_helper='sudo', run_as_root=True)
def consume_in_thread(self): """Runs the ZmqProxy service""" ipc_dir = CONF.rpc_zmq_ipc_dir consume_in = "tcp://%s:%s" % \ (CONF.rpc_zmq_bind_address, CONF.rpc_zmq_port) consumption_proxy = InternalContext(None) if not os.path.isdir(ipc_dir): try: utils.execute('mkdir', '-p', ipc_dir, run_as_root=True) utils.execute('chown', "%s:%s" % (os.getuid(), os.getgid()), ipc_dir, run_as_root=True) utils.execute('chmod', '750', ipc_dir, run_as_root=True) except utils.ProcessExecutionError: with excutils.save_and_reraise_exception(): LOG.error(_("Could not create IPC directory %s") % (ipc_dir, )) try: self.register(consumption_proxy, consume_in, zmq.PULL, out_bind=True) except zmq.ZMQError: with excutils.save_and_reraise_exception(): LOG.error(_("Could not create ZeroMQ receiver daemon. " "Socket may already be in use.")) super(ZmqProxy, self).consume_in_thread()
def consume_in_thread(self): """Runs the ZmqProxy service""" ipc_dir = CONF.rpc_zmq_ipc_dir consume_in = "tcp://%s:%s" % \ (CONF.rpc_zmq_bind_address, CONF.rpc_zmq_port) consumption_proxy = InternalContext(None) if not os.path.isdir(ipc_dir): try: utils.execute('mkdir', '-p', ipc_dir, run_as_root=True) utils.execute('chown', "%s:%s" % (os.getuid(), os.getgid()), ipc_dir, run_as_root=True) utils.execute('chmod', '750', ipc_dir, run_as_root=True) except utils.ProcessExecutionError: with excutils.save_and_reraise_exception(): LOG.error( _("Could not create IPC directory %s") % (ipc_dir, )) try: self.register(consumption_proxy, consume_in, zmq.PULL, out_bind=True) except zmq.ZMQError: with excutils.save_and_reraise_exception(): LOG.error( _("Could not create ZeroMQ receiver daemon. " "Socket may already be in use.")) super(ZmqProxy, self).consume_in_thread()
def delete_volume(self, volume): """Deletes a logical volume.""" if not volume['provider_location']: LOG.warn(_('Volume %s does not have provider_location specified, ' 'skipping'), volume['name']) return mounted_path = self.local_path(volume) #if not self._path_exists(mounted_path): if not os.path.exists(mounted_path): volume = volume['name'] LOG.warn(_('Trying to delete non-existing volume %(volume)s at ' 'path %(mounted_path)s') % locals()) return recycle = self.recycle_path() fileutils.ensure_tree(recycle) cmd = ('mv', mounted_path, recycle) processutils.execute(*cmd, run_as_root=True)
def _get_devstack_info(devstack_location): stack_info = {} with _cd(devstack_location): stack_info['devstack_path'] = devstack_location out, err = putils.execute('cat', './localrc') localrc_list = out.split() stack_info['local_rc'] =\ [_scrub_passwords(item) for item in localrc_list] _process_git_status(stack_info) return stack_info
def execute(*cmd, **kwargs): """Convenience wrapper around oslo's execute() method.""" if 'run_as_root' in kwargs and not 'root_helper' in kwargs: kwargs['root_helper'] = get_root_helper() try: (stdout, stderr) = processutils.execute(*cmd, **kwargs) except processutils.ProcessExecutionError as ex: raise exception.ProcessExecutionError(exit_code=ex.exit_code, stderr=ex.stderr, stdout=ex.stdout, cmd=ex.cmd, description=ex.description) except processutils.UnknownArgumentError as ex: raise exception.Error(ex.message) return (stdout, stderr)
def _vg_exists(self): """Simple check to see if VG exists. :returns: True if vg specified in object exists, else False """ exists = False cmd = ['vgs', '--noheadings', '-o', 'name'] (out, err) = putils.execute(*cmd, root_helper='sudo', run_as_root=True) if out is not None: volume_groups = out.split() if self.vg_name in volume_groups: exists = True return exists
def execute(*cmd, **kwargs): """Convenience wrapper around oslo's execute() method.""" if 'run_as_root' in kwargs and not 'root_helper' in kwargs: kwargs['root_helper'] = get_root_helper() try: (stdout, stderr) = processutils.execute(*cmd, **kwargs) except processutils.ProcessExecutionError as ex: raise exception.ProcessExecutionError( exit_code=ex.exit_code, stderr=ex.stderr, stdout=ex.stdout, cmd=ex.cmd, description=ex.description) except processutils.UnknownArgumentError as ex: raise exception.Error(ex.message) return (stdout, stderr)
def _update_info_from_rpm(self): LOG.debug('Trying rpm command.') try: out, err = putils.execute("rpm", "-qa", "--queryformat", "'%{version}\t%{release}\t%{vendor}'", self.PACKAGE_NAME) if not out: LOG.info(_('No rpm info found for %(pkg)s package.') % { 'pkg': self.PACKAGE_NAME}) return False parts = out.split() self._version = parts[0] self._release = parts[1] self._vendor = ' '.join(parts[2::]) return True except Exception as e: LOG.info(_('Could not run rpm command: %(msg)s.') % { 'msg': e}) return False
def _update_info_from_rpm(self): LOG.debug('Trying rpm command.') try: out, err = putils.execute("rpm", "-q", "--queryformat", "'%{version}\t%{release}\t%{vendor}'", self.PACKAGE_NAME) if not out: LOG.info( _('No rpm info found for %(pkg)s package.') % {'pkg': self.PACKAGE_NAME}) return False parts = out.split() self._version = parts[0] self._release = parts[1] self._vendor = ' '.join(parts[2::]) return True except Exception as e: LOG.info(_('Could not run rpm command: %(msg)s.') % {'msg': e}) return False
def get_all_volumes(vg_name=None): """Static method to get all LV's on a system. :param vg_name: optional, gathers info for only the specified VG :returns: List of Dictionaries with LV info """ cmd = ['lvs', '--noheadings', '-o', 'vg_name,name,size'] if vg_name is not None: cmd += [vg_name] (out, err) = putils.execute(*cmd, root_helper='sudo', run_as_root=True) lv_list = [] if out is not None: volumes = out.split() for vg, name, size in izip(*[iter(volumes)] * 3): lv_list.append({"vg": vg, "name": name, "size": size}) return lv_list
def supports_thin_provisioning(): """Static method to check for thin LVM support on a system. :returns: True if supported, False otherwise """ cmd = ['vgs', '--version'] (out, err) = putils.execute(*cmd, root_helper='sudo', run_as_root=True) lines = out.split('\n') for line in lines: if 'LVM version' in line: version_list = line.split() version = version_list[2] if '(2)' in version: version = version.replace('(2)', '') version_tuple = tuple(map(int, version.split('.'))) if version_tuple >= (2, 2, 95): return True return False
def get_lvm_version(root_helper): """Static method to get LVM version from system. :param root_helper: root_helper to use for execute :returns: version 3-tuple """ cmd = ['vgs', '--version'] (out, err) = putils.execute(*cmd, root_helper=root_helper, run_as_root=True) lines = out.split('\n') for line in lines: if 'LVM version' in line: version_list = line.split() # NOTE(gfidente): version is formatted as follows: # major.minor.patchlevel(library API version)[-customisation] version = version_list[2] version_filter = "(\d+)\.(\d+)\.(\d+).*" r = re.search(version_filter, version) version_tuple = tuple(map(int, r.group(1, 2, 3))) return version_tuple
def execute(*cmd, **kwargs): """Convenience wrapper around oslo's execute() method.""" if 'run_as_root' in kwargs and not 'root_helper' in kwargs: kwargs['root_helper'] = get_root_helper() return processutils.execute(*cmd, **kwargs)
def _create_vg(self, pv_list): cmd = ['vgcreate', self.vg_name, ','.join(pv_list)] putils.execute(*cmd, root_helper='sudo', run_as_root=True)