Sha256: 4e05746cc4a52f5ed4d5d51608753d867adfd3d8545787e59ca67a7b8c005e2d

Contents?: true

Size: 849 Bytes

Versions: 8

Compression:

Stored size: 849 Bytes

Contents

require 'i18n'

module VagrantPlugins
  module VCenter
    module Action
      # This class powers off the VM that the Vagrant provider is managing.
      class PowerOff
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new('vagrant_vcenter::action::poweroff')
        end

        def call(env)
          config = env[:machine].provider_config
          # FIXME: Raise a correct exception
          dc = config.vcenter_cnx.serviceInstance.find_datacenter(
               config.datacenter_name) or abort 'datacenter not found'
          root_vm_folder = dc.vmFolder
          vm = root_vm_folder.findByUuid(env[:machine].id)

          # Poweroff VM
          env[:ui].info('Powering off VM...')
          vm.PowerOffVM_Task.wait_for_completion

          @app.call env
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vagrant-vcenter-0.3.2 lib/vagrant-vcenter/action/power_off.rb
vagrant-vcenter-0.3.1 lib/vagrant-vcenter/action/power_off.rb
vagrant-vcenter-0.3.0 lib/vagrant-vcenter/action/power_off.rb
vagrant-vcenter-0.2.1 lib/vagrant-vcenter/action/power_off.rb
vagrant-vcenter-0.2.0 lib/vagrant-vcenter/action/power_off.rb
vagrant-vcenter-0.1.1 lib/vagrant-vcenter/action/power_off.rb
vagrant-vcenter-0.1.0 lib/vagrant-vcenter/action/power_off.rb
vagrant-vcenter-0.0.2.pre.dev lib/vagrant-vcenter/action/power_off.rb