Private
Server IP : 195.201.23.43  /  Your IP : 3.145.85.212
Web Server : Apache
System : Linux webserver2.vercom.be 5.4.0-192-generic #212-Ubuntu SMP Fri Jul 5 09:47:39 UTC 2024 x86_64
User : kdecoratie ( 1041)
PHP Version : 7.1.33-63+ubuntu20.04.1+deb.sury.org+1
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/awscli/customizations/ec2/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /lib/python3/dist-packages/awscli/customizations/ec2/addcount.py
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
#     http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import logging

from botocore import model

from awscli.arguments import BaseCLIArgument


logger = logging.getLogger(__name__)


DEFAULT = 1
HELP = """
<p>Number of instances to launch. If a single number is provided, it
is assumed to be the minimum to launch (defaults to %d).  If a range is
provided in the form <code>min:max</code> then the first number is
interpreted as the minimum number of instances to launch and the second
is interpreted as the maximum number of instances to launch.</p>""" % DEFAULT


def register_count_events(event_handler):
    event_handler.register(
        'building-argument-table.ec2.run-instances', ec2_add_count)
    event_handler.register(
        'before-parameter-build.ec2.RunInstances', set_default_count)


def ec2_add_count(argument_table, **kwargs):
    argument_table['count'] = CountArgument('count')
    del argument_table['min-count']
    del argument_table['max-count']


def set_default_count(params, **kwargs):
    params.setdefault('MaxCount', DEFAULT)
    params.setdefault('MinCount', DEFAULT)


class CountArgument(BaseCLIArgument):

    def __init__(self, name):
        self.argument_model = model.Shape('CountArgument', {'type': 'string'})
        self._name = name
        self._required = False

    @property
    def cli_name(self):
        return '--' + self._name

    @property
    def cli_type_name(self):
        return 'string'

    @property
    def required(self):
        return self._required

    @required.setter
    def required(self, value):
        self._required = value

    @property
    def documentation(self):
        return HELP

    def add_to_parser(self, parser):
        # We do NOT set default value here. It will be set later by event hook.
        parser.add_argument(self.cli_name, metavar=self.py_name,
                            help='Number of instances to launch')

    def add_to_params(self, parameters, value):
        if value is None:
            # NO-OP if value is not explicitly set by user
            return
        try:
            if ':' in value:
                minstr, maxstr = value.split(':')
            else:
                minstr, maxstr = (value, value)
            parameters['MinCount'] = int(minstr)
            parameters['MaxCount'] = int(maxstr)
        except:
            msg = ('count parameter should be of '
                   'form min[:max] (e.g. 1 or 1:10)')
            raise ValueError(msg)
Private