def test_arn_to_platform__raises_when_argument_is_not_arn_like(self): arn = 'node.js' with self.assertRaises( PlatformVersion.UnableToParseArnException) as context_manager: PlatformVersion.arn_to_platform(arn) self.assertEqual("Unable to parse arn 'node.js'", context_manager.exception.message)
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), # Packer is our only builder type at this point formatter=platformops.PackerStreamFormatter()) except NotFoundError: raise NotFoundError('Unable to find logs in CloudWatch.') else: # print with paginator paginate_cloudwatch_logs(platform_name, version)
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)
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 list_platform_versions_sorted_by_name(platform_name=None, status=None, owner=None, show_status=False, excludeEBOwned=True): platform_list = elasticbeanstalk.list_platform_versions( platform_name=platform_name, status=status, owner=owner) platform_tuples = list() platforms = list() arn_index = 0 status_index = 1 for platform in platform_list: arn = platform['PlatformArn'] owner = platform['PlatformOwner'] if excludeEBOwned and owner == Constants.AWS_ELASTIC_BEANSTALK_ACCOUNT: continue _, platform_name, _ = PlatformVersion.arn_to_platform(arn) platform_tuples.append((arn, platform['PlatformStatus'])) # Sort by name, then by version platform_tuples.sort(key=lambda platform: (PlatformVersion.get_platform_name(platform[arn_index]), Version(PlatformVersion.get_platform_version(platform[arn_index]))), reverse=True) for platform in platform_tuples: if show_status: platforms.append("%s Status: %s" % (platform[arn_index], platform[status_index])) else: platforms.append(platform[arn_index]) return platforms
def delete_platform_version(platform_version, force=False): arn = _version_to_arn(platform_version) 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)
def delete_platform_version(platform_version, force=False): arn = _version_to_arn(platform_version) 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)
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 get_latest_platform(platform_arn): account_id, platform_name, platform_version = PlatformVersion.arn_to_platform(platform_arn) platforms = elasticbeanstalk.list_platform_versions(platform_name, 'latest', 'Ready', account_id) if len(platforms) == 1: return PlatformVersion(platforms[0]['PlatformArn']) # The customer doesn't have access to the platform anymore? return PlatformVersion(platform_arn)
def get_latest_eb_managed_platform(platform_arn): account_id, platform_name, platform_version = PlatformVersion.arn_to_platform( platform_arn) if not account_id: matching_platforms = list_eb_managed_platform_versions( platform_name=platform_name, status='Ready') if matching_platforms: return PlatformVersion(matching_platforms[0])
def get_custom_platform(custom_platforms): accounts = dict() platform_names = [] for platform_arn in custom_platforms: account_id, platform_name, platform_version = PlatformVersion.arn_to_platform( platform_arn) try: platforms = accounts[account_id] except KeyError: platforms = dict() try: platform = platforms[platform_name] except KeyError: platform = dict() platform[platform_version] = platform_arn platforms[platform_name] = platform accounts[account_id] = platforms platform_names.append(platform_name) longest_platform_name = len(max(platform_names, key=len)) platforms = [] for account in accounts: for platform in accounts[account]: platforms.append("%-*s (Owned by: %s)" % (longest_platform_name, platform, account)) io.echo() io.echo(prompts['platform.prompt']) selected_platform = utils.prompt_for_item_in_list(platforms) option_pattern = re.compile('^(.+)\s+\(Owned by: (.+)\)$') match = option_pattern.match(selected_platform) selected_platform_name, selected_account = match.group(1, 2) selected_platform_name = selected_platform_name.strip() versions = [] for version in accounts[selected_account][selected_platform_name]: versions.append(version) if len(versions) > 1: versions.sort(key=lambda arn: Version(arn), reverse=True) io.echo() io.echo(prompts['sstack.version']) version = utils.prompt_for_item_in_list(versions) else: version = versions[0] return PlatformVersion( accounts[selected_account][selected_platform_name][version])
def get_latest_eb_managed_platform(platform_arn): account_id, platform_name, platform_version = PlatformVersion.arn_to_platform(platform_arn) if not account_id: matching_platforms = list_eb_managed_platform_versions( platform_name=platform_name, status='Ready' ) if matching_platforms: return PlatformVersion(matching_platforms[0])
def get_latest_custom_platform(platform): """ :param platform: A custom platform ARN or a custom platform name :return: A PlatformVersion object representing the latest version of `platform` """ account_id, platform_name, platform_version = PlatformVersion.arn_to_platform( platform) if account_id: matching_platforms = list_custom_platform_versions( platform_name=platform_name, status='Ready') if matching_platforms: return PlatformVersion(matching_platforms[0])
def get_platforms(platform_name=None, ignored_states=None, owner=None, platform_version=None): platform_list = list_custom_platform_versions( platform_name=platform_name, platform_version=platform_version ) platforms = dict() for platform in platform_list: if ignored_states and platform['PlatformStatus'] in ignored_states: continue _, platform_name, platform_version = PlatformVersion.arn_to_platform(platform) platforms[platform_name] = platform_version return platforms
def get_platforms(platform_name=None, ignored_states=None, owner=None, platform_version=None): platform_list = list_custom_platform_versions( platform_name=platform_name, platform_version=platform_version ) platforms = dict() for platform in platform_list: if ignored_states and platform['PlatformStatus'] in ignored_states: continue _, platform_name, platform_version = PlatformVersion.arn_to_platform(platform) platforms[platform_name] = platform_version return platforms
def set_platform(platform_name, platform_version=None, verify=True): if verify: arn = _name_to_arn(platform_name) _, platform_name, platform_version = PlatformVersion.arn_to_platform(arn) fileoperations.update_platform_name(platform_name) fileoperations.update_platform_version(platform_version) io.echo(strings['platformset.version']) try: get_version_status(platform_version) except InvalidPlatformVersionError: io.echo(strings['platformset.newplatform'] % platform_name)
def set_platform(platform_name, platform_version=None, verify=True): if verify: arn = _name_to_arn(platform_name) _, platform_name, platform_version = PlatformVersion.arn_to_platform(arn) fileoperations.update_platform_name(platform_name) fileoperations.update_platform_version(platform_version) io.echo(strings['platformset.version']) # This could fail if the customer elected to create a new platform try: get_version_status(platform_version) except InvalidPlatformVersionError: io.echo(strings['platformset.newplatform'] % platform_name)
def set_platform(platform_name, platform_version=None, verify=True): if verify: arn = _name_to_arn(platform_name) _, platform_name, platform_version = PlatformVersion.arn_to_platform( arn) fileoperations.update_platform_name(platform_name) fileoperations.update_platform_version(platform_version) io.echo(strings['platformset.version']) # This could fail if the customer elected to create a new platform try: get_version_status(platform_version) except InvalidPlatformVersionError: io.echo(strings['platformset.newplatform'] % platform_name)
def get_platforms(platform_name=None, ignored_states=None, owner=None, platform_version=None): platform_list = elasticbeanstalk.list_platform_versions( platform_name=platform_name, owner=owner, platform_version=platform_version) platforms = dict() for platform in platform_list: if ignored_states and platform['PlatformStatus'] in ignored_states: continue _, platform_name, platform_version = PlatformVersion.arn_to_platform( platform['PlatformArn']) platforms[platform_name] = platform_version return platforms
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)
def test_arn_to_platform__managed_platform_arn(self): arn = 'arn:aws:elasticbeanstalk:us-east-1::platform/Name/1.0.0' self.assertEqual(('', 'Name', '1.0.0'), PlatformVersion.arn_to_platform(arn))
def test_arn_to_platform__custom_platform_arn(self): arn = 'arn:aws:elasticbeanstalk:us-east-1:00000000000:platform/Name/0.0.0' self.assertEqual(('00000000000', 'Name', '0.0.0'), PlatformVersion.arn_to_platform(arn))