more capabilities for OpenBSD guest
This commit is contained in:
parent
2b3951b91c
commit
91db685295
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
dhcp
|
|
@ -0,0 +1 @@
|
|||
inet <%= options[:ip] %> <%= options[:netmask] %> NONE
|
Loading…
Reference in New Issue