Esempio n. 1
0
    def Run(self, args):
        """Retrieves response with nodes in the node group."""
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client

        group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
            args,
            holder.resources,
            scope_lister=compute_flags.GetDefaultScopeLister(holder.client))

        request = client.messages.ComputeNodeGroupsListNodesRequest(
            nodeGroup=group_ref.Name(),
            zone=group_ref.zone,
            project=group_ref.project)

        errors = []
        results = list(
            request_helper.MakeRequests(requests=[
                (client.apitools_client.nodeGroups, 'ListNodes', request)
            ],
                                        http=client.apitools_client.http,
                                        batch_url=client.batch_url,
                                        errors=errors))

        if errors:
            utils.RaiseToolException(errors)

        return self.getItems(results)
Esempio n. 2
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client
        messages = holder.client.messages

        node_group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
            args,
            holder.resources,
            scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
        node_template_ref = util.ParseNodeTemplate(
            holder.resources,
            args.node_template,
            project=node_group_ref.project,
            region=compute_utils.ZoneNameToRegionName(node_group_ref.zone))

        node_group = messages.NodeGroup(
            name=node_group_ref.Name(),
            description=args.description,
            nodeTemplate=node_template_ref.SelfLink())
        request = messages.ComputeNodeGroupsInsertRequest(
            nodeGroup=node_group,
            initialNodeCount=args.target_size,
            project=node_group_ref.project,
            zone=node_group_ref.zone)

        service = holder.client.apitools_client.nodeGroups
        return client.MakeRequests([(service, 'Insert', request)])[0]
Esempio n. 3
0
 def Args(parser):
     flags.MakeNodeGroupArg().AddArgument(parser)
     flags.AddCreateArgsToParser(parser)
     flags.AddMaintenancePolicyArgToParser(parser)
     flags.AddAutoscalingPolicyArgToParser(parser, required_mode=True)
     flags.AddMaintenanceWindowArgToParser(parser)
     flags.AddLocationHintArgToParser(parser)
Esempio n. 4
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        messages = holder.client.messages
        groups_client = node_groups.NodeGroupsClient(
            holder.client.apitools_client, messages, holder.resources)

        node_group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
            args,
            holder.resources,
            scope_lister=compute_flags.GetDefaultScopeLister(holder.client))

        autoscaling_policy = (hasattr(args, 'autoscaler_mode') and args.IsSpecified('autoscaler_mode')) or \
                             (hasattr(args, 'min_nodes') and args.IsSpecified('min_nodes')) or \
                             (hasattr(args, 'max_nodes') and args.IsSpecified('max_nodes'))

        share_setting = hasattr(args, 'share_setting') and hasattr(
            args, 'share_with') and (args.IsSpecified('share_setting')
                                     or args.IsSpecified('share_with'))

        return groups_client.Update(
            node_group_ref,
            node_template=args.node_template,
            additional_node_count=args.add_nodes,
            delete_nodes=args.delete_nodes,
            autoscaling_policy_args=args if autoscaling_policy else None,
            share_setting_args=args if share_setting else None)
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        client = holder.client
        messages = holder.client.messages

        node_group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
            args,
            holder.resources,
            scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
        node_template_ref = util.ParseNodeTemplate(
            holder.resources,
            args.node_template,
            project=node_group_ref.project,
            region=compute_utils.ZoneNameToRegionName(node_group_ref.zone))

        node_group = messages.NodeGroup(
            name=node_group_ref.Name(),
            description=args.description,
            nodeTemplate=node_template_ref.SelfLink())

        if hasattr(args, 'maintenance_policy'):
            mapper = flags.GetMaintenancePolicyEnumMapper(messages)
            maintenance_policy = mapper.GetEnumForChoice(
                args.maintenance_policy)
            node_group.maintenancePolicy = maintenance_policy

        if hasattr(args, 'autoscaler_mode') and args.autoscaler_mode:
            if args.autoscaler_mode != 'off' and args.max_nodes is None:
                raise exceptions.RequiredArgumentException(
                    '--max-nodes', '--autoscaler-mode is on')
            autoscaling_policy = util.BuildAutoscaling(args, messages)
            node_group.autoscalingPolicy = autoscaling_policy

        if args.maintenance_window_start_time:
            node_group.maintenanceWindow = messages.NodeGroupMaintenanceWindow(
                startTime=args.maintenance_window_start_time)

        if hasattr(args, 'location_hint') and args.location_hint:
            node_group.locationHint = args.location_hint

        if hasattr(args, 'share_setting'):
            node_group.shareSettings = util.BuildShareSettings(messages, args)

        request = messages.ComputeNodeGroupsInsertRequest(
            nodeGroup=node_group,
            initialNodeCount=args.target_size,
            project=node_group_ref.project,
            zone=node_group_ref.zone)

        service = holder.client.apitools_client.nodeGroups
        return client.MakeRequests([(service, 'Insert', request)])[0]
