close #72 possibility to give VMs a name

This commit is contained in:
dima
2013-10-19 23:10:31 +02:00
parent b68adff5cb
commit be44fc10b8
3 changed files with 12 additions and 11 deletions

View File

@@ -3,10 +3,10 @@ require 'vagrant-libvirt/plugin'
module VagrantPlugins
module ProviderLibvirt
lib_path = Pathname.new(File.expand_path("../vagrant-libvirt", __FILE__))
autoload :Action, lib_path.join("action")
autoload :Errors, lib_path.join("errors")
autoload :Util, lib_path.join("util")
lib_path = Pathname.new(File.expand_path('../vagrant-libvirt', __FILE__))
autoload :Action, lib_path.join('action')
autoload :Errors, lib_path.join('errors')
autoload :Util, lib_path.join('util')
# Hold connection handler so there is no need to connect more times than
# one. This can be annoying when there are more machines to create, or when
@@ -23,7 +23,7 @@ module VagrantPlugins
end
def self.source_root
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
@source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
end
end
end

View File

@@ -1,4 +1,4 @@
require "log4r"
require 'log4r'
module VagrantPlugins
module ProviderLibvirt
@@ -8,7 +8,7 @@ module VagrantPlugins
class ReadState
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant_libvirt::action::read_state")
@logger = Log4r::Logger.new('vagrant_libvirt::action::read_state')
end
def call(env)
@@ -21,9 +21,9 @@ module VagrantPlugins
# Find the machine
server = libvirt.servers.get(machine.id)
if server.nil? || [:"shutting-down", :terminated].include?(server.state.to_sym)
if server.nil? || [:'shutting-down', :terminated].include?(server.state.to_sym)
# The machine can't be found
@logger.info("Machine not found or terminated, assuming it got destroyed.")
@logger.info('Machine not found or terminated, assuming it got destroyed.')
machine.id = nil
return :not_created
end

View File

@@ -11,8 +11,9 @@ module VagrantPlugins
def call(env)
require 'securerandom'
env[:domain_name] = env[:root_path].basename.to_s.dup
env[:domain_name].gsub!(/[^-a-z0-9_]/i, "")
env[:domain_name] << "_#{SecureRandom.hex}"
env[:domain_name].gsub!(/[^-a-z0-9_]/i, '')
env[:domain_name] << '_'
env[:domain_name] << env[:machine].name.to_s
# Check if the domain name is not already taken
domain = ProviderLibvirt::Util::Collection.find_matching(