Beispiel #1
0
  def _CreateInstanceGroupManager(self, args, group_ref, template_ref, client,
                                  holder):
    """Create parts of Instance Group Manager shared for the track."""
    instance_groups_flags.ValidateManagedInstanceGroupScopeArgs(
        args, holder.resources)
    health_check = managed_instance_groups_utils.GetHealthCheckUri(
        holder.resources, args)
    auto_healing_policies = (
        managed_instance_groups_utils.CreateAutohealingPolicies(
            client.messages, health_check, args.initial_delay))
    managed_instance_groups_utils.ValidateAutohealingPolicies(
        auto_healing_policies)
    instance_groups_flags.ValidateMigInstanceRedistributionTypeFlag(
        args.GetValue('instance_redistribution_type'), group_ref)
    update_policy = (managed_instance_groups_utils
                     .ApplyInstanceRedistributionTypeToUpdatePolicy)(
                         client, args.GetValue('instance_redistribution_type'),
                         None)

    return client.messages.InstanceGroupManager(
        name=group_ref.Name(),
        description=args.description,
        instanceTemplate=template_ref.SelfLink(),
        baseInstanceName=self._GetInstanceGroupManagerBaseInstanceName(
            args.base_instance_name, group_ref),
        targetPools=self._GetInstanceGroupManagerTargetPools(
            args.target_pool, group_ref, holder),
        targetSize=int(args.size),
        autoHealingPolicies=auto_healing_policies,
        distributionPolicy=self._CreateDistributionPolicy(
            args.zones, holder.resources, client.messages),
        updatePolicy=update_policy,
    )
Beispiel #2
0
 def _CreateInstanceGroupManager(self, args, group_ref, template_ref,
                                 client, holder):
     """Create parts of Instance Group Manager shared for the track."""
     instance_groups_flags.ValidateManagedInstanceGroupScopeArgs(
         args, holder.resources)
     instance_groups_flags.ValidateManagedInstanceGroupStatefulProperties(
         args)
     health_check = managed_instance_groups_utils.GetHealthCheckUri(
         holder.resources, args, self.HEALTH_CHECK_ARG)
     return client.messages.InstanceGroupManager(
         name=group_ref.Name(),
         description=args.description,
         instanceTemplate=template_ref.SelfLink(),
         baseInstanceName=self._GetInstanceGroupManagerBaseInstanceName(
             args.base_instance_name, group_ref),
         targetPools=self._GetInstanceGroupManagerTargetPools(
             args.target_pool, group_ref, holder),
         targetSize=int(args.size),
         autoHealingPolicies=(
             managed_instance_groups_utils.CreateAutohealingPolicies(
                 client.messages, health_check, args.initial_delay)),
         distributionPolicy=self._CreateDistributionPolicy(
             args.zones, holder.resources, client.messages),
         statefulPolicy=self._GetStatefulPolicy(args, client),
     )
Beispiel #3
0
 def _CreateInstanceGroupManager(
     self, args, group_ref, template_ref, client, holder):
   """Create parts of Instance Group Manager shared for the track."""
   if (group_ref.Collection() != 'compute.instanceGroupManagers' and
       args.IsSpecified('stateful_disks')):
     raise exceptions.BadArgumentException(
         '--stateful-disks',
         'Allowed only with zonal managed instance groups.')
   instance_groups_flags.ValidateManagedInstanceGroupScopeArgs(
       args, holder.resources)
   health_check = managed_instance_groups_utils.GetHealthCheckUri(
       holder.resources, args, self.HEALTH_CHECK_ARG)
   return client.messages.InstanceGroupManager(
       name=group_ref.Name(),
       description=args.description,
       instanceTemplate=template_ref.SelfLink(),
       baseInstanceName=self._GetInstanceGroupManagerBaseInstanceName(
           args.base_instance_name, group_ref),
       targetPools=self._GetInstanceGroupManagerTargetPools(
           args.target_pool, group_ref, holder),
       targetSize=int(args.size),
       autoHealingPolicies=(
           managed_instance_groups_utils.CreateAutohealingPolicies(
               client.messages, health_check, args.initial_delay)),
       distributionPolicy=self._CreateDistributionPolicy(
           args.zones, holder.resources, client.messages),
       statefulPolicy=self._GetStatefulPolicy(args.stateful_disks, client),
   )
Beispiel #4
0
 def _GetValidatedAutohealingPolicies(self, holder, client, args,
                                      igm_resource):
     health_check = managed_instance_groups_utils.GetHealthCheckUri(
         holder.resources, args)
     auto_healing_policies = (
         managed_instance_groups_utils.ModifyAutohealingPolicies(
             igm_resource.autoHealingPolicies, client.messages, args,
             health_check))
     managed_instance_groups_utils.ValidateAutohealingPolicies(
         auto_healing_policies)
     return auto_healing_policies
    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))
        health_check = managed_instance_groups_utils.GetHealthCheckUri(
            holder.resources, args, self.HEALTH_CHECK_ARG)
        auto_healing_policies = (
            managed_instance_groups_utils.CreateAutohealingPolicies(
                client.messages, health_check, args.initial_delay))

        managed_instance_groups_utils.ValidateAutohealingPolicies(
            auto_healing_policies)

        if igm_ref.Collection() == 'compute.instanceGroupManagers':
            service = client.apitools_client.instanceGroupManagers
            request = (
                client.messages.
                ComputeInstanceGroupManagersSetAutoHealingPoliciesRequest(
                    project=igm_ref.project,
                    zone=igm_ref.zone,
                    instanceGroupManager=igm_ref.Name(),
                    instanceGroupManagersSetAutoHealingRequest=(
                        client.messages.
                        InstanceGroupManagersSetAutoHealingRequest(
                            autoHealingPolicies=auto_healing_policies))))
        else:
            service = client.apitools_client.regionInstanceGroupManagers
            request = (
                client.messages.
                ComputeRegionInstanceGroupManagersSetAutoHealingPoliciesRequest(
                    project=igm_ref.project,
                    region=igm_ref.region,
                    instanceGroupManager=igm_ref.Name(),
                    regionInstanceGroupManagersSetAutoHealingRequest=(
                        client.messages.
                        RegionInstanceGroupManagersSetAutoHealingRequest(
                            autoHealingPolicies=auto_healing_policies))))

        return client.MakeRequests([(service, 'SetAutoHealingPolicies',
                                     request)])
