Convert arch to capabilities

This commit is contained in:
Mitchell Hashimoto 2013-04-04 11:39:58 -07:00
parent 0fbe9b0aca
commit 7f33081387
4 changed files with 52 additions and 35 deletions

View File

@ -0,0 +1,18 @@
module VagrantPlugins
module GuestArch
module Cap
class ChangeHostName
def self.change_host_name(machine, name)
machine.communicate.tap do |comm|
# Only do this if the hostname is not already set
if !comm.test("sudo hostname | grep '#{name}'")
comm.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/rc.conf")
comm.sudo("hostname #{name}")
comm.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} @' /etc/hosts")
end
end
end
end
end
end
end

View File

@ -0,0 +1,23 @@
module VagrantPlugins
module GuestArch
module Cap
class ConfigureNetworks
def self.configure_networks(machine, networks)
networks.each do |network|
entry = TemplateRenderer.render("guests/arch/network_#{network[:type]}",
:options => network)
temp = Tempfile.new("vagrant")
temp.binmode
temp.write(entry)
temp.close
machine.communicate.upload(temp.path, "/tmp/vagrant_network")
machine.communicate.sudo("mv /tmp/vagrant_network /etc/network.d/interfaces/eth#{network[:interface]}")
machine.communicate.sudo("netcfg interfaces/eth#{network[:interface]}")
end
end
end
end
end
end

View File

@ -1,45 +1,11 @@
require 'set'
require 'tempfile'
require "vagrant" require "vagrant"
require 'vagrant/util/template_renderer'
require Vagrant.source_root.join("plugins/guests/linux/guest")
module VagrantPlugins module VagrantPlugins
module GuestArch module GuestArch
class Guest < VagrantPlugins::GuestLinux::Guest class Guest < Vagrant.plugin("2", :guest)
# Make the TemplateRenderer top-level
include Vagrant::Util
def detect?(machine) def detect?(machine)
machine.communicate.test("cat /etc/arch-release") machine.communicate.test("cat /etc/arch-release")
end end
def change_host_name(name)
# Only do this if the hostname is not already set
if !vm.communicate.test("sudo hostname | grep '#{name}'")
vm.communicate.sudo("sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/rc.conf")
vm.communicate.sudo("hostname #{name}")
vm.communicate.sudo("sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} @' /etc/hosts")
end
end
def configure_networks(networks)
networks.each do |network|
entry = TemplateRenderer.render("guests/arch/network_#{network[:type]}",
:options => network)
temp = Tempfile.new("vagrant")
temp.binmode
temp.write(entry)
temp.close
vm.communicate.upload(temp.path, "/tmp/vagrant_network")
vm.communicate.sudo("mv /tmp/vagrant_network /etc/network.d/interfaces/eth#{network[:interface]}")
vm.communicate.sudo("netcfg interfaces/eth#{network[:interface]}")
end
end
end end
end end
end end

View File

@ -10,6 +10,16 @@ module VagrantPlugins
require File.expand_path("../guest", __FILE__) require File.expand_path("../guest", __FILE__)
Guest Guest
end end
guest_capability("arch", "change_host_name") do
require_relative "cap/change_host_name"
Cap::ChangeHostName
end
guest_capability("arch", "configure_networks") do
require_relative "cap/configure_networks"
Cap::ConfigureNetworks
end
end end
end end
end end