def execute(self, dry_run=False): """ primary execution checkpoint for Target Discovery """ self.dry_run = dry_run # setup iSCSI so that all iSCSI physical and logical devices can be # discovered self.setup_iscsi() # for sparc, check each disk to make sure there's a label if self.arch == "sparc": self.sparc_label_check() # check to see if the user specified a search_type if self.search_type == DISK_SEARCH_NAME: try: # check to see if the search name is either c#t#d# or c#d# if re.match(DISK_RE, self.search_name, re.I): dmd = diskmgt.descriptor_from_key(const.ALIAS, self.search_name) alias = diskmgt.DMAlias(dmd.value) drive = alias.drive else: dmd = diskmgt.descriptor_from_key(const.DRIVE, self.search_name) drive = diskmgt.DMDrive(dmd.value) except OSError as err: raise RuntimeError("Unable to look up %s - %s" % \ (self.search_name, err)) # insert the drive information into the tree new_disk = self.discover_disk(drive) if new_disk is not None: self.root.insert_children(new_disk) elif self.search_type == ZPOOL_SEARCH_NAME: self.discover_entire_system(add_physical=False) self.root.insert_children(self.discover_zpools( self.search_name)) # Add all Boot Environments that are contained in this zpool self.discover_BEs(self.search_name) else: self.discover_entire_system() # Add the discovered zpool objects self.root.insert_children(self.discover_zpools()) # Add all Boot Environments self.discover_BEs() # Add the root node to the DOC self.doc.persistent.insert_children(self.root)
def retrieve_drive(name): """ function to return a drive object based on a specific name """ try: # check to see if the search name is either c#t#d# or c#d# if re.match(DISK_RE, name, re.I): dmd = diskmgt.descriptor_from_key(const.ALIAS, name) alias = diskmgt.DMAlias(dmd.value) drive = alias.drive else: dmd = diskmgt.descriptor_from_key(const.DRIVE, name) drive = diskmgt.DMDrive(dmd.value) except (KeyError, OSError) as err: raise RuntimeError("Unable to look up %s - %s" % (name, err)) return drive
def get_curr_bootdisk(): """ get_curr_bootdisk() - function to return the ctd string of the system's bootdisk """ # set up a logger logger = logging.getLogger(ILN) # query libdevinfo for the bootdev list bootdevs = C.POINTER(BootDevp)() err = C.c_int() err = cfunc.devfs_bootdev_get_list("/", C.byref(bootdevs)) # trap on DEVFS_ERROR. Typically happens after fast-reboot if err == -1: logger.debug("devfs_bootdev_get_list(): unable to open " + "GRUB disk map. Did you fast-reboot?") return None # trap on all other errors elif err != 0: logger.debug("devfs_bootdev_get_list(): %s" % os.strerror(err)) return None try: # walk the null terminated bootdevs list of boot_dev structures to # construct a simplier list to iterate over i = 0 bootdev_list = [] while bootdevs[i]: bootdev_list.append(bootdevs[i].contents) i += 1 for bootdev in bootdev_list: # dereference the bootdev_trans char** ctd_path = bootdev.bootdev_trans.contents.value # ensure there's something present to split on if ctd_path is None: continue # calculate the ctd string from the full /dev path (_none, sep, disk) = ctd_path.partition("/dev/dsk/") if sep: ctd = re.split("[sp]", disk)[0] else: continue # check to see if it's a CD-ROM drive dmd = diskmgt.descriptor_from_key(ldm_const.ALIAS, ctd) alias = diskmgt.DMAlias(dmd.value) drive = alias.drive if not drive.cdrom: return ctd finally: cfunc.devfs_bootdev_free_list(bootdevs) return None
def in_use_check(self, ctds): """ in_use_check() - method to query libdiskmgt to check for in_use confilcts. """ try: dmd = diskmgt.descriptor_from_key(ldm_const.SLICE, "/dev/dsk/" + ctds) except KeyError: # the requested slice doesn't exist so simply skip the check return dict() else: dm_slice = diskmgt.DMSlice(dmd.value) return dm_slice.use_stats
def __init__(self, methodName="runTest"): unittest.TestCase.__init__(self, methodName) # extract drive informtion to construct a bare-bones DOC object dmd = diskmgt.descriptor_from_key(ALIAS, MASTER_CTD) alias = diskmgt.DMAlias(dmd.value) drive = alias.drive dma = drive.media.attributes if dma.ncylinders is None: raise RuntimeError("Unable to process disk label. Please " + "place a VTOC label on the disk.") # get the maximum size of the disk fd = os.open("/dev/rdsk/" + MASTER_CTD + "s2", os.O_RDONLY | os.O_NDELAY) try: media_info = drive.DKMinfo() fcntl.ioctl(fd, diskmgt.DKIOCGMEDIAINFO, C.addressof(media_info)) except IOError as error: print 'ioctl failed: ', str(error) raise finally: os.close(fd) # set the basic geometry self.disk = Disk(MASTER_CTD) self.disk.ctd = MASTER_CTD self.disk.disk_prop = DiskProp() self.disk.disk_prop.dev_size = Size( str(media_info.dki_capacity) + Size.sector_units) self.disk_size = self.disk.disk_prop.dev_size.sectors self.disk.geometry = DiskGeometry(dma.blocksize, dma.nheads * dma.nsectors) self.disk.geometry.ncyl = dma.ncylinders self.disk.geometry.nhead = dma.nheads self.disk.geometry.nsectors = dma.nsectors self.target = Target(Target.DESIRED) self.target.insert_children(self.disk)
def __init__(self, methodName="runTest"): unittest.TestCase.__init__(self, methodName) # extract drive informtion to construct a bare-bones DOC object dmd = diskmgt.descriptor_from_key(ALIAS, MASTER_CTD) alias = diskmgt.DMAlias(dmd.value) drive = alias.drive dma = drive.media.attributes if dma.ncylinders is None: raise RuntimeError("Unable to process disk label. Please " + "place a VTOC label on the disk.") # get the maximum size of the disk fd = os.open("/dev/rdsk/" + MASTER_CTD + "s2", os.O_RDONLY|os.O_NDELAY) try: media_info = drive.DKMinfo() fcntl.ioctl(fd, diskmgt.DKIOCGMEDIAINFO, C.addressof(media_info)) except IOError as error: print 'ioctl failed: ', str(error) raise finally: os.close(fd) # set the basic geometry self.disk = Disk(MASTER_CTD) self.disk.ctd = MASTER_CTD self.disk.disk_prop = DiskProp() self.disk.disk_prop.dev_size = Size(str(media_info.dki_capacity) + Size.sector_units) self.disk_size = self.disk.disk_prop.dev_size.sectors self.disk.geometry = DiskGeometry(dma.blocksize, dma.nheads * dma.nsectors) self.disk.geometry.ncyl = dma.ncylinders self.disk.geometry.nhead = dma.nheads self.disk.geometry.nsectors = dma.nsectors self.target = Target(Target.DESIRED) self.target.insert_children(self.disk)