Example #1
0
def update_environment_with_config_data(env_name, data,
                                        nohang, timeout=None):

    if fileoperations.env_yaml_exists():
        io.echo(strings['config.envyamlexists'])
    commonops.update_environment(env_name, None, nohang,
                                  timeout=timeout, template_body=data)
Example #2
0
def update_environment_with_config_data(env_name, data,
                                        nohang, timeout=None):

    if fileoperations.env_yaml_exists():
        io.echo(strings['config.envyamlexists'])
    commonops.update_environment(env_name, None, nohang,
                                  timeout=timeout, template_body=data)
Example #3
0
def enable_cloudwatch_logs(app_name, env_name, cloudwatch_log_source):
    """
    Enables CloudWatch log-streaming for the given environment if the required streaming of the
    specified `cloudwatch_log_source`s is not already enabled
    :param app_name: application name
    :param env_name: environment name
    :param cloudwatch_log_source: the source of logs. Defaults to 'instance' if value is 'None'.
        Use
            - 'instance' to enable instance log0streaming
            - 'health' to enable health transition log-streaming
            - 'all': enable streaming of all CloudWatch log sources
    :return None
    """
    cloudwatch_log_source = cloudwatch_log_source or logs_operations_constants.LOG_SOURCES.INSTANCE_LOG_SOURCE

    configuration_settings = elasticbeanstalk.describe_configuration_settings(
        app_name, env_name)
    option_settings = []
    timeout = 5

    if cloudwatch_log_source in [
            logs_operations_constants.LOG_SOURCES.ALL_LOG_SOURCES,
            logs_operations_constants.LOG_SOURCES.INSTANCE_LOG_SOURCE
    ]:
        if not instance_log_streaming_enabled(
                app_name, env_name, config_settings=configuration_settings):
            timeout = 15
            option_settings.append(_instance_log_streaming_option_setting())
            io.echo(strings['cloudwatch_instance_log_streaming.enable'])
        else:
            io.echo(
                strings['cloudwatch_instance_log_streaming.already_enabled'])

    if cloudwatch_log_source in [
            logs_operations_constants.LOG_SOURCES.ALL_LOG_SOURCES,
            logs_operations_constants.LOG_SOURCES.
            ENVIRONMENT_HEALTH_LOG_SOURCE,
    ]:
        _raise_if_environment_is_not_using_enhanced_health(
            configuration_settings)

        if not environment_health_streaming_enabled(
                app_name, env_name, config_settings=configuration_settings):
            option_settings.append(
                _environment_health_log_streaming_option_setting())
            io.echo(
                strings['cloudwatch_environment_health_log_streaming.enable'])
        else:
            io.echo(strings[
                'cloudwatch_environment_health_log_streaming.already_enabled'])

    if not option_settings:
        return

    _echo_link_to_cloudwatch_console(env_name)

    commonops.update_environment(env_name,
                                 changes=option_settings,
                                 nohang=False,
                                 timeout=timeout)
Example #4
0
def enable_cloudwatch_logs(env_name):
    # Add option settings needed for log streaming
    """
        Enables cloudwatch log streaming for the given environment
        :param env_name: environment name
    """
    option_settings = [
        elasticbeanstalk.create_option_setting(namespaces.CLOUDWATCH_LOGS,
                                               option_names.STREAM_LOGS,
                                               'true'),
    ]
    io.echo(strings['cloudwatch-logs.enable'])
    # echo link to cloudwatch console, BJS console link is different
    region = commonops.get_default_region()
    if region == 'cn-north-1':
        cw_link_regionalized = strings['cloudwatch-logs.bjslink']
    else:
        cw_link_regionalized = strings['cloudwatch-logs.link']
    io.echo(
        cw_link_regionalized.replace('{region}',
                                     region).replace('{env_name}', env_name))

    commonops.update_environment(env_name,
                                 changes=option_settings,
                                 nohang=False)
