diff --git a/.gitignore b/.gitignore index 17c8429d9..1b95fe5fb 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ test/vagrant-spec/.vagrant/ /pkg data.db vagrant-restore.db.lock +cmd/vagrant/Vagrantfile # Bundler/Rubygems *.gem diff --git a/internal/core/target.go b/internal/core/target.go index 2147d8cd4..7a0e91c56 100644 --- a/internal/core/target.go +++ b/internal/core/target.go @@ -3,6 +3,7 @@ package core import ( "context" "fmt" + "os" "strings" "sync" "time" @@ -81,12 +82,15 @@ func (t *Target) Provider() (p core.Provider, err error) { // VagrantfileName implements core.Target func (t *Target) VagrantfileName() (name string, err error) { - return + // TODO: store and retrieve Vagrantfile name + return "Vagrantfile", nil } // VagrantfilePath implements core.Target func (t *Target) VagrantfilePath() (p path.Path, err error) { - return + // TODO: store and retrieve Vagrantfile path + cwd, err := os.Getwd() + return path.NewPath(cwd), err } // Communicate implements core.Target diff --git a/internal/plugin/plugin.go b/internal/plugin/plugin.go index 21a8ac74b..4f8afe6cf 100644 --- a/internal/plugin/plugin.go +++ b/internal/plugin/plugin.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/go-multierror" "github.com/hashicorp/go-plugin" - "github.com/hashicorp/vagrant-plugin-sdk" + sdk "github.com/hashicorp/vagrant-plugin-sdk" "github.com/hashicorp/vagrant-plugin-sdk/component" "github.com/hashicorp/vagrant/builtin/myplugin" "github.com/hashicorp/vagrant/builtin/otherplugin" diff --git a/lib/vagrant/machine_index.rb b/lib/vagrant/machine_index.rb index 255ddcaa6..9ae7657dd 100644 --- a/lib/vagrant/machine_index.rb +++ b/lib/vagrant/machine_index.rb @@ -402,7 +402,7 @@ module Vagrant # @return [Hash] attr_accessor :extra_data - attr_accessor :remote_machine + attr_accessor :machine_client # Initializes an entry. # @@ -425,7 +425,7 @@ module Vagrant # TODO(mitchellh): parse into a proper datetime @updated_at = raw["updated_at"] @extra_data = raw["extra_data"] || {} - @remote_machine = raw["remote_machine"] + @machine_client = raw["machine_client"] # Be careful with the paths @local_data_path = nil if @local_data_path == "" diff --git a/lib/vagrant/machine_index/remote.rb b/lib/vagrant/machine_index/remote.rb index b331245bd..70b400a3c 100644 --- a/lib/vagrant/machine_index/remote.rb +++ b/lib/vagrant/machine_index/remote.rb @@ -27,7 +27,7 @@ module Vagrant # @return [Boolean] true if delete is successful def delete(entry) @machines.delete(entry.id) - machine = entry.remote_machine.client.ref + machine = entry.machine_client.ref @client.delete(machine) end @@ -67,7 +67,7 @@ module Vagrant # @return [Entry] def set(entry) @machines[entry.id] = entry - entry.remote_machine.client.save + entry.machine_client.save entry end @@ -96,14 +96,25 @@ module Vagrant # @param [Hashicorp::Vagrant::Sdk::Args::Target] # @return [Vagrant::MachineIndex::Entry] def machine_to_entry(machine) - @logger.debug("machine name: #{machine.name}") + @logger.debug("transforming machine #{machine}") + conn = @client.broker.dial(machine.stream_id) + target_service = Hashicorp::Vagrant::Sdk::TargetService::Stub.new(conn.to_s, :this_channel_is_insecure) + machine = target_service.specialize(Google::Protobuf::Any.new) + m = Hashicorp::Vagrant::Sdk::Args::Target::Machine.decode(machine.value) + conn = @client.broker.dial(m.stream_id) + machine_client = VagrantPlugins::CommandServe::Client::Machine.new(conn.to_s) raw = { - "name" => machine.name, - "vagrantfile_path" => machine.project.path, - "provider" => provider, + "name" => machine_client.get_name(), + "local_data_path" => machine_client.get_local_data_path(), + # TODO: get the provider! + "provider" => "virtualbox", + "state" => machine_client.get_state(), + "vagrantfile_name" => machine_client.get_vagrantfile_name(), + "vagrantfile_path" => machine_client.get_vagrantfile_path(), + "machine_client" => machine_client, } entry = Vagrant::MachineIndex::Entry.new( - id=machine.name, raw=raw + id=machine_client.resource_id, raw=raw ) return entry end diff --git a/plugins/commands/serve/client/machine.rb b/plugins/commands/serve/client/machine.rb index 7c24fea52..63cc05000 100644 --- a/plugins/commands/serve/client/machine.rb +++ b/plugins/commands/serve/client/machine.rb @@ -6,12 +6,13 @@ module VagrantPlugins attr_reader :client attr_reader :resource_id - def initialize(conn) + def initialize(conn, broker=nil) @logger = Log4r::Logger.new("vagrant::command::serve::client::machine") @logger.debug("connecting to target machine service on #{conn}") if !conn.nil? @client = SDK::TargetMachineService::Stub.new(conn, :this_channel_is_insecure) end + @broker = broker end def self.load(raw_machine, broker:) @@ -77,10 +78,7 @@ module VagrantPlugins # TODO: local data path comes from the project def get_local_data_path - req = SDK::Machine::LocalDataPathRequest.new( - machine: ref - ) - @client.localdatapath(req).path + #TODO end def get_provider @@ -111,9 +109,9 @@ module VagrantPlugins resp = @client.get_state(req) @logger.debug("Got state #{resp}") Vagrant::MachineState.new( - resp.state.id.to_sym, - resp.state.short_description, - resp.state.long_description + resp.id.to_sym, + resp.short_description, + resp.long_description ) end diff --git a/plugins/commands/serve/client/machine_index.rb b/plugins/commands/serve/client/machine_index.rb index e06cfa021..8d88d1e35 100644 --- a/plugins/commands/serve/client/machine_index.rb +++ b/plugins/commands/serve/client/machine_index.rb @@ -4,18 +4,20 @@ module VagrantPlugins class MachineIndex attr_reader :client + attr_reader :broker def self.load(raw, broker:) conn = broker.dial(raw.stream_id) - self.new(conn.to_s) + self.new(conn.to_s, broker) end - def initialize(conn) + def initialize(conn, broker=nil) @logger = Log4r::Logger.new("vagrant::command::serve::client::machineindex") @logger.debug("connecting to target index service on #{conn}") if !conn.nil? @client = SDK::TargetIndexService::Stub.new(conn, :this_channel_is_insecure) end + @broker = broker end # @param [Hashicorp::Vagrant::Sdk::Args::Target]