From 21db4470a0c5344933ffa42285fa1588f5676944 Mon Sep 17 00:00:00 2001 From: Fabio Rapposelli Date: Mon, 20 Apr 2015 10:13:21 -0700 Subject: [PATCH] Add Guest support for VMware Photon. Signed-off-by: Fabio Rapposelli --- plugins/guests/photon/cap/change_host_name.rb | 15 ++++++++++ .../guests/photon/cap/configure_networks.rb | 27 +++++++++++++++++ plugins/guests/photon/cap/docker.rb | 11 +++++++ plugins/guests/photon/guest.rb | 9 ++++++ plugins/guests/photon/plugin.rb | 30 +++++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 plugins/guests/photon/cap/change_host_name.rb create mode 100644 plugins/guests/photon/cap/configure_networks.rb create mode 100644 plugins/guests/photon/cap/docker.rb create mode 100644 plugins/guests/photon/guest.rb create mode 100644 plugins/guests/photon/plugin.rb diff --git a/plugins/guests/photon/cap/change_host_name.rb b/plugins/guests/photon/cap/change_host_name.rb new file mode 100644 index 000000000..5249dadba --- /dev/null +++ b/plugins/guests/photon/cap/change_host_name.rb @@ -0,0 +1,15 @@ +module VagrantPlugins + module GuestPhoton + module Cap + class ChangeHostName + def self.change_host_name(machine, name) + machine.communicate.tap do |comm| + unless comm.test("sudo hostname --fqdn | grep '#{name}'") + comm.sudo("hostname #{name.split('.')[0]}") + end + end + end + end + end + end +end diff --git a/plugins/guests/photon/cap/configure_networks.rb b/plugins/guests/photon/cap/configure_networks.rb new file mode 100644 index 000000000..5e06f00eb --- /dev/null +++ b/plugins/guests/photon/cap/configure_networks.rb @@ -0,0 +1,27 @@ +require 'tempfile' +require 'vagrant/util/template_renderer' + +module VagrantPlugins + module GuestPhoton + module Cap + class ConfigureNetworks + include Vagrant::Util + + def self.configure_networks(machine, networks) + machine.communicate.tap do |comm| + # Read network interface names + interfaces = [] + comm.sudo("ifconfig | grep 'eth' | cut -f1 -d' '") do |_, result| + interfaces = result.split("\n") + end + + # Configure interfaces + networks.each do |network| + comm.sudo("ifconfig #{interfaces[network[:interface].to_i]} #{network[:ip]} netmask #{network[:netmask]}") + end + end + end + end + end + end +end diff --git a/plugins/guests/photon/cap/docker.rb b/plugins/guests/photon/cap/docker.rb new file mode 100644 index 000000000..954777908 --- /dev/null +++ b/plugins/guests/photon/cap/docker.rb @@ -0,0 +1,11 @@ +module VagrantPlugins + module GuestPhoton + module Cap + module Docker + def self.docker_daemon_running(machine) + machine.communicate.test('test -S /run/docker.sock') + end + end + end + end +end diff --git a/plugins/guests/photon/guest.rb b/plugins/guests/photon/guest.rb new file mode 100644 index 000000000..c33a9f8a2 --- /dev/null +++ b/plugins/guests/photon/guest.rb @@ -0,0 +1,9 @@ +module VagrantPlugins + module GuestPhoton + class Guest < Vagrant.plugin('2', :guest) + def detect?(machine) + machine.communicate.test("cat /etc/photon-release | grep 'VMware Photon Linux'") + end + end + end +end diff --git a/plugins/guests/photon/plugin.rb b/plugins/guests/photon/plugin.rb new file mode 100644 index 000000000..a56a0f44f --- /dev/null +++ b/plugins/guests/photon/plugin.rb @@ -0,0 +1,30 @@ +require 'vagrant' + +module VagrantPlugins + module GuestPhoton + class Plugin < Vagrant.plugin('2') + name 'VMware Photon guest' + description 'VMware Photon guest support.' + + guest('photon', 'linux') do + require File.expand_path("../guest", __FILE__) + Guest + end + + guest_capability('photon', 'change_host_name') do + require_relative 'cap/change_host_name' + Cap::ChangeHostName + end + + guest_capability('photon', 'configure_networks') do + require_relative 'cap/configure_networks' + Cap::ConfigureNetworks + end + + guest_capability('photon', 'docker_daemon_running') do + require_relative 'cap/docker' + Cap::Docker + end + end + end +end