def main(client, parent_id):
  # Initialize appropriate service.
  inventory_service = client.GetService('InventoryService', version='v201508')

  # Create a query to select ad units under the parent ad unit and the parent ad
  # unit.
  values = [{
      'key': 'parentId',
      'value': {
          'xsi_type': 'NumberValue',
          'value': parent_id
      }
  }]
  query = 'WHERE parentId = :parentId or id = :parentId'
  statement = dfp.FilterStatement(query, values)

  ad_units_archived = 0

  # Get ad units by statement.
  while True:
    response = inventory_service.getAdUnitsByStatement(
        statement.ToStatement())
    if 'results' in response:
      for ad_unit in response['results']:
        print ('Ad unit with ID \'%s\' and name \'%s\' will be archived.'
               % (ad_unit['id'], ad_unit['name']))
      # Perform action.
      result = inventory_service.performAdUnitAction(
          {'xsi_type': 'ArchiveAdUnits'}, statement.ToStatement())
      if result and int(result['numChanges']) > 0:
        ad_units_archived += int(result['numChanges'])
      statement.offset += dfp.SUGGESTED_PAGE_LIMIT
    else:
      break

  # Display results.
  if ad_units_archived > 0:
    print 'Number of ad units archived: %s' % ad_units_archived
  else:
    print 'No ad units were archived.'
dataset/ETHPy150Open googleads/googleads-python-lib/examples/dfp/v201508/inventory_service/archive_ad_units.py/main/original