Remove global variables
This commit is contained in:
parent
18a6749321
commit
eb07788db1
|
@ -81,10 +81,10 @@ module Vagrant
|
||||||
names.each do |name|
|
names.each do |name|
|
||||||
raise Errors::MultiVMEnvironmentRequired if !@env.multivm?
|
raise Errors::MultiVMEnvironmentRequired if !@env.multivm?
|
||||||
|
|
||||||
if name =~ /^\/(.+?)\/$/
|
if pattern = name[/^\/(.+?)\/$/, 1]
|
||||||
# This is a regular expression name, so we convert to a regular
|
# This is a regular expression name, so we convert to a regular
|
||||||
# expression and allow that sort of matching.
|
# expression and allow that sort of matching.
|
||||||
regex = Regexp.new($1.to_s)
|
regex = Regexp.new(pattern)
|
||||||
|
|
||||||
@env.vms.each do |name, vm|
|
@env.vms.each do |name, vm|
|
||||||
vms << vm if name =~ regex
|
vms << vm if name =~ regex
|
||||||
|
|
|
@ -25,8 +25,8 @@ module Vagrant
|
||||||
def clear_shared_folders
|
def clear_shared_folders
|
||||||
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
||||||
info.split("\n").each do |line|
|
info.split("\n").each do |line|
|
||||||
if line =~ /^SharedFolderNameMachineMapping\d+="(.+?)"$/
|
if name = line[/^SharedFolderNameMachineMapping\d+="(.+?)"$/, 1]
|
||||||
execute("sharedfolder", "remove", @uuid, "--name", $1.to_s)
|
execute("sharedfolder", "remove", @uuid, "--name", name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -42,8 +42,8 @@ module Vagrant
|
||||||
|
|
||||||
def create_host_only_network(options)
|
def create_host_only_network(options)
|
||||||
# Create the interface
|
# Create the interface
|
||||||
execute("hostonlyif", "create") =~ /^Interface '(.+?)' was successfully created$/
|
interface = execute("hostonlyif", "create")
|
||||||
name = $1.to_s
|
name = interface[/^Interface '(.+?)' was successfully created$/, 1]
|
||||||
|
|
||||||
# Configure it
|
# Configure it
|
||||||
execute("hostonlyif", "ipconfig", name,
|
execute("hostonlyif", "ipconfig", name,
|
||||||
|
@ -66,15 +66,17 @@ module Vagrant
|
||||||
def delete_unused_host_only_networks
|
def delete_unused_host_only_networks
|
||||||
networks = []
|
networks = []
|
||||||
execute("list", "hostonlyifs").split("\n").each do |line|
|
execute("list", "hostonlyifs").split("\n").each do |line|
|
||||||
networks << $1.to_s if line =~ /^Name:\s+(.+?)$/
|
if network_name = line[/^Name:\s+(.+?)$/, 1]
|
||||||
|
networks << network_name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
execute("list", "vms").split("\n").each do |line|
|
execute("list", "vms").split("\n").each do |line|
|
||||||
if line =~ /^".+?"\s+\{(.+?)\}$/
|
if vm_name = line[/^".+?"\s+\{(.+?)\}$/, 1]
|
||||||
info = execute("showvminfo", $1.to_s, "--machinereadable", :retryable => true)
|
info = execute("showvminfo", vm_name, "--machinereadable", :retryable => true)
|
||||||
info.split("\n").each do |line|
|
info.split("\n").each do |line|
|
||||||
if line =~ /^hostonlyadapter\d+="(.+?)"$/
|
if network_name = line[/^hostonlyadapter\d+="(.+?)"$/, 1]
|
||||||
networks.delete($1.to_s)
|
networks.delete(network_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -170,8 +172,7 @@ module Vagrant
|
||||||
if lines.include?("OK.")
|
if lines.include?("OK.")
|
||||||
# The progress of the import will be in the last line. Do a greedy
|
# The progress of the import will be in the last line. Do a greedy
|
||||||
# regular expression to find what we're looking for.
|
# regular expression to find what we're looking for.
|
||||||
if lines.last =~ /.+(\d{2})%/
|
if current = lines.last[/.+(\d{2})%/, 1]
|
||||||
current = $1.to_i
|
|
||||||
if current > last
|
if current > last
|
||||||
last = current
|
last = current
|
||||||
yield current if block_given?
|
yield current if block_given?
|
||||||
|
@ -182,16 +183,15 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find the name of the VM name
|
# Find the name of the VM name
|
||||||
if output !~ /Suggested VM name "(.+?)"/
|
name = output[/Suggested VM name "(.+?)"/, 1]
|
||||||
|
if !name
|
||||||
@logger.error("Couldn't find VM name in the output.")
|
@logger.error("Couldn't find VM name in the output.")
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
name = $1.to_s
|
|
||||||
|
|
||||||
output = execute("list", "vms")
|
output = execute("list", "vms")
|
||||||
if output =~ /^"#{Regexp.escape(name)}" \{(.+?)\}$/
|
if existing_vm = output[/^"#{Regexp.escape(name)}" \{(.+?)\}$/, 1]
|
||||||
return $1.to_s
|
return existing_vm
|
||||||
end
|
end
|
||||||
|
|
||||||
nil
|
nil
|
||||||
|
@ -208,17 +208,19 @@ module Vagrant
|
||||||
info.split("\n").each do |line|
|
info.split("\n").each do |line|
|
||||||
# This is how we find the nic that a FP is attached to,
|
# This is how we find the nic that a FP is attached to,
|
||||||
# since this comes first.
|
# since this comes first.
|
||||||
current_nic = $1.to_i if line =~ /^nic(\d+)=".+?"$/
|
if nic = line[/^nic(\d+)=".+?"$/, 1]
|
||||||
|
current_nic = nic.to_i
|
||||||
|
end
|
||||||
|
|
||||||
# If we care about active VMs only, then we check the state
|
# If we care about active VMs only, then we check the state
|
||||||
# to verify the VM is running.
|
# to verify the VM is running.
|
||||||
if active_only && line =~ /^VMState="(.+?)"$/ && $1.to_s != "running"
|
if active_only && (state = line[/^VMState="(.+?)"$/, 1] and state != "running")
|
||||||
return []
|
return []
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse out the forwarded port information
|
# Parse out the forwarded port information
|
||||||
if line =~ /^Forwarding.+?="(.+?),.+?,.*?,(.+?),.*?,(.+?)"$/
|
if matcher = line =~ /^Forwarding.+?="(.+?),.+?,.*?,(.+?),.*?,(.+?)"$/
|
||||||
result = [current_nic, $1.to_s, $2.to_i, $3.to_i]
|
result = [current_nic, matcher[1], matcher[2].to_i, matcher[3].to_i]
|
||||||
@logger.debug(" - #{result.inspect}")
|
@logger.debug(" - #{result.inspect}")
|
||||||
results << result
|
results << result
|
||||||
end
|
end
|
||||||
|
@ -232,14 +234,14 @@ module Vagrant
|
||||||
info = {}
|
info = {}
|
||||||
|
|
||||||
block.split("\n").each do |line|
|
block.split("\n").each do |line|
|
||||||
if line =~ /^Name:\s+(.+?)$/
|
if name = line[/^Name:\s+(.+?)$/, 1]
|
||||||
info[:name] = $1.to_s
|
info[:name] = name
|
||||||
elsif line =~ /^IPAddress:\s+(.+?)$/
|
elsif ip = line[/^IPAddress:\s+(.+?)$/, 1]
|
||||||
info[:ip] = $1.to_s
|
info[:ip] = ip
|
||||||
elsif line =~ /^NetworkMask:\s+(.+?)$/
|
elsif netmask = line[/^NetworkMask:\s+(.+?)$/, 1]
|
||||||
info[:netmask] = $1.to_s
|
info[:netmask] = netmask
|
||||||
elsif line =~ /^Status:\s+(.+?)$/
|
elsif status = line[/^Status:\s+(.+?)$/, 1]
|
||||||
info[:status] = $1.to_s
|
info[:status] = status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -251,11 +253,10 @@ module Vagrant
|
||||||
def read_guest_additions_version
|
def read_guest_additions_version
|
||||||
output = execute("guestproperty", "get", @uuid, "/VirtualBox/GuestAdd/Version",
|
output = execute("guestproperty", "get", @uuid, "/VirtualBox/GuestAdd/Version",
|
||||||
:retryable => true)
|
:retryable => true)
|
||||||
if output =~ /^Value: (.+?)$/
|
if value = output[/^Value: (.+?)$/, 1]
|
||||||
# Split the version by _ since some distro versions modify it
|
# Split the version by _ since some distro versions modify it
|
||||||
# to look like this: 4.1.2_ubuntu, and the distro part isn't
|
# to look like this: 4.1.2_ubuntu, and the distro part isn't
|
||||||
# too important.
|
# too important.
|
||||||
value = $1.to_s
|
|
||||||
return value.split("_").first
|
return value.split("_").first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -268,14 +269,14 @@ module Vagrant
|
||||||
info = {}
|
info = {}
|
||||||
|
|
||||||
block.split("\n").each do |line|
|
block.split("\n").each do |line|
|
||||||
if line =~ /^NetworkName:\s+HostInterfaceNetworking-(.+?)$/
|
if network = line[/^NetworkName:\s+HostInterfaceNetworking-(.+?)$/, 1]
|
||||||
info[:network] = $1.to_s
|
info[:network] = network
|
||||||
elsif line =~ /^IP:\s+(.+?)$/
|
elsif ip = line[/^IP:\s+(.+?)$/, 1]
|
||||||
info[:ip] = $1.to_s
|
info[:ip] = ip
|
||||||
elsif line =~ /^lowerIPAddress:\s+(.+?)$/
|
elsif lower = line[/^lowerIPAddress:\s+(.+?)$/, 1]
|
||||||
info[:lower] = $1.to_s
|
info[:lower] = lower
|
||||||
elsif line =~ /^upperIPAddress:\s+(.+?)$/
|
elsif upper = line[/^upperIPAddress:\s+(.+?)$/, 1]
|
||||||
info[:upper] = $1.to_s
|
info[:upper] = upper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -287,14 +288,14 @@ module Vagrant
|
||||||
info = {}
|
info = {}
|
||||||
|
|
||||||
block.split("\n").each do |line|
|
block.split("\n").each do |line|
|
||||||
if line =~ /^Name:\s+(.+?)$/
|
if name = line[/^Name:\s+(.+?)$/, 1]
|
||||||
info[:name] = $1.to_s
|
info[:name] = name
|
||||||
elsif line =~ /^IPAddress:\s+(.+?)$/
|
elsif ip = line[/^IPAddress:\s+(.+?)$/, 1]
|
||||||
info[:ip] = $1.to_s
|
info[:ip] = ip
|
||||||
elsif line =~ /^NetworkMask:\s+(.+?)$/
|
elsif netmask = line[/^NetworkMask:\s+(.+?)$/, 1]
|
||||||
info[:netmask] = $1.to_s
|
info[:netmask] = netmask
|
||||||
elsif line =~ /^Status:\s+(.+?)$/
|
elsif status = line[/^Status:\s+(.+?)$/, 1]
|
||||||
info[:status] = $1.to_s
|
info[:status] = status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -308,7 +309,9 @@ module Vagrant
|
||||||
def read_mac_address
|
def read_mac_address
|
||||||
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
||||||
info.split("\n").each do |line|
|
info.split("\n").each do |line|
|
||||||
return $1.to_s if line =~ /^macaddress1="(.+?)"$/
|
if mac = line[/^macaddress1="(.+?)"$/, 1]
|
||||||
|
return mac
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
nil
|
nil
|
||||||
|
@ -316,8 +319,8 @@ module Vagrant
|
||||||
|
|
||||||
def read_machine_folder
|
def read_machine_folder
|
||||||
execute("list", "systemproperties", :retryable => true).split("\n").each do |line|
|
execute("list", "systemproperties", :retryable => true).split("\n").each do |line|
|
||||||
if line =~ /^Default machine folder:\s+(.+?)$/i
|
if folder = line[/^Default machine folder:\s+(.+?)$/i, 1]
|
||||||
return $1.to_s
|
return folder
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -328,21 +331,21 @@ module Vagrant
|
||||||
nics = {}
|
nics = {}
|
||||||
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
||||||
info.split("\n").each do |line|
|
info.split("\n").each do |line|
|
||||||
if line =~ /^nic(\d+)="(.+?)"$/
|
if matcher = line =~ /^nic(\d+)="(.+?)"$/
|
||||||
adapter = $1.to_i
|
adapter = matcher[1].to_i
|
||||||
type = $2.to_sym
|
type = matcher[2].to_sym
|
||||||
|
|
||||||
nics[adapter] ||= {}
|
nics[adapter] ||= {}
|
||||||
nics[adapter][:type] = type
|
nics[adapter][:type] = type
|
||||||
elsif line =~ /^hostonlyadapter(\d+)="(.+?)"$/
|
elsif matcher = line =~ /^hostonlyadapter(\d+)="(.+?)"$/
|
||||||
adapter = $1.to_i
|
adapter = matcher[1].to_i
|
||||||
network = $2.to_s
|
network = matcher[2].to_s
|
||||||
|
|
||||||
nics[adapter] ||= {}
|
nics[adapter] ||= {}
|
||||||
nics[adapter][:hostonly] = network
|
nics[adapter][:hostonly] = network
|
||||||
elsif line =~ /^bridgeadapter(\d+)="(.+?)"$/
|
elsif matcher = line =~ /^bridgeadapter(\d+)="(.+?)"$/
|
||||||
adapter = $1.to_i
|
adapter = matcher[1].to_i
|
||||||
network = $2.to_s
|
network = matcher[2].to_s
|
||||||
|
|
||||||
nics[adapter] ||= {}
|
nics[adapter] ||= {}
|
||||||
nics[adapter][:bridge] = network
|
nics[adapter][:bridge] = network
|
||||||
|
@ -356,8 +359,8 @@ module Vagrant
|
||||||
output = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
output = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
||||||
if output =~ /^name="<inaccessible>"$/
|
if output =~ /^name="<inaccessible>"$/
|
||||||
return :inaccessible
|
return :inaccessible
|
||||||
elsif output =~ /^VMState="(.+?)"$/
|
elsif state = output[/^VMState="(.+?)"$/, 1]
|
||||||
return $1.to_sym
|
return state.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
nil
|
nil
|
||||||
|
@ -366,9 +369,7 @@ module Vagrant
|
||||||
def read_used_ports
|
def read_used_ports
|
||||||
ports = []
|
ports = []
|
||||||
execute("list", "vms", :retryable => true).split("\n").each do |line|
|
execute("list", "vms", :retryable => true).split("\n").each do |line|
|
||||||
if line =~ /^".+?" \{(.+?)\}$/
|
if uuid = line[/^".+?" \{(.+?)\}$/, 1]
|
||||||
uuid = $1.to_s
|
|
||||||
|
|
||||||
# Ignore our own used ports
|
# Ignore our own used ports
|
||||||
next if uuid == @uuid
|
next if uuid == @uuid
|
||||||
|
|
||||||
|
@ -384,8 +385,8 @@ module Vagrant
|
||||||
def read_vms
|
def read_vms
|
||||||
results = []
|
results = []
|
||||||
execute("list", "vms", :retryable => true).split("\n").each do |line|
|
execute("list", "vms", :retryable => true).split("\n").each do |line|
|
||||||
if line =~ /^".+?" \{(.+?)\}$/
|
if vm = line[/^".+?" \{(.+?)\}$/, 1]
|
||||||
results << $1.to_s
|
results << vm
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ module Vagrant
|
||||||
def clear_shared_folders
|
def clear_shared_folders
|
||||||
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
||||||
info.split("\n").each do |line|
|
info.split("\n").each do |line|
|
||||||
if line =~ /^SharedFolderNameMachineMapping\d+="(.+?)"$/
|
if folder = line[/^SharedFolderNameMachineMapping\d+="(.+?)"$/, 1]
|
||||||
execute("sharedfolder", "remove", @uuid, "--name", $1.to_s)
|
execute("sharedfolder", "remove", @uuid, "--name", folder)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -42,8 +42,8 @@ module Vagrant
|
||||||
|
|
||||||
def create_host_only_network(options)
|
def create_host_only_network(options)
|
||||||
# Create the interface
|
# Create the interface
|
||||||
execute("hostonlyif", "create") =~ /^Interface '(.+?)' was successfully created$/
|
interface = execute("hostonlyif", "create")
|
||||||
name = $1.to_s
|
name = interface[/^Interface '(.+?)' was successfully created$/, 1]
|
||||||
|
|
||||||
# Configure it
|
# Configure it
|
||||||
execute("hostonlyif", "ipconfig", name,
|
execute("hostonlyif", "ipconfig", name,
|
||||||
|
@ -66,15 +66,17 @@ module Vagrant
|
||||||
def delete_unused_host_only_networks
|
def delete_unused_host_only_networks
|
||||||
networks = []
|
networks = []
|
||||||
execute("list", "hostonlyifs").split("\n").each do |line|
|
execute("list", "hostonlyifs").split("\n").each do |line|
|
||||||
networks << $1.to_s if line =~ /^Name:\s+(.+?)$/
|
if network = line[/^Name:\s+(.+?)$/, 1]
|
||||||
|
networks << network
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
execute("list", "vms").split("\n").each do |line|
|
execute("list", "vms").split("\n").each do |line|
|
||||||
if line =~ /^".+?"\s+\{(.+?)\}$/
|
if vm = line[/^".+?"\s+\{(.+?)\}$/, 1]
|
||||||
info = execute("showvminfo", $1.to_s, "--machinereadable", :retryable => true)
|
info = execute("showvminfo", vm, "--machinereadable", :retryable => true)
|
||||||
info.split("\n").each do |line|
|
info.split("\n").each do |line|
|
||||||
if line =~ /^hostonlyadapter\d+="(.+?)"$/
|
if adapter = line[/^hostonlyadapter\d+="(.+?)"$/, 1]
|
||||||
networks.delete($1.to_s)
|
networks.delete(adapter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -170,8 +172,7 @@ module Vagrant
|
||||||
if lines.include?("OK.")
|
if lines.include?("OK.")
|
||||||
# The progress of the import will be in the last line. Do a greedy
|
# The progress of the import will be in the last line. Do a greedy
|
||||||
# regular expression to find what we're looking for.
|
# regular expression to find what we're looking for.
|
||||||
if lines.last =~ /.+(\d{2})%/
|
if current = lines.last[/.+(\d{2})%/, 1]
|
||||||
current = $1.to_i
|
|
||||||
if current > last
|
if current > last
|
||||||
last = current
|
last = current
|
||||||
yield current if block_given?
|
yield current if block_given?
|
||||||
|
@ -182,16 +183,15 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
# Find the name of the VM name
|
# Find the name of the VM name
|
||||||
if output !~ /Suggested VM name "(.+?)"/
|
name = output[/Suggested VM name "(.+?)"/, 1]
|
||||||
|
if !name
|
||||||
@logger.error("Couldn't find VM name in the output.")
|
@logger.error("Couldn't find VM name in the output.")
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
name = $1.to_s
|
|
||||||
|
|
||||||
output = execute("list", "vms")
|
output = execute("list", "vms")
|
||||||
if output =~ /^"#{Regexp.escape(name)}" \{(.+?)\}$/
|
if existing_vm = output[/^"#{Regexp.escape(name)}" \{(.+?)\}$/, 1]
|
||||||
return $1.to_s
|
return existing_vm
|
||||||
end
|
end
|
||||||
|
|
||||||
nil
|
nil
|
||||||
|
@ -208,17 +208,19 @@ module Vagrant
|
||||||
info.split("\n").each do |line|
|
info.split("\n").each do |line|
|
||||||
# This is how we find the nic that a FP is attached to,
|
# This is how we find the nic that a FP is attached to,
|
||||||
# since this comes first.
|
# since this comes first.
|
||||||
current_nic = $1.to_i if line =~ /^nic(\d+)=".+?"$/
|
if nic = line[/^nic(\d+)=".+?"$/, 1]
|
||||||
|
current_nic = nic.to_i
|
||||||
|
end
|
||||||
|
|
||||||
# If we care about active VMs only, then we check the state
|
# If we care about active VMs only, then we check the state
|
||||||
# to verify the VM is running.
|
# to verify the VM is running.
|
||||||
if active_only && line =~ /^VMState="(.+?)"$/ && $1.to_s != "running"
|
if active_only && (state = line[/^VMState="(.+?)"$/, 1] and state != "running")
|
||||||
return []
|
return []
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse out the forwarded port information
|
# Parse out the forwarded port information
|
||||||
if line =~ /^Forwarding.+?="(.+?),.+?,.*?,(.+?),.*?,(.+?)"$/
|
if matcher = line =~ /^Forwarding.+?="(.+?),.+?,.*?,(.+?),.*?,(.+?)"$/
|
||||||
result = [current_nic, $1.to_s, $2.to_i, $3.to_i]
|
result = [current_nic, matcher[1], matcher[2].to_i, matcher[3].to_i]
|
||||||
@logger.debug(" - #{result.inspect}")
|
@logger.debug(" - #{result.inspect}")
|
||||||
results << result
|
results << result
|
||||||
end
|
end
|
||||||
|
@ -232,14 +234,14 @@ module Vagrant
|
||||||
info = {}
|
info = {}
|
||||||
|
|
||||||
block.split("\n").each do |line|
|
block.split("\n").each do |line|
|
||||||
if line =~ /^Name:\s+(.+?)$/
|
if name = line[/^Name:\s+(.+?)$/, 1]
|
||||||
info[:name] = $1.to_s
|
info[:name] = name
|
||||||
elsif line =~ /^IPAddress:\s+(.+?)$/
|
elsif ip = line[/^IPAddress:\s+(.+?)$/, 1]
|
||||||
info[:ip] = $1.to_s
|
info[:ip] = ip
|
||||||
elsif line =~ /^NetworkMask:\s+(.+?)$/
|
elsif netmask = line[/^NetworkMask:\s+(.+?)$/, 1]
|
||||||
info[:netmask] = $1.to_s
|
info[:netmask] = netmask
|
||||||
elsif line =~ /^Status:\s+(.+?)$/
|
elsif status = line[/^Status:\s+(.+?)$/, 1]
|
||||||
info[:status] = $1.to_s
|
info[:status] = status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -251,11 +253,10 @@ module Vagrant
|
||||||
def read_guest_additions_version
|
def read_guest_additions_version
|
||||||
output = execute("guestproperty", "get", @uuid, "/VirtualBox/GuestAdd/Version",
|
output = execute("guestproperty", "get", @uuid, "/VirtualBox/GuestAdd/Version",
|
||||||
:retryable => true)
|
:retryable => true)
|
||||||
if output =~ /^Value: (.+?)$/
|
if value = output[/^Value: (.+?)$/, 1]
|
||||||
# Split the version by _ since some distro versions modify it
|
# Split the version by _ since some distro versions modify it
|
||||||
# to look like this: 4.1.2_ubuntu, and the distro part isn't
|
# to look like this: 4.1.2_ubuntu, and the distro part isn't
|
||||||
# too important.
|
# too important.
|
||||||
value = $1.to_s
|
|
||||||
return value.split("_").first
|
return value.split("_").first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -268,14 +269,14 @@ module Vagrant
|
||||||
info = {}
|
info = {}
|
||||||
|
|
||||||
block.split("\n").each do |line|
|
block.split("\n").each do |line|
|
||||||
if line =~ /^NetworkName:\s+HostInterfaceNetworking-(.+?)$/
|
if network = line[/^NetworkName:\s+HostInterfaceNetworking-(.+?)$/, 1]
|
||||||
info[:network] = $1.to_s
|
info[:network] = network
|
||||||
elsif line =~ /^IP:\s+(.+?)$/
|
elsif ip = line[/^IP:\s+(.+?)$/, 1]
|
||||||
info[:ip] = $1.to_s
|
info[:ip] = ip
|
||||||
elsif line =~ /^lowerIPAddress:\s+(.+?)$/
|
elsif lower = line[/^lowerIPAddress:\s+(.+?)$/, 1]
|
||||||
info[:lower] = $1.to_s
|
info[:lower] = lower
|
||||||
elsif line =~ /^upperIPAddress:\s+(.+?)$/
|
elsif upper = line[/^upperIPAddress:\s+(.+?)$/, 1]
|
||||||
info[:upper] = $1.to_s
|
info[:upper] = upper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -287,14 +288,14 @@ module Vagrant
|
||||||
info = {}
|
info = {}
|
||||||
|
|
||||||
block.split("\n").each do |line|
|
block.split("\n").each do |line|
|
||||||
if line =~ /^Name:\s+(.+?)$/
|
if name = line[/^Name:\s+(.+?)$/, 1]
|
||||||
info[:name] = $1.to_s
|
info[:name] = name
|
||||||
elsif line =~ /^IPAddress:\s+(.+?)$/
|
elsif ip = line[/^IPAddress:\s+(.+?)$/, 1]
|
||||||
info[:ip] = $1.to_s
|
info[:ip] = ip
|
||||||
elsif line =~ /^NetworkMask:\s+(.+?)$/
|
elsif netmask = line[/^NetworkMask:\s+(.+?)$/, 1]
|
||||||
info[:netmask] = $1.to_s
|
info[:netmask] = netmask
|
||||||
elsif line =~ /^Status:\s+(.+?)$/
|
elsif status = line[/^Status:\s+(.+?)$/, 1]
|
||||||
info[:status] = $1.to_s
|
info[:status] = status
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -308,7 +309,9 @@ module Vagrant
|
||||||
def read_mac_address
|
def read_mac_address
|
||||||
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
||||||
info.split("\n").each do |line|
|
info.split("\n").each do |line|
|
||||||
return $1.to_s if line =~ /^macaddress1="(.+?)"$/
|
if mac = line[/^macaddress1="(.+?)"$/, 1]
|
||||||
|
return mac
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
nil
|
nil
|
||||||
|
@ -316,8 +319,8 @@ module Vagrant
|
||||||
|
|
||||||
def read_machine_folder
|
def read_machine_folder
|
||||||
execute("list", "systemproperties", :retryable => true).split("\n").each do |line|
|
execute("list", "systemproperties", :retryable => true).split("\n").each do |line|
|
||||||
if line =~ /^Default machine folder:\s+(.+?)$/i
|
if folder = line[/^Default machine folder:\s+(.+?)$/i, 1]
|
||||||
return $1.to_s
|
return folder
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -328,21 +331,21 @@ module Vagrant
|
||||||
nics = {}
|
nics = {}
|
||||||
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
||||||
info.split("\n").each do |line|
|
info.split("\n").each do |line|
|
||||||
if line =~ /^nic(\d+)="(.+?)"$/
|
if matcher = line =~ /^nic(\d+)="(.+?)"$/
|
||||||
adapter = $1.to_i
|
adapter = matcher[1].to_i
|
||||||
type = $2.to_sym
|
type = matcher[2].to_sym
|
||||||
|
|
||||||
nics[adapter] ||= {}
|
nics[adapter] ||= {}
|
||||||
nics[adapter][:type] = type
|
nics[adapter][:type] = type
|
||||||
elsif line =~ /^hostonlyadapter(\d+)="(.+?)"$/
|
elsif matcher = line =~ /^hostonlyadapter(\d+)="(.+?)"$/
|
||||||
adapter = $1.to_i
|
adapter = matcher[1].to_i
|
||||||
network = $2.to_s
|
network = matcher[2].to_s
|
||||||
|
|
||||||
nics[adapter] ||= {}
|
nics[adapter] ||= {}
|
||||||
nics[adapter][:hostonly] = network
|
nics[adapter][:hostonly] = network
|
||||||
elsif line =~ /^bridgeadapter(\d+)="(.+?)"$/
|
elsif matcher = line =~ /^bridgeadapter(\d+)="(.+?)"$/
|
||||||
adapter = $1.to_i
|
adapter = matcher[1].to_i
|
||||||
network = $2.to_s
|
network = matcher[2].to_s
|
||||||
|
|
||||||
nics[adapter] ||= {}
|
nics[adapter] ||= {}
|
||||||
nics[adapter][:bridge] = network
|
nics[adapter][:bridge] = network
|
||||||
|
@ -356,8 +359,8 @@ module Vagrant
|
||||||
output = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
output = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
|
||||||
if output =~ /^name="<inaccessible>"$/
|
if output =~ /^name="<inaccessible>"$/
|
||||||
return :inaccessible
|
return :inaccessible
|
||||||
elsif output =~ /^VMState="(.+?)"$/
|
elsif state = output[/^VMState="(.+?)"$/, 1]
|
||||||
return $1.to_sym
|
return state.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
nil
|
nil
|
||||||
|
@ -366,9 +369,7 @@ module Vagrant
|
||||||
def read_used_ports
|
def read_used_ports
|
||||||
ports = []
|
ports = []
|
||||||
execute("list", "vms", :retryable => true).split("\n").each do |line|
|
execute("list", "vms", :retryable => true).split("\n").each do |line|
|
||||||
if line =~ /^".+?" \{(.+?)\}$/
|
if uuid = line[/^".+?" \{(.+?)\}$/, 1]
|
||||||
uuid = $1.to_s
|
|
||||||
|
|
||||||
# Ignore our own used ports
|
# Ignore our own used ports
|
||||||
next if uuid == @uuid
|
next if uuid == @uuid
|
||||||
|
|
||||||
|
@ -384,8 +385,8 @@ module Vagrant
|
||||||
def read_vms
|
def read_vms
|
||||||
results = []
|
results = []
|
||||||
execute("list", "vms", :retryable => true).split("\n").each do |line|
|
execute("list", "vms", :retryable => true).split("\n").each do |line|
|
||||||
if line =~ /^".+?" \{(.+?)\}$/
|
if vm line[/^".+?" \{(.+?)\}$/, 1]
|
||||||
results << $1.to_s
|
results << vm
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -66,9 +66,9 @@ module Vagrant
|
||||||
output = false
|
output = false
|
||||||
|
|
||||||
File.read("/etc/exports").lines.each do |line|
|
File.read("/etc/exports").lines.each do |line|
|
||||||
if line =~ /^# VAGRANT-BEGIN: (.+?)$/
|
if id = line[/^# VAGRANT-BEGIN: (.+?)$/, 1]
|
||||||
if valid_ids.include?($1.to_s)
|
if valid_ids.include?(id)
|
||||||
@logger.debug("Valid ID: #{$1.to_s}")
|
@logger.debug("Valid ID: #{id}")
|
||||||
else
|
else
|
||||||
if !output
|
if !output
|
||||||
# We want to warn the user but we only want to output once
|
# We want to warn the user but we only want to output once
|
||||||
|
@ -76,8 +76,8 @@ module Vagrant
|
||||||
output = true
|
output = true
|
||||||
end
|
end
|
||||||
|
|
||||||
@logger.info("Invalid ID, pruning: #{$1.to_s}")
|
@logger.info("Invalid ID, pruning: #{id}")
|
||||||
nfs_cleanup($1.to_s)
|
nfs_cleanup(id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -63,9 +63,9 @@ module Vagrant
|
||||||
output = false
|
output = false
|
||||||
|
|
||||||
File.read("/etc/exports").lines.each do |line|
|
File.read("/etc/exports").lines.each do |line|
|
||||||
if line =~ /^# VAGRANT-BEGIN: (.+?)$/
|
if id = line[/^# VAGRANT-BEGIN: (.+?)$/, 1]
|
||||||
if valid_ids.include?($1.to_s)
|
if valid_ids.include?(id)
|
||||||
@logger.debug("Valid ID: #{$1.to_s}")
|
@logger.debug("Valid ID: #{id}")
|
||||||
else
|
else
|
||||||
if !output
|
if !output
|
||||||
# We want to warn the user but we only want to output once
|
# We want to warn the user but we only want to output once
|
||||||
|
@ -73,8 +73,8 @@ module Vagrant
|
||||||
output = true
|
output = true
|
||||||
end
|
end
|
||||||
|
|
||||||
@logger.info("Invalid ID, pruning: #{$1.to_s}")
|
@logger.info("Invalid ID, pruning: #{id}")
|
||||||
nfs_cleanup($1.to_s)
|
nfs_cleanup(id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,7 +33,7 @@ Gem::Specification.new do |s|
|
||||||
s.add_development_dependency "rspec-mocks", "~> 2.8.0"
|
s.add_development_dependency "rspec-mocks", "~> 2.8.0"
|
||||||
|
|
||||||
s.files = `git ls-files`.split("\n")
|
s.files = `git ls-files`.split("\n")
|
||||||
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
s.executables = `git ls-files`.split("\n").map{|f| f[/^bin\/(.*)/, 1]}.compact
|
||||||
s.require_path = 'lib'
|
s.require_path = 'lib'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue