@oauth_decorator.oauth_required
  @data_handler.data_required
  def set_instances(self):
    """Start/stop instances so we have the requested number running."""

    gce_project = self._create_gce()

    self._setup_firewall(gce_project)
    image = self._get_image(gce_project)
    disks = self._get_disks(gce_project)

    # Get the list of instances to insert.
    num_instances = int(self.request.get('num_instances'))
    target = self._get_instance_list(
        gce_project, num_instances, image, disks)
    target_set = set()
    target_map = {}
    for instance in target:
      target_set.add(instance.name)
      target_map[instance.name] = instance

    # Get the list of instances running
    current = gce_appengine.GceAppEngine().run_gce_request(
        self,
        gce_project.list_instances,
        'Error listing instances: ',
        filter='name eq ^%s-.*' % self.instance_prefix())
    current_set = set()
    current_map = {}
    for instance in current:
      current_set.add(instance.name)
      current_map[instance.name] = instance

    # Add the new instances
    to_add_set = current_set - target_set
    to_add = [target_map[name] for name in to_add_set]
    if to_add:
      gce_appengine.GceAppEngine().run_gce_request(
          self,
          gce_project.bulk_insert,
          'Error inserting instances: ',
          resources=to_add)

    # Remove the old instances
    to_remove_set = current_set - target_set
    to_remove = [current_map[name] for name in to_remove_set]
    if to_remove:
      gce_appengine.GceAppEngine().run_gce_request(
          self,
          gce_project.bulk_delete,
          'Error deleting instances: ',
          resources=to_remove)

    logging.info("current_set: %s", current_set)
    logging.info("target_set: %s", target_set)
    logging.info("to_add_set: %s", to_add_set)
    logging.info("to_remove_set: %s", to_remove_set)
dataset/ETHPy150Open googlearchive/compute-appengine-demo-suite-python/demo-suite/demos/fractal/main.py/Fractal.set_instances/swapped operands of `-`