Sha256: 8fec918bc75590f0b184d219c416fd9dd1c1feb897c4b3db3c188f6ee17f4b44

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

module VagrantPlugins
  module VCloud
    module Action
      class PowerOffVApp
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new('vagrant_vcloud::action::poweroff_vapp')
        end

        def call(env)
          cfg = env[:machine].provider_config
          cnx = cfg.vcloud_cnx.driver

          vapp_id = env[:machine].get_vapp_id

          test_vapp = cnx.get_vapp(vapp_id)

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

          # this is a helper to get vapp_edge_ip into cache for later destroy
          # of edge gateway rules
          if cfg.network_bridge.nil? && cfg.networks.nil?
            vapp_edge_ip = cnx.get_vapp_edge_public_ip(vapp_id)
          end

          # Poweroff vApp
          env[:ui].info('Single VM left in the vApp, Powering off vApp...')
          vapp_stop_task = cnx.poweroff_vapp(vapp_id)
          vapp_stop_wait = cnx.wait_task_completion(vapp_stop_task)

          unless vapp_stop_wait[:errormsg].nil?
            fail Errors::StopVAppError, :message => vapp_stop_wait[:errormsg]
          end

          @app.call env
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-vcloud-0.5.0 lib/vagrant-vcloud/action/power_off_vapp.rb
vagrant-vcloud-0.4.7 lib/vagrant-vcloud/action/power_off_vapp.rb
vagrant-vcloud-0.4.6 lib/vagrant-vcloud/action/power_off_vapp.rb