예제 #1
0
    def post(self):
        """Catalogs instances in the Machine Provider.

    Params:
      dimensions: JSON-encoded string representation of
        machine_provider.Dimensions describing the members of the instance
        group.
      group: Name of the instance group whose instances are being cataloged.
      instance_map: JSON-encoded dict mapping instance names to service accounts
        to use for Cloud Pub/Sub communication with the Machine Provider.
      policies: JSON-encoded string representation of machine_provider.Policies
        governing the members of the instance group.
    """
        dimensions = json.loads(self.request.get('dimensions'))
        group = self.request.get('group')
        instance_map = json.loads(self.request.get('instance_map'))
        policies = json.loads(self.request.get('policies'))

        requests = {}

        for instance_name, service_account in instance_map.iteritems():
            requests[instance_name] = {
                'dimensions': dimensions.copy(),
                'policies': policies
            }
            requests[instance_name]['dimensions']['hostname'] = instance_name
            requests[instance_name]['policies']['machine_service_account'] = (
                service_account)

        try:
            responses = machine_provider.add_machines(requests.values()).get(
                'responses', {})
        except net.Error as e:
            logging.warning(e)
            responses = {}

        for response in responses:
            request = response.get('machine_addition_request', {})
            error = response.get('error')
            instance_name = request.get('dimensions', {}).get('hostname')
            if instance_name in requests.keys():
                if not error:
                    logging.info('Instance added to Catalog: %s',
                                 instance_name)
                    requests.pop(instance_name)
                elif error == 'HOSTNAME_REUSE':
                    logging.warning('Hostname reuse in Catalog: %s',
                                    instance_name)
                    requests.pop(instance_name)
                else:
                    logging.warning('Instance not added to Catalog: %s',
                                    instance_name)
            else:
                logging.info('Unknown instance: %s', instance_name)

        reschedule_instance_cataloging(
            models.InstanceGroup.generate_key(group), requests.keys())
예제 #2
0
    def post(self):
        """Reclaim a machine.

    Params:
      dimensions: JSON-encoded string representation of
        machine_provider.Dimensions describing the members of the instance
        group.
      instances: JSON-encoded list of instances in the instance group to
        catalog:
      policies: JSON-encoded string representation of machine_provider.Policies
        governing the members of the instance group.
    """
        dimensions = json.loads(self.request.get('dimensions'))
        instances = json.loads(self.request.get('instances'))
        policies = json.loads(self.request.get('policies'))

        requests = []
        instances_to_uncatalog = set()

        for instance_name in instances:
            instances_to_uncatalog.add(instance_name)
            requests.append({
                'dimensions': dimensions.copy(),
                'policies': policies
            })
            requests[-1]['dimensions']['hostname'] = instance_name

        try:
            responses = machine_provider.add_machines(requests).get(
                'responses', {})
        except net.Error as e:
            logging.warning(e)
            responses = {}

        for response in responses:
            request = response.get('machine_addition_request', {})
            error = response.get('error')
            instance_name = request.get('dimensions', {}).get('hostname')
            if instance_name in instances:
                if not error:
                    logging.info('Instance added to Catalog: %s',
                                 instance_name)
                    instances_to_uncatalog.discard(instance_name)
                elif error == 'HOSTNAME_REUSE':
                    logging.warning('Hostname reuse in Catalog: %s',
                                    instance_name)
                    instances_to_uncatalog.discard(instance_name)
                else:
                    logging.warning('Instance not added to Catalog: %s',
                                    instance_name)
            else:
                logging.info('Unknown instance: %s', instance_name)

        uncatalog_instances(instances_to_uncatalog)
예제 #3
0
  def post(self):
    """Catalogs instances in the Machine Provider.

    Params:
      dimensions: JSON-encoded string representation of
        machine_provider.Dimensions describing the members of the instance
        group.
      group: Name of the instance group whose instances are being cataloged.
      instance_map: JSON-encoded dict mapping instance names to service accounts
        to use for Cloud Pub/Sub communication with the Machine Provider.
      policies: JSON-encoded string representation of machine_provider.Policies
        governing the members of the instance group.
    """
    dimensions = json.loads(self.request.get('dimensions'))
    group = self.request.get('group')
    instance_map = json.loads(self.request.get('instance_map'))
    policies = json.loads(self.request.get('policies'))

    requests = {}

    for instance_name, service_account in instance_map.iteritems():
      requests[instance_name] = {
          'dimensions': dimensions.copy(), 'policies': policies}
      requests[instance_name]['dimensions']['hostname'] = instance_name
      requests[instance_name]['policies']['machine_service_account'] = (
          service_account)

    try:
      responses = machine_provider.add_machines(
          requests.values()).get('responses', {})
    except net.Error as e:
      logging.warning(e)
      responses = {}

    for response in responses:
      request = response.get('machine_addition_request', {})
      error = response.get('error')
      instance_name = request.get('dimensions', {}).get('hostname')
      if instance_name in requests.keys():
        if not error:
          logging.info('Instance added to Catalog: %s', instance_name)
          requests.pop(instance_name)
        elif error == 'HOSTNAME_REUSE':
          logging.warning('Hostname reuse in Catalog: %s', instance_name)
          requests.pop(instance_name)
        else:
          logging.warning('Instance not added to Catalog: %s', instance_name)
      else:
        logging.info('Unknown instance: %s', instance_name)

    reschedule_instance_cataloging(
        models.InstanceGroup.generate_key(group), requests.keys())
예제 #4
0
  def post(self):
    """Reclaim a machine.

    Params:
      dimensions: JSON-encoded string representation of
        machine_provider.Dimensions describing the members of the instance
        group.
      instances: JSON-encoded list of instances in the instance group to
        catalog:
      policies: JSON-encoded string representation of machine_provider.Policies
        governing the members of the instance group.
    """
    dimensions = json.loads(self.request.get('dimensions'))
    instances = json.loads(self.request.get('instances'))
    policies = json.loads(self.request.get('policies'))

    requests = []
    instances_to_uncatalog = set()

    for instance_name in instances:
      instances_to_uncatalog.add(instance_name)
      requests.append({
          'dimensions': dimensions.copy(), 'policies': policies})
      requests[-1]['dimensions']['hostname'] = instance_name

    try:
      responses = machine_provider.add_machines(requests).get('responses', {})
    except net.Error as e:
      logging.warning(e)
      responses = {}

    for response in responses:
      request = response.get('machine_addition_request', {})
      error = response.get('error')
      instance_name = request.get('dimensions', {}).get('hostname')
      if instance_name in instances:
        if not error:
          logging.info('Instance added to Catalog: %s', instance_name)
          instances_to_uncatalog.discard(instance_name)
        elif error == 'HOSTNAME_REUSE':
          logging.warning('Hostname reuse in Catalog: %s', instance_name)
          instances_to_uncatalog.discard(instance_name)
        else:
          logging.warning('Instance not added to Catalog: %s', instance_name)
      else:
        logging.info('Unknown instance: %s', instance_name)

    uncatalog_instances(instances_to_uncatalog)