Ejemplo n.º 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)
     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),
     )
Ejemplo n.º 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)
    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,
    )
Ejemplo n.º 3
0
    def CreateRequests(self, args):
        group_ref = self.CreateInstanceGroupReference(name=args.name,
                                                      region=args.region,
                                                      zone=args.zone)
        auto_healing_policies = (
            managed_instance_groups_utils.CreateAutohealingPolicies(
                self, args))

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

        return [(service, self.method, request)]
Ejemplo n.º 4
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),
   )
Ejemplo n.º 5
0
    def CreateRequests(self, args):
        """Creates and returns an instanceGroupManagers.Insert request.

    Args:
      args: the argparse arguments that this command was invoked with.

    Returns:
      request: a singleton list containing
               ComputeManagedInstanceGroupsInsertRequest message object.
    """
        instance_groups_flags.ValidateManagedInstanceGroupScopeArgs(
            args, self.resources)
        group_ref = self._CreateGroupReference(args)
        template_ref = self.resources.Parse(
            args.template, collection='compute.instanceTemplates')
        instance_group_manager = self._CreateInstanceGroupManager(
            args, group_ref, template_ref)
        instance_group_manager.autoHealingPolicies = (
            managed_instance_groups_utils.CreateAutohealingPolicies(
                self.resources, self.messages, args))
        instance_group_manager.distributionPolicy = self._CreateDistributionPolicy(
            args.zones)
        request = self.CreateResourceRequest(group_ref, instance_group_manager)
        service = self.GetServiceForGroup(group_ref)
        return [(service, self.method, request)]
Ejemplo n.º 6
0
    def CreateRequests(self, args):
        """Creates and returns an instanceGroupManagers.Insert request.

    Args:
      args: the argparse arguments that this command was invoked with.

    Returns:
      request: a singleton list containing
               ComputeManagedInstanceGroupsInsertRequest message object.
    """
        group_ref = self.CreateGroupReference(args)
        template_ref = self.resources.Parse(
            args.template,
            params={'project': properties.VALUES.core.project.GetOrFail},
            collection='compute.instanceTemplates')
        if args.target_pool:
            region = self.GetRegionForGroup(group_ref)
            pool_refs = [
                self.resources.Parse(
                    pool,
                    params={
                        'project': properties.VALUES.core.project.GetOrFail,
                        'region': region
                    },
                    collection='compute.targetPools')
                for pool in args.target_pool
            ]
            pools = [pool_ref.SelfLink() for pool_ref in pool_refs]
        else:
            pools = []

        name = group_ref.Name()
        if args.base_instance_name:
            base_instance_name = args.base_instance_name
        else:
            base_instance_name = name[0:54]

        instance_group_manager = self.messages.InstanceGroupManager(
            name=name,
            description=args.description,
            instanceTemplate=template_ref.SelfLink(),
            baseInstanceName=base_instance_name,
            targetPools=pools,
            targetSize=int(args.size))
        auto_healing_policies = (
            managed_instance_groups_utils.CreateAutohealingPolicies(
                self.resources, self.messages, args))
        if auto_healing_policies:
            instance_group_manager.autoHealingPolicies = auto_healing_policies

        request = self.CreateResourceRequest(group_ref, instance_group_manager)
        service = self.GetServiceForGroup(group_ref)
        return [(service, self.method, request)]
Ejemplo n.º 7
0
 def CreateRequests(self, args):
     ref = self.CreateZonalReference(args.name, args.zone)
     auto_healing_policies = (
         managed_instance_groups_utils.CreateAutohealingPolicies(
             self, args))
     request = (
         self.messages.
         ComputeInstanceGroupManagersSetAutoHealingPoliciesRequest(
             project=self.project,
             zone=ref.zone,
             instanceGroupManager=ref.Name(),
             instanceGroupManagersSetAutoHealingRequest=(
                 self.messages.InstanceGroupManagersSetAutoHealingRequest(
                     autoHealingPolicies=auto_healing_policies))))
     return [request]
 def _CreateInstanceGroupManager(self, args, group_ref, template_ref,
                                 client, holder):
     """Create parts of Instance Group Manager shared between tracks."""
     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(
                 holder.resources, client.messages, args)),
     )
Ejemplo n.º 9
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))
        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)])
    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
