def _rootfs_guess_by_image(target, image, boot_dev): # Gave a None partition, means pick our own based on a guess. We # know what image we want to install, so we will scan the all the # target's root partitions (defined in tags/properties # pos_root_XYZ) to see who has installed the most similar thing to # image and use that (so it is faster to rsync it). partl = {} empties = [] # refresh target information FIXME: need a better method target.rt = target.rtb.rest_tb_target_update(target.id) for tag, value in target.rt.iteritems(): if not tag.startswith("pos_root_"): continue dev_basename = tag.replace("pos_root_", "") dev_name = "/dev/" + dev_basename if value == 'EMPTY': empties.append(dev_name) else: partl[dev_name] = value target.report_info("POS: %s: empty partitions: %s" % (boot_dev, " ".join(empties)), dlevel = 2) target.report_info("POS: %s: imaged partitions: %s" % (boot_dev, " ".join([ i[0] + "|" + i[1] for i in partl.items() ])), dlevel = 2) if not partl and not empties: # there were no pos_root_XYZ entries, so that means we are not # initialized properly, reinit target.report_info("POS: %s: no root partitions known, uninitialized?" % boot_dev, dlevel = 1) return None # We don't have empties to spare, so choose one that is the most # similar, to improve the transfer rate # # This prolly can be made more efficient, like collect least-used # partition data? to avoid the situation where two clients keep # imaging over each other when they could have two separate images root_part_dev, score, seed = pos.image_seed_match(partl, image) if score == 0: # none is a good match, find an empty one...if there are # non empty, just any if empties: root_part_dev = random.choice(empties) target.report_info("POS: picked up empty root partition %s" % root_part_dev, dlevel = 2) else: root_part_dev = random.choice(partl.keys()) target.report_info( "POS: picked up random partition %s, because none of the " "existing installed ones was a good match and there " "are no empty ones" % root_part_dev, dlevel = 2) else: target.report_info("POS: picked up root partition %s for %s " "due to a %.02f similarity with %s" % (root_part_dev, seed, score, seed), dlevel = 2) return root_part_dev
def _rootfs_guess_by_image(target, image, boot_dev): # Gave a None partition, means pick our own based on a guess. We # know what image we want to install, so we will scan the all the # target's root partitions (defined in tags/properties # pos_root_XYZ) to see who has installed the most similar thing to # image and use that (so it is faster to rsync it). partl = {} empties = [] # refresh target information FIXME: need a better method target.rt = target.rtb.rest_tb_target_update(target.id) for tag, value in target.rt.iteritems(): if not tag.startswith("pos_root_"): continue dev_basename = tag.replace("pos_root_", "") dev_name = "/dev/" + dev_basename if value == 'EMPTY': empties.append(dev_name) else: partl[dev_name] = value target.report_info("POS: %s: empty partitions: %s" % (boot_dev, " ".join(empties)), dlevel=2) target.report_info( "POS: %s: imaged partitions: %s" % (boot_dev, " ".join([i[0] + "|" + i[1] for i in partl.items()])), dlevel=2) if not partl and not empties: # there were no pos_root_XYZ entries, so that means we are not # initialized properly, reinit target.report_info( "POS: %s: no root partitions known, uninitialized?" % boot_dev, dlevel=1) return None # We don't have empties to spare, so choose one that is the most # similar, to improve the transfer rate # # This prolly can be made more efficient, like collect least-used # partition data? to avoid the situation where two clients keep # imaging over each other when they could have two separate images root_part_dev, score, check_empties, seed = pos.image_seed_match( partl, image) if score == 0: # none is a good match, find an empty one...if there are # non empty, just any if empties: root_part_dev = random.choice(empties) target.report_info("POS: picked up empty root partition %s" % root_part_dev, dlevel=2) else: root_part_dev = random.choice(partl.keys()) target.report_info( "POS: picked up random partition %s, because none of the " "existing installed ones was a good match and there " "are no empty ones" % root_part_dev, dlevel=2) elif check_empties and empties: # This is for the case where image and seed have the same distro # but different spin. We want to check our luck if there is an empty # partition. If there isn't, we will just take the given one from # pos.image_seed_match. root_part_dev = random.choice(empties) target.report_info("POS: picked up empty root partition %s" % root_part_dev, dlevel=2) else: target.report_info("POS: picked up root partition %s for %s " "due to a %.02f similarity with %s" % (root_part_dev, seed, score, seed), dlevel=2) return root_part_dev