def show_platform_events(follow, version):
    platform_name = fileoperations.get_platform_name()

    if version is None:
        version = fileoperations.get_platform_version()

        if version is None:
            raise InvalidPlatformVersionError(
                strings['exit.nosuchplatformversion'])

        platform = _get_platform(platform_name,
                                 version,
                                 owner=Constants.OWNED_BY_SELF)

        if platform is None:
            raise InvalidPlatformVersionError(
                strings['exit.nosuchplatformversion'])

        arn = platform['PlatformArn']
    else:
        arn = _version_to_arn(version)

    if arn is None:
        raise InvalidPlatformVersionError(
            strings['exit.nosuchplatformversion'])

    print_events(follow=follow, platform_arn=arn, app_name=None, env_name=None)
Beispiel #2
0
def get_version_status(version):
    platform_name = fileoperations.get_platform_name()

    if version is None:
        version = fileoperations.get_platform_version()

    if version is None:
        version = _get_latest_version(platform_name)
        fileoperations.update_platform_version(version)

    if version is None:
        raise InvalidPlatformVersionError(
            strings['exit.nosuchplatformversion'])

    arn = _version_to_arn(version)

    _, platform_name, platform_version = PlatformVersion.arn_to_platform(arn)

    platform = describe_custom_platform_version(
        platform_arn=arn,
        owner=Constants.OWNED_BY_SELF,
        platform_name=platform_name,
        platform_version=platform_version,
    )

    if not platform:
        raise InvalidPlatformVersionError(
            strings['exit.nosuchplatformversion'])

    created = platform.get('DateCreated')
    description = platform.get('Description')
    maintainer = platform.get('Maintainer')
    status = platform.get('PlatformStatus')
    updated = platform.get('DateUpdated')
    framework_name = platform.get('FrameworkName')
    framework_version = platform.get('FrameworkVersion')
    os_name = platform.get('OperatingSystemName')
    os_version = platform.get('OperatingSystemVersion')
    language_name = platform.get('ProgrammingLanguageName')
    language_version = platform.get('ProgrammingLanguageVersion')
    supported_tiers = platform.get('SupportedTierList')

    io.echo('Platform: ', arn)
    io.echo('Name: ', platform_name)
    io.echo('Version: ', version)
    io.echo('Maintainer: ', maintainer) if maintainer else None
    io.echo('Description: ', description) if description else None
    io.echo('Framework: ', framework_name) if framework_name else None
    io.echo('Framework: ', framework_name) if framework_name else None
    io.echo('Framework Version: ',
            framework_version) if framework_version else None
    io.echo('Operating System: ', os_name) if os_name else None
    io.echo('Operating System Version: ', os_version) if os_version else None
    io.echo('Programming Language: ', language_name) if language_name else None
    io.echo('Programming Language Version: ',
            language_version) if language_version else None
    io.echo('Supported Tiers: ', supported_tiers) if supported_tiers else None
    io.echo('Status: ', status)
    io.echo('Created: ', created)
    io.echo('Updated: ', updated)
def delete_platform_version(platform_version, force=False):
    arn = _version_to_arn(platform_version)

    if arn is None:
        raise InvalidPlatformVersionError(
            strings['exit.nosuchplatformversion'])

    if not force:
        io.echo(prompts['platformdelete.confirm'].replace(
            '{platform-arn}', arn))
        io.validate_action(prompts['platformdelete.validate'], arn)

    environments = []
    try:
        environments = [
            env for env in elasticbeanstalk.get_environments()
            if env.platform.version == arn
        ]
    except NotFoundError:
        pass

    if len(environments) > 0:
        _, platform_name, platform_version = PlatformVersion.arn_to_platform(
            arn)
        raise ValidationError(strings['platformdeletevalidation.error'].format(
            platform_name, platform_version,
            '\n '.join([env.name for env in environments])))

    response = elasticbeanstalk.delete_platform(arn)
    request_id = response['ResponseMetadata']['RequestId']
    timeout = 10

    commonops.wait_for_success_events(request_id,
                                      timeout_in_minutes=timeout,
                                      platform_arn=arn)