Beispiel #6
0
 def _CreateInstanceGroupManager(self, args, group_ref, template_ref,
                                 client, holder):
     """Create parts of Instance Group Manager shared between tracks."""
     health_check = managed_instance_groups_utils.GetHealthCheckUri(
         holder.resources, args, self.HEALTH_CHECK_ARG)
     return client.messages.InstanceGroupManager(
         name=group_ref.Name(),
         description=args.description,
         instanceTemplate=template_ref.SelfLink(),
         baseInstanceName=self._GetInstanceGroupManagerBaseInstanceName(
             args.base_instance_name, group_ref),
         targetPools=self._GetInstanceGroupManagerTargetPools(
             args.target_pool, group_ref, holder),
         targetSize=int(args.size),
         autoHealingPolicies=(
             managed_instance_groups_utils.CreateAutohealingPolicies(
                 client.messages, health_check, args.initial_delay)),
     )
    def _CreateInstanceGroupManager(self, args, group_ref, template_ref,
                                    client, holder):
        """Create parts of Instance Group Manager shared for the track."""
        managed_flags.ValidateRegionalMigFlagsUsage(args, REGIONAL_FLAGS,
                                                    group_ref)
        instance_groups_flags.ValidateManagedInstanceGroupScopeArgs(
            args, holder.resources)
        health_check = managed_instance_groups_utils.GetHealthCheckUri(
            holder.resources, args)
        auto_healing_policies = (
            managed_instance_groups_utils.CreateAutohealingPolicies(
                client.messages, health_check, args.initial_delay))
        managed_instance_groups_utils.ValidateAutohealingPolicies(
            auto_healing_policies)
        update_policy = (managed_instance_groups_utils.
                         ApplyInstanceRedistributionTypeToUpdatePolicy)(
                             client,
                             args.GetValue('instance_redistribution_type'),
                             None)

        instance_group_manager = client.messages.InstanceGroupManager(
            name=group_ref.Name(),
            description=args.description,
            instanceTemplate=template_ref.SelfLink(),
            baseInstanceName=args.base_instance_name,
            targetPools=self._GetInstanceGroupManagerTargetPools(
                args.target_pool, group_ref, holder),
            targetSize=int(args.size),
            autoHealingPolicies=auto_healing_policies,
            distributionPolicy=self._CreateDistributionPolicy(
                args, holder.resources, client.messages),
            updatePolicy=update_policy,
        )

        self._HandleStatefulArgs(instance_group_manager, args, client)

        # Validate updatePolicy + statefulPolicy combination
        ValidateUpdatePolicyAgainstStateful(
            instance_group_manager.updatePolicy, group_ref,
            instance_group_manager.statefulPolicy, client)

        return instance_group_manager
  def Run(self, args):
    holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    client = holder.client
    messages = client.messages

    health_check = managed_instance_groups_utils.GetHealthCheckUri(
        holder.resources, args)
    auto_healing_policies = (
        managed_instance_groups_utils.CreateAutohealingPolicies(
            client.messages, health_check, args.initial_delay))

    managed_instance_groups_utils.ValidateAutohealingPolicies(
        auto_healing_policies)

    resource_arg = instance_groups_flags.MULTISCOPE_INSTANCE_GROUP_MANAGER_ARG
    default_scope = compute_scope.ScopeEnum.ZONE
    scope_lister = flags.GetDefaultScopeLister(client)
    igm_ref = resource_arg.ResolveAsResource(
        args,
        holder.resources,
        default_scope=default_scope,
        scope_lister=scope_lister)
    igm_resource = messages.InstanceGroupManager(
        autoHealingPolicies=auto_healing_policies)

    if igm_ref.Collection() == 'compute.instanceGroupManagers':
      service = client.apitools_client.instanceGroupManagers
      request_type = messages.ComputeInstanceGroupManagersPatchRequest
    elif igm_ref.Collection() == 'compute.regionInstanceGroupManagers':
      service = client.apitools_client.regionInstanceGroupManagers
      request_type = messages.ComputeRegionInstanceGroupManagersPatchRequest
    else:
      raise ValueError('Unknown reference type {0}'.format(
          igm_ref.Collection()))

    request = request_type(**igm_ref.AsDict())
    request.instanceGroupManagerResource = igm_resource

    return client.MakeRequests([(service, 'Patch', request)])