def _diff_disk_lists(old, new):
    '''
    Compare disk definitions to extract the changes and fix target devices

    :param old: list of ElementTree nodes representing the old disks
    :param new: list of ElementTree nodes representing the new disks
    '''
    # Change the target device to avoid duplicates before diffing: this may lead
    # to additional changes. Think of unchanged disk 'hda' and another disk listed
    # before it becoming 'hda' too... the unchanged need to turn into 'hdb'.
    targets = []
    prefixes = ['fd', 'hd', 'vd', 'sd', 'xvd', 'ubd']
    for disk in new:
        target_node = disk.find('target')
        target = target_node.get('dev')
        prefix = [item for item in prefixes if target.startswith(item)][0]
        new_target = ['{0}{1}'.format(prefix, string.ascii_lowercase[i]) for i in range(len(new))
                      if '{0}{1}'.format(prefix, string.ascii_lowercase[i]) not in targets][0]
        target_node.set('dev', new_target)
        targets.append(new_target)

    return _diff_lists(old, new, _disks_equal)
def _diff_disk_lists ( old , new ) : targets = [ ] prefixes = [ 'fd' , 'hd' , 'vd' , 'sd' , 'xvd' , 'ubd' ] for disk in new : target_node = disk . find ( 'target' ) target = target_node . get ( 'dev' ) prefix = [ item for item in prefixes if target . startswith ( item ) ] [ 0 ] new_target = [ '{0}{1}' . format ( prefix , string . ascii_lowercase [ i ] ) for i in range ( len ( new ) ) if '{0}{1}' . format ( prefix , string . ascii_lowercase [ i ] ) not in targets ] [ 0 ] target_node . set ( 'dev' , new_target ) targets . append ( new_target ) return _diff_lists ( old , new , _disks_equal )
Compare disk definitions to extract the changes and fix target devices

    :param old: list of ElementTree nodes representing the old disks
    :param new: list of ElementTree nodes representing the new disks