def interactive_update_lifcycle_policy(app_name): # Get current application settings api_model = elasticbeanstalk.describe_application(app_name) # Convert into yaml format from raw API lifecycle_config = LifecycleConfiguration(api_model) usr_model = lifecycle_config.convert_api_to_usr_model() # Save yaml file into temp file file_location = fileoperations.save_app_file(usr_model) fileoperations.open_file_for_editing(file_location) # Update and delete file try: usr_model = fileoperations.get_application_from_file(app_name) config_changes = lifecycle_config.collect_changes(usr_model) fileoperations.delete_app_file(app_name) except InvalidSyntaxError: io.log_error(strings['lifecycle.invalidsyntax']) fileoperations.delete_app_file(app_name) return if not config_changes: # no changes made, exit io.log_warning(strings['lifecycle.updatenochanges']) return elasticbeanstalk.update_application_resource_lifecycle(app_name, config_changes) io.echo(strings['lifecycle.success'])
def interactive_update_lifcycle_policy(app_name): api_model = elasticbeanstalk.describe_application(app_name) lifecycle_config = LifecycleConfiguration(api_model) usr_model = lifecycle_config.convert_api_to_usr_model() file_location = fileoperations.save_app_file(usr_model) fileoperations.open_file_for_editing(file_location) try: usr_model = fileoperations.get_application_from_file(app_name) config_changes = lifecycle_config.collect_changes(usr_model) fileoperations.delete_app_file(app_name) except InvalidSyntaxError: io.log_error(strings['lifecycle.invalidsyntax']) fileoperations.delete_app_file(app_name) return if not config_changes: io.log_warning(strings['lifecycle.updatenochanges']) return elasticbeanstalk.update_application_resource_lifecycle( app_name, config_changes) io.echo(strings['lifecycle.success'])
def interactive_update_lifcycle_policy(app_name): # Get current application settings api_model = elasticbeanstalk.describe_application(app_name) # Convert into yaml format from raw API lifecycle_config = LifecycleConfiguration(api_model) usr_model = lifecycle_config.convert_api_to_usr_model() # Save yaml file into temp file file_location = fileoperations.save_app_file(usr_model) fileoperations.open_file_for_editing(file_location) # Update and delete file try: usr_model = fileoperations.get_application_from_file(app_name) config_changes = lifecycle_config.collect_changes(usr_model) fileoperations.delete_app_file(app_name) except InvalidSyntaxError: io.log_error(strings['lifecycle.invalidsyntax']) fileoperations.delete_app_file(app_name) return if not config_changes: # no changes made, exit io.log_warning(strings['lifecycle.updatenochanges']) return elasticbeanstalk.update_application_resource_lifecycle( app_name, config_changes) io.echo(strings['lifecycle.success'])
def test_open_file_for_editing__editor_could_not_open_file( self, log_error_mock, system_mock, get_editor_mock): file_to_open = 'config.yml' get_editor_mock.return_value = 'vim' system_mock.side_effect = OSError fileoperations.open_file_for_editing(file_to_open) log_error_mock.assert_called_with( 'EB CLI cannot open the file using the editor vim.')
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)
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)
def test_open_file_for_editing(self, system_mock, get_editor_mock): file_to_open = 'config.yml' get_editor_mock.return_value = 'vim' system_mock.side_effect = None fileoperations.open_file_for_editing(file_to_open)