def do_upgrade(env_name,
               add_rolling,
               timeout,
               solution_stack_name,
               health_based=False,
               platform_arn=None):
    if add_rolling:
        if health_based:
            roll_type = 'Health'
        else:
            roll_type = 'Time'
        changes = [
            elasticbeanstalk.create_option_setting(
                namespaces.ROLLING_UPDATES,
                option_names.ROLLING_UPDATE_ENABLED, 'true'),
            elasticbeanstalk.create_option_setting(
                namespaces.ROLLING_UPDATES, option_names.ROLLING_UPDATE_TYPE,
                roll_type)
        ]
        io.log_warning(prompts['upgrade.applyrolling'].format(roll_type))
    else:
        changes = None

    if PlatformVersion.is_valid_arn(platform_arn):
        commonops.update_environment(env_name,
                                     changes,
                                     None,
                                     timeout=timeout,
                                     platform_arn=platform_arn)
    else:
        commonops.update_environment(env_name,
                                     changes,
                                     None,
                                     timeout=timeout,
                                     solution_stack_name=solution_stack_name)
Example #6
0
    def do_command(self):
        app_name = self.get_app_name()
        env_name = self.get_env_name(cmd_example='eb labs setup-ssl')
        certfile = self.app.pargs.cert_file
        privatekey = self.app.pargs.private_key
        certchain = self.app.pargs.cert_chain
        cert_name = self.app.pargs.name

        # Make sure arguments are valid
        if certfile or privatekey or certfile:
            if not (certfile and privatekey):
                raise InvalidOptionsError(
                    'When providing your own certificate the --cert-file '
                    'and --private-key options are both required.')
            _validate_files_exists(certfile, privatekey, certchain)

        if not cert_name:
            cert_name = env_name

        # Check environment is not single instance
        if _is_single_instance(app_name, env_name):
            raise NotSupportedError('This command is currently not supported '
                                    'for single instance environments. \n'
                                    'For more information please see '
                                    'http://docs.aws.amazon.com/elasticbeanstalk/'
                                    'latest/dg/SSL.SingleInstance.html')

        # Generate cert if not provided
        if not certfile:
            privatekey, certfile = generate_self_signed_cert(cert_name)

        certfile = fileoperations.read_from_text_file(certfile)
        privatekey = fileoperations.read_from_text_file(privatekey)
        if certchain:
            certchain = fileoperations.read_from_text_file(certchain)

        result = iam.upload_server_certificate(cert_name + '.crt', certfile,
                                               privatekey, chain=certchain)
        arn = result['Arn']

        # Update environment
        option_settings = [
            elasticbeanstalk.create_option_setting(
                namespaces.LOAD_BALANCER,
                option_names.LOAD_BALANCER_HTTP_PORT,
                'OFF'
            ),
            elasticbeanstalk.create_option_setting(
                namespaces.LOAD_BALANCER,
                option_names.LOAD_BALANCER_HTTPS_PORT,
                '443'
            ),
            elasticbeanstalk.create_option_setting(
                namespaces.LOAD_BALANCER,
                option_names.SSL_CERT_ID,
                arn
            ),
        ]
        commonops.update_environment(env_name, changes=option_settings,
                                     nohang=False)
Example #7
0
def disable_cloudwatch_logs(env_name):
    """
        Disables cloudwatch log streaming for the given environment
        :param env_name: environment name
    """
    # Add option settings needed for log streaming
    option_settings = [
        elasticbeanstalk.create_option_setting(
            namespaces.CLOUDWATCH_LOGS,
            option_names.STREAM_LOGS,
            'false'),
    ]
    io.echo(strings['cloudwatch-logs.disable'])
    commonops.update_environment(env_name, changes=option_settings, nohang=False)
Example #8
0
def setup_ssh(env_name, keyname, timeout=None):
    io.log_warning(prompts['ssh.setupwarn'].replace('{env-name}', env_name))

    keyname = prompt_for_ec2_keyname(env_name=env_name, keyname=keyname)

    if keyname:
        options = [{
            'Namespace': 'aws:autoscaling:launchconfiguration',
            'OptionName': 'EC2KeyName',
            'Value': keyname
        }]
        commonops.update_environment(env_name,
                                     options,
                                     False,
                                     timeout=timeout or 5)
