Save point: connect to machine index service
This commit is contained in:
parent
c124a583d7
commit
c123335456
@ -1,3 +1,5 @@
|
||||
require 'vagrant/machine_index/remote'
|
||||
|
||||
module Vagrant
|
||||
class Environment
|
||||
module Remote
|
||||
@ -9,6 +11,7 @@ module Vagrant
|
||||
end
|
||||
|
||||
def initialize(opts={})
|
||||
@client = opts[:client]
|
||||
super
|
||||
@client = opts[:client]
|
||||
if @client.nil?
|
||||
@ -24,6 +27,17 @@ module Vagrant
|
||||
def get_target(name)
|
||||
client.target(name)
|
||||
end
|
||||
|
||||
# The {MachineIndex} to store information about the machines.
|
||||
#
|
||||
# @return [MachineIndex]
|
||||
def machine_index
|
||||
if !@client.nil?
|
||||
machine_index_client = @client.machine_index
|
||||
@machine_index ||= Vagrant::MachineIndex.new(client: machine_index_client)
|
||||
end
|
||||
@machine_index
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -36,6 +36,8 @@ module Vagrant
|
||||
# }
|
||||
#
|
||||
class MachineIndex
|
||||
autoload :Remote, "vagrant/machine_index/remote"
|
||||
|
||||
include Enumerable
|
||||
|
||||
# Initializes a MachineIndex at the given file location.
|
||||
|
||||
22
lib/vagrant/machine_index/remote.rb
Normal file
22
lib/vagrant/machine_index/remote.rb
Normal file
@ -0,0 +1,22 @@
|
||||
module Vagrant
|
||||
class MachineIndex
|
||||
# This module enables the MachineIndex for server mode
|
||||
module Remote
|
||||
|
||||
# Add an attribute reader for the client
|
||||
# when applied to the MachineIndex class
|
||||
def self.prepended(klass)
|
||||
klass.class_eval do
|
||||
attr_reader :client
|
||||
end
|
||||
end
|
||||
|
||||
# Initializes a MachineIndex
|
||||
def initialize(*args, **kwargs)
|
||||
@machines = {}
|
||||
@machine_locks = {}
|
||||
@client = kwargs.key("client")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -9,6 +9,7 @@ module VagrantPlugins
|
||||
autoload :Machine, Vagrant.source_root.join("plugins/commands/serve/client/machine").to_s
|
||||
autoload :Project, Vagrant.source_root.join("plugins/commands/serve/client/project").to_s
|
||||
autoload :Terminal, Vagrant.source_root.join("plugins/commands/serve/client/terminal").to_s
|
||||
autoload :MachineIndex, Vagrant.source_root.join("plugins/commands/serve/client/machine_index").to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -5,6 +5,11 @@ module VagrantPlugins
|
||||
|
||||
attr_reader :client
|
||||
|
||||
def self.load(raw, broker:)
|
||||
conn = broker.dial(raw.stream_id)
|
||||
self.new(conn.to_s)
|
||||
end
|
||||
|
||||
def initialize(conn)
|
||||
@logger = Log4r::Logger.new("vagrant::command::serve::client::machine")
|
||||
@logger.debug("connecting to target index service on #{conn}")
|
||||
@ -14,15 +19,19 @@ module VagrantPlugins
|
||||
end
|
||||
|
||||
def delete(machine)
|
||||
@logger.debug("deleting machine #{machine} from index")
|
||||
end
|
||||
|
||||
def get(uuid)
|
||||
@logger.debug("getting machine with uuid #{uuid} from index")
|
||||
end
|
||||
|
||||
def include?(uuid)
|
||||
@logger.debug("checking for machine with uuid #{uuid} in index")
|
||||
end
|
||||
|
||||
def set(entry)
|
||||
@logger.debug("setting machine #{entry} in index")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -40,6 +40,25 @@ module VagrantPlugins
|
||||
conn = @broker.dial(m.stream_id)
|
||||
return Machine.new(conn.to_s)
|
||||
end
|
||||
|
||||
# return [VagrantPlugins::CommandServe::Client::MachineIndex]
|
||||
def machine_index
|
||||
@logger.debug("connecting to machine index")
|
||||
req = Google::Protobuf::Empty.new
|
||||
begin
|
||||
raw_target_index = @client.target_index(req)
|
||||
rescue => error
|
||||
@logger.debug("target index unreachable")
|
||||
@logger.debug(error.message)
|
||||
end
|
||||
@logger.debug("got response #{raw_target_index}")
|
||||
# ti = SDK::Args::TargetIndex.decode(raw_target_index)
|
||||
# @logger.debug("decoded: #{ti}")
|
||||
@logger.debug("at stream id: #{raw_target_index.stream_id}")
|
||||
m = MachineIndex.load(raw_target_index, broker: @broker)
|
||||
@logger.debug("got machine index #{m}")
|
||||
m
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user