Add disk variables

netsetup
Mike Hiretsky 14 years ago
parent 3520ad2ecb
commit 87facedfd4

@ -49,6 +49,130 @@ class fillVars(object, glob_attr):
if not ip:
listInterfacesInfo.append((interfaces, "Off"))
return ", ".join(map(lambda x:"%s (%s)"%(x[0],x[1]),listInterfacesInfo))
def get_os_disk_hash(self):
reWrongDevice = re.compile("|".join(['ram','loop']))
reSdaPart = re.compile("^/dev/sd([a-z])(\d+)$")
rePartInfo = re.compile("""
^(?P<dev>/dev/[^:]+):\s*
(LABEL=\"(?P<name>[^\"]*)\")?\s*
(UUID=\"(?P<uuid>[^\"]*)\")?\s*
(TYPE=\"(?P<format>[^\"]*)\")?""", re.X)
devices = filter( lambda x: not reWrongDevice.search(x),
os.listdir('/sys/block'))
disks = reduce( lambda x,y: x +
map( lambda x: "/dev/%s"%x,
filter(lambda x: y in x,os.listdir('/sys/block/%s'%y))),
devices, [] )
disk_hash = {}
# fill grub info
for dev in disks:
disk_hash[dev] = {}
match = reSdaPart.match(dev)
if match:
disk_hash[dev]['grub'] = "%d,%d" % \
(ord(match.groups()[0])-ord('a'),
int(match.groups()[1]))
curDevice = None
# parse all parted lines started with Disk and started with number
partedLines = \
filter(lambda x: x.startswith("Disk") or
x.strip()[:1].isdigit(),
self._runos('LANG=C /usr/sbin/parted -l',ret_list=True))
for line in partedLines:
# split data
parts = filter(lambda x: x, line.strip().split(' '))
# if start device description
if parts[0] == "Disk":
curDevice = parts[1][:-1]
continue
# if first part is number then it is partition description
if parts[0].isdigit():
# part name it is devicename + partition number
partition = curDevice + parts[0]
# create entry if hash hasn't it
if not partition in disk_hash:
disk_hash[partition] = {}
disk_hash[partition]['part'] = parts[4]
disk_hash[partition]['size'] = parts[3]
# fill format, name and uuid
for line in self._runos('/sbin/blkid',ret_list=True):
partinfo = rePartInfo.search(line)
partinfo = partinfo.groupdict() if partinfo else None
if partinfo and partinfo['dev'] in disks:
dev = partinfo['dev']
disk_hash[dev]['format'] = partinfo['format'] or ""
disk_hash[dev]['name'] = partinfo['name'] or ""
disk_hash[dev]['uuid'] = partinfo['uuid'] or ""
return disk_hash
def get_os_disk_dev(self):
"""List of available partition devices"""
return sorted(self.Get('os_disk_hash').keys())
def getAttributeFromHash(self,attr):
hash = self.Get('os_disk_hash')
return map(lambda x: hash[x][attr] if attr in hash[x] else "",
sorted(hash.keys()))
def get_os_disk_uuid(self):
"""List uudi for partition devices"""
return self.getAttributeFromHash('uuid')
def get_os_disk_install(self):
"""List mounted points for installed system"""
return self.getAttributeFromHash('install')
def get_os_disk_load(self):
"""List mounted points for current operation system"""
return self.getAttributeFromHash('load')
def get_os_disk_format(self):
"""List filesystem for partition devices"""
return self.getAttributeFromHash('format')
def get_os_disk_grub(self):
"""List grub id for partition devices"""
return self.getAttributeFromHash('grub')
def get_os_disk_part(self):
"""Type of partition devices (primary, extended or logical)"""
return self.getAttributeFromHash('part')
def get_os_disk_size(self):
"""Partition size"""
return self.getAttributeFromHash('size')
def get_os_disk_name(self):
"""Label of partitions"""
return self.getAttributeFromHash('name')
def get_os_device_dev(self):
"""Devices"""
pass
def get_os_device_type(self):
"""Device type (hdd,cdrom,usb-flash)"""
pass
def get_os_device_map(self):
"""Map number for grub"""
pass
def get_os_grub_info(self):
"""Part of current grub.conf"""
pass
def get_os_grub_devicemap_info(self):
"""Content of device.map file for grub"""
pass
def get_os_fstab_mount_info(self):
"""Information about mount points for fstab"""
pass
def get_os_fstab_swap_info(self):
"""Information about swap for fstab"""
pass

@ -37,6 +37,9 @@ class Data:
# inforamation about net interfaces
os_net_interfaces_info = {}
# infomation about disk in hash
os_disk_hash = {'official':True}
# list of available partition devices
os_disk_dev = {}

@ -0,0 +1,2 @@
# Calculate belong()!=&&pkg(sys-boot/grub)!= path=/boot

@ -1 +1 @@
# Calculate path=/etc name=conf.d
# Calculate path=/etc

Loading…
Cancel
Save