Beispiel #4
0
    def do_command(self):
        version = self.app.pargs.version
        stream = self.app.pargs.stream

        if version is None:
            platform_name = fileoperations.get_platform_name()
            version = fileoperations.get_platform_version()
        else:
            platform_name = fileoperations.get_platform_name()

            if VALID_PLATFORM_VERSION_FORMAT.match(version):
                pass
            elif PlatformVersion.is_valid_arn(version):
                _, platform_name, version = PlatformVersion.arn_to_platform(version)
            elif VALID_PLATFORM_SHORT_FORMAT.match(version):
                match = VALID_PLATFORM_SHORT_FORMAT.match(version)
                platform_name, version = match.group(1, 2)
            else:
                raise InvalidPlatformVersionError(strings['exit.invalidversion'])

        io.echo('Retrieving logs...')

        if stream:
            try:
                logsops.stream_platform_logs(
                    platform_name,
                    version,
                    log_name="%s/%s" % (platform_name, version),
                    formatter=platformops.PackerStreamFormatter())
            except NotFoundError:
                raise NotFoundError('Unable to find logs in CloudWatch.')
        else:
            paginate_cloudwatch_logs(platform_name, version)
Beispiel #5
0
 def do_command(self):
     try:
         platformops.get_version_status(self.app.pargs.version)
     except InvalidPlatformVersionError:
         if not self.app.pargs.version:
             io.log_error("This workspace is currently associated with a deleted version.")
         else:
             raise InvalidPlatformVersionError(strings['exit.nosuchplatformversion'])
Beispiel #6
0
def _name_to_arn(platform_name):
    arn = None
    if PlatformRegExpressions.VALID_PLATFORM_NAME_FORMAT.match(platform_name):
        arn = platform_version_ops.get_platform_arn(platform_name, "latest", owner=Constants.OWNED_BY_SELF)
    elif PlatformVersion.is_valid_arn(platform_name):
        arn = platform_name
    elif PlatformRegExpressions.VALID_PLATFORM_SHORT_FORMAT.match(platform_name):
        match = PlatformRegExpressions.VALID_PLATFORM_SHORT_FORMAT.match(platform_name)
        platform_name, platform_version = match.group(1, 2)
        arn = platform_version_ops.get_platform_arn(platform_name, platform_version, owner=Constants.OWNED_BY_SELF)

    if not arn:
        raise InvalidPlatformVersionError(strings['exit.nosuchplatform'])

    return arn
def version_to_arn(platform_version):
    platform_name = fileoperations.get_platform_name()

    arn = None
    if PlatformRegExpressions.VALID_PLATFORM_VERSION_FORMAT.match(platform_version):
        arn = get_platform_arn(platform_name, platform_version, owner=Constants.OWNED_BY_SELF)
    elif PlatformVersion.is_valid_arn(platform_version):
        arn = platform_version
    elif PlatformRegExpressions.VALID_PLATFORM_SHORT_FORMAT.match(platform_version):
        match = PlatformRegExpressions.VALID_PLATFORM_SHORT_FORMAT.match(platform_version)
        platform_name, platform_version = match.group(1, 2)
        arn = get_platform_arn(platform_name, platform_version, owner=Constants.OWNED_BY_SELF)

    if not arn:
        raise InvalidPlatformVersionError(strings['exit.nosuchplatformversion'])

    return arn
