Add remote vagrantfile implementation
This commit is contained in:
parent
e47da98810
commit
972ba095e9
@ -270,6 +270,7 @@ module Vagrant
|
||||
->{ Vagrant::MachineIndex::Entry.extend(Vagrant::MachineIndex::Entry::Remote::ClassMethods) },
|
||||
->{ Vagrant::Action::Builtin::MixinSyncedFolders.prepend(Vagrant::Action::Builtin::Remote::MixinSyncedFolders) },
|
||||
->{ Vagrant::Action::Builtin::SSHRun.prepend(Vagrant::Action::Builtin::Remote::SSHRun) },
|
||||
->{ Vagrant::Vagrantfile.prepend(Vagrant::Vagrantfile::Remote) },
|
||||
->{ Vagrant::Util::SSH.prepend(Vagrant::Util::Remote::SSH) },
|
||||
].freeze
|
||||
end
|
||||
|
||||
@ -12,6 +12,8 @@ module Vagrant
|
||||
# loading the configuration of a specific machine/provider combo,
|
||||
# etc.
|
||||
class Vagrantfile
|
||||
autoload :Remote, "vagrant/vagrantfile/remote"
|
||||
|
||||
# This is the configuration loaded as-is given the loader and
|
||||
# keys to #initialize.
|
||||
attr_reader :config
|
||||
|
||||
67
lib/vagrant/vagrantfile/remote.rb
Normal file
67
lib/vagrant/vagrantfile/remote.rb
Normal file
@ -0,0 +1,67 @@
|
||||
# lib/remote.rb
|
||||
|
||||
module Vagrant
|
||||
class Vagrantfile
|
||||
module Remote
|
||||
# Add an attribute reader for the client
|
||||
# when applied to the Machine class
|
||||
def self.prepended(klass)
|
||||
klass.class_eval do
|
||||
attr_reader :client
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(*_, client:)
|
||||
@client = client
|
||||
@config = ConfigWrapper.new(client: client)
|
||||
end
|
||||
|
||||
# @return [Machine]
|
||||
def machine(name, provider, _, _, _)
|
||||
client.machine(name, provider)
|
||||
end
|
||||
|
||||
def machine_names
|
||||
client.target_names
|
||||
end
|
||||
|
||||
def machine_config(name, provider, _, _, validate_provider)
|
||||
client.machine_config(name, provider, validate_provider)
|
||||
end
|
||||
end
|
||||
|
||||
class ConfigWrapper
|
||||
def initialize(client:)
|
||||
@client = client
|
||||
@logger = Log4r::Logger.new(self.class.name.downcase)
|
||||
@root = Vagrant::Config::V2::Root.new(Vagrant.plugin("2").local_manager.config)
|
||||
end
|
||||
|
||||
def method_missing(*args, **opts, &block)
|
||||
case args.size
|
||||
when 1
|
||||
namespace = args.first
|
||||
when 2
|
||||
if args.first.to_s != "[]"
|
||||
raise ArgumentError,
|
||||
"Expected #[] but received ##{args.first} on config wrapper"
|
||||
end
|
||||
namespace = args.last
|
||||
else
|
||||
#raise ArgumentError,
|
||||
@logger.error("Cannot handle wrapped request for: #{args.inspect}")
|
||||
end
|
||||
|
||||
# TODO: Check args, opts, and block and return error if any are set
|
||||
@logger.info("config wrapper fetching config value for namespace: #{namespace}")
|
||||
begin
|
||||
@client.get_config(namespace)
|
||||
rescue => err
|
||||
val = @root.send(*args)
|
||||
@logger.warn("failed to get config value, reason: #{err} - returning val: #{val}")
|
||||
val
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user