frapposelli / vagrant-vcenter

A Vagrant provider for VMware vCenter®
MIT License
106 stars 36 forks source link

is_created? undefined method `serviceInstance' for nil:NilClass (NoMethodError) #16

Closed epcim closed 9 years ago

epcim commented 9 years ago

Hi, I am able to upload image, create VM, power ON, but thing hangs during the cookbook upload. This does not pain much since I should be able to repeat the vagrant provision action.

However that one or even vagrant ssh HOST fails with this issue:

vums git:(master) ✗ vagrant ssh docker
/home/xyzuser/.vagrant.d/gems/gems/vagrant-vcenter-0.3.0/lib/vagrant-vcenter/action/is_created.rb:22:in `call': undefined method `serviceInstance' for nil:NilClass (NoMethodError)
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builder.rb:116:in `call'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `block in run'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/util/busy.rb:19:in `busy'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `run'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builtin/call.rb:43:in `call'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
    from /home/pmichalec/.vagrant.d/gems/gems/vagrant-chef-zero-0.7.1/lib/vagrant-chef-zero/action/reconfig.rb:33:in `call'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builtin/env_set.rb:19:in `call'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/warden.rb:34:in `call'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/builder.rb:116:in `call'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `block in run'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/util/busy.rb:19:in `busy'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/action/runner.rb:66:in `run'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:196:in `action_raw'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:173:in `block in action'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:157:in `call'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:157:in `block in action'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:161:in `call'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/machine.rb:161:in `action'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/plugins/commands/ssh/command.rb:59:in `block in execute'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/plugin/v2/command.rb:226:in `block in with_target_vms'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/plugin/v2/command.rb:220:in `each'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/plugin/v2/command.rb:220:in `with_target_vms'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/plugins/commands/ssh/command.rb:41:in `execute'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/cli.rb:42:in `execute'
    from /opt/vagrant/embedded/gems/gems/vagrant-1.6.3/lib/vagrant/environment.rb:252:in `cli'
    from /opt/vagrant/bin/../embedded/gems/gems/vagrant-1.6.3/bin/vagrant:166:in `<main>'
➜  vums git:(master) ✗ 

What is the ServiceInstanace object and why it might be missing in provider_config?

see the is_created.rb:

module VagrantPlugins
  module VCenter
    module Action
      # This class verifies if the VM has been created.
      class IsCreated
        def initialize(app, env)
          @app = app
          @logger = Log4r::Logger.new('vagrant_vcenter::action::is_created')
        end

        def call(env)
          vm_id = env[:machine].id
          if vm_id

            # VM is in the vagrant registry, now we need to check if it's
            # actually in vcenter

            # FIXME: this part needs some cleanup
            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)

            unless vm
              @logger.info('VM is in the vagrant registry but not in vcenter')
              # Clear the ID
              env[:machine].id = nil
              env[:result] = false
            end
frapposelli commented 9 years ago

would you care running the command like this?

VAGRANT_LOG=DEBUG vagrant ssh docker

and post the log (use pastebin if it's too long).

epcim commented 9 years ago

Sure .. getting used to it .. http://pastebin.com/PuCqjsqf

frapposelli commented 9 years ago

Thanks, wow, that was a massive overlooking on my side, cutting version 0.3.1 right now.

frapposelli commented 9 years ago

version 0.3.1 is on ruby gems, update the plugin from vagrant and try again :)