Esempio n. 6
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        messages = holder.client.messages
        groups_client = node_groups.NodeGroupsClient(
            holder.client.apitools_client, messages, holder.resources)

        node_group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
            args,
            holder.resources,
            scope_lister=compute_flags.GetDefaultScopeLister(holder.client))

        return groups_client.Update(node_group_ref,
                                    node_template=args.node_template,
                                    additional_node_count=args.add_nodes,
                                    delete_node_indexes=args.delete_nodes)
Esempio n. 7
0
  def Run(self, args):
    holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    client = holder.client

    node_group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
        args, holder.resources,
        scope_lister=compute_flags.GetDefaultScopeLister(holder.client))

    messages = holder.client.messages
    request = messages.ComputeNodeGroupsGetRequest(
        nodeGroup=node_group_ref.Name(),
        project=node_group_ref.project,
        zone=node_group_ref.zone)

    service = holder.client.apitools_client.nodeGroups
    return client.MakeRequests([(service, 'Get', request)])[0]
Esempio n. 8
0
  def Run(self, args):
    holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    client = holder.client
    messages = holder.client.messages

    node_group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
        args, holder.resources,
        scope_lister=compute_flags.GetDefaultScopeLister(holder.client))
    node_template_ref = util.ParseNodeTemplate(
        holder.resources,
        args.node_template,
        project=node_group_ref.project,
        region=compute_utils.ZoneNameToRegionName(node_group_ref.zone))

    node_group = messages.NodeGroup(
        name=node_group_ref.Name(),
        description=args.description,
        nodeTemplate=node_template_ref.SelfLink())

    if hasattr(args, 'maintenance_policy'):
      mapper = flags.GetMaintenancePolicyEnumMapper(messages)
      maintenance_policy = mapper.GetEnumForChoice(args.maintenance_policy)
      node_group.maintenancePolicy = maintenance_policy

    if hasattr(args, 'autoscaling_policy') and args.autoscaling_policy:
      mapper = flags.GetAutoscalingModeEnumMapper(messages)
      mode = mapper.GetEnumForChoice(args.autoscaling_policy['mode'])
      autoscaling_policy = messages.NodeGroupAutoscalingPolicy(
          mode=mode,
          minSize=args.autoscaling_policy.get('min-size'),
          maxSize=args.autoscaling_policy.get('max-size'))
      node_group.autoscalingPolicy = autoscaling_policy

    request = messages.ComputeNodeGroupsInsertRequest(
        nodeGroup=node_group,
        initialNodeCount=args.target_size,
        project=node_group_ref.project,
        zone=node_group_ref.zone)

    service = holder.client.apitools_client.nodeGroups
    return client.MakeRequests([(service, 'Insert', request)])[0]
Esempio n. 9
0
  def Run(self, args):
    holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
    client = holder.client

    node_group_ref = flags.MakeNodeGroupArg().ResolveAsResource(
        args, holder.resources,
        scope_lister=compute_flags.GetDefaultScopeLister(holder.client))

    console_io.PromptContinue(
        'You are about to delete node group: [{}]'.format(
            node_group_ref.Name()),
        throw_if_unattended=True, cancel_on_no=True)

    messages = holder.client.messages
    request = messages.ComputeNodeGroupsDeleteRequest(
        nodeGroup=node_group_ref.Name(),
        project=node_group_ref.project,
        zone=node_group_ref.zone)

    service = holder.client.apitools_client.nodeGroups
    return client.MakeRequests([(service, 'Delete', request)])
Esempio n. 10
0
 def Args(parser):
     flags.MakeNodeGroupArg().AddArgument(parser)
Esempio n. 11
0
 def Args(parser):
     flags.MakeNodeGroupArg().AddArgument(parser)
     flags.AddUpdateArgsToParser(parser)
     flags.AddAutoscalingPolicyArgToParser(parser)
Esempio n. 12
0
 def Args(parser):
     flags.MakeNodeGroupArg().AddArgument(parser)
     flags.AddUpdateArgsToParser(parser)
Esempio n. 13
0
 def Args(parser):
     parser.display_info.AddFormat(
         'table(name, status, nodeType.basename(),'
         'instances.map().basename().list())')
     flags.MakeNodeGroupArg().AddArgument(parser)
Esempio n. 14
0
 def Args(parser):
     flags.MakeNodeGroupArg().AddArgument(parser)
     flags.AddCreateArgsToParser(parser)
     flags.AddAutoscalingPolicyArgToParser(parser, required_mode=True)
Esempio n. 15
0
 def Args(parser):
     flags.MakeNodeGroupArg().AddArgument(parser)
     flags.AddCreateArgsToParser(parser)
     flags.AddMaintenancePolicyArgToParser(parser)
     flags.AddAutoscalingPolicyArgToParser(parser)