def execute(self, parameter_pool): eb_client = ElasticBeanstalkClient(parameter_pool.get_value(ParameterName.AwsAccessKeyId), parameter_pool.get_value(ParameterName.AwsSecretAccessKey), parameter_pool.get_value(ParameterName.ServiceEndpoint)) prompt.action(ListSolutionStackOpMessage.Start) response = eb_client.list_available_solutionstacks() name_set = set() name_string = '\n\t' for stack in response.result: name_set.add(stack.solutionstack_name) name_string += stack.solutionstack_name + '\n\t' log.info('Available solution stacks: \n{0}'.format(name_string)) prompt.result(ListSolutionStackOpMessage.Result.format(name_string)) parameter_pool.put(Parameter(ParameterName.AvailableSolutionStacks, name_set, ParameterSource.OperationOutput)) ret_result = OperationResult(self, response.request_id, ListSolutionStackOpMessage.Result.format(name_string), response.result) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) app_name = parameter_pool.get_value(ParameterName.ApplicationName, False) prompt.action(DeleteApplicationOpMessage.Start.format(app_name)) try: response = eb_client.delete_application(app_name, u'true') except OperationInProgressException: log.info(u'Deleting Application "{0}" already in progress'.format( app_name)) prompt.result( DeleteApplicationOpMessage.AlreadyDelete.format(app_name)) ret_result = OperationResult( self, None, DeleteApplicationOpMessage.AlreadyDelete.format(app_name), None) else: log.info(u'Received response for DeleteApplication call.') self._log_api_result(self.__class__.__name__, u'DeleteApplication', response.result) prompt.result(DeleteApplicationOpMessage.Succeed.format(app_name)) ret_result = OperationResult( self, response.request_id, DeleteApplicationOpMessage.Succeed.format(app_name), response.result) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) app_name = parameter_pool.get_value(ParameterName.ApplicationName) try: response = eb_client.create_application(app_name) prompt.result(CreateApplicationOpMessage.Start.format(app_name)) except AlreadyExistException: log.info('Application "{0}" already exists.'.format(app_name)) prompt.result( CreateApplicationOpMessage.AlreadyExist.format(app_name)) ret_result = OperationResult( self, None, CreateApplicationOpMessage.AlreadyExist.format(app_name), None) else: log.info('Received response for CreateApplication call.') prompt.info(CreateApplicationOpMessage.Succeed.format(app_name)) self._log_api_result(self.__class__.__name__, 'CreateApplication', response.result) ret_result = OperationResult( self, response.request_id, CreateApplicationOpMessage.Succeed.format(app_name), response.result) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False) prompt.action(TerminateEnvironmentOpMessage.Start.format(env_name)) try: response = eb_client.terminate_environment(env_name) except: raise else: log.info(u'Received response for TerminateEnvironemnt call.') prompt.result( TerminateEnvironmentOpMessage.Succeed.format(env_name)) self._log_api_result(self.__class__.__name__, u'TerminateEnvironment', response.result) parameter_pool.put( Parameter(ParameterName.TerminateEnvironmentRequestID, response.request_id, ParameterSource.OperationOutput)) ret_result = OperationResult(self, response.request_id, TerminateEnvironmentOpMessage.Succeed, response.result) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) app_name = parameter_pool.get_value(ParameterName.ApplicationName, False) version_name = eb_utils.check_app_version(parameter_pool, eb_client) env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False) stack_name = parameter_pool.get_value(ParameterName.SolutionStack, False) tier = parameter_pool.get_value(ParameterName.EnvironmentTier, False) spec = TemplateSpecification() # Try load option setting file if exist option_location = parameter_pool.get_value(ParameterName.OptionSettingFile, False) option_settings = config_file.load_env_option_setting_file(option_location, quiet = True) if option_settings is not None and len(option_settings) > 0: prompt.info(CreateEnvironmentOpMessage.UsingOptionSetting.format(option_location)) else: option_settings = dict() option_remove = dict() # Process extensions first before we process options self._extension_handler(parameter_pool, spec, stack_name, option_settings, option_remove) # Process options self._option_setting_handler(parameter_pool, spec, stack_name, None, option_settings, option_remove) prompt.action(CreateEnvironmentOpMessage.Start.format(env_name)) try: response = eb_client.create_environment(application = app_name, environment = env_name, solution_stack = stack_name, version_label = version_name, option_settings = option_settings, option_remove = option_remove, template_specification = spec, tier = tier) except AlreadyExistException: log.info(u'Environment "{0}" already exist.'.format(env_name)) prompt.result(CreateEnvironmentOpMessage.AlreadyExist.format(env_name)) ret_result = OperationResult(self, None, CreateEnvironmentOpMessage.AlreadyExist.format(env_name), None) else: log.info(u'Received response for CreateEnvironemnt call.') prompt.info(CreateEnvironmentOpMessage.Succeed) prompt.result(CreateEnvironmentOpMessage.WaitAfterLaunch.format(env_name)) self._log_api_result(self.__class__.__name__, u'CreateEnvironment', response.result) parameter_pool.put(Parameter(ParameterName.CreateEnvironmentRequestID, response.request_id, ParameterSource.OperationOutput)) ret_result = OperationResult(self, response.request_id, CreateEnvironmentOpMessage.Succeed, response.result) return ret_result
def execute(self, parameter_pool): eb_client = ElasticBeanstalkClient( parameter_pool.get_value(ParameterName.AwsAccessKeyId), parameter_pool.get_value(ParameterName.AwsSecretAccessKey), parameter_pool.get_value(ParameterName.ServiceEndpoint), ) env_name = parameter_pool.get_value(ParameterName.EnvironmentName) prompt.action(TerminateEnvironmentOpMessage.Start.format(env_name)) try: response = eb_client.terminate_environment(env_name) except: raise else: log.info(u"Received response for TerminateEnvironemnt call.") prompt.result(TerminateEnvironmentOpMessage.Succeed.format(env_name)) self._log_api_result(self.__class__.__name__, u"TerminateEnvironment", response.result) parameter_pool.put( Parameter( ParameterName.TerminateEnvironmentRequestID, response.request_id, ParameterSource.OperationOutput ) ) ret_result = OperationResult( self, response.request_id, TerminateEnvironmentOpMessage.Succeed, response.result ) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) prompt.action(ListSolutionStackOpMessage.Start) response = eb_client.list_available_solutionstacks() name_set = set() name_string = u'\n\t' for stack in response.result: name_set.add(stack.solutionstack_name) name_string += stack.solutionstack_name + u'\n\t' log.info(u'Available solution stacks: \n{0}'.format(name_string)) prompt.result(ListSolutionStackOpMessage.Result.format(name_string)) parameter_pool.put(Parameter(ParameterName.AvailableSolutionStacks, name_set, ParameterSource.OperationOutput)) ret_result = OperationResult(self, response.request_id, ListSolutionStackOpMessage.Result.format(name_string), response.result) return ret_result
def execute(self, parameter_pool): eb_client = ElasticBeanstalkClient(parameter_pool.get_value(ParameterName.AwsAccessKeyId), parameter_pool.get_value(ParameterName.AwsSecretAccessKey), parameter_pool.get_value(ParameterName.ServiceEndpoint)) app_name = parameter_pool.get_value(ParameterName.ApplicationName) try: response = eb_client.create_application(app_name) prompt.result(CreateApplicationOpMessage.Start.format(app_name)) except AlreadyExistException: log.info('Application "{0}" already exists.'.format(app_name)) prompt.result(CreateApplicationOpMessage.AlreadyExist.format(app_name)) ret_result = OperationResult(self, None, CreateApplicationOpMessage.AlreadyExist.format(app_name), None) else: log.info('Received response for CreateApplication call.') prompt.info(CreateApplicationOpMessage.Succeed.format(app_name)) self._log_api_result(self.__class__.__name__, 'CreateApplication', response.result) ret_result = OperationResult(self, response.request_id, CreateApplicationOpMessage.Succeed.format(app_name), response.result) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) prompt.action(ListSolutionStackOpMessage.Start) response = eb_client.list_available_solutionstacks() name_set = set() name_string = '\n\t' for stack in response.result: name_set.add(stack.solutionstack_name) name_string += stack.solutionstack_name + '\n\t' log.info('Available solution stacks: \n{0}'.format(name_string)) prompt.result(ListSolutionStackOpMessage.Result.format(name_string)) parameter_pool.put(Parameter(ParameterName.AvailableSolutionStacks, name_set, ParameterSource.OperationOutput)) ret_result = OperationResult(self, response.request_id, ListSolutionStackOpMessage.Result.format(name_string), response.result) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) app_name = parameter_pool.get_value(ParameterName.ApplicationName, False) try: response = eb_client.create_application(app_name) prompt.result(CreateApplicationOpMessage.Start.format(app_name)) except AlreadyExistException: log.info(u'Application "{0}" already exists.'.format(app_name)) prompt.result(CreateApplicationOpMessage.AlreadyExist.format(app_name)) ret_result = OperationResult(self, None, CreateApplicationOpMessage.AlreadyExist.format(app_name), None) else: log.info(u'Received response for CreateApplication call.') prompt.info(CreateApplicationOpMessage.Succeed.format(app_name)) self._log_api_result(self.__class__.__name__, u'CreateApplication', response.result) ret_result = OperationResult(self, response.request_id, CreateApplicationOpMessage.Succeed.format(app_name), response.result) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) app_name = parameter_pool.get_value(ParameterName.ApplicationName, False) prompt.action(DeleteApplicationOpMessage.Start.format(app_name)) try: response = eb_client.delete_application(app_name, u'true') except OperationInProgressException: log.info(u'Deleting Application "{0}" already in progress'.format(app_name)) prompt.result(DeleteApplicationOpMessage.AlreadyDelete.format(app_name)) ret_result = OperationResult(self, None, DeleteApplicationOpMessage.AlreadyDelete.format(app_name), None) else: log.info(u'Received response for DeleteApplication call.') self._log_api_result(self.__class__.__name__, u'DeleteApplication', response.result) prompt.result(DeleteApplicationOpMessage.Succeed.format(app_name)) ret_result = OperationResult(self, response.request_id, DeleteApplicationOpMessage.Succeed.format(app_name), response.result) return ret_result
def ask_branch(cls, parameter_pool): current_branch = parameter_pool.get_value(ParameterName.CurrentBranch, False) prompt.result(TerminalPromptSettingParameterMessage[ParameterName.CurrentBranch]\ .format(current_branch)) previous_env_name = parameter_pool.get_value(ParameterName.EnvironmentName) print "The env name is %s \n" % previous_env_name #cls.ask_branch_environment_name(parameter_pool) # Ask whether copy from default def_env_name = parameter_pool.get_value(ParameterName.DefaultEnvironmentName, False) print "The Default env name is %s \n" % def_env_name #Added for eb branch automation param = Parameter("EnvironmentName", def_env_name, "Terminal") parameter_pool.put(param, True) #if previous_env_name is None: # if cls.ask_confirmation(TerminalMessage.CopyDefaultToBranch.format(def_env_name)): # return True #Copy from default # ## Ask for branch environment settings #cls.ask_environment_type(parameter_pool) #RdsTerminal.ask_rds_creation(parameter_pool) #IamTerminal.ask_profile_creation(parameter_pool) return False # Use user input
def execute(self, parameter_pool): command = parameter_pool.get_value(ParameterName.Command) if parameter_pool.has(ParameterName.ApplicationName)\ and parameter_pool.has(ParameterName.EnvironmentName): app_name = parameter_pool.get_value(ParameterName.ApplicationName) env_name = parameter_pool.get_value(ParameterName.EnvironmentName) policy = rds_utils.is_rds_delete_to_snapshot(parameter_pool, app_name, env_name) local_rds_switch = parameter_pool.get_value(ParameterName.RdsEnabled) if policy is not None and not RdsDefault.del_policy_to_bool(policy): if command == CommandType.UPDATE: if local_rds_switch: pass else: prompt.result(AskConfirmationOpMessage.CommandWarning[command]) else: prompt.result(AskConfirmationOpMessage.CommandWarning[command]) if (parameter_pool.has(ParameterName.Force) \ and parameter_pool.get_value(ParameterName.Force) == ServiceDefault.ENABLED) \ or TerminalBase.ask_confirmation(AskConfirmationOpMessage.CommandConfirmation[command]): ret_result = OperationResult(self, None, None, None) return ret_result else: log.info('User cancelled command.') raise EBSCliException()
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False) prompt.action(TerminateEnvironmentOpMessage.Start.format(env_name)) try: response = eb_client.terminate_environment(env_name) except: raise else: log.info("Received response for TerminateEnvironemnt call.") prompt.result(TerminateEnvironmentOpMessage.Succeed.format(env_name)) self._log_api_result(self.__class__.__name__, "TerminateEnvironment", response.result) parameter_pool.put( Parameter( ParameterName.TerminateEnvironmentRequestID, response.request_id, ParameterSource.OperationOutput ) ) ret_result = OperationResult( self, response.request_id, TerminateEnvironmentOpMessage.Succeed, response.result ) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) app_name = parameter_pool.get_value(ParameterName.ApplicationName, False) env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False) stack_name = parameter_pool.get_value(ParameterName.SolutionStack, False) prompt.action( UpdateEnvironmentOptionSettingOpMessage.Start.format(env_name)) spec = TemplateSpecification() # Try load option setting file if exist option_location = parameter_pool.get_value( ParameterName.OptionSettingFile, False) option_settings = config_file.load_env_option_setting_file( option_location, quiet=True) if option_settings is not None and len(option_settings) > 0: prompt.info( UpdateEnvironmentOptionSettingOpMessage.UsingOptionSetting. format(option_location)) else: option_settings = dict() option_remove = dict() self._option_setting_handler(parameter_pool, spec, stack_name, option_settings, option_remove) self._validate_change(parameter_pool, eb_client, app_name, env_name, option_settings, option_remove, spec) try: response = eb_client.update_environment( env_name, option_settings=option_settings, option_remove=option_remove, template_specification=spec) except: raise else: log.info(u'Received response for UpdateEnvironemnt call.') prompt.result( UpdateEnvironmentOptionSettingOpMessage.Succeed.format( env_name)) self._log_api_result(self.__class__.__name__, u'UpdateEnvironment', response.result) parameter_pool.put( Parameter(ParameterName.UpdateEnvironmentRequestID, response.request_id, ParameterSource.OperationOutput)) ret_result = OperationResult( self, response.request_id, UpdateEnvironmentOptionSettingOpMessage.Succeed.format( env_name), response.result) return ret_result
def apply_environment_type(parameter_pool, template_spec, stack_name, env_name, option_settings, option_to_remove): # If not specified, skip envtype = parameter_pool.get_value(PName.EnvironmentType) if envtype: # Describe applicable option settings eb_client = api_wrapper.create_eb_client(parameter_pool) app_name = parameter_pool.get_value(PName.ApplicationName, False) if env_name: raw_option_defs = api_wrapper.retrieve_configuration_options( eb_client=eb_client, app_name=app_name, env_name=env_name, template_specification=template_spec, options=None) else: raw_option_defs = api_wrapper.retrieve_configuration_options( eb_client=eb_client, app_name=app_name, solution_stack=stack_name, template_specification=template_spec, options=None) option_defs = set() for raw_option_def in raw_option_defs: option_defs.add(raw_option_def.namespace + u'-' + raw_option_def.name) # Return if environment type option is not available if OptionSettingEnvironmentType.Namespace + u'-' + \ OptionSettingEnvironmentType.OptionName not in option_defs: prompt.result( ValidationMessage.EnvTypeInapplicable.format(envtype)) return # remove inapplicable option settings removed = False for namespace in option_settings.keys(): # TODO Fix this temporary hack to let environment tier options pass through if namespace == u'aws:elasticbeanstalk:sqsd': continue for option_name in option_settings[namespace].keys(): if not is_customizable_namespace(namespace)\ and namespace + u'-' + option_name not in option_defs: remove_option_setting(option_settings, option_to_remove, namespace, option_name, False) removed = True if removed: prompt.result(ValidationMessage.EnvTypeBlowAwayOptionSettings) # Set environment type add_option_setting(option_settings, option_to_remove, OptionSettingEnvironmentType.Namespace, OptionSettingEnvironmentType.OptionName, envtype)
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) app_name = parameter_pool.get_value(ParameterName.ApplicationName, False) env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False) stack_name = parameter_pool.get_value(ParameterName.SolutionStack, False) prompt.action(UpdateEnvironmentOptionSettingOpMessage.Start.format(env_name)) tier = parameter_pool.get_value(ParameterName.EnvironmentTier, False) spec = TemplateSpecification() # Try load option setting file if exist option_location = parameter_pool.get_value(ParameterName.OptionSettingFile, False) option_settings = config_file.load_env_option_setting_file(option_location, quiet=True) if option_settings is not None and len(option_settings) > 0: prompt.info(UpdateEnvironmentOptionSettingOpMessage.UsingOptionSetting.format(option_location)) else: option_settings = dict() option_remove = dict() # Process extensions first before we process options self._extension_handler(parameter_pool, spec, stack_name, option_settings, option_remove) # Process options self._option_setting_handler(parameter_pool, spec, stack_name, env_name, option_settings, option_remove) self._validate_change(parameter_pool, eb_client, app_name, env_name, option_settings, option_remove, spec) try: response = eb_client.update_environment( env_name, option_settings=option_settings, option_remove=option_remove, template_specification=spec, tier=tier, ) except: raise else: log.info("Received response for UpdateEnvironemnt call.") prompt.result(UpdateEnvironmentOptionSettingOpMessage.Succeed.format(env_name)) self._log_api_result(self.__class__.__name__, "UpdateEnvironment", response.result) parameter_pool.put( Parameter( ParameterName.UpdateEnvironmentRequestID, response.request_id, ParameterSource.OperationOutput ) ) ret_result = OperationResult( self, response.request_id, UpdateEnvironmentOptionSettingOpMessage.Succeed.format(env_name), response.result, ) return ret_result
def execute(self, parameter_pool): eb_client = ElasticBeanstalkClient( parameter_pool.get_value(ParameterName.AwsAccessKeyId), parameter_pool.get_value(ParameterName.AwsSecretAccessKey), parameter_pool.get_value(ParameterName.ServiceEndpoint)) app_name = parameter_pool.get_value(ParameterName.ApplicationName) env_name = parameter_pool.get_value(ParameterName.EnvironmentName) stack_name = parameter_pool.get_value(ParameterName.SolutionStack) prompt.action( UpdateEnvironmentOptionSettingOpMessage.Start.format(env_name)) location = parameter_pool.get_value(ParameterName.OptionSettingFile) option_settings = config_file.load_env_option_setting_file(location, quiet=True) if option_settings is not None and len(option_settings) > 0: prompt.info( UpdateEnvironmentOptionSettingOpMessage.UsingOptionSetting. format(location)) else: option_settings = [] option_remove = set() spec = TemplateSpecification() rds_utils.rds_handler(parameter_pool, spec, stack_name, option_settings, option_remove) self._option_setting_handler(option_settings, option_remove) self._validate_change(parameter_pool, eb_client, app_name, env_name, option_settings, option_remove, spec) try: response = eb_client.update_environment( env_name, option_settings=option_settings, option_remove=option_remove, template_specification=spec) except: raise else: log.info('Received response for UpdateEnvironemnt call.') prompt.result( UpdateEnvironmentOptionSettingOpMessage.Succeed.format( env_name)) self._log_api_result(self.__class__.__name__, 'UpdateEnvironment', response.result) parameter_pool.put( Parameter(ParameterName.UpdateEnvironmentRequestID, response.request_id, ParameterSource.OperationOutput)) ret_result = OperationResult( self, response.request_id, UpdateEnvironmentOptionSettingOpMessage.Succeed.format( env_name), response.result) return ret_result
def execute(self, parameter_pool): eb_client = ElasticBeanstalkClient(parameter_pool.get_value(ParameterName.AwsAccessKeyId), parameter_pool.get_value(ParameterName.AwsSecretAccessKey), parameter_pool.get_value(ParameterName.ServiceEndpoint)) app_name = parameter_pool.get_value(ParameterName.ApplicationName) version_name = parameter_pool.get_value(ParameterName.ApplicationVersionName) env_name = parameter_pool.get_value(ParameterName.EnvironmentName) stack_name = parameter_pool.get_value(ParameterName.SolutionStack) # Try load option setting file if exist option_file_location = parameter_pool.get_value(ParameterName.OptionSettingFile) option_settings = config_file.load_env_option_setting_file(option_file_location, quiet = True) if option_settings is not None and len(option_settings) > 0: prompt.info(CreateEnvironmentOpMessage.UsingOptionSetting.format(option_file_location)) else: option_settings = [] option_remove = set() spec = TemplateSpecification() rds_utils.rds_handler(parameter_pool, spec, stack_name, option_settings, option_remove) self._option_setting_handler(option_settings, option_remove) prompt.action(CreateEnvironmentOpMessage.Start.format(env_name)) try: response = eb_client.create_environment(application = app_name, environment = env_name, solution_stack = stack_name, version_label = version_name, option_settings = option_settings, option_remove = option_remove, template_specification = spec, ) except AlreadyExistException: log.info(u'Environment "{0}" already exist.'.format(env_name)) prompt.result(CreateEnvironmentOpMessage.AlreadyExist.format(env_name)) ret_result = OperationResult(self, None, CreateEnvironmentOpMessage.AlreadyExist.format(env_name), None) else: log.info(u'Received response for CreateEnvironemnt call.') prompt.info(CreateEnvironmentOpMessage.Succeed) prompt.result(CreateEnvironmentOpMessage.WaitAfterLaunch.format(env_name)) self._log_api_result(self.__class__.__name__, u'CreateEnvironment', response.result) parameter_pool.put(Parameter(ParameterName.CreateEnvironmentRequestID, response.request_id, ParameterSource.OperationOutput)) ret_result = OperationResult(self, response.request_id, CreateEnvironmentOpMessage.Succeed, response.result) return ret_result
def execute(self, parameter_pool): func_matrix = [] # Loop over default settings for name, _, to_file in CredentialFileParameters: if not parameter_pool.has(name): continue elif ParameterSource.is_ahead(ParameterSource.Terminal,\ parameter_pool.get_source(name)): continue else: func_matrix.append((None, name, to_file)) # Loop over current branch settings cur_branch = parameter_pool.get_value(ParameterName.CurrentBranch)\ if parameter_pool.has(ParameterName.CurrentBranch) else None if cur_branch and ParameterSource.is_ahead( parameter_pool.get_source(ParameterName.Branches), ParameterSource.ConfigFile): branch_setting = parameter_pool.get_value( ParameterName.Branches)[cur_branch] for name, _, to_file in CredentialFileParameters: if not name in branch_setting: continue else: func_matrix.append((cur_branch, name, to_file)) if len(func_matrix) < 1: log.info( 'Skipped updating credential file as credentials are not changed.' ) return location = config_file.default_aws_credential_file_location() # Create directory if needed try: config_file.create_directory( config_file.default_aws_credential_file_path()) config_file.write_aws_credential_file(location, parameter_pool, func_matrix) except BaseException as ex: log.error('Encountered error when creating AWS Credential file at "{0}", because {1}.'.\ format(location, ex)) return else: log.info(WriteAwsCredentialFileOpMessage.Succeed.format(location)) prompt.result( WriteAwsCredentialFileOpMessage.Succeed.format(location)) parameter_pool.put( Parameter(ParameterName.AwsCredentialFile, location, ParameterSource.OperationOutput), True) ret_result = OperationResult(self, None, None, None) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False) wait_timeout = parameter_pool.get_value( ParameterName.WaitForUpdateTimeout, False) poll_delay = parameter_pool.get_value(ParameterName.PollDelay, False) info_request_id = parameter_pool.get_value( ParameterName.RequestEnvInfoRequestID) self._wait_for_env_operation_finish( eb_client=eb_client, env_name=env_name, original_request_id=info_request_id, pending_status=EnvironmentStatus.Updating, expected_health=None, operation_name=self.__class__.__name__, action_name=EnvRetrieveInfoOpMessage.Action, wait_timeout=wait_timeout, poll_delay=poll_delay, include_deleted=u'false', initial_delay=ServiceDefault.UPDATE_ENV_POLL_DELAY, quiet=False) # After polling _, subcommands = parameter_pool.command info_type = subcommands[0].lower( ) if len(subcommands) > 0 else EbDefault.TailLog response = eb_client.retrieve_environment_info(env_name, info_type=info_type) # Sort and find latest log for each instance instance_timestamps = dict() instance_logs = dict() for env_info in response.result: instance_id = env_info.ec2_instance_id timestamp = env_info.sample_timestamp url = env_info.message if not instance_timestamps.has_key(instance_id)\ or instance_timestamps[instance_id] < timestamp: instance_timestamps[instance_id] = timestamp instance_logs[instance_id] = url for instance_id in sorted(instance_logs.keys()): content = misc.to_unicode( requests.get(instance_logs[instance_id]).content) prompt.result(os.linesep + misc.to_terminal_codepage( EnvRetrieveInfoOpMessage.FileOuputPrefix.format(instance_id))) prompt.result(misc.to_terminal_codepage(content)) ret_result = OperationResult(self, None, None, None) return ret_result
def apply_environment_type(parameter_pool, template_spec, stack_name, env_name, option_settings, option_to_remove): # If not specified, skip envtype = parameter_pool.get_value(PName.EnvironmentType) if envtype: # Describe applicable option settings eb_client = api_wrapper.create_eb_client(parameter_pool) app_name = parameter_pool.get_value(PName.ApplicationName, False) if env_name: raw_option_defs = api_wrapper.retrieve_configuration_options(eb_client=eb_client, app_name=app_name, env_name=env_name, template_specification=template_spec, options=None) else: raw_option_defs = api_wrapper.retrieve_configuration_options(eb_client=eb_client, app_name=app_name, solution_stack=stack_name, template_specification=template_spec, options=None) option_defs = set() for raw_option_def in raw_option_defs: option_defs.add(raw_option_def.namespace + '-' + raw_option_def.name) # Return if environment type option is not available if OptionSettingEnvironmentType.Namespace + '-' + \ OptionSettingEnvironmentType.OptionName not in option_defs: prompt.result(ValidationMessage.EnvTypeInapplicable.format(envtype)) return # remove inapplicable option settings removed = False for namespace in list(option_settings.keys()): # TODO Fix this temporary hack to let environment tier options pass through if namespace == 'aws:elasticbeanstalk:sqsd': continue for option_name in list(option_settings[namespace].keys()): if not is_customizable_namespace(namespace)\ and namespace + '-' + option_name not in option_defs: remove_option_setting(option_settings, option_to_remove, namespace, option_name, False) removed = True if removed: prompt.result(ValidationMessage.EnvTypeBlowAwayOptionSettings) # Set environment type add_option_setting(option_settings, option_to_remove, OptionSettingEnvironmentType.Namespace, OptionSettingEnvironmentType.OptionName, envtype)
def execute(self, parameter_pool): func_matrix = [] # Loop over default settings for name, _, to_file in CredentialFileParameters: if not parameter_pool.has(name): continue elif ParameterSource.is_ahead(ParameterSource.Terminal, parameter_pool.get_source(name)): continue else: func_matrix.append((None, name, to_file)) # Loop over current branch settings cur_branch = ( parameter_pool.get_value(ParameterName.CurrentBranch) if parameter_pool.has(ParameterName.CurrentBranch) else None ) if cur_branch and ParameterSource.is_ahead( parameter_pool.get_source(ParameterName.Branches), ParameterSource.ConfigFile ): branch_setting = parameter_pool.get_value(ParameterName.Branches)[cur_branch] for name, _, to_file in CredentialFileParameters: if not name in branch_setting: continue else: func_matrix.append((cur_branch, name, to_file)) if len(func_matrix) < 1: log.info(u"Skipped updating credential file as credentials are not changed.") return location = config_file.default_aws_credential_file_location() # Create directory if needed try: config_file.create_directory(config_file.default_aws_credential_file_path()) config_file.write_aws_credential_file(location, parameter_pool, func_matrix) except BaseException as ex: log.error( u'Encountered error when creating AWS Credential file at "{0}", because {1}.'.format(location, ex) ) return else: log.info(WriteAwsCredentialFileOpMessage.Succeed.format(location)) prompt.result(WriteAwsCredentialFileOpMessage.Succeed.format(location)) parameter_pool.put( Parameter(ParameterName.AwsCredentialFile, location, ParameterSource.OperationOutput), True ) ret_result = OperationResult(self, None, None, None) return ret_result
def execute(self, parameter_pool): eb_client = ElasticBeanstalkClient( parameter_pool.get_value(ParameterName.AwsAccessKeyId), parameter_pool.get_value(ParameterName.AwsSecretAccessKey), parameter_pool.get_value(ParameterName.ServiceEndpoint)) env_name = parameter_pool.get_value(ParameterName.EnvironmentName) wait_timeout = parameter_pool.get_value( ParameterName.WaitForUpdateTimeout) poll_delay = parameter_pool.get_value(ParameterName.PollDelay) # update_request_id = parameter_pool.get_value(ParameterName.UpdateEnvironmentRequestID)\ # if parameter_pool.has(ParameterName.UpdateEnvironmentRequestID) else None result = self._wait_for_env_operation_finish( eb_client=eb_client, env_name=env_name, original_request_id=None, pending_status=EnvironmentStatus.Updating, expected_health=EnvironmentHealth.Green, operation_name=self.__class__.__name__, action_name=WaitForUpdateEnvOptionSettingFinishOpMessage.Action, wait_timeout=wait_timeout, poll_delay=poll_delay, include_deleted='false', initial_delay=ServiceDefault.UPDATE_ENV_POLL_DELAY) # After polling status = result[0].status health = result[0].health cname = result[0].cname log.info('Stopped polling. Environment "{0}" is now {1}, health is {2}.\nURL is "{3}".'.\ format(env_name, status, health, cname)) if status.lower() == EnvironmentStatus.Ready.lower() \ and health.lower() == EnvironmentHealth.Green.lower(): prompt.result( WaitForUpdateEnvOptionSettingFinishOpMessage.Succeed.format( env_name)) else: prompt.result( WaitForUpdateEnvOptionSettingFinishOpMessage.Timeout.format( env_name)) prompt.info(WaitForUpdateEnvOptionSettingFinishOpMessage.Result.\ format(cname, status, health)) ret_result = OperationResult(self, None, WaitForUpdateEnvOptionSettingFinishOpMessage.Result.\ format(cname, status, health), result) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False) wait_timeout = parameter_pool.get_value(ParameterName.WaitForUpdateTimeout, False) poll_delay = parameter_pool.get_value(ParameterName.PollDelay, False) info_request_id = parameter_pool.get_value(ParameterName.RequestEnvInfoRequestID) self._wait_for_env_operation_finish( eb_client = eb_client, env_name = env_name, original_request_id = info_request_id, pending_status = EnvironmentStatus.Updating, expected_health = None, operation_name = self.__class__.__name__, action_name = EnvRetrieveInfoOpMessage.Action, wait_timeout = wait_timeout, poll_delay = poll_delay, include_deleted = 'false', initial_delay = ServiceDefault.UPDATE_ENV_POLL_DELAY, quiet = False) # After polling _, subcommands = parameter_pool.command info_type = subcommands[0].lower() if len(subcommands) > 0 else EbDefault.TailLog response = eb_client.retrieve_environment_info(env_name, info_type=info_type) # Sort and find latest log for each instance instance_timestamps = dict() instance_logs = dict() for env_info in response.result: instance_id = env_info.ec2_instance_id timestamp = env_info.sample_timestamp url = env_info.message if instance_id not in instance_timestamps\ or instance_timestamps[instance_id] < timestamp: instance_timestamps[instance_id] = timestamp instance_logs[instance_id] = url for instance_id in sorted(instance_logs.keys()): content = misc.to_unicode(requests.get(instance_logs[instance_id]).content) prompt.result(os.linesep + misc.to_terminal_codepage(EnvRetrieveInfoOpMessage.FileOuputPrefix.format(instance_id))) prompt.result(misc.to_terminal_codepage(content)) ret_result = OperationResult(self, None, None, None) return ret_result
def execute(self, parameter_pool): eb_client = ElasticBeanstalkClient( parameter_pool.get_value(ParameterName.AwsAccessKeyId), parameter_pool.get_value(ParameterName.AwsSecretAccessKey), parameter_pool.get_value(ParameterName.ServiceEndpoint), ) env_name = parameter_pool.get_value(ParameterName.EnvironmentName) wait_timeout = parameter_pool.get_value(ParameterName.WaitForFinishTimeout) poll_delay = parameter_pool.get_value(ParameterName.PollDelay) create_request_id = ( parameter_pool.get_value(ParameterName.CreateEnvironmentRequestID) if parameter_pool.has(ParameterName.CreateEnvironmentRequestID) else None ) result = self._wait_for_env_operation_finish( eb_client=eb_client, env_name=env_name, original_request_id=create_request_id, pending_status=EnvironmentStatus.Launching, expected_health=None, operation_name=self.__class__.__name__, action_name=WaitForCreateEnvironmentFinishOpMessage.Action, wait_timeout=wait_timeout, poll_delay=poll_delay, include_deleted=u"false", initial_delay=0, ) # After polling status = result[0].status health = result[0].health cname = result[0].cname log.info( u'Stopped polling. Environment "{0}" is now {1}, health is {2}.\nURL is "{3}".'.format( env_name, status, health, cname ) ) if status.lower() == EnvironmentStatus.Ready.lower() and health.lower() == EnvironmentHealth.Green.lower(): prompt.info(WaitForCreateEnvironmentFinishOpMessage.Succeed.format(env_name)) prompt.result(WaitForCreateEnvironmentFinishOpMessage.Result.format(cname)) else: prompt.info(WaitForCreateEnvironmentFinishOpMessage.Timeout.format(env_name)) ret_result = OperationResult( self, None, WaitForCreateEnvironmentFinishOpMessage.Result.format(cname, status, health), result ) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False) wait_timeout = parameter_pool.get_value( ParameterName.WaitForFinishTimeout, False) poll_delay = parameter_pool.get_value(ParameterName.PollDelay, False) create_request_id = parameter_pool.get_value( ParameterName.CreateEnvironmentRequestID) result = self._wait_for_env_operation_finish( eb_client=eb_client, env_name=env_name, original_request_id=create_request_id, pending_status=EnvironmentStatus.Launching, expected_health=None, operation_name=self.__class__.__name__, action_name=WaitForCreateEnvironmentFinishOpMessage.Action, wait_timeout=wait_timeout, poll_delay=poll_delay, include_deleted=u'false', initial_delay=0) # After polling status = result[0].status health = result[0].health cname = result[0].cname log.info(u'Stopped polling. Environment "{0}" is now {1}, health is {2}.\nURL is "{3}".'.\ format(env_name, status, health, cname)) if status.lower() == EnvironmentStatus.Ready.lower() \ and health.lower() == EnvironmentHealth.Green.lower(): prompt.info( WaitForCreateEnvironmentFinishOpMessage.Succeed.format( env_name)) prompt.result( WaitForCreateEnvironmentFinishOpMessage.Result.format(cname)) else: prompt.info( WaitForCreateEnvironmentFinishOpMessage.Timeout.format( env_name)) ret_result = OperationResult(self, None, WaitForCreateEnvironmentFinishOpMessage.Result.\ format(cname, status, health), result) return ret_result
def execute(self, parameter_pool): eb_client = ElasticBeanstalkClient( parameter_pool.get_value(ParameterName.AwsAccessKeyId), parameter_pool.get_value(ParameterName.AwsSecretAccessKey), parameter_pool.get_value(ParameterName.ServiceEndpoint), ) app_name = parameter_pool.get_value(ParameterName.ApplicationName) env_name = parameter_pool.get_value(ParameterName.EnvironmentName) stack_name = parameter_pool.get_value(ParameterName.SolutionStack) prompt.action(UpdateEnvironmentOptionSettingOpMessage.Start.format(env_name)) location = parameter_pool.get_value(ParameterName.OptionSettingFile) option_settings = config_file.load_env_option_setting_file(location, quiet=True) if option_settings is not None and len(option_settings) > 0: prompt.info(UpdateEnvironmentOptionSettingOpMessage.UsingOptionSetting.format(location)) else: option_settings = [] option_remove = set() spec = rds_utils.rds_handler(parameter_pool, stack_name, option_settings, option_remove) self._validate_change(parameter_pool, eb_client, app_name, env_name, option_settings, option_remove, spec) try: response = eb_client.update_environment( env_name, option_settings=option_settings, option_remove=option_remove, template_specification=spec ) except: raise else: log.info(u"Received response for UpdateEnvironemnt call.") prompt.result(UpdateEnvironmentOptionSettingOpMessage.Succeed.format(env_name)) self._log_api_result(self.__class__.__name__, u"UpdateEnvironment", response.result) parameter_pool.put( Parameter( ParameterName.UpdateEnvironmentRequestID, response.request_id, ParameterSource.OperationOutput ) ) ret_result = OperationResult( self, response.request_id, UpdateEnvironmentOptionSettingOpMessage.Succeed.format(env_name), response.result, ) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) env_name = parameter_pool.get_value(ParameterName.EnvironmentName) wait_timeout = parameter_pool.get_value(ParameterName.WaitForUpdateTimeout) poll_delay = parameter_pool.get_value(ParameterName.PollDelay) # update_request_id = parameter_pool.get_value(ParameterName.UpdateEnvironmentRequestID)\ # if parameter_pool.has(ParameterName.UpdateEnvironmentRequestID) else None result = self._wait_for_env_operation_finish( eb_client = eb_client, env_name = env_name, original_request_id = None, pending_status = EnvironmentStatus.Updating, expected_health = EnvironmentHealth.Green, operation_name = self.__class__.__name__, action_name = WaitForUpdateEnvOptionSettingFinishOpMessage.Action, wait_timeout = wait_timeout, poll_delay = poll_delay, include_deleted = 'false', initial_delay = ServiceDefault.UPDATE_ENV_POLL_DELAY) # After polling status = result[0].status health = result[0].health cname = result[0].cname log.info('Stopped polling. Environment "{0}" is now {1}, health is {2}.\nURL is "{3}".'.\ format(env_name, status, health, cname)) if status.lower() == EnvironmentStatus.Ready.lower() \ and health.lower() == EnvironmentHealth.Green.lower(): prompt.result(WaitForUpdateEnvOptionSettingFinishOpMessage.Succeed.format(env_name)) else: prompt.result(WaitForUpdateEnvOptionSettingFinishOpMessage.Timeout.format(env_name)) prompt.info(WaitForUpdateEnvOptionSettingFinishOpMessage.Result.\ format(cname, status, health)) ret_result = OperationResult(self, None, WaitForUpdateEnvOptionSettingFinishOpMessage.Result.\ format(cname, status, health), result) return ret_result
def _probe_rds_change(self, parameter_pool, command): if parameter_pool.has(PName.ApplicationName)\ and parameter_pool.has(PName.EnvironmentName): app_name = parameter_pool.get_value(PName.ApplicationName, False) env_name = parameter_pool.get_value(PName.EnvironmentName, False) policy = rds_utils.is_rds_delete_to_snapshot(parameter_pool, app_name, env_name) local_rds_switch = parameter_pool.get_value(PName.RdsEnabled, False) if policy is not None and not RdsDefault.del_policy_to_bool(policy): if command == CommandType.UPDATE: if local_rds_switch: pass else: prompt.result(AskConfirmationOpMessage.CommandWarning[command]) else: prompt.result(AskConfirmationOpMessage.CommandWarning[command])
def _probe_rds_change(self, parameter_pool, command): if parameter_pool.has(ParameterName.ApplicationName)\ and parameter_pool.has(ParameterName.EnvironmentName): app_name = parameter_pool.get_value(ParameterName.ApplicationName) env_name = parameter_pool.get_value(ParameterName.EnvironmentName) policy = rds_utils.is_rds_delete_to_snapshot(parameter_pool, app_name, env_name) local_rds_switch = parameter_pool.get_value(ParameterName.RdsEnabled) if policy is not None and not RdsDefault.del_policy_to_bool(policy): if command == CommandType.UPDATE: if local_rds_switch: pass else: prompt.result(AskConfirmationOpMessage.CommandWarning[command]) else: prompt.result(AskConfirmationOpMessage.CommandWarning[command])
def ask_branch(cls, parameter_pool): current_branch = parameter_pool.get_value(ParameterName.CurrentBranch) prompt.result(TerminalPromptSettingParameterMessage[ParameterName.CurrentBranch]\ .format(current_branch)) previous_env_name = parameter_pool.get_value(ParameterName.EnvironmentName)\ if parameter_pool.has(ParameterName.EnvironmentName) else None cls.ask_branch_environment_name(parameter_pool) # Ask whether copy from default def_env_name = parameter_pool.get_value(ParameterName.DefaultEnvironmentName) if previous_env_name is None: if cls.ask_confirmation(TerminalMessage.CopyDefaultToBranch.format(def_env_name)): return True #Copy from default # Ask for branch environment settings RdsTerminal.ask_rds_creation(parameter_pool) return False # Use user input
def ask_branch(cls, parameter_pool): current_branch = parameter_pool.get_value(ParameterName.CurrentBranch, False) prompt.result(TerminalPromptSettingParameterMessage[ParameterName.CurrentBranch]\ .format(current_branch)) previous_env_name = parameter_pool.get_value(ParameterName.EnvironmentName) cls.ask_branch_environment_name(parameter_pool) # Ask whether copy from default def_env_name = parameter_pool.get_value(ParameterName.DefaultEnvironmentName, False) if previous_env_name is None: if cls.ask_confirmation(TerminalMessage.CopyDefaultToBranch.format(def_env_name)): return True #Copy from default # Ask for branch environment settings cls.ask_environment_type(parameter_pool) RdsTerminal.ask_rds_creation(parameter_pool) IamTerminal.ask_profile_creation(parameter_pool) return False # Use user input
def execute(self, parameter_pool): func_matrix = [] for param in CredentialFileParameters: if not parameter_pool.has(param[0]): continue elif ParameterSource.is_ahead(ParameterSource.Terminal,\ parameter_pool.get_source(param[0])): continue else: func_matrix.append((param[0], param[2])) if len(func_matrix) < 1: log.info( 'Skipped updating credential file as credentials are not changed.' ) return location = config_file.default_aws_credential_file_location() # Create directory if needed try: config_file.create_directory( config_file.default_aws_credential_file_path()) config_file.write_aws_credential_file(location, parameter_pool, func_matrix) except BaseException as ex: log.error('Encountered error when creating AWS Credential file at "{0}", because {1}.'.\ format(location, ex)) return else: log.info(WriteAwsCredentialFileOpMessage.Succeed.format(location)) prompt.result( WriteAwsCredentialFileOpMessage.Succeed.format(location)) parameter_pool.put( Parameter(ParameterName.AwsCredentialFile, location, ParameterSource.OperationOutput), True) ret_result = OperationResult(self, None, None, None) return ret_result
def execute(self, parameter_pool): eb_client = ElasticBeanstalkClient( parameter_pool.get_value(ParameterName.AwsAccessKeyId), parameter_pool.get_value(ParameterName.AwsSecretAccessKey), parameter_pool.get_value(ParameterName.ServiceEndpoint)) app_name = parameter_pool.get_value(ParameterName.ApplicationName) env_name = parameter_pool.get_value(ParameterName.EnvironmentName) prompt.action(DeleteApplicationOpMessage.Start.format(app_name)) try: response = eb_client.delete_application(app_name, 'true') except OperationInProgressException: log.info('Deleting Application "{0}" already in progress'.format( app_name)) prompt.result( DeleteApplicationOpMessage.AlreadyDelete.format(app_name)) ret_result = OperationResult( self, None, DeleteApplicationOpMessage.AlreadyDelete.format(app_name), None) else: log.info('Received response for DeleteApplication call.') self._log_api_result(self.__class__.__name__, 'DeleteApplication', response.result) prompt.result(DeleteApplicationOpMessage.Succeed.format(app_name)) credential_file_loc = config_file.default_aws_credential_file_location( ) param_list = [rds_utils.password_key_name(env_name)] config_file.trim_aws_credential_file(credential_file_loc, parameter_pool, param_list, True) ret_result = OperationResult( self, response.request_id, DeleteApplicationOpMessage.Succeed.format(app_name), response.result) return ret_result
def apply_environment_type(parameter_pool, stack_name, option_settings, option_to_remove): # If not specified, skip envtype = parameter_pool.get_value(PName.EnvironmentType) if envtype: # Describe applicable option settings eb_client = api_wrapper.create_eb_client(parameter_pool) app_name = parameter_pool.get_value(PName.ApplicationName, False) raw_option_defs = api_wrapper.retrieve_configuration_options( eb_client=eb_client, app_name=app_name, solution_stack=stack_name, options=None) option_defs = set() for raw_option_def in raw_option_defs: option_defs.add(raw_option_def.namespace + u'-' + raw_option_def.name) # Return if environment type option is not available if OptionSettingEnvironmentType.Namespace + u'-' + \ OptionSettingEnvironmentType.OptionName not in option_defs: prompt.result( ValidationMessage.EnvTypeInapplicable.format(envtype)) return # remove inapplicable option settings removed = False for namespace in option_settings.keys(): for option_name in option_settings[namespace].keys(): if namespace + u'-' + option_name not in option_defs: remove_option_setting(option_settings, option_to_remove, namespace, option_name, False) removed = True if removed: prompt.result(ValidationMessage.EnvTypeBlowAwayOptionSettings) # Set environment type add_option_setting(option_settings, option_to_remove, OptionSettingEnvironmentType.Namespace, OptionSettingEnvironmentType.OptionName, envtype)
def apply_environment_type(parameter_pool, stack_name, option_settings, option_to_remove): # If not specified, skip envtype = parameter_pool.get_value(PName.EnvironmentType) if envtype: # Describe applicable option settings eb_client = api_wrapper.create_eb_client(parameter_pool) app_name = parameter_pool.get_value(PName.ApplicationName, False) raw_option_defs = api_wrapper.retrieve_configuration_options(eb_client = eb_client, app_name = app_name, solution_stack =stack_name, options = None) option_defs = set() for raw_option_def in raw_option_defs: option_defs.add(raw_option_def.namespace + u'-' + raw_option_def.name) # Return if environment type option is not available if OptionSettingEnvironmentType.Namespace + u'-' + \ OptionSettingEnvironmentType.OptionName not in option_defs: prompt.result(ValidationMessage.EnvTypeInapplicable.format(envtype)) return # remove inapplicable option settings removed = False for namespace in option_settings.keys(): for option_name in option_settings[namespace].keys(): if namespace + u'-' + option_name not in option_defs: remove_option_setting(option_settings, option_to_remove, namespace, option_name, False) removed = True if removed: prompt.result(ValidationMessage.EnvTypeBlowAwayOptionSettings) # Set environment type add_option_setting(option_settings, option_to_remove, OptionSettingEnvironmentType.Namespace, OptionSettingEnvironmentType.OptionName, envtype)
def execute(self, parameter_pool): func_matrix = [] for param in CredentialFileParameters: if not parameter_pool.has(param[0]): continue elif ParameterSource.is_ahead(ParameterSource.Terminal,\ parameter_pool.get_source(param[0])): continue else: func_matrix.append((param[0], param[2])) if len(func_matrix) < 1: log.info('Skipped updating credential file as credentials are not changed.') return location = config_file.default_aws_credential_file_location() # Create directory if needed try: config_file.create_directory(config_file.default_aws_credential_file_path()) config_file.write_aws_credential_file(location, parameter_pool, func_matrix) except BaseException as ex: log.error('Encountered error when creating AWS Credential file at "{0}", because {1}.'.\ format(location, ex)) return else: log.info(WriteAwsCredentialFileOpMessage.Succeed.format(location)) prompt.result(WriteAwsCredentialFileOpMessage.Succeed.format(location)) parameter_pool.put(Parameter(ParameterName.AwsCredentialFile, location, ParameterSource.OperationOutput), True) ret_result = OperationResult(self, None, None, None) return ret_result
def execute(self, parameter_pool): eb_client = ElasticBeanstalkClient(parameter_pool.get_value(ParameterName.AwsAccessKeyId), parameter_pool.get_value(ParameterName.AwsSecretAccessKey), parameter_pool.get_value(ParameterName.ServiceEndpoint)) app_name = parameter_pool.get_value(ParameterName.ApplicationName) env_name = parameter_pool.get_value(ParameterName.EnvironmentName) prompt.action(DeleteApplicationOpMessage.Start.format(app_name)) try: response = eb_client.delete_application(app_name, 'true') except OperationInProgressException: log.info('Deleting Application "{0}" already in progress'.format(app_name)) prompt.result(DeleteApplicationOpMessage.AlreadyDelete.format(app_name)) ret_result = OperationResult(self, None, DeleteApplicationOpMessage.AlreadyDelete.format(app_name), None) else: log.info('Received response for DeleteApplication call.') self._log_api_result(self.__class__.__name__, 'DeleteApplication', response.result) prompt.result(DeleteApplicationOpMessage.Succeed.format(app_name)) credential_file_loc = config_file.default_aws_credential_file_location() param_list = [rds_utils.password_key_name(env_name)] config_file.trim_aws_credential_file(credential_file_loc, parameter_pool, param_list, True) ret_result = OperationResult(self, response.request_id, DeleteApplicationOpMessage.Succeed.format(app_name), response.result) return ret_result
def execute(self, parameter_pool): eb_client = ElasticBeanstalkClient( parameter_pool.get_value(ParameterName.AwsAccessKeyId), parameter_pool.get_value(ParameterName.AwsSecretAccessKey), parameter_pool.get_value(ParameterName.ServiceEndpoint)) env_name = parameter_pool.get_value(ParameterName.EnvironmentName) wait_timeout = parameter_pool.get_value( ParameterName.WaitForFinishTimeout) poll_delay = parameter_pool.get_value(ParameterName.PollDelay) terminate_request_id = parameter_pool.get_value(ParameterName.TerminateEnvironmentRequestID)\ if parameter_pool.has(ParameterName.TerminateEnvironmentRequestID) else None result = self._wait_for_env_operation_finish( eb_client=eb_client, env_name=env_name, original_request_id=terminate_request_id, pending_status=EnvironmentStatus.Terminating, expected_health=None, operation_name=self.__class__.__name__, action_name=WaitForTerminateEnvironmentFinishOpMessage.Action, wait_timeout=wait_timeout, poll_delay=poll_delay, include_deleted='true', initial_delay=ServiceDefault.TERMINATE_ENV_POLL_DELAY) # After polling status = result[0].status health = result[0].health log.info('Stopped polling. Environment "{0}" is now {1}, health is {2}.'.format\ (env_name, status, health)) if status.lower() == EnvironmentStatus.Terminated.lower(): prompt.result( WaitForTerminateEnvironmentFinishOpMessage.Succeed.format( env_name)) else: prompt.result( WaitForTerminateEnvironmentFinishOpMessage.Timeout.format( env_name)) prompt.result( WaitForTerminateEnvironmentFinishOpMessage.Status.format( status, health)) ret_result = OperationResult( self, None, WaitForTerminateEnvironmentFinishOpMessage.Result.format(status), result) return ret_result
def execute(self, parameter_pool): eb_client = ElasticBeanstalkClient( parameter_pool.get_value(ParameterName.AwsAccessKeyId), parameter_pool.get_value(ParameterName.AwsSecretAccessKey), parameter_pool.get_value(ParameterName.ServiceEndpoint), ) env_name = parameter_pool.get_value(ParameterName.EnvironmentName) wait_timeout = parameter_pool.get_value(ParameterName.WaitForFinishTimeout) poll_delay = parameter_pool.get_value(ParameterName.PollDelay) terminate_request_id = ( parameter_pool.get_value(ParameterName.TerminateEnvironmentRequestID) if parameter_pool.has(ParameterName.TerminateEnvironmentRequestID) else None ) result = self._wait_for_env_operation_finish( eb_client=eb_client, env_name=env_name, original_request_id=terminate_request_id, pending_status=EnvironmentStatus.Terminating, expected_health=None, operation_name=self.__class__.__name__, action_name=WaitForTerminateEnvironmentFinishOpMessage.Action, wait_timeout=wait_timeout, poll_delay=poll_delay, include_deleted=u"true", initial_delay=ServiceDefault.TERMINATE_ENV_POLL_DELAY, ) # After polling status = result[0].status health = result[0].health log.info(u'Stopped polling. Environment "{0}" is now {1}, health is {2}.'.format(env_name, status, health)) if status.lower() == EnvironmentStatus.Terminated.lower(): prompt.result(WaitForTerminateEnvironmentFinishOpMessage.Succeed.format(env_name)) else: prompt.result(WaitForTerminateEnvironmentFinishOpMessage.Timeout.format(env_name)) prompt.result(WaitForTerminateEnvironmentFinishOpMessage.Status.format(status, health)) ret_result = OperationResult( self, None, WaitForTerminateEnvironmentFinishOpMessage.Result.format(status), result ) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) app_name = parameter_pool.get_value(ParameterName.ApplicationName, False) env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False) prompt.action(DescribeEnvironmentOpMessage.Start.format(env_name)) response = eb_client.describe_environments(app_name, env_name, include_deleted = 'false') log.info('Received response for DescribeEnvironemnts call.') self._log_api_result(self.__class__.__name__, 'DescribeEnvironments', response.result) if len(response.result) > 0: # If have result env_info = response.result[0] message = DescribeEnvironmentOpMessage.Result.format(env_info.cname, env_info.status, env_info.health) prompt.result(message) prompt.info(DescribeEnvironmentOpMessage.Detail.format(env_info.environment_name, env_info.environment_id, env_info.solution_stack_name, env_info.version_label, env_info.date_created, env_info.date_updated, env_info.description if env_info.description else '')) # If not Green, pull the most recent warning and error events if env_info.health in [EnvironmentHealth.Red, EnvironmentHealth.Yellow] \ or (env_info.status == EnvironmentStatus.Ready \ and env_info.health == EnvironmentHealth.Grey): events = eb_client.describe_events(app_name, env_name, max_records = ServiceDefault.STATUS_EVENT_MAX_NUM, severity = ServiceDefault.STATUS_EVENT_LEVEL) if len(events.result) > 0: # Having one error event for event in events.result: msg = '{0}\t{1}\t{2}'.format(event.event_date, event.severity, event.message) log.info('Found last error event: {0}'.format(msg)) prompt.plain(msg) # Display RDS instance host info try: logical_id, rds_property = rds_utils.retrieve_rds_instance_property\ (parameter_pool, env_name) if rds_property is not None: prompt.result(DescribeEnvironmentOpMessage.RdsInfo.format\ (logical_id, rds_property.endpoint.address, rds_property.endpoint.port)) prompt.info(DescribeEnvironmentOpMessage.RdsDetail.format\ (rds_property.engine + ' ' + rds_property.engine_version, rds_property.allocated_storage, rds_property.db_instance_class, rds_property.multi_az, rds_property.master_username, rds_property.instance_create_time, rds_property.db_instance_status)) except BaseException as ex: log.error('Encountered error when retrieve environment resources: {0}.'.format(ex)) raise else: # No result. Environment not exist. message = DescribeEnvironmentOpMessage.NoEnvironment.format(env_name) prompt.result(message) ret_result = OperationResult(self, response.request_id, message, response.result) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) app_name = parameter_pool.get_value(ParameterName.ApplicationName, False) env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False) prompt.action(DescribeEnvironmentOpMessage.Start.format(env_name)) response = eb_client.describe_environments(app_name, env_name, include_deleted = u'false') log.info(u'Received response for DescribeEnvironemnts call.') self._log_api_result(self.__class__.__name__, u'DescribeEnvironments', response.result) # Also look up environment resources for future use resources = None try: resources = api_wrapper.retrieve_environment_resources(parameter_pool, env_name) except InvalidParameterValueException: pass env_present = (len(response.result) > 0) and bool(resources) if env_present: # If have result env_info = response.result[0] message = DescribeEnvironmentOpMessage.Result.format(env_info.cname, env_info.status, env_info.health) prompt.result(message) # Display sqs queue info before environment detail if resources.queues: for queue in resources.queues: message = DescribeEnvironmentOpMessage.QueueInfo.format(queue.name, queue.url) prompt.result(message) tier_serialized = env_info.tier.to_serialized_string() if env_info.tier else u'' prompt.info(DescribeEnvironmentOpMessage.Detail.format(env_info.environment_name, env_info.environment_id, tier_serialized, env_info.solution_stack_name, env_info.version_label, env_info.date_created, env_info.date_updated, env_info.description if env_info.description else u'')) # If not Green, pull the most recent warning and error events if env_info.health in [EnvironmentHealth.Red, EnvironmentHealth.Yellow] \ or (env_info.status == EnvironmentStatus.Ready \ and env_info.health == EnvironmentHealth.Grey): events = eb_client.describe_events(app_name, env_name, max_records = ServiceDefault.STATUS_EVENT_MAX_NUM, severity = ServiceDefault.STATUS_EVENT_LEVEL) if len(events.result) > 0: # Having one error event for event in events.result: msg = u'{0}\t{1}\t{2}'.format(event.event_date, event.severity, event.message) log.info(u'Found last error event: {0}'.format(msg)) prompt.plain(msg) # Display RDS instance host info try: logical_id, rds_property = rds_utils.retrieve_rds_instance_property\ (parameter_pool, resources) if rds_property is not None: prompt.result(DescribeEnvironmentOpMessage.RdsInfo.format\ (logical_id, rds_property.endpoint.address, rds_property.endpoint.port)) prompt.info(DescribeEnvironmentOpMessage.RdsDetail.format\ (rds_property.engine + u' ' + rds_property.engine_version, rds_property.allocated_storage, rds_property.db_instance_class, rds_property.multi_az, rds_property.master_username, rds_property.instance_create_time, rds_property.db_instance_status)) except BaseException as ex: log.error(u'Encountered error when retrieve environment resources: {0}.'.format(ex)) raise # Subcommand _, subcommands = parameter_pool.command subcommand = subcommands[0].upper() if len(subcommands) > 0 else None if subcommand == SubCommandType.OPEN: urlpath = u'' if len(subcommands) > 1: urlpath = subcommands[1] if subcommands[1].startswith(u'/') else u'/' + subcommands[1] shell_utils.open_url(env_info.cname + urlpath, False) else: # No result. Environment not exist. message = DescribeEnvironmentOpMessage.NoEnvironment.format(env_name) prompt.result(message) ret_result = OperationResult(self, response.request_id, message, response.result) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) app_name = parameter_pool.get_value(ParameterName.ApplicationName, False) version_name = eb_utils.check_app_version(parameter_pool, eb_client) env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False) stack_name = parameter_pool.get_value(ParameterName.SolutionStack, False) tier = parameter_pool.get_value(ParameterName.EnvironmentTier, False) spec = TemplateSpecification() # Try load option setting file if exist option_location = parameter_pool.get_value( ParameterName.OptionSettingFile, False) option_settings = config_file.load_env_option_setting_file( option_location, quiet=True) if option_settings is not None and len(option_settings) > 0: prompt.info( CreateEnvironmentOpMessage.UsingOptionSetting.format( option_location)) else: option_settings = dict() option_remove = dict() # Process extensions first before we process options self._extension_handler(parameter_pool, spec, stack_name, option_settings, option_remove) # Process options self._option_setting_handler(parameter_pool, spec, stack_name, None, option_settings, option_remove) prompt.action(CreateEnvironmentOpMessage.Start.format(env_name)) try: response = eb_client.create_environment( application=app_name, environment=env_name, solution_stack=stack_name, version_label=version_name, option_settings=option_settings, option_remove=option_remove, template_specification=spec, tier=tier) except AlreadyExistException: log.info(u'Environment "{0}" already exist.'.format(env_name)) prompt.result( CreateEnvironmentOpMessage.AlreadyExist.format(env_name)) ret_result = OperationResult( self, None, CreateEnvironmentOpMessage.AlreadyExist.format(env_name), None) else: log.info(u'Received response for CreateEnvironemnt call.') prompt.info(CreateEnvironmentOpMessage.Succeed) prompt.result( CreateEnvironmentOpMessage.WaitAfterLaunch.format(env_name)) self._log_api_result(self.__class__.__name__, u'CreateEnvironment', response.result) parameter_pool.put( Parameter(ParameterName.CreateEnvironmentRequestID, response.request_id, ParameterSource.OperationOutput)) ret_result = OperationResult(self, response.request_id, CreateEnvironmentOpMessage.Succeed, response.result) return ret_result
def execute(self, parameter_pool): eb_client = self._get_eb_client(parameter_pool) app_name = parameter_pool.get_value(ParameterName.ApplicationName, False) env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False) prompt.action(DescribeEnvironmentOpMessage.Start.format(env_name)) response = eb_client.describe_environments(app_name, env_name, include_deleted=u'false') log.info(u'Received response for DescribeEnvironemnts call.') self._log_api_result(self.__class__.__name__, u'DescribeEnvironments', response.result) # Also look up environment resources for future use resources = None try: resources = api_wrapper.retrieve_environment_resources( parameter_pool, env_name) except InvalidParameterValueException: pass env_present = (len(response.result) > 0) and bool(resources) if env_present: # If have result env_info = response.result[0] message = DescribeEnvironmentOpMessage.Result.format( env_info.cname, env_info.status, env_info.health) prompt.result(message) # Display sqs queue info before environment detail if resources.queues: for queue in resources.queues: message = DescribeEnvironmentOpMessage.QueueInfo.format( queue.name, queue.url) prompt.result(message) tier_serialized = env_info.tier.to_serialized_string( ) if env_info.tier else u'' prompt.info( DescribeEnvironmentOpMessage.Detail.format( env_info.environment_name, env_info.environment_id, tier_serialized, env_info.solution_stack_name, env_info.version_label, env_info.date_created, env_info.date_updated, env_info.description if env_info.description else u'')) # If not Green, pull the most recent warning and error events if env_info.health in [EnvironmentHealth.Red, EnvironmentHealth.Yellow] \ or (env_info.status == EnvironmentStatus.Ready \ and env_info.health == EnvironmentHealth.Grey): events = eb_client.describe_events( app_name, env_name, max_records=ServiceDefault.STATUS_EVENT_MAX_NUM, severity=ServiceDefault.STATUS_EVENT_LEVEL) if len(events.result) > 0: # Having one error event for event in events.result: msg = u'{0}\t{1}\t{2}'.format(event.event_date, event.severity, event.message) log.info(u'Found last error event: {0}'.format(msg)) prompt.plain(msg) # Display RDS instance host info try: logical_id, rds_property = rds_utils.retrieve_rds_instance_property\ (parameter_pool, resources) if rds_property is not None: prompt.result(DescribeEnvironmentOpMessage.RdsInfo.format\ (logical_id, rds_property.endpoint.address, rds_property.endpoint.port)) prompt.info(DescribeEnvironmentOpMessage.RdsDetail.format\ (rds_property.engine + u' ' + rds_property.engine_version, rds_property.allocated_storage, rds_property.db_instance_class, rds_property.multi_az, rds_property.master_username, rds_property.instance_create_time, rds_property.db_instance_status)) except BaseException as ex: log.error( u'Encountered error when retrieve environment resources: {0}.' .format(ex)) raise # Subcommand _, subcommands = parameter_pool.command subcommand = subcommands[0].upper( ) if len(subcommands) > 0 else None if subcommand == SubCommandType.OPEN: urlpath = u'' if len(subcommands) > 1: urlpath = subcommands[1] if subcommands[1].startswith( u'/') else u'/' + subcommands[1] shell_utils.open_url(env_info.cname + urlpath, False) else: # No result. Environment not exist. message = DescribeEnvironmentOpMessage.NoEnvironment.format( env_name) prompt.result(message) ret_result = OperationResult(self, response.request_id, message, response.result) return ret_result