From 7f33081387d1cfe726414b926c6c204e67f0e08d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 4 Apr 2013 11:39:58 -0700 Subject: [PATCH] Convert arch to capabilities --- plugins/guests/arch/cap/change_host_name.rb | 18 ++++++++++ plugins/guests/arch/cap/configure_networks.rb | 23 ++++++++++++ plugins/guests/arch/guest.rb | 36 +------------------ plugins/guests/arch/plugin.rb | 10 ++++++ 4 files changed, 52 insertions(+), 35 deletions(-) create mode 100644 plugins/guests/arch/cap/change_host_name.rb create mode 100644 plugins/guests/arch/cap/configure_networks.rb diff --git a/plugins/guests/arch/cap/change_host_name.rb b/plugins/guests/arch/cap/change_host_name.rb new file mode 100644 index 000000000..a32da048e --- /dev/null +++ b/plugins/guests/arch/cap/change_host_name.rb @@ -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 diff --git a/plugins/guests/arch/cap/configure_networks.rb b/plugins/guests/arch/cap/configure_networks.rb new file mode 100644 index 000000000..11fda5ded --- /dev/null +++ b/plugins/guests/arch/cap/configure_networks.rb @@ -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 diff --git a/plugins/guests/arch/guest.rb b/plugins/guests/arch/guest.rb index a354f6799..116484fd8 100644 --- a/plugins/guests/arch/guest.rb +++ b/plugins/guests/arch/guest.rb @@ -1,45 +1,11 @@ -require 'set' -require 'tempfile' - require "vagrant" -require 'vagrant/util/template_renderer' - -require Vagrant.source_root.join("plugins/guests/linux/guest") module VagrantPlugins module GuestArch - class Guest < VagrantPlugins::GuestLinux::Guest - # Make the TemplateRenderer top-level - include Vagrant::Util - + class Guest < Vagrant.plugin("2", :guest) def detect?(machine) machine.communicate.test("cat /etc/arch-release") 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 diff --git a/plugins/guests/arch/plugin.rb b/plugins/guests/arch/plugin.rb index 36c2d76ce..ab3a0b016 100644 --- a/plugins/guests/arch/plugin.rb +++ b/plugins/guests/arch/plugin.rb @@ -10,6 +10,16 @@ module VagrantPlugins require File.expand_path("../guest", __FILE__) Guest 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