def _version_to_arn(platform_version):
    platform_name = fileoperations.get_platform_name()

    if VALID_PLATFORM_VERSION_FORMAT.match(platform_version):
        arn = _get_platform_arn(platform_name,
                                platform_version,
                                owner=Constants.OWNED_BY_SELF)
    elif PlatformVersion.is_valid_arn(platform_version):
        arn = platform_version
    elif VALID_PLATFORM_SHORT_FORMAT.match(platform_version):
        match = VALID_PLATFORM_SHORT_FORMAT.match(platform_version)
        platform_name, platform_version = match.group(1, 2)
        arn = _get_platform_arn(platform_name,
                                platform_version,
                                owner=Constants.OWNED_BY_SELF)
    else:
        raise InvalidPlatformVersionError(strings['exit.invalidversion'])

    return arn
Beispiel #9
0
def create_platform_version(version,
                            major_increment,
                            minor_increment,
                            patch_increment,
                            instance_type,
                            vpc=None,
                            staged=False,
                            timeout=None):

    platform_name = fileoperations.get_platform_name()
    instance_profile = fileoperations.get_instance_profile(None)
    key_name = commonops.get_default_keyname()

    if version is None:
        version = _get_latest_version(platform_name=platform_name,
                                      owner=Constants.OWNED_BY_SELF,
                                      ignored_states=[])

        if version is None:
            version = '1.0.0'
        else:
            major, minor, patch = version.split('.', 3)

            if major_increment:
                major = str(int(major) + 1)
                minor = '0'
                patch = '0'
            if minor_increment:
                minor = str(int(minor) + 1)
                patch = '0'
            if patch_increment or not (major_increment or minor_increment):
                patch = str(int(patch) + 1)

            version = "%s.%s.%s" % (major, minor, patch)

    if not VALID_PLATFORM_VERSION_FORMAT.match(version):
        raise InvalidPlatformVersionError(strings['exit.invalidversion'])

    cwd = os.getcwd()
    fileoperations._traverse_to_project_root()

    try:
        if heuristics.directory_is_empty():
            raise PlatformWorkspaceEmptyError(
                strings['exit.platformworkspaceempty'])
    finally:
        os.chdir(cwd)

    if not heuristics.has_platform_definition_file():
        raise PlatformWorkspaceEmptyError(strings['exit.no_pdf_file'])

    source_control = SourceControl.get_source_control()
    if source_control.untracked_changes_exist():
        io.log_warning(strings['sc.unstagedchanges'])

    version_label = source_control.get_version_label()
    if staged:
        # Make a unique version label
        timestamp = datetime.now().strftime("%y%m%d_%H%M%S")
        version_label = version_label + '-stage-' + timestamp

    file_descriptor, original_platform_yaml = tempfile.mkstemp()
    os.close(file_descriptor)

    copyfile('platform.yaml', original_platform_yaml)

    try:
        # Add option settings to platform.yaml
        _enable_healthd()

        s3_bucket, s3_key = get_app_version_s3_location(
            platform_name, version_label)

        # Create zip file if the application version doesn't exist
        if s3_bucket is None and s3_key is None:
            file_name, file_path = _zip_up_project(version_label,
                                                   source_control,
                                                   staged=staged)
        else:
            file_name = None
            file_path = None
    finally:
        # Restore original platform.yaml
        move(original_platform_yaml, 'platform.yaml')

    # Use existing bucket if it exists
    bucket = elasticbeanstalk.get_storage_location(
    ) if s3_bucket is None else s3_bucket

    # Use existing key if it exists
    key = platform_name + '/' + file_name if s3_key is None else s3_key

    try:
        s3.get_object_info(bucket, key)
        io.log_info('S3 Object already exists. Skipping upload.')
    except NotFoundError:
        io.log_info('Uploading archive to s3 location: ' + key)
        s3.upload_platform_version(bucket, key, file_path)

    # Just deletes the local zip
    fileoperations.delete_app_versions()
    io.log_info('Creating Platform Version ' + version_label)
    response = elasticbeanstalk.create_platform_version(
        platform_name, version, bucket, key, instance_profile, key_name,
        instance_type, vpc)

    # TODO: Enable this once the API returns the name of the environment associated with a
    # CreatePlatformRequest, and remove hard coded value. There is currently only one type
    # of platform builder, we may support additional builders in the future.
    #environment_name = response['PlatformSummary']['EnvironmentName']
    environment_name = 'eb-custom-platform-builder-packer'

    io.echo(
        colored(
            strings['platformbuildercreation.info'].format(environment_name),
            attrs=['reverse']))

    fileoperations.update_platform_version(version)
    commonops.set_environment_for_current_branch(environment_name)

    arn = response['PlatformSummary']['PlatformArn']
    request_id = response['ResponseMetadata']['RequestId']

    if not timeout:
        timeout = 30

    # Share streamer for platform events and builder events
    streamer = io.get_event_streamer()

    builder_events = threading.Thread(target=logsops.stream_platform_logs,
                                      args=(platform_name, version, streamer,
                                            5, None, PackerStreamFormatter()))
    builder_events.daemon = True

    # Watch events from builder logs
    builder_events.start()
    commonops.wait_for_success_events(request_id,
                                      platform_arn=arn,
                                      streamer=streamer,
                                      timeout_in_minutes=timeout)