Ejemplo n.º 11
0
    def CreateRequests(self, args):
        """Creates and returns an instanceGroupManagers.Insert request.

    Args:
      args: the argparse arguments that this command was invoked with.

    Returns:
      request: a singleton list containing
               ComputeManagedInstanceGroupsInsertRequest message object.
    """
        group_ref = self.CreateZonalReference(args.name, args.zone)
        self.WarnForZonalCreation([group_ref])
        template_ref = self.CreateGlobalReference(
            args.template, resource_type='instanceTemplates')
        if args.target_pool:
            region = utils.ZoneNameToRegionName(group_ref.zone)
            pool_refs = self.CreateRegionalReferences(
                args.target_pool, region, resource_type='targetPools')
            pools = [pool_ref.SelfLink() for pool_ref in pool_refs]
        else:
            pools = []

        instance_group_manager = self.messages.InstanceGroupManager(
            name=group_ref.Name(),
            zone=group_ref.zone,
            baseInstanceName=args.base_instance_name,
            description=args.description,
            instanceTemplate=template_ref.SelfLink(),
            targetPools=pools,
            targetSize=int(args.size))
        auto_healing_policies = (
            managed_instance_groups_utils.CreateAutohealingPolicies(
                self, args))
        if auto_healing_policies:
            instance_group_manager.autoHealingPolicies = auto_healing_policies
        request = self.messages.ComputeInstanceGroupManagersInsertRequest(
            instanceGroupManager=instance_group_manager,
            project=self.project,
            zone=group_ref.zone)

        return [request]
Ejemplo n.º 12
0
  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)])
Ejemplo n.º 13
0
    def CreateRequests(self, args):
        igm_ref = (instance_groups_flags.MULTISCOPE_INSTANCE_GROUP_MANAGER_ARG.
                   ResolveAsResource)(
                       args,
                       self.resources,
                       default_scope=compute_scope.ScopeEnum.ZONE,
                       scope_lister=flags.GetDefaultScopeLister(
                           self.compute_client))
        auto_healing_policies = (
            managed_instance_groups_utils.CreateAutohealingPolicies(
                self.resources, self.messages, args))

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

        return [(service, self.method, request)]
Ejemplo n.º 14
0
    def Run(self, args):
        """Creates and issues an instanceGroupManagers.Insert request.

    Args:
      args: the argparse arguments that this command was invoked with.

    Returns:
      List containing one dictionary: resource augmented with 'autoscaled'
      property
    """
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client

        group_ref = self.CreateGroupReference(args, client, holder.resources)
        template_ref = holder.resources.Parse(
            args.template,
            params={'project': properties.VALUES.core.project.GetOrFail},
            collection='compute.instanceTemplates')
        if args.target_pool:
            region = self.GetRegionForGroup(group_ref)
            pool_refs = [
                holder.resources.Parse(
                    pool,
                    params={
                        'project': properties.VALUES.core.project.GetOrFail,
                        'region': region
                    },
                    collection='compute.targetPools')
                for pool in args.target_pool
            ]
            pools = [pool_ref.SelfLink() for pool_ref in pool_refs]
        else:
            pools = []

        name = group_ref.Name()
        if args.base_instance_name:
            base_instance_name = args.base_instance_name
        else:
            base_instance_name = name[0:54]

        instance_group_manager = client.messages.InstanceGroupManager(
            name=name,
            description=args.description,
            instanceTemplate=template_ref.SelfLink(),
            baseInstanceName=base_instance_name,
            targetPools=pools,
            targetSize=int(args.size))
        auto_healing_policies = (
            managed_instance_groups_utils.CreateAutohealingPolicies(
                holder.resources, client.messages, args))
        if auto_healing_policies:
            instance_group_manager.autoHealingPolicies = auto_healing_policies

        request = self.CreateResourceRequest(group_ref, instance_group_manager,
                                             client, holder.resources)
        service = self.GetServiceForGroup(group_ref, client.apitools_client)
        migs = client.MakeRequests([(service, 'Insert', request)])

        migs_as_dicts = [encoding.MessageToDict(m) for m in migs]
        _, augmented_migs = (
            managed_instance_groups_utils.AddAutoscaledPropertyToMigs(
                migs_as_dicts, client, holder.resources))
        return augmented_migs