Sha256: 52b8b759d9f7792208e8ac3e9b2457dd4a00fb665789cabcde719da44a28ca8d

Contents?: true

Size: 1.16 KB

Versions: 13

Compression:

Stored size: 1.16 KB

Contents

require "log4r"

module VagrantPlugins
  module ProviderVirtualBox
    module Action
      class SetName
        def initialize(app, env)
          @logger = Log4r::Logger.new("vagrant::action::vm::setname")
          @app = app
        end

        def call(env)
          name = env[:machine].provider_config.name

          # If no name was manually set, then use a default
          if !name
            prefix = env[:root_path].basename.to_s
            prefix.gsub!(/[^-a-z0-9_]/i, "")
            name = prefix + "_#{Time.now.to_i}"
          end

          # Verify the name is not taken
          vms = env[:machine].provider.driver.read_vms
          raise Vagrant::Errors::VMNameExists, :name => name if \
            vms.has_key?(name) && vms[name] != env[:machine].id

          if vms.has_key?(name)
            @logger.info("Not setting the name because our name is already set.")
          else
            @logger.info("Setting the name of the VM: #{name}")
            env[:ui].info(I18n.t("vagrant.actions.vm.set_name.setting_name"))
            env[:machine].provider.driver.set_name(name)
          end

          @app.call(env)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 5 rubygems

Version Path
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/providers/virtualbox/action/set_name.rb
tnargav-1.2.3 plugins/providers/virtualbox/action/set_name.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/plugins/providers/virtualbox/action/set_name.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/plugins/providers/virtualbox/action/set_name.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/plugins/providers/virtualbox/action/set_name.rb
tnargav-1.2.2 plugins/providers/virtualbox/action/set_name.rb
vagrantup-1.1.3 plugins/providers/virtualbox/action/set_name.rb
vagrantup-1.1.2 plugins/providers/virtualbox/action/set_name.rb
vagrantup-1.1.1 plugins/providers/virtualbox/action/set_name.rb
vagrantup-1.1.0 plugins/providers/virtualbox/action/set_name.rb
vagrantup-1.1.4 plugins/providers/virtualbox/action/set_name.rb
vagrant-actionio-0.0.9 vendor/bundle/bundler/gems/vagrant-c74251a1d9c0/plugins/providers/virtualbox/action/set_name.rb
vagrant-lxc-0.0.1 vendor/vagrant/plugins/providers/virtualbox/action/set_name.rb