def cache_status(self): if not self.is_cached(): raise ValueError('LV is of wrong type') devpath = self.path s = os.stat(devpath) major, minor = os.major(s.st_rdev), os.minor(s.st_rdev) mapper = find_device('/dev/mapper', major, minor) if mapper is None: raise KeyError('failed to find device mapper entry for ' '%s/%s' % (self.vg.name, self.name)) status = dmsetup('status', mapper) status = dict( zip(cache_status_fields, status.strip().split()[:len(cache_status_fields)])) status['read_hits_ratio'] = \ 100 * float(status['read_hits']) / (float(status['read_hits']) + float(status['read_misses'])) status['write_hits_ratio'] = \ 100 * float(status['write_hits']) / (float(status['write_hits']) + float(status['write_misses'])) for k in status.keys(): if isinstance(status[k], basestring): if status[k].isdigit(): status[k] = int(status[k]) elif '/' in status[k]: a, b = [int(x) for x in status[k].split('/')] status['%s_pct' % k] = (a * 1.0 / b * 1.0) * 100 return status
def cache_status(self): if not self.is_cached(): raise ValueError('LV is of wrong type') devpath = self.path s = os.stat(devpath) major, minor = os.major(s.st_rdev), os.minor(s.st_rdev) mapper = find_device('/dev/mapper', major, minor) if mapper is None: raise KeyError('failed to find device mapper entry for ' '%s/%s' % (self.vg.name, self.name)) status = dmsetup('status', mapper) status = dict(zip(cache_status_fields, status.strip().split()[:len(cache_status_fields)])) for k in status.keys(): if status[k].isdigit(): status[k] = int(status[k]) elif '/' in status[k]: a, b = [int(x) for x in status[k].split('/')] status['%s_pct' % k] = (a*1.0/b*1.0)*100 return status
def resize(cls, container_id, new_size=10240): """resize container disk space, only support devicemapper storage backend args: new_size: 1024Mb """ dev_path = glob.glob("/dev/mapper/docker-*-*-%s*" % container_id) if dev_path: dev = os.path.basename(dev_path[0]) else: return #load table = sh.dmsetup('table', dev).split() table[1] = str(int(new_size) * 1024 * 1024 / 512) sh.dmsetup((sh.echo(' '.join(table))), 'load', dev) sh.dmsetup('resume', dev) sh.resize2fs(dev_path[0])
def resize(cls, container_id, new_size=10240): """resize container disk space, only support devicemapper storage backend args: new_size: 1024Mb """ dev_path = glob.glob("/dev/mapper/docker-*-*-%s*" % container_id) if dev_path: dev = os.path.basename(dev_path[0]) else: return #load table = sh.dmsetup('table', dev).split() table[1] = str(int(new_size)*1024*1024/512) sh.dmsetup((sh.echo(' '.join(table))), 'load', dev) sh.dmsetup('resume', dev) sh.resize2fs(dev_path[0])
def cache_status(self): if not self.is_cached(): raise ValueError("LV is of wrong type") devpath = self.lv_dm_path s = os.stat(devpath) major, minor = os.major(s.st_rdev), os.minor(s.st_rdev) mapper = find_device("/dev/mapper", major, minor) if mapper is None: raise KeyError("failed to find device mapper entry for " "%s/%s" % (self.vg.name, self.name)) status = dmsetup("status", mapper) status = dict(zip(cache_status_fields, status.strip().split()[: len(cache_status_fields)])) for k in status.keys(): if status[k].isdigit(): status[k] = int(status[k]) elif "/" in status[k]: a, b = [int(x) for x in status[k].split("/")] status["%s_pct" % k] = (a * 1.0 / b * 1.0) * 100 return status