Пример #1
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client

        managed_instance_groups_utils.ValidateAutoscalerArgs(args)

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

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

        # Require confirmation if autoscaling a GKE node group.
        self._PromptToAutoscaleGKENodeGroup(args)

        autoscaler_resource, is_new = self.CreateAutoscalerResource(
            client, holder.resources, igm_ref, args)

        autoscalers_client = autoscalers_api.GetClient(client, igm_ref)
        if is_new:
            managed_instance_groups_utils.AdjustAutoscalerNameForCreation(
                autoscaler_resource, igm_ref)
            return autoscalers_client.Insert(igm_ref, autoscaler_resource)
        return autoscalers_client.Update(igm_ref, autoscaler_resource)
Пример #2
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client
        managed_instance_groups_utils.ValidateAutoscalerArgs(args)
        managed_instance_groups_utils.ValidateStackdriverMetricsFlags(args)
        managed_instance_groups_utils.ValidateConflictsWithAutoscalingFile(
            args, (managed_instance_groups_utils.
                   ARGS_CONFLICTING_WITH_AUTOSCALING_FILE_ALPHA))
        igm_ref = self.CreateGroupReference(client, holder.resources, args)

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

        autoscaler_resource, is_new = self.CreateAutoscalerResource(
            client, holder.resources, igm_ref, args)

        managed_instance_groups_utils.ValidateGeneratedAutoscalerIsValid(
            args, autoscaler_resource)

        if args.IsSpecified('autoscaling_file'):
            if is_new:
                existing_autoscaler_name = None
            else:
                existing_autoscaler_name = autoscaler_resource.name
            return self._SetAutoscalerFromFile(args.autoscaling_file, client,
                                               igm_ref,
                                               existing_autoscaler_name)

        if is_new:
            managed_instance_groups_utils.AdjustAutoscalerNameForCreation(
                autoscaler_resource, igm_ref)
            return self._InsertAutoscaler(client, igm_ref, autoscaler_resource)
        return self._UpdateAutoscaler(client, igm_ref, autoscaler_resource)
Пример #3
0
    def CreateRequests(self, args):
        managed_instance_groups_utils.ValidateAutoscalerArgs(args)

        igm_ref = self.CreateGroupReference(args)
        service = self.GetAutoscalerServiceForGroup(igm_ref)

        managed_instance_groups_utils.AssertInstanceGroupManagerExists(
            igm_ref, self.project, self.compute, self.http, self.batch_url)

        autoscaler_resource, is_new = self.CreateAutoscalerResource(
            igm_ref, args)

        if is_new:
            method = 'Insert'
            request = service.GetRequestType(method)(project=self.project)
            managed_instance_groups_utils.AdjustAutoscalerNameForCreation(
                autoscaler_resource)
            request.autoscaler = autoscaler_resource
        else:
            method = 'Update'
            request = service.GetRequestType(method)(project=self.project)
            request.autoscaler = autoscaler_resource.name
            request.autoscalerResource = autoscaler_resource

        self.ScopeRequest(request, igm_ref)
        return ((service, method, request), )
Пример #4
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client

        managed_instance_groups_utils.ValidateAutoscalerArgs(args)

        igm_ref = self.CreateGroupReference(client, holder.resources, args)
        service = self.GetAutoscalerServiceForGroup(client, igm_ref)

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

        autoscaler_resource, is_new = self.CreateAutoscalerResource(
            client, holder.resources, igm_ref, args)

        if is_new:
            method = 'Insert'
            request = service.GetRequestType(method)(project=igm_ref.project)
            managed_instance_groups_utils.AdjustAutoscalerNameForCreation(
                autoscaler_resource)
            request.autoscaler = autoscaler_resource
        else:
            method = 'Update'
            request = service.GetRequestType(method)(project=igm_ref.project)
            request.autoscaler = autoscaler_resource.name
            request.autoscalerResource = autoscaler_resource

        self.ScopeRequest(request, igm_ref)
        return client.MakeRequests([(service, method, request)])
Пример #5
0
    def CreateRequests(self, args):
        managed_instance_groups_utils.ValidateAutoscalerArgs(args)

        igm_ref = self.CreateZonalReference(
            args.name, args.zone, resource_type='instanceGroupManagers')
        # We need the zone name, which might have been passed after prompting.
        # In that case, we get it from the reference.
        zone = args.zone or igm_ref.zone

        managed_instance_groups_utils.AssertInstanceGroupManagerExists(
            igm_ref, self.project, self.messages, self.compute, self.http,
            self.batch_url)

        autoscaler = managed_instance_groups_utils.AutoscalerForMig(
            mig_name=args.name,
            autoscalers=managed_instance_groups_utils.AutoscalersForZones(
                zones=[zone],
                project=self.project,
                compute=self.compute,
                http=self.http,
                batch_url=self.batch_url),
            zone=zone,
            project=self.project)
        autoscaler_name = getattr(autoscaler, 'name', None)
        as_ref = self.CreateZonalReference(autoscaler_name or args.name, zone)
        autoscaler_resource = managed_instance_groups_utils.BuildAutoscaler(
            args, self.messages, as_ref, igm_ref)

        if autoscaler_name is None:
            self._method = 'Insert'
            request = self.messages.ComputeAutoscalersInsertRequest(
                project=self.project)
            managed_instance_groups_utils.AdjustAutoscalerNameForCreation(
                autoscaler_resource)
            request.autoscaler = autoscaler_resource
        else:
            self._method = 'Update'
            request = self.messages.ComputeAutoscalersUpdateRequest(
                project=self.project)
            request.autoscaler = as_ref.Name()
            request.autoscalerResource = autoscaler_resource

        request.zone = as_ref.zone
        return (request, )
Пример #6
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client

        managed_instance_groups_utils.ValidateAutoscalerArgs(args)

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

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

        autoscaler_resource, is_new = self.CreateAutoscalerResource(
            client, holder.resources, igm_ref, args)

        if is_new:
            managed_instance_groups_utils.AdjustAutoscalerNameForCreation(
                autoscaler_resource, igm_ref)
            return self._InsertAutoscaler(client, igm_ref, autoscaler_resource)
        return self._UpdateAutoscaler(client, igm_ref, autoscaler_resource)