Ejemplo n.º 1
0
def download_source_bundle(app_name, env_name):
    env = elasticbeanstalk.get_environment(app_name=app_name,
                                           env_name=env_name)
    if env.version_label and env.version_label != 'Sample Application':
        app_version = elasticbeanstalk.get_application_versions(
            app_name,
            version_labels=[env.version_label])['ApplicationVersions'][0]

        source_bundle = app_version['SourceBundle']
        bucket_name = source_bundle['S3Bucket']
        key_name = source_bundle['S3Key']
        io.echo('Downloading application version...')
        data = s3.get_object(bucket_name, key_name)
        filename = get_filename(key_name)
    else:
        # sample app
        template = cloudformation.get_template('awseb-' + env.id + '-stack')
        try:
            url = template['TemplateBody']['Parameters']['AppSource'][
                'Default']
        except KeyError:
            raise NotFoundError('Can not find app source for environment')
        utils.get_data_from_url(url)
        io.echo('Downloading application version...')
        data = utils.get_data_from_url(url, timeout=30)
        filename = 'sample.zip'

    fileoperations.make_eb_dir('downloads/')
    location = fileoperations.get_eb_file_full_location('downloads/' +
                                                        filename)
    fileoperations.write_to_data_file(location, data)
    io.echo('Application version downloaded to:', location)

    cwd = os.getcwd()
    try:
        fileoperations._traverse_to_project_root()
        if heuristics.directory_is_empty():
            # If we dont have any project code, unzip as current project
            io.echo('Unzipping application version as project files.')
            fileoperations.unzip_folder(location, os.getcwd())
            io.echo('Done.')
    finally:
        os.chdir(cwd)
Ejemplo n.º 2
0
def retrieve_application_version_url(env_name):
    """
    Method retrieves the URL of the application version of the environment, 'env_name',
    for the CLI to download from.

    The method waits for the CloudFormation stack associated with `env_name` to come
    into existence, after which, it retrieves the 'url' of the application version.

    :param env_name: Name of the environment that launched with the sample application
    :return: The URL of the application version.
    """
    env = elasticbeanstalk.get_environment(env_name=env_name)
    cloudformation_stack_name = 'awseb-' + env.id + '-stack'
    cloudformation.wait_until_stack_exists(cloudformation_stack_name)
    template = cloudformation.get_template(cloudformation_stack_name)

    url = None
    try:
        url = template['TemplateBody']['Parameters']['AppSource']['Default']
    except KeyError:
        io.log_warning('{}. '.format(strings['cloudformation.cannot_find_app_source_for_environment']))

    return url
Ejemplo n.º 3
0
def retrieve_application_version_url(env_name):
    """
    Method retrieves the URL of the application version of the environment, 'env_name',
    for the CLI to download from.

    The method waits for the CloudFormation stack associated with `env_name` to come
    into existence, after which, it retrieves the 'url' of the application version.

    :param env_name: Name of the environment that launched with the sample application
    :return: The URL of the application version.
    """
    env = elasticbeanstalk.get_environment(env_name=env_name)
    cloudformation_stack_name = 'awseb-' + env.id + '-stack'
    cloudformation.wait_until_stack_exists(cloudformation_stack_name)
    template = cloudformation.get_template(cloudformation_stack_name)

    url = None
    try:
        url = template['TemplateBody']['Parameters']['AppSource']['Default']
    except KeyError:
        io.log_warning('{}. '.format(strings['cloudformation.cannot_find_app_source_for_environment']))

    return url
    def test_get_template(self, make_api_call_mock):
        make_api_call_mock.return_value = mock_responses.GET_TEMPLATE_RESPONSE

        self.assertEqual(mock_responses.GET_TEMPLATE_RESPONSE,
                         cloudformation.get_template('mystackname'))