From 2e00a007ce166619d61e64fc2946c6cd53531fa2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 26 Jun 2012 14:59:26 -0700 Subject: [PATCH] Move provisioner superclass into the V1 namespace --- lib/vagrant.rb | 1 - lib/vagrant/plugin/v1/provisioner.rb | 50 +++++++++++++++++++ lib/vagrant/provisioners.rb | 44 ---------------- plugins/kernel_v1/config/vm_provisioner.rb | 2 +- plugins/provisioners/chef/provisioner/base.rb | 6 +-- .../provisioners/puppet/provisioner/puppet.rb | 2 +- .../puppet/provisioner/puppet_server.rb | 2 +- plugins/provisioners/shell/provisioner.rb | 2 +- templates/locales/en.yml | 7 ++- 9 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 lib/vagrant/plugin/v1/provisioner.rb delete mode 100644 lib/vagrant/provisioners.rb diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 5c7c1fb01..8696620b5 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -73,7 +73,6 @@ module Vagrant autoload :Guest, 'vagrant/guest' autoload :Hosts, 'vagrant/hosts' autoload :Plugin, 'vagrant/plugin' - autoload :Provisioners, 'vagrant/provisioners' autoload :Registry, 'vagrant/registry' autoload :SSH, 'vagrant/ssh' autoload :TestHelpers, 'vagrant/test_helpers' diff --git a/lib/vagrant/plugin/v1/provisioner.rb b/lib/vagrant/plugin/v1/provisioner.rb new file mode 100644 index 000000000..9ea705fba --- /dev/null +++ b/lib/vagrant/plugin/v1/provisioner.rb @@ -0,0 +1,50 @@ +module Vagrant + module Plugin + module V1 + # This is the base class for a provisioner for the V1 API. A provisioner + # is primarily responsible for installing software on a Vagrant guest. + class Provisioner + # The environment which provisioner is running in. This is the + # action environment, not a Vagrant::Environment. + attr_reader :env + + # The configuration for this provisioner. This will be an instance of + # the `Config` class which is part of the provisioner. + attr_reader :config + + def initialize(env, config) + @env = env + @config = config + end + + # This method is expected to return a class that is used for + # configuring the provisioner. This return value is expected to be + # a subclass of {Config}. + # + # @return [Config] + def self.config_class + end + + # This is the method called to "prepare" the provisioner. This is called + # before any actions are run by the action runner (see {Vagrant::Actions::Runner}). + # This can be used to setup shared folders, forward ports, etc. Whatever is + # necessary on a "meta" level. + # + # No return value is expected. + def prepare + end + + # This is the method called to provision the system. This method + # is expected to do whatever necessary to provision the system (create files, + # SSH, etc.) + def provision! + end + + # This is the method called to when the system is being destroyed + # and allows the provisioners to engage in any cleanup tasks necessary. + def cleanup + end + end + end + end +end diff --git a/lib/vagrant/provisioners.rb b/lib/vagrant/provisioners.rb deleted file mode 100644 index a896c2427..000000000 --- a/lib/vagrant/provisioners.rb +++ /dev/null @@ -1,44 +0,0 @@ -module Vagrant - module Provisioners - # The base class for a "provisioner." A provisioner is responsible for - # provisioning a Vagrant system. - # - # This has been abstracted out so it is easy to provide support for - # multiple solutions. - class Base - include Vagrant::Util - - # The environment which provisioner is running in. This is the - # action environment, not a Vagrant::Environment. - attr_reader :env - - # The configuration for this provisioner. This will be an instance of - # the `Config` class which is part of the provisioner. - attr_reader :config - - def initialize(env, config) - @env = env - @config = config - end - - # This method is expected to return a class that is used for configuration - # for the provisioner. - def self.config_class; end - - # This is the method called to "prepare" the provisioner. This is called - # before any actions are run by the action runner (see {Vagrant::Actions::Runner}). - # This can be used to setup shared folders, forward ports, etc. Whatever is - # necessary on a "meta" level. - def prepare; end - - # This is the method called to provision the system. This method - # is expected to do whatever necessary to provision the system (create files, - # SSH, etc.) - def provision!; end - - # This is the method called to when the system is being destroyed - # and allows the provisioners to engage in any cleanup tasks necessary. - def cleanup; end - end - end -end diff --git a/plugins/kernel_v1/config/vm_provisioner.rb b/plugins/kernel_v1/config/vm_provisioner.rb index 1772593b9..acd96ae19 100644 --- a/plugins/kernel_v1/config/vm_provisioner.rb +++ b/plugins/kernel_v1/config/vm_provisioner.rb @@ -48,7 +48,7 @@ module VagrantPlugins return end - if !(provisioner <= Vagrant::Provisioners::Base) + if !(provisioner <= Vagrant::Plugin::V1::Provisioner) errors.add(I18n.t("vagrant.config.vm.provisioner_invalid_class", :shortcut => shortcut)) end diff --git a/plugins/provisioners/chef/provisioner/base.rb b/plugins/provisioners/chef/provisioner/base.rb index 3b88aeb58..683071369 100644 --- a/plugins/provisioners/chef/provisioner/base.rb +++ b/plugins/provisioners/chef/provisioner/base.rb @@ -6,7 +6,7 @@ module VagrantPlugins # This class is a base class where the common functionality shared between # chef-solo and chef-client provisioning are stored. This is **not an actual # provisioner**. Instead, {ChefSolo} or {ChefServer} should be used. - class Base < Vagrant::Provisioners::Base + class Base < Vagrant::Plugin::V1::Provisioner include Vagrant::Util::Counter def initialize(env, config) @@ -15,10 +15,6 @@ module VagrantPlugins config.provisioning_path ||= "/tmp/vagrant-chef-#{get_and_update_counter(:provisioning_path)}" end - def prepare - raise ChefError, :invalid_provisioner - end - def verify_binary(binary) # Checks for the existence of chef binary and error if it # doesn't exist. diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb index 30d7cf12c..4f1c2dfc9 100644 --- a/plugins/provisioners/puppet/provisioner/puppet.rb +++ b/plugins/provisioners/puppet/provisioner/puppet.rb @@ -7,7 +7,7 @@ module VagrantPlugins error_namespace("vagrant.provisioners.puppet") end - class Puppet < Vagrant::Provisioners::Base + class Puppet < Vagrant::Plugin::V1::Provisioner class Config < Vagrant::Plugin::V1::Config attr_accessor :manifest_file attr_accessor :manifests_path diff --git a/plugins/provisioners/puppet/provisioner/puppet_server.rb b/plugins/provisioners/puppet/provisioner/puppet_server.rb index 537a3d94f..bc59eb995 100644 --- a/plugins/provisioners/puppet/provisioner/puppet_server.rb +++ b/plugins/provisioners/puppet/provisioner/puppet_server.rb @@ -5,7 +5,7 @@ module VagrantPlugins error_namespace("vagrant.provisioners.puppet_server") end - class PuppetServer < Base + class PuppetServer < Vagrant::Plugin::V1::Provisioner class Config < Vagrant::Plugin::V1::Config attr_accessor :puppet_server attr_accessor :puppet_node diff --git a/plugins/provisioners/shell/provisioner.rb b/plugins/provisioners/shell/provisioner.rb index 1f7ef866d..00e4301b0 100644 --- a/plugins/provisioners/shell/provisioner.rb +++ b/plugins/provisioners/shell/provisioner.rb @@ -3,7 +3,7 @@ require "tempfile" module VagrantPlugins module Shell - class Provisioner < Vagrant::Provisioners::Base + class Provisioner < Vagrant::Plugin::V1::Provisioner class Config < Vagrant::Plugin::V1::Config attr_accessor :inline attr_accessor :path diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 7a4f47010..5c6c8ed18 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -251,7 +251,9 @@ en: shared_folder_nfs_owner_group: |- Shared folder '%{name}': NFS does not support the owner/group settings. provisioner_not_found: "The provisioner '%{shortcut}' doesn't exist." - provisioner_invalid_class: "The provisioner '%{shortcut}' must inherit from `Vagrant::Provisioners::Base`." + provisioner_invalid_class: |- + The provisioner '%{shortcut}' must inherit from + `Vagrant::Plugin::V1::Provisioner`." #------------------------------------------------------------------------------- # Translations for commands. e.g. `vagrant x` @@ -647,9 +649,6 @@ en: running_client_again: "Running chef-client again (failed to converge)..." running_solo: "Running chef-solo..." running_solo_again: "Running chef-solo again (failed to converge)..." - invalid_provisioner: |- - Vagrant::Provisioners::Chef is not a valid provisioner! Use - ChefSolo or ChefClient instead. missing_shared_folders: |- Shared folders that Chef requires are missing on the virtual machine. This is usually due to configuration changing after already booting the