def _raise_if_version_format_is_invalid(version):
    if not VALID_PLATFORM_VERSION_FORMAT.match(version):
        raise InvalidPlatformVersionError(strings['exit.invalidversion'])
def get_version_status(version):
    platform_name = fileoperations.get_platform_name()

    if version is None:
        version = fileoperations.get_platform_version()

    if version is None:
        version = _get_latest_version(platform_name)
        fileoperations.update_platform_version(version)

    if version is None:
        raise InvalidPlatformVersionError(
            strings['exit.nosuchplatformversion'])

    arn = _version_to_arn(version)

    if arn is None:
        raise InvalidPlatformVersionError(
            strings['exit.nosuchplatformversion'])

    _, platform_name, platform_version = PlatformVersion.arn_to_platform(arn)

    platform = _get_platform(platform_name,
                             platform_version,
                             owner=Constants.OWNED_BY_SELF)
    platform_status = elasticbeanstalk.list_platform_versions(
        platform_name=platform_name,
        platform_version=platform_version,
        owner=Constants.OWNED_BY_SELF)

    if platform is None:
        raise InvalidPlatformVersionError(
            strings['exit.nosuchplatformversion'])

    try:
        description = platform['Description']
    except KeyError:
        description = None

    status = platform['PlatformStatus']
    created = platform['DateCreated']
    updated = platform['DateUpdated']

    io.echo('Platform: ', arn)
    io.echo('Name: ', platform_name)
    io.echo('Version: ', version)

    # TODO: Cleanup this odd pattern used here.
    try:
        io.echo('Maintainer: ', platform['Maintainer'])
    except KeyError:
        pass

    if description:
        io.echo('Description: ', description)

    if platform_status:
        platform_status = platform_status[0]

        try:
            io.echo('Framework: ', platform_status['FrameworkName'])
        except KeyError:
            pass

        try:
            io.echo('Framework Version: ', platform_status['FrameworkVersion'])
        except KeyError:
            pass

        try:
            io.echo('Operating System: ',
                    platform_status['OperatingSystemName'])
        except KeyError:
            pass

        try:
            io.echo('Operating System Version: ',
                    platform_status['OperatingSystemVersion'])
        except KeyError:
            pass

        try:
            io.echo('Programming Language: ',
                    platform_status['ProgrammingLanguageName'])
        except KeyError:
            pass

        try:
            io.echo('Programming Language Version: ',
                    platform_status['ProgrammingLanguageVersion'])
        except KeyError:
            pass

        try:
            io.echo('Supported Tiers: ',
                    str.join(',', platform_status['SupportedTierList']))
        except KeyError:
            pass

    io.echo('Status: ', status)
    io.echo('Created: ', created)
    io.echo('Updated: ', updated)