Update remote plugins to subclass V2 plugins
This commit is contained in:
parent
095a0f8847
commit
aa98e48e28
@ -1,74 +1,66 @@
|
||||
module Vagrant
|
||||
module Plugin
|
||||
module Remote
|
||||
class Communicator
|
||||
# This module enables Communicator for server mode
|
||||
module Remote
|
||||
class Communicator < V2::Communicator
|
||||
# Add an attribute accesor for the client
|
||||
# when applied to the Communicator class
|
||||
attr_accessor :client
|
||||
|
||||
# Add an attribute accesor for the client
|
||||
# when applied to the Communicator class
|
||||
def self.prepended(klass)
|
||||
klass.class_eval do
|
||||
attr_accessor :client
|
||||
end
|
||||
end
|
||||
def initialize(machine)
|
||||
@logger = Log4r::Logger.new("vagrant::remote::communicator")
|
||||
@logger.debug("initializing communicator with remote backend")
|
||||
@machine = machine
|
||||
@client = machine.client.communicate
|
||||
end
|
||||
|
||||
def initialize(machine)
|
||||
@logger = Log4r::Logger.new("vagrant::remote::communicator")
|
||||
@logger.debug("initializing communicator with remote backend")
|
||||
@machine = machine
|
||||
@client = machine.client.communicate
|
||||
end
|
||||
def ready?
|
||||
@logger.debug("remote communicator, checking if it's ready")
|
||||
@client.ready(@machine)
|
||||
end
|
||||
|
||||
def ready?
|
||||
@logger.debug("remote communicator, checking if it's ready")
|
||||
@client.ready(@machine)
|
||||
end
|
||||
def wait_for_ready(time)
|
||||
@logger.debug("remote communicator, waiting for ready")
|
||||
@client.wait_for_ready(@machine, time)
|
||||
end
|
||||
|
||||
def wait_for_ready(time)
|
||||
@logger.debug("remote communicator, waiting for ready")
|
||||
@client.wait_for_ready(@machine, time)
|
||||
end
|
||||
def download(from, to)
|
||||
@logger.debug("remote communicator, downloading #{from} -> #{to}")
|
||||
@client.download(@machine, from, to)
|
||||
end
|
||||
|
||||
def download(from, to)
|
||||
@logger.debug("remote communicator, downloading #{from} -> #{to}")
|
||||
@client.download(@machine, from, to)
|
||||
end
|
||||
def upload(from, to)
|
||||
@logger.debug("remote communicator, uploading #{from} -> #{to}")
|
||||
@client.upload(@machine, from, to)
|
||||
end
|
||||
|
||||
def upload(from, to)
|
||||
@logger.debug("remote communicator, uploading #{from} -> #{to}")
|
||||
@client.upload(@machine, from, to)
|
||||
end
|
||||
def execute(cmd, opts=nil, &block)
|
||||
@logger.debug("remote communicator, executing command")
|
||||
res = @client.execute(@machine, cmd, opts)
|
||||
yield :stdout, res.stdout if block_given?
|
||||
yield :stderr, res.stderr if block_given?
|
||||
res.exit_code
|
||||
end
|
||||
|
||||
def execute(cmd, opts=nil, &block)
|
||||
@logger.debug("remote communicator, executing command")
|
||||
res = @client.execute(@machine, cmd, opts)
|
||||
yield :stdout, res.stdout if block_given?
|
||||
yield :stderr, res.stderr if block_given?
|
||||
res.exit_code
|
||||
end
|
||||
|
||||
def sudo(cmd, opts=nil, &block)
|
||||
@logger.debug("remote communicator, executing (privileged) command")
|
||||
res = @client.privileged_execute(@machine, cmd, opts)
|
||||
yield :stdout, res.stdout if block_given?
|
||||
yield :stderr, res.stderr if block_given?
|
||||
res.exit_code
|
||||
end
|
||||
def sudo(cmd, opts=nil, &block)
|
||||
@logger.debug("remote communicator, executing (privileged) command")
|
||||
res = @client.privileged_execute(@machine, cmd, opts)
|
||||
yield :stdout, res.stdout if block_given?
|
||||
yield :stderr, res.stderr if block_given?
|
||||
res.exit_code
|
||||
end
|
||||
|
||||
def test(cmd, opts=nil)
|
||||
@logger.debug("remote communicator, testing command")
|
||||
@client.test(@machine, cmd, opts)
|
||||
end
|
||||
def test(cmd, opts=nil)
|
||||
@logger.debug("remote communicator, testing command")
|
||||
@client.test(@machine, cmd, opts)
|
||||
end
|
||||
|
||||
def reset!
|
||||
@logger.debug("remote communicator, reseting")
|
||||
@client.reset(@machine)
|
||||
end
|
||||
|
||||
def to_proto
|
||||
client.proto
|
||||
end
|
||||
def reset!
|
||||
@logger.debug("remote communicator, reseting")
|
||||
@client.reset(@machine)
|
||||
end
|
||||
|
||||
def to_proto
|
||||
client.proto
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,61 +1,55 @@
|
||||
module Vagrant
|
||||
module Plugin
|
||||
module Remote
|
||||
class Provider
|
||||
# This module enables Provider for server mode
|
||||
module Remote
|
||||
class Provider < V2::Provider
|
||||
class << self
|
||||
attr_reader :client
|
||||
end
|
||||
|
||||
# Add an attribute accesor for the client
|
||||
# when applied to the Provider class
|
||||
def self.prepended(klass)
|
||||
klass.class_eval do
|
||||
attr_accessor :client
|
||||
end
|
||||
end
|
||||
attr_accessor :client
|
||||
|
||||
def self.usable?(raise_error=false)
|
||||
client.usable?
|
||||
end
|
||||
def self.usable?(raise_error=false)
|
||||
client.usable?
|
||||
end
|
||||
|
||||
def self.installed?
|
||||
client.installed?
|
||||
end
|
||||
def self.installed?
|
||||
client.installed?
|
||||
end
|
||||
|
||||
def initialize(machine, **opts)
|
||||
@logger = Log4r::Logger.new("vagrant::remote::provider")
|
||||
@logger.debug("initializing provider with remote backend")
|
||||
@machine = machine
|
||||
if opts[:client].nil?
|
||||
raise ArgumentError,
|
||||
"Remote client is required for `#{self.class.name}`"
|
||||
end
|
||||
@client = opts[:client]
|
||||
super(machine)
|
||||
def initialize(machine, **opts)
|
||||
@logger = Log4r::Logger.new("vagrant::remote::provider")
|
||||
@logger.debug("initializing provider with remote backend")
|
||||
@machine = machine
|
||||
if opts[:client].nil?
|
||||
raise ArgumentError,
|
||||
"Remote client is required for `#{self.class.name}`"
|
||||
end
|
||||
@client = opts[:client]
|
||||
super(machine)
|
||||
end
|
||||
|
||||
def action(name)
|
||||
client.action(@machine.to_proto, name)
|
||||
end
|
||||
def action(name)
|
||||
client.action(@machine.to_proto, name)
|
||||
end
|
||||
|
||||
def machine_id_changed
|
||||
client.machine_id_changed(@machine.to_proto)
|
||||
end
|
||||
def machine_id_changed
|
||||
client.machine_id_changed(@machine.to_proto)
|
||||
end
|
||||
|
||||
def ssh_info
|
||||
client.ssh_info(@machine.to_proto)
|
||||
end
|
||||
def ssh_info
|
||||
client.ssh_info(@machine.to_proto)
|
||||
end
|
||||
|
||||
def state
|
||||
client.state(@machine.to_proto)
|
||||
end
|
||||
def state
|
||||
client.state(@machine.to_proto)
|
||||
end
|
||||
|
||||
def initialize_capabilities!(*args, **opts)
|
||||
# no-op
|
||||
end
|
||||
def initialize_capabilities!(*args, **opts)
|
||||
# no-op
|
||||
end
|
||||
|
||||
def to_proto
|
||||
client.proto
|
||||
end
|
||||
def to_proto
|
||||
client.proto
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,25 +1,23 @@
|
||||
module Vagrant
|
||||
module Plugin
|
||||
module Remote
|
||||
class Push
|
||||
# This module enables Push for server mode
|
||||
module Remote
|
||||
# Add an attribute accesor for the client
|
||||
# when applied to the Push class
|
||||
def self.prepended(klass)
|
||||
klass.class_eval do
|
||||
attr_accessor :client
|
||||
end
|
||||
end
|
||||
# This class enables Push for server mode
|
||||
class Push < V2::Push
|
||||
# Add an attribute accesor for the client
|
||||
# when applied to the Push class
|
||||
attr_accessor :client
|
||||
|
||||
def initialize(env, config, **opts)
|
||||
@client = opts[:client]
|
||||
super(env, config)
|
||||
def initialize(env, config, **opts)
|
||||
if opts[:client].nil?
|
||||
raise ArgumentError,
|
||||
"Remote client is required for `#{self.class.name}`"
|
||||
end
|
||||
@client = opts[:client]
|
||||
super(env, config)
|
||||
end
|
||||
|
||||
def push
|
||||
client.push
|
||||
end
|
||||
def push
|
||||
client.push
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,109 +1,102 @@
|
||||
module Vagrant
|
||||
module Plugin
|
||||
module Remote
|
||||
class SyncedFolder
|
||||
# This module enables SyncedFolder for server mode
|
||||
module Remote
|
||||
class SyncedFolder < V2::SyncedFolder
|
||||
# Add an attribute accesor for the client
|
||||
# when applied to the SyncedFolder class
|
||||
attr_accessor :client
|
||||
|
||||
# Add an attribute accesor for the client
|
||||
# when applied to the SyncedFolder class
|
||||
def self.prepended(klass)
|
||||
klass.class_eval do
|
||||
attr_accessor :client
|
||||
end
|
||||
def initialize(client: nil)
|
||||
if client.nil?
|
||||
raise ArgumentError,
|
||||
"Remote client is required for `#{self.class.name}`"
|
||||
end
|
||||
@client = client
|
||||
@logger = Log4r::Logger.new("vagrant::remote::synced_folder::#{self.class.name}")
|
||||
if client.nil?
|
||||
@logger.warn("synced folder remote client is unset")
|
||||
end
|
||||
end
|
||||
|
||||
def _initialize(machine, synced_folder_type, client=nil)
|
||||
if client.nil? && Manager.client
|
||||
@client = Manager.client.get_plugin(
|
||||
name: synced_folder_type,
|
||||
type: :synced_folder,
|
||||
)
|
||||
else
|
||||
raise "Cannot set remote client for synced folder, no manager available"
|
||||
end
|
||||
|
||||
def initialize(client: nil)
|
||||
@client = client
|
||||
@logger = Log4r::Logger.new("vagrant::remote::synced_folder::#{self.class.name}")
|
||||
if client.nil?
|
||||
@logger.warn("synced folder remote client is unset")
|
||||
end
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def _initialize(machine, synced_folder_type, client=nil)
|
||||
if client.nil?
|
||||
info = Thread.current.thread_variable_get(:service_info)
|
||||
if info&.plugin_manager
|
||||
@client = info.plugin_manager.get_plugin(
|
||||
name: synced_folder_type,
|
||||
type: :synced_folder,
|
||||
)
|
||||
else
|
||||
raise "Cannot set remote client for synced folder, no manager available"
|
||||
end
|
||||
end
|
||||
self
|
||||
end
|
||||
def initialize_capabilities!(host, hosts, capabilities, *args)
|
||||
# no-op
|
||||
end
|
||||
|
||||
def initialize_capabilities!(host, hosts, capabilities, *args)
|
||||
# no-op
|
||||
end
|
||||
# @param [Machine] machine
|
||||
# @param [Hash] folders The folders to remove. This will not contain
|
||||
# any folders that should remain.
|
||||
# @param [Hash] opts Any options for the synced folders.
|
||||
def prepare(machine, folders, opts)
|
||||
client.prepare(machine.to_proto, folders, opts)
|
||||
end
|
||||
|
||||
# @param [Machine] machine
|
||||
# @param [Boolean] raise_error If true, should raise an exception
|
||||
# if it isn't usable.
|
||||
# @return [Boolean]
|
||||
def usable?(machine, raise_error=false)
|
||||
begin
|
||||
client.usable(machine.to_proto)
|
||||
rescue
|
||||
raise if raise_error
|
||||
end
|
||||
# @param [Machine] machine
|
||||
# @param [Boolean] raise_error If true, should raise an exception
|
||||
# if it isn't usable.
|
||||
# @return [Boolean]
|
||||
def usable?(machine, raise_error=false)
|
||||
begin
|
||||
client.usable(machine.to_proto)
|
||||
rescue
|
||||
raise if raise_error
|
||||
end
|
||||
end
|
||||
|
||||
# @param [Machine] machine
|
||||
# @param [Hash] folders The folders to remove. This will not contain
|
||||
# any folders that should remain.
|
||||
# @param [Hash] opts Any options for the synced folders.
|
||||
def prepare(machine, folders, opts)
|
||||
client.prepare(machine.to_proto, folders, opts)
|
||||
end
|
||||
# @param [Machine] machine
|
||||
# @param [Hash] folders Folders to remove
|
||||
# @param [Hash] opts Any options for the synced folders.
|
||||
def enable(machine, folders, opts)
|
||||
client.enable(machine, folders, opts)
|
||||
end
|
||||
|
||||
# @param [Machine] machine
|
||||
# @param [Hash] folders The folders to remove. This will not contain
|
||||
# any folders that should remain.
|
||||
# @param [Hash] opts Any options for the synced folders.
|
||||
def enable(machine, folders, opts)
|
||||
client.enable(machine.to_proto, folders, opts)
|
||||
end
|
||||
# @param [Machine] machine The machine to modify.
|
||||
# @param [Hash] folders The folders to remove. This will not contain
|
||||
# any folders that should remain.
|
||||
# @param [Hash] opts Any options for the synced folders.
|
||||
def disable(machine, folders, opts)
|
||||
client.disable(machine, folders, opts)
|
||||
end
|
||||
|
||||
# @param [Machine] machine The machine to modify.
|
||||
# @param [Hash] folders The folders to remove. This will not contain
|
||||
# any folders that should remain.
|
||||
# @param [Hash] opts Any options for the synced folders.
|
||||
def disable(machine, folders, opts)
|
||||
client.disable(machine.to_proto, folders, opts)
|
||||
end
|
||||
# @param [Machine] machine
|
||||
# @param [Hash] opts
|
||||
def cleanup(machine, opts)
|
||||
client.cleanup(machine, opts)
|
||||
end
|
||||
|
||||
# @param [Machine] machine
|
||||
# @param [Hash] opts
|
||||
def cleanup(machine, opts)
|
||||
client.cleanup(machine.to_proto, opts)
|
||||
end
|
||||
# Executes the capability with the given name, optionally passing more
|
||||
# arguments onwards to the capability. If the capability returns a value,
|
||||
# it will be returned.
|
||||
#
|
||||
# @param [Symbol] cap_name Name of the capability
|
||||
def capability(cap_name, *args)
|
||||
@logger.debug("running remote synced folder capability #{cap_name} with args #{args}")
|
||||
client.capability(cap_name, *args)
|
||||
end
|
||||
|
||||
# Executes the capability with the given name, optionally passing more
|
||||
# arguments onwards to the capability. If the capability returns a value,
|
||||
# it will be returned.
|
||||
#
|
||||
# @param [Symbol] cap_name Name of the capability
|
||||
def capability(cap_name, *args)
|
||||
@logger.debug("running remote synced folder capability #{cap_name} with args #{args}")
|
||||
client.capability(cap_name, *args)
|
||||
end
|
||||
# Tests whether the given capability is possible.
|
||||
#
|
||||
# @param [Symbol] cap_name Capability name
|
||||
# @return [Boolean]
|
||||
def capability?(cap_name)
|
||||
@logger.debug("checking for remote synced folder capability #{cap_name}")
|
||||
client.has_capability?(cap_name)
|
||||
end
|
||||
|
||||
# Tests whether the given capability is possible.
|
||||
#
|
||||
# @param [Symbol] cap_name Capability name
|
||||
# @return [Boolean]
|
||||
def capability?(cap_name)
|
||||
@logger.debug("checking for remote synced folder capability #{cap_name}")
|
||||
client.has_capability?(cap_name)
|
||||
end
|
||||
|
||||
def to_proto
|
||||
client.proto
|
||||
end
|
||||
def to_proto
|
||||
client.proto
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user