Class: VagrantPlugins::OpenStack::Action::DeleteOrchestrationStack
- Inherits:
-
Object
- Object
- VagrantPlugins::OpenStack::Action::DeleteOrchestrationStack
- Defined in:
- lib/vagrant-openstack-plugin/action/delete_orchestration_stack.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ DeleteOrchestrationStack
constructor
A new instance of DeleteOrchestrationStack.
Constructor Details
#initialize(app, env) ⇒ DeleteOrchestrationStack
Returns a new instance of DeleteOrchestrationStack.
9 10 11 12 13 |
# File 'lib/vagrant-openstack-plugin/action/delete_orchestration_stack.rb', line 9 def initialize(app, env) @app = app @logger = Log4r::Logger.new( "vagrant_openstack::action::delete_orchestration_stack") end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vagrant-openstack-plugin/action/delete_orchestration_stack.rb', line 15 def call(env) # Get the config. config = env[:machine].provider_config # Load IDs for orchestration stacks created by vagrant and this # project. created_stacks_fname = env[:machine].data_dir + 'orchestration_stacks' # Return if no action is needed. if not config.orchestration_stack_destroy or not File.exist?(created_stacks_fname) env[:machine].id = nil return @app.call(env) end # Create new fog orchestration service. env[:openstack_orchestration] = Fog::Orchestration.new( env[:fog_openstack_params]) # Load IDs of stacks to be deleted. available_stacks = env[:openstack_orchestration].list_stacks.body['stacks'] stacks_to_delete = [] File.open(created_stacks_fname) { |file| file.each_line do |stack_id| stack = find_stack(available_stacks, stack_id.chomp!) next if not stack stacks_to_delete << stack end } # Delete stacks. if stacks_to_delete.length > 0 env[:ui].info(I18n.t("vagrant_openstack.deleting_orchestration_stacks")) end stacks_to_delete.each do |stack| @logger.info("Removing orchestration stack #{stack['stack_name']} (#{stack['id']}).") env[:openstack_orchestration].delete_stack( stack['stack_name'], stack['id']) stacks_from_file.delete(stack) end # Delete file holding created stack IDs. @logger.info("Deleting file #{created_stacks_fname}.") File.delete(created_stacks_fname) env[:machine].id = nil @app.call(env) end |