Sha256: f06aab45d86933faea37ecc29689da708141bad770a816c95e19faeaf8211936

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

module VagrantPlugins
  module VCloudAir
    module Action
      class DestroyVApp
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new('vagrant_vcloudair::action::destroy_vapp')
        end

        def call(env)
          cfg = env[:machine].provider_config
          cnx = cfg.vcloudair_cnx.driver
          vapp_id = env[:machine].get_vapp_id

          cfg.org = cnx.get_organization_by_name(cfg.vdc_name)
          cfg.vdc_id = cnx.get_vdc_id_by_name(cfg.org, cfg.vdc_name)

          test_vapp = cnx.get_vapp(vapp_id)

          @logger.debug(
            "Number of VMs in the vApp: #{test_vapp[:vms_hash].count}"
          )

          if cfg.vdc_edge_gateway_ip && cfg.vdc_edge_gateway
            env[:ui].info(I18n.t('vagrant_vcloudair.edge.removing_nat_rules',
                                 vdc_edge_gateway: cfg.vdc_edge_gateway,
                                 vdc_edge_gateway_ip: cfg.vdc_edge_gateway_ip))

            @logger.debug(
              "Deleting Edge Gateway rules - vdc id: #{cfg.vdc_id}"
            )
            edge_remove = cnx.remove_edge_gateway_rules(
              cfg.vdc_edge_gateway,
              cfg.vdc_id,
              cfg.vdc_edge_gateway_ip,
              vapp_id
            )
            cnx.wait_task_completion(edge_remove)
          end

          env[:ui].info(I18n.t('vagrant_vcloudair.vapp.destroy_vapp'))
          vapp_delete_task = cnx.delete_vapp(vapp_id)
          @logger.debug("vApp Delete task id #{vapp_delete_task}")
          cnx.wait_task_completion(vapp_delete_task)

          env[:machine].id = nil
          env[:machine].vappid = nil

          @app.call env
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-vcloudair-0.5.3 lib/vagrant-vcloudair/action/destroy_vapp.rb
vagrant-vcloudair-0.5.2 lib/vagrant-vcloudair/action/destroy_vapp.rb
vagrant-vcloudair-0.5.1 lib/vagrant-vcloudair/action/destroy_vapp.rb
vagrant-vcloudair-0.5.0 lib/vagrant-vcloudair/action/destroy_vapp.rb