Пример #1
0
 def _GetPerInstanceConfigMessage(holder, instance_ref, stateful_disks,
                                  stateful_metadata):
     disk_getter = instance_disk_getter.InstanceDiskGetter(
         instance_ref=instance_ref, holder=holder)
     messages = holder.client.messages
     disk_overrides = [
         instance_configs_messages.GetDiskOverride(
             messages=messages,
             stateful_disk=stateful_disk,
             disk_getter=disk_getter)
         for stateful_disk in stateful_disks or []
     ]
     metadata_overrides = [
         messages.ManagedInstanceOverride.MetadataValueListEntry(
             key=metadata_key, value=metadata_value)
         for metadata_key, metadata_value in sorted(
             six.iteritems(stateful_metadata))
     ]
     return messages.PerInstanceConfig(
         instance=str(instance_ref),
         name=str(instance_ref).rsplit('/', 1)[-1],
         override=messages.ManagedInstanceOverride(
             disks=disk_overrides, metadata=metadata_overrides),
         preservedState=\
             instance_configs_messages.MakePreservedStateFromOverrides(
                 holder.client.messages, disk_overrides, metadata_overrides))
 def _GetPerInstanceConfigMessage(holder, instance_ref, stateful_disks):
     disk_getter = instance_disk_getter.InstanceDiskGetter(
         instance_ref=instance_ref, holder=holder)
     messages = holder.client.messages
     disk_overrides = [
         instance_configs_messages.GetDiskOverride(
             messages=messages,
             stateful_disk=stateful_disk,
             disk_getter=disk_getter)
         for stateful_disk in stateful_disks or []
     ]
     return messages.PerInstanceConfig(
         instance=str(instance_ref),
         override=messages.ManagedInstanceOverride(disks=disk_overrides))
Пример #3
0
  def _CombinePerInstanceConfigMessage(holder, configs_getter, igm_ref,
                                       instance_ref, update_stateful_disks,
                                       remove_stateful_disks):
    disk_getter = instance_disk_getter.InstanceDiskGetter(
        instance_ref=instance_ref, holder=holder)
    messages = holder.client.messages
    per_instance_config = configs_getter.get_instance_config(
        igm_ref=igm_ref, instance_ref=instance_ref)

    per_instance_config.override.reset('origin')

    remove_stateful_disks_set = set(remove_stateful_disks or [])
    update_stateful_disks_dict = Update._UpdateStatefulDisksToDict(
        update_stateful_disks)

    new_stateful_disks = []
    for current_stateful_disk in per_instance_config.override.disks:
      if current_stateful_disk.deviceName in remove_stateful_disks_set:
        continue
      if current_stateful_disk.deviceName in update_stateful_disks_dict:
        update_stateful_disk = update_stateful_disks_dict[
            current_stateful_disk.deviceName]
        source = update_stateful_disk.get('source')
        mode = update_stateful_disk.get('mode')
        if not (source or mode):
          raise exceptions.InvalidArgumentException(
              parameter_name='--update-stateful-disk',
              message=('[source] or [mode] is required when updating'
                       ' [device-name] already existing in instance config'))
        if source:
          current_stateful_disk.source = source
        if mode:
          current_stateful_disk.mode = instance_configs_messages.GetMode(
              messages=messages, mode=mode)
        del update_stateful_disks_dict[current_stateful_disk.deviceName]
      new_stateful_disks.append(current_stateful_disk)

    for update_stateful_disk in update_stateful_disks_dict.values():
      new_stateful_disks.append(
          instance_configs_messages.GetDiskOverride(
              messages=messages,
              stateful_disk=update_stateful_disk,
              disk_getter=disk_getter))

    per_instance_config.override.disks = new_stateful_disks

    return per_instance_config
Пример #4
0
    def _CombinePerInstanceConfigMessage(holder, configs_getter, igm_ref,
                                         instance_ref, update_stateful_disks,
                                         remove_stateful_disks,
                                         update_stateful_metadata,
                                         remove_stateful_metadata):
        disk_getter = instance_disk_getter.InstanceDiskGetter(
            instance_ref=instance_ref, holder=holder)
        messages = holder.client.messages
        per_instance_config = configs_getter.get_instance_config(
            igm_ref=igm_ref, instance_ref=instance_ref)

        per_instance_config.override.reset('origin')

        remove_stateful_disks_set = set(remove_stateful_disks or [])
        update_stateful_disks_dict = Update._UpdateStatefulDisksToDict(
            update_stateful_disks)

        new_stateful_disks = []
        for current_stateful_disk in per_instance_config.override.disks:
            if current_stateful_disk.deviceName in remove_stateful_disks_set:
                continue
            if current_stateful_disk.deviceName in update_stateful_disks_dict:
                update_stateful_disk = update_stateful_disks_dict[
                    current_stateful_disk.deviceName]
                source = update_stateful_disk.get('source')
                mode = update_stateful_disk.get('mode')
                if not (source or mode):
                    raise exceptions.InvalidArgumentException(
                        parameter_name='--update-stateful-disk',
                        message=(
                            '[source] or [mode] is required when updating'
                            ' [device-name] already existing in instance config'
                        ))
                if source:
                    current_stateful_disk.source = source
                if mode:
                    current_stateful_disk.mode = instance_configs_messages.GetMode(
                        messages=messages, mode=mode)
                del update_stateful_disks_dict[
                    current_stateful_disk.deviceName]
            new_stateful_disks.append(current_stateful_disk)

        for update_stateful_disk in update_stateful_disks_dict.values():
            new_stateful_disks.append(
                instance_configs_messages.GetDiskOverride(
                    messages=messages,
                    stateful_disk=update_stateful_disk,
                    disk_getter=disk_getter))

        per_instance_config.override.disks = new_stateful_disks

        new_stateful_metadata = {
            metadata.key: metadata.value
            for metadata in per_instance_config.override.metadata
        }

        for stateful_metadata_key_to_remove in remove_stateful_metadata or []:
            if stateful_metadata_key_to_remove in new_stateful_metadata:
                del new_stateful_metadata[stateful_metadata_key_to_remove]
            else:
                raise exceptions.InvalidArgumentException(
                    parameter_name='--remove-stateful-metadata',
                    message=
                    ('stateful metadata key to remove `{0}` does not exist in'
                     ' the given instance config'.format(
                         stateful_metadata_key_to_remove)))

        new_stateful_metadata.update(update_stateful_metadata)

        per_instance_config.override.metadata = [
            messages.ManagedInstanceOverride.MetadataValueListEntry(
                key=metadata_key, value=metadata_value) for metadata_key,
            metadata_value in sorted(new_stateful_metadata.iteritems())
        ]

        return per_instance_config