Esempio n. 1
0
  def _PatchStatefulPolicy(self, igm_patch, args, igm_resource, client, holder):
    """Patch the stateful policy specified in args, to igm_patch."""
    # If we're potentially introducing statefulness to the MIG, we should
    # validate if this MIG is allowed to be stateful
    if self._StatefulnessIntroduced(args):
      managed_instance_groups_utils.ValidateIgmReadyForStatefulness(
          igm_resource, client)
    instance_groups_flags.ValidateUpdateStatefulPolicyParams(
        args, igm_resource.statefulPolicy)

    igm_patch.statefulPolicy = self._GetUpdatedStatefulPolicy(
        client, igm_resource.statefulPolicy, args.stateful_disk,
        args.remove_stateful_disks)
    return igm_patch
Esempio n. 2
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client
        igm_ref = (instance_groups_flags.MULTISCOPE_INSTANCE_GROUP_MANAGER_ARG.
                   ResolveAsResource)(
                       args,
                       holder.resources,
                       default_scope=compute_scope.ScopeEnum.ZONE,
                       scope_lister=flags.GetDefaultScopeLister(client))

        if igm_ref.Collection() not in [
                'compute.instanceGroupManagers',
                'compute.regionInstanceGroupManagers'
        ]:
            raise ValueError('Unknown reference type {0}'.format(
                igm_ref.Collection()))

        instance_groups_flags.ValidateMigInstanceRedistributionTypeFlag(
            args.GetValue('instance_redistribution_type'), igm_ref)

        igm_resource = managed_instance_groups_utils.GetInstanceGroupManagerOrThrow(
            igm_ref, client)
        if self._StatefulnessIntroduced(args):
            managed_instance_groups_utils.ValidateIgmReadyForStatefulness(
                igm_resource, client)

        device_names = instance_groups_flags.ValidateUpdateStatefulPolicyParams(
            args, igm_resource.statefulPolicy)

        update_policy = (managed_instance_groups_utils.
                         ApplyInstanceRedistributionTypeToUpdatePolicy)(
                             client,
                             args.GetValue('instance_redistribution_type'),
                             igm_resource.updatePolicy)

        auto_healing_policies = self._GetValidatedAutohealingPolicies(
            holder, client, args, igm_resource)

        if not self._StatefulArgsSet(args):
            igm_updated_resource = client.messages.InstanceGroupManager(
                updatePolicy=update_policy)
            if auto_healing_policies is not None:
                igm_updated_resource.autoHealingPolicies = auto_healing_policies
            return self._MakePatchRequest(client, igm_ref,
                                          igm_updated_resource)

        if not device_names:
            # TODO(b/70314588): Use Patch instead of manual Update.
            if igm_resource.statefulPolicy:
                igm_resource.statefulPolicy = self._UpdateStatefulPolicy(
                    client, igm_resource.statefulPolicy,
                    args.update_stateful_disk, args.remove_stateful_disks)
            igm_resource.updatePolicy = update_policy
            if auto_healing_policies is not None:
                igm_resource.autoHealingPolicies = auto_healing_policies
            return self._MakeUpdateRequest(client, igm_ref, igm_resource)

        stateful_policy = self._UpdateStatefulPolicy(
            client, igm_resource.statefulPolicy, args.update_stateful_disk,
            args.remove_stateful_disks)
        igm_updated_resource = client.messages.InstanceGroupManager(
            statefulPolicy=stateful_policy, updatePolicy=update_policy)
        if auto_healing_policies is not None:
            igm_updated_resource.autoHealingPolicies = auto_healing_policies

        return self._MakePatchRequest(client, igm_ref, igm_updated_resource)
 def _ValidateStatefulPolicyParams(self, args, stateful_policy):
     instance_groups_flags.ValidateUpdateStatefulPolicyParams(
         args, stateful_policy)