Example #9
0
def enable_cloudwatch_logs(app_name, env_name, cloudwatch_log_source):
    """
    Enables CloudWatch log-streaming for the given environment if the required streaming of the
    specified `cloudwatch_log_source`s is not already enabled
    :param app_name: application name
    :param env_name: environment name
    :param cloudwatch_log_source: the source of logs. Defaults to 'instance' if value is 'None'.
        Use
            - 'instance' to enable instance log0streaming
            - 'health' to enable health transition log-streaming
            - 'all': enable streaming of all CloudWatch log sources
    :return None
    """
    cloudwatch_log_source = cloudwatch_log_source or logs_operations_constants.LOG_SOURCES.INSTANCE_LOG_SOURCE

    configuration_settings = elasticbeanstalk.describe_configuration_settings(app_name, env_name)
    option_settings = []
    timeout = 5

    if cloudwatch_log_source in [
        logs_operations_constants.LOG_SOURCES.ALL_LOG_SOURCES,
        logs_operations_constants.LOG_SOURCES.INSTANCE_LOG_SOURCE
    ]:
        if not instance_log_streaming_enabled(app_name, env_name, config_settings=configuration_settings):
            timeout = 15
            option_settings.append(_instance_log_streaming_option_setting())
            io.echo(strings['cloudwatch_instance_log_streaming.enable'])
        else:
            io.echo(strings['cloudwatch_instance_log_streaming.already_enabled'])

    if cloudwatch_log_source in [
        logs_operations_constants.LOG_SOURCES.ALL_LOG_SOURCES,
        logs_operations_constants.LOG_SOURCES.ENVIRONMENT_HEALTH_LOG_SOURCE,
    ]:
        _raise_if_environment_is_not_using_enhanced_health(configuration_settings)

        if not environment_health_streaming_enabled(app_name, env_name, config_settings=configuration_settings):
            option_settings.append(_environment_health_log_streaming_option_setting())
            io.echo(strings['cloudwatch_environment_health_log_streaming.enable'])
        else:
            io.echo(strings['cloudwatch_environment_health_log_streaming.already_enabled'])

    if not option_settings:
        return

    _echo_link_to_cloudwatch_console(env_name)

    commonops.update_environment(env_name, changes=option_settings, nohang=False, timeout=timeout)
Example #10
0
def update_environment_configuration(app_name, env_name, nohang, timeout=None):
    # get environment setting
    api_model = elasticbeanstalk.describe_configuration_settings(
        app_name, env_name)

    # Convert the raw api return to yaml format
    env_settings = EnvironmentSettings(api_model)
    usr_model = env_settings.convert_api_to_usr_model()

    # Save the yaml in a temp file
    file_location = fileoperations.save_env_file(usr_model)
    fileoperations.open_file_for_editing(file_location)

    platform_arn = None

    # Update and delete file
    try:
        usr_model = fileoperations.get_environment_from_file(env_name)
        changes, remove = env_settings.collect_changes(usr_model)
        if api_model['PlatformArn'] != usr_model['PlatformArn']:
            platform_arn = usr_model['PlatformArn']
        fileoperations.delete_env_file(env_name)
    except InvalidSyntaxError:
        io.log_error(prompts['update.invalidsyntax'])
        return

    if not changes and not remove and not platform_arn:
        # no changes made, exit
        io.log_warning('No changes made. Exiting.')
        return

    if fileoperations.env_yaml_exists():
        io.echo(strings['config.envyamlexists'])

    commonops.update_environment(env_name,
                                 changes,
                                 nohang,
                                 remove=remove,
                                 timeout=timeout,
                                 solution_stack_name=None,
                                 platform_arn=platform_arn)
Example #11
0
def update_environment_configuration(app_name, env_name, nohang,
                                     timeout=None):
    # get environment setting
    api_model = elasticbeanstalk.describe_configuration_settings(
        app_name, env_name
    )

    # Convert the raw api return to yaml format
    env_settings = EnvironmentSettings(api_model)
    usr_model = env_settings.convert_api_to_usr_model()

    # Save the yaml in a temp file
    file_location = fileoperations.save_env_file(usr_model)
    fileoperations.open_file_for_editing(file_location)

    platform_arn = None

    # Update and delete file
    try:
        usr_model = fileoperations.get_environment_from_file(env_name)
        changes, remove = env_settings.collect_changes(usr_model)
        if api_model['PlatformArn'] != usr_model['PlatformArn']:
            platform_arn = usr_model['PlatformArn']
        fileoperations.delete_env_file(env_name)
    except InvalidSyntaxError:
        io.log_error(prompts['update.invalidsyntax'])
        return

    if not changes and not remove and not platform_arn:
        # no changes made, exit
        io.log_warning('No changes made. Exiting.')
        return

    if fileoperations.env_yaml_exists():
        io.echo(strings['config.envyamlexists'])

    commonops.update_environment(env_name, changes, nohang,
                                 remove=remove, timeout=timeout,
                                 solution_stack_name=None,
                                 platform_arn=platform_arn)