diff --git a/plugins/guests/openbsd/cap/change_host_name.rb b/plugins/guests/openbsd/cap/change_host_name.rb new file mode 100644 index 000000000..d47b659c8 --- /dev/null +++ b/plugins/guests/openbsd/cap/change_host_name.rb @@ -0,0 +1,14 @@ +module VagrantPlugins + module GuestOpenBSD + module Cap + class ChangeHostName + def self.change_host_name(machine, name) + if !machine.communicate.test("hostname | grep '^#{name}$'") + machine.communicate.sudo("sh -c \"echo '#{name}' > /etc/myname\"") + machine.communicate.sudo("hostname #{name}") + end + end + end + end + end +end diff --git a/plugins/guests/openbsd/cap/configure_networks.rb b/plugins/guests/openbsd/cap/configure_networks.rb new file mode 100644 index 000000000..820627a80 --- /dev/null +++ b/plugins/guests/openbsd/cap/configure_networks.rb @@ -0,0 +1,40 @@ +require "tempfile" + +require "vagrant/util/template_renderer" + +module VagrantPlugins + module GuestOpenBSD + module Cap + class ConfigureNetworks + include Vagrant::Util + + def self.configure_networks(machine, networks) + networks.each do |network| + entry = TemplateRenderer.render("guests/openbsd/network_#{network[:type]}", + :options => network) + + temp = Tempfile.new("vagrant") + temp.binmode + temp.write(entry) + temp.close + + ifname = "em#{network[:interface]}" + + machine.communicate.upload(temp.path, "/tmp/vagrant-network-entry") + machine.communicate.sudo("mv /tmp/vagrant-network-entry /etc/hostname.#{ifname}") + + # remove old configurations + machine.communicate.sudo("sudo ifconfig #{ifname} inet delete", { :error_check => false }) + machine.communicate.sudo("pkill -f 'dhclient: #{ifname}'", { :error_check => false }) + + if network[:type].to_sym == :static + machine.communicate.sudo("ifconfig #{ifname} inet #{network[:ip]} netmask #{network[:netmask]}") + elsif network[:type].to_sym == :dhcp + machine.communicate.sudo("dhclient #{ifname}") + end + end + end + end + end + end +end diff --git a/plugins/guests/openbsd/cap/mount_nfs_folder.rb b/plugins/guests/openbsd/cap/mount_nfs_folder.rb new file mode 100644 index 000000000..20a97b9a6 --- /dev/null +++ b/plugins/guests/openbsd/cap/mount_nfs_folder.rb @@ -0,0 +1,14 @@ +module VagrantPlugins + module GuestOpenBSD + module Cap + class MountNFSFolder + def self.mount_nfs_folder(machine, ip, folders) + folders.each do |name, opts| + machine.communicate.sudo("mkdir -p #{opts[:guestpath]}") + machine.communicate.sudo("mount '#{ip}:#{opts[:hostpath]}' '#{opts[:guestpath]}'") + end + end + end + end + end +end diff --git a/plugins/guests/openbsd/plugin.rb b/plugins/guests/openbsd/plugin.rb index b3e3312a8..fc1043a53 100644 --- a/plugins/guests/openbsd/plugin.rb +++ b/plugins/guests/openbsd/plugin.rb @@ -11,10 +11,25 @@ module VagrantPlugins Guest end + guest_capability("openbsd", "change_host_name") do + require_relative "cap/change_host_name" + Cap::ChangeHostName + end + + guest_capability("openbsd", "configure_networks") do + require_relative "cap/configure_networks" + Cap::ConfigureNetworks + end + guest_capability("openbsd", "halt") do require_relative "cap/halt" Cap::Halt end + + guest_capability("openbsd", "mount_nfs_folder") do + require_relative "cap/mount_nfs_folder" + Cap::MountNFSFolder + end end end end diff --git a/templates/guests/openbsd/network_dhcp.erb b/templates/guests/openbsd/network_dhcp.erb new file mode 100644 index 000000000..72ab18f1e --- /dev/null +++ b/templates/guests/openbsd/network_dhcp.erb @@ -0,0 +1 @@ +dhcp diff --git a/templates/guests/openbsd/network_static.erb b/templates/guests/openbsd/network_static.erb new file mode 100644 index 000000000..7b62997bf --- /dev/null +++ b/templates/guests/openbsd/network_static.erb @@ -0,0 +1 @@ +inet <%= options[:ip] %> <%= options[:netmask] %> NONE