Record machine client in machine index entry
This commit is contained in:
parent
6eea1b0afd
commit
47a0a2d7d2
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,6 +18,7 @@ test/vagrant-spec/.vagrant/
|
||||
/pkg
|
||||
data.db
|
||||
vagrant-restore.db.lock
|
||||
cmd/vagrant/Vagrantfile
|
||||
|
||||
# Bundler/Rubygems
|
||||
*.gem
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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 == ""
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user