Exemplo n.º 1
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

        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]
    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]