def _CreatePatchInstanceFilter(messages, filter_all, filter_group_labels,
                               filter_zones, filter_names,
                               filter_name_prefixes):
  """Creates a PatchInstanceFilter message from its components."""
  group_labels = []
  for group_label in filter_group_labels:
    pairs = []
    for key, value in group_label.items():
      pairs.append(
          messages.PatchInstanceFilterGroupLabel.LabelsValue.AdditionalProperty(
              key=key, value=value))
    group_labels.append(
        messages.PatchInstanceFilterGroupLabel(
            labels=messages.PatchInstanceFilterGroupLabel.LabelsValue(
                additionalProperties=pairs)))

  return messages.PatchInstanceFilter(
      all=filter_all,
      groupLabels=group_labels,
      zones=filter_zones,
      instances=filter_names,
      instanceNamePrefixes=filter_name_prefixes,
  )