nodes: 0, module; 1, function_definition; 2, function_name:_sort_shared_logical_disks; 3, parameters; 4, block; 5, identifier:logical_disks; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, comment:# Separate logical disks based on share_physical_disks value.; 10, comment:# 'logical_disks_shared' when share_physical_disks is True and; 11, comment:# 'logical_disks_nonshared' when share_physical_disks is False; 12, expression_statement; 13, expression_statement; 14, for_statement; 15, comment:# Separete logical disks with raid 1 from the 'logical_disks_shared' into; 16, comment:# 'logical_disks_shared_raid1' and remaining as; 17, comment:# 'logical_disks_shared_excl_raid1'.; 18, expression_statement; 19, expression_statement; 20, for_statement; 21, comment:# Sort the 'logical_disks_shared' in reverse order based on; 22, comment:# 'number_of_physical_disks' attribute, if provided, otherwise minimum; 23, comment:# disks required to create the logical volume.; 24, expression_statement; 25, comment:# Move RAID 1+0 to first in 'logical_disks_shared' when number of physical; 26, comment:# disks needed to create logical volume cannot be shared with odd number of; 27, comment:# disks and disks higher than that of RAID 1+0.; 28, expression_statement; 29, for_statement; 30, comment:# Final 'logical_disks_sorted' list should have non shared logical disks; 31, comment:# first, followed by shared logical disks with RAID 1, and finally by the; 32, comment:# shared logical disks sorted based on number of disks and RAID 1+0; 33, comment:# condition.; 34, expression_statement; 35, return_statement; 36, comment:"""Sort the logical disks based on the following conditions.
  
      When the share_physical_disks is True make sure we create the volume
      which needs more disks first. This avoids the situation of insufficient
      disks for some logical volume request.
  
      For example,
        - two logical disk with number of disks - LD1(3), LD2(4)
        - have 4 physical disks
      In this case, if we consider LD1 first then LD2 will fail since not
      enough disks available to create LD2. So follow a order for allocation
      when share_physical_disks is True.
  
      Also RAID1 can share only when there is logical volume with only 2 disks.
      So make sure we create RAID 1 first when share_physical_disks is True.
  
      And RAID 1+0 can share only when the logical volume with even number of
      disks.
      :param logical_disks: 'logical_disks' to be sorted for shared logical
      disks.
      :returns: the logical disks sorted based the above conditions.
      """; 37, assignment; 38, assignment; 39, assignment; 40, assignment; 41, identifier:x; 42, identifier:logical_disks; 43, block; 44, assignment; 45, assignment; 46, identifier:x; 47, identifier:logical_disks_shared; 48, block; 49, assignment; 50, assignment; 51, identifier:x; 52, identifier:logical_disks_shared; 53, block; 54, assignment; 55, identifier:logical_disks_sorted; 56, identifier:is_shared; 57, parenthesized_expression; 58, identifier:num_of_disks; 59, parenthesized_expression; 60, identifier:logical_disks_shared; 61, list; 62, identifier:logical_disks_nonshared; 63, list; 64, expression_statement; 65, expression_statement; 66, identifier:logical_disks_shared_raid1; 67, list; 68, identifier:logical_disks_shared_excl_raid1; 69, list; 70, expression_statement; 71, expression_statement; 72, identifier:logical_disks_shared; 73, call; 74, identifier:check; 75, True; 76, if_statement; 77, if_statement; 78, identifier:logical_disks_sorted; 79, parenthesized_expression; 80, lambda; 81, lambda; 82, assignment; 83, call; 84, assignment; 85, call; 86, identifier:sorted; 87, argument_list; 88, comparison_operator:x['raid_level'] == "1+0"; 89, block; 90, not_operator; 91, block; 92, binary_operator:logical_disks_nonshared +
                              logical_disks_shared_raid1 +
                              logical_disks_shared; 93, lambda_parameters; 94, conditional_expression:True if ('share_physical_disks' in x and
                                      x['share_physical_disks']) else False; 95, lambda_parameters; 96, conditional_expression:x['number_of_physical_disks']
                      if 'number_of_physical_disks' in x else
                      constants.RAID_LEVEL_MIN_DISKS[x['raid_level']]; 97, identifier:target; 98, parenthesized_expression; 99, attribute; 100, argument_list; 101, identifier:target; 102, parenthesized_expression; 103, attribute; 104, argument_list; 105, identifier:logical_disks_shared_excl_raid1; 106, keyword_argument; 107, keyword_argument; 108, subscript; 109, string:"1+0"; 110, expression_statement; 111, for_statement; 112, identifier:check; 113, expression_statement; 114, expression_statement; 115, expression_statement; 116, binary_operator:logical_disks_nonshared +
                              logical_disks_shared_raid1; 117, identifier:logical_disks_shared; 118, identifier:x; 119, True; 120, parenthesized_expression; 121, False; 122, identifier:x; 123, subscript; 124, comparison_operator:'number_of_physical_disks' in x; 125, subscript; 126, conditional_expression:logical_disks_shared if is_shared(x)
                    else logical_disks_nonshared; 127, identifier:target; 128, identifier:append; 129, identifier:x; 130, conditional_expression:logical_disks_shared_raid1 if x['raid_level'] == '1'
                    else logical_disks_shared_excl_raid1; 131, identifier:target; 132, identifier:append; 133, identifier:x; 134, identifier:reverse; 135, True; 136, identifier:key; 137, identifier:num_of_disks; 138, identifier:x; 139, string; 140, assignment; 141, identifier:y; 142, identifier:logical_disks_shared; 143, block; 144, call; 145, call; 146, assignment; 147, identifier:logical_disks_nonshared; 148, identifier:logical_disks_shared_raid1; 149, boolean_operator; 150, identifier:x; 151, string; 152, string; 153, identifier:x; 154, attribute; 155, subscript; 156, identifier:logical_disks_shared; 157, call; 158, identifier:logical_disks_nonshared; 159, identifier:logical_disks_shared_raid1; 160, comparison_operator:x['raid_level'] == '1'; 161, identifier:logical_disks_shared_excl_raid1; 162, string_content:raid_level; 163, identifier:x_num; 164, call; 165, if_statement; 166, attribute; 167, argument_list; 168, attribute; 169, argument_list; 170, identifier:check; 171, True; 172, comparison_operator:'share_physical_disks' in x; 173, subscript; 174, string_content:number_of_physical_disks; 175, string_content:number_of_physical_disks; 176, identifier:constants; 177, identifier:RAID_LEVEL_MIN_DISKS; 178, identifier:x; 179, string; 180, identifier:is_shared; 181, argument_list; 182, subscript; 183, string; 184, identifier:num_of_disks; 185, argument_list; 186, comparison_operator:y['raid_level'] != "1+0"; 187, block; 188, identifier:logical_disks_shared; 189, identifier:remove; 190, identifier:x; 191, identifier:logical_disks_shared; 192, identifier:insert; 193, integer:0; 194, identifier:x; 195, string; 196, identifier:x; 197, identifier:x; 198, string; 199, string_content:raid_level; 200, identifier:x; 201, identifier:x; 202, string; 203, string_content:1; 204, identifier:x; 205, subscript; 206, string:"1+0"; 207, expression_statement; 208, if_statement; 209, string_content:share_physical_disks; 210, string_content:share_physical_disks; 211, string_content:raid_level; 212, identifier:y; 213, string; 214, assignment; 215, comparison_operator:x_num < y_num; 216, block; 217, string_content:raid_level; 218, identifier:y_num; 219, call; 220, identifier:x_num; 221, identifier:y_num; 222, expression_statement; 223, if_statement; 224, identifier:num_of_disks; 225, argument_list; 226, assignment; 227, identifier:check; 228, block; 229, identifier:y; 230, identifier:check; 231, parenthesized_expression; 232, break_statement; 233, conditional_expression:True if y_num % 2 == 0 else False; 234, True; 235, comparison_operator:y_num % 2 == 0; 236, False; 237, binary_operator:y_num % 2; 238, integer:0; 239, identifier:y_num; 240, integer:2
code: def _sort_shared_logical_disks(logical_disks):
      """Sort the logical disks based on the following conditions.
  
      When the share_physical_disks is True make sure we create the volume
      which needs more disks first. This avoids the situation of insufficient
      disks for some logical volume request.
  
      For example,
        - two logical disk with number of disks - LD1(3), LD2(4)
        - have 4 physical disks
      In this case, if we consider LD1 first then LD2 will fail since not
      enough disks available to create LD2. So follow a order for allocation
      when share_physical_disks is True.
  
      Also RAID1 can share only when there is logical volume with only 2 disks.
      So make sure we create RAID 1 first when share_physical_disks is True.
  
      And RAID 1+0 can share only when the logical volume with even number of
      disks.
      :param logical_disks: 'logical_disks' to be sorted for shared logical
      disks.
      :returns: the logical disks sorted based the above conditions.
      """
      is_shared = (lambda x: True if ('share_physical_disks' in x and
                                      x['share_physical_disks']) else False)
      num_of_disks = (lambda x: x['number_of_physical_disks']
                      if 'number_of_physical_disks' in x else
                      constants.RAID_LEVEL_MIN_DISKS[x['raid_level']])
  
      # Separate logical disks based on share_physical_disks value.
      # 'logical_disks_shared' when share_physical_disks is True and
      # 'logical_disks_nonshared' when share_physical_disks is False
      logical_disks_shared = []
      logical_disks_nonshared = []
      for x in logical_disks:
          target = (logical_disks_shared if is_shared(x)
                    else logical_disks_nonshared)
          target.append(x)
  
      # Separete logical disks with raid 1 from the 'logical_disks_shared' into
      # 'logical_disks_shared_raid1' and remaining as
      # 'logical_disks_shared_excl_raid1'.
      logical_disks_shared_raid1 = []
      logical_disks_shared_excl_raid1 = []
      for x in logical_disks_shared:
          target = (logical_disks_shared_raid1 if x['raid_level'] == '1'
                    else logical_disks_shared_excl_raid1)
          target.append(x)
  
      # Sort the 'logical_disks_shared' in reverse order based on
      # 'number_of_physical_disks' attribute, if provided, otherwise minimum
      # disks required to create the logical volume.
      logical_disks_shared = sorted(logical_disks_shared_excl_raid1,
                                    reverse=True,
                                    key=num_of_disks)
  
      # Move RAID 1+0 to first in 'logical_disks_shared' when number of physical
      # disks needed to create logical volume cannot be shared with odd number of
      # disks and disks higher than that of RAID 1+0.
      check = True
      for x in logical_disks_shared:
          if x['raid_level'] == "1+0":
              x_num = num_of_disks(x)
              for y in logical_disks_shared:
                  if y['raid_level'] != "1+0":
                      y_num = num_of_disks(y)
                      if x_num < y_num:
                          check = (True if y_num % 2 == 0 else False)
                          if check:
                              break
          if not check:
              logical_disks_shared.remove(x)
              logical_disks_shared.insert(0, x)
              check = True
  
      # Final 'logical_disks_sorted' list should have non shared logical disks
      # first, followed by shared logical disks with RAID 1, and finally by the
      # shared logical disks sorted based on number of disks and RAID 1+0
      # condition.
      logical_disks_sorted = (logical_disks_nonshared +
                              logical_disks_shared_raid1 +
                              logical_disks_shared)
      return logical_disks_sorted