コード例 #1
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client
        igm_ref = instance_groups_flags.CreateGroupReference(
            client, holder.resources, args)

        # Assert that Instance Group Manager exists.
        mig_utils.GetInstanceGroupManagerOrThrow(igm_ref, client)

        old_autoscaler = mig_utils.AutoscalerForMigByRef(
            client, holder.resources, igm_ref)
        if mig_utils.IsAutoscalerNew(old_autoscaler):
            raise NoMatchingAutoscalerFoundError(
                'Instance group manager [{}] has no existing autoscaler; '
                'cannot update.'.format(igm_ref.Name()))

        autoscalers_client = autoscalers_api.GetClient(client, igm_ref)
        new_autoscaler = autoscalers_client.message_type(
            name=old_autoscaler.name,  # PATCH needs this
            autoscalingPolicy=client.messages.AutoscalingPolicy())
        if args.IsSpecified('mode'):
            mode = mig_utils.ParseModeString(args.mode, client.messages)
            new_autoscaler.autoscalingPolicy.mode = mode

        if self.scale_in:
            if args.IsSpecified('clear_scale_in_control'):
                new_autoscaler.autoscalingPolicy.scaleDownControl = None
            else:
                new_autoscaler.autoscalingPolicy.scaleDownControl = \
                  mig_utils.BuildScaleDown(args, client.messages)

        return self._SendPatchRequest(args, client, autoscalers_client,
                                      igm_ref, new_autoscaler)
コード例 #2
0
 def CreateAutoscalerResource(self, client, resources, igm_ref, args):
     autoscaler = managed_instance_groups_utils.AutoscalerForMigByRef(
         client, resources, igm_ref)
     autoscaler_name = getattr(autoscaler, 'name', None)
     new_one = autoscaler_name is None
     autoscaler_name = autoscaler_name or args.name
     autoscaler_resource = managed_instance_groups_utils.BuildAutoscaler(
         args, client.messages, igm_ref, autoscaler_name, autoscaler)
     return autoscaler_resource, new_one
コード例 #3
0
 def CreateAutoscalerResource(self, client, resources, igm_ref, args,
                              mode_enabled=False, scale_down=False):
   autoscaler = managed_instance_groups_utils.AutoscalerForMigByRef(
       client, resources, igm_ref)
   autoscaler_name = getattr(autoscaler, 'name', None)
   new_one = managed_instance_groups_utils.IsAutoscalerNew(autoscaler)
   autoscaler_name = autoscaler_name or args.name
   autoscaler_resource = managed_instance_groups_utils.BuildAutoscaler(
       args, client.messages, igm_ref, autoscaler_name, autoscaler,
       mode_enabled=mode_enabled, scale_down=scale_down)
   return autoscaler_resource, new_one
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client
        igm_ref = instance_groups_flags.CreateGroupReference(
            client, holder.resources, args)

        # Assert that Instance Group Manager exists.
        mig_utils.GetInstanceGroupManagerOrThrow(igm_ref, client)

        old_autoscaler = mig_utils.AutoscalerForMigByRef(
            client, holder.resources, igm_ref)
        if mig_utils.IsAutoscalerNew(old_autoscaler):
            raise NoMatchingAutoscalerFoundError(
                'Instance group manager [{}] has no existing autoscaler; '
                'cannot update.'.format(igm_ref.Name()))

        autoscalers_client = autoscalers_api.GetClient(client, igm_ref)
        new_autoscaler = autoscalers_client.message_type(
            name=old_autoscaler.name,  # PATCH needs this
            autoscalingPolicy=client.messages.AutoscalingPolicy())
        if args.IsSpecified('mode'):
            mode = mig_utils.ParseModeString(args.mode, client.messages)
            new_autoscaler.autoscalingPolicy.mode = mode

        if args.IsSpecified('clear_scale_in_control'):
            new_autoscaler.autoscalingPolicy.scaleInControl = None
        else:
            new_autoscaler.autoscalingPolicy.scaleInControl = \
              mig_utils.BuildScaleIn(args, client.messages)

        if self.clear_scale_down and args.IsSpecified(
                'clear_scale_down_control'):
            new_autoscaler.autoscalingPolicy.scaleDownControl = None

        if args.IsSpecified('cpu_utilization_predictive_method'):
            cpu_predictive_enum = client.messages.AutoscalingPolicyCpuUtilization.PredictiveMethodValueValuesEnum
            new_autoscaler.autoscalingPolicy.cpuUtilization = client.messages.AutoscalingPolicyCpuUtilization(
            )
            new_autoscaler.autoscalingPolicy.cpuUtilization.predictiveMethod = arg_utils.ChoiceToEnum(
                args.cpu_utilization_predictive_method, cpu_predictive_enum)

        scheduled = mig_utils.BuildSchedules(args, client.messages)
        if scheduled:
            new_autoscaler.autoscalingPolicy.scalingSchedules = scheduled

        if args.IsSpecified('min_num_replicas'):
            new_autoscaler.autoscalingPolicy.minNumReplicas = args.min_num_replicas
        if args.IsSpecified('max_num_replicas'):
            new_autoscaler.autoscalingPolicy.maxNumReplicas = args.max_num_replicas

        return self._SendPatchRequest(args, client, autoscalers_client,
                                      igm_ref, new_autoscaler)
コード例 #5
0
  def Run(self, args):
    holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    client = holder.client

    igm_ref = instance_groups_flags.CreateGroupReference(
        client, holder.resources, args)

    autoscaler = managed_instance_groups_utils.AutoscalerForMigByRef(
        client, holder.resources, igm_ref)
    if autoscaler:
      autoscaler_dict = encoding.MessageToDict(autoscaler)
      for f in _IGNORED_FIELDS:
        if f in autoscaler_dict:
          del autoscaler_dict[f]
    else:
      autoscaler_dict = None
    with open(args.autoscaling_file, 'w') as f:
      json.dump(autoscaler_dict, f)