Upload targets found in Vagrantfile

This commit is contained in:
sophia 2021-07-07 17:35:46 -05:00 committed by Paul Hinze
parent 8d1b9a4a8c
commit ada96f13a3
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
7 changed files with 1560 additions and 1511 deletions

View File

@ -55,7 +55,7 @@ func (p *Project) LoadVagrantfiles() error {
}
p.project.Configuration = vagrantfile
// Push Vagrantfile updates to project
p.basis.client.UpsertProject(
projectRef, err := p.basis.client.UpsertProject(
context.Background(),
&vagrant_server.UpsertProjectRequest{
Project: p.project,
@ -64,6 +64,32 @@ func (p *Project) LoadVagrantfiles() error {
if err != nil {
return err
}
for _, machineConfig := range vagrantfile.MachineConfigs {
vagrant_server_target := &vagrant_server.Target{
Configuration: machineConfig,
Name: machineConfig.Name,
Project: &vagrant_plugin_sdk.Ref_Project{ResourceId: projectRef.Project.ResourceId},
}
newTarget := &Target{
ui: p.ui,
project: p,
target: vagrant_server_target,
}
p.Targets = append(p.Targets, newTarget)
_, err := p.basis.client.UpsertTarget(
context.Background(),
&vagrant_server.UpsertTargetRequest{
Project: &vagrant_plugin_sdk.Ref_Project{ResourceId: projectRef.Project.ResourceId},
Target: vagrant_server_target,
},
)
if err != nil {
return err
}
}
if err != nil {
return err
}
return nil
}

File diff suppressed because it is too large Load Diff

View File

@ -287,7 +287,7 @@ message Target {
sdk.Args.MetadataSet metadata = 9;
// Serialized configuration of the target (Vagrantfile)
sdk.Vagrantfile.Vagrantfile configuration = 10;
sdk.Vagrantfile.MachineConfig configuration = 10;
// Specialized target information (from provider)
google.protobuf.Any record = 11;

View File

@ -54,7 +54,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
optional :parent, :message, 7, "hashicorp.vagrant.Target"
optional :uuid, :string, 8
optional :metadata, :message, 9, "hashicorp.vagrant.sdk.Args.MetadataSet"
optional :configuration, :message, 10, "hashicorp.vagrant.sdk.Vagrantfile.Vagrantfile"
optional :configuration, :message, 10, "hashicorp.vagrant.sdk.Vagrantfile.MachineConfig"
optional :record, :message, 11, "google.protobuf.Any"
optional :remote_enabled, :bool, 100
optional :data_source, :message, 101, "hashicorp.vagrant.Job.DataSource"

View File

@ -9,7 +9,9 @@ module VagrantPlugins
def initialize(conn)
@logger = Log4r::Logger.new("vagrant::command::serve::client::machine")
@logger.debug("connecting to target machine service on #{conn}")
@client = SDK::TargetMachineService::Stub.new(conn, :this_channel_is_insecure)
if !conn.nil?
@client = SDK::TargetMachineService::Stub.new(conn, :this_channel_is_insecure)
end
end
def self.load(raw_machine, broker:)

View File

@ -22,7 +22,12 @@ module VagrantPlugins
def target(name)
@logger.debug("searching for target #{name}")
req = SDK::Project::TargetRequest.new(name: name)
raw_target = @client.target(req)
begin
raw_target = @client.target(req)
rescue
@logger.debug("no target found for #{name}")
return Machine.new(nil)
end
@logger.debug("got target #{raw_target}")
conn = @broker.dial(raw_target.stream_id)
target_service = SDK::TargetService::Stub.new(conn.to_s, :this_channel_is_insecure)

View File

@ -13,6 +13,8 @@ module VagrantPlugins
prepend Util::HasBroker
prepend Util::ExceptionLogger
LOG = Log4r::Logger.new("vagrant::command::serve::service::internal")
PROVIDER_PROTO_CLS = Hashicorp::Vagrant::Sdk::Vagrantfile::Provider
PROVISION_PROTO_CLS = Hashicorp::Vagrant::Sdk::Vagrantfile::Provisioner
SYNCED_FOLDER_PROTO_CLS = Hashicorp::Vagrant::Sdk::Vagrantfile::SyncedFolder
@ -53,32 +55,44 @@ module VagrantPlugins
Vagrant::Config::VERSIONS, Vagrant::Config::VERSIONS_ORDER)
config_loader.set(:root, path)
v = Vagrant::Vagrantfile.new(config_loader, [:root])
LOG.debug("loaded vagrantfile")
machine_configs = []
# Get the config for each machine
v.machine_names.each do |mach|
LOG.debug("loading machine config for #{mach}")
machine_info = v.machine_config(mach, nil, nil, false)
root_config = machine_info[:config]
vm_config = root_config.vm
LOG.debug("extracting config.ssh")
# Get config.ssh.*
config_ssh_proto = extract_communicator(CONFIG_SSH_CLS, root_config.ssh)
LOG.debug("extracting config.winrm")
# Get config.winrm.*
config_winrm_proto = extract_communicator(CONFIG_WINRM_CLS, root_config.winrm)
LOG.debug("extracting config.winssh")
#Get config.winssh.*
config_winssh_proto = extract_communicator(CONFIG_WINSSH_CLS, root_config.winssh)
LOG.debug("extracting config.vagrant")
# Get config.vagrant.*
config_vagrant_proto = extract_config_component(CONFIG_VAGRANT_CLS, root_config.vagrant)
LOG.debug("extracting config.vm")
# Get's config.vm.*
config_vm_proto = extract_config_component(CONFIG_VM_CLS, vm_config)
LOG.debug("extracting provisioners")
extract_provisioners(config_vm_proto.provisioners, vm_config.provisioners)
LOG.debug("extracting network")
extract_network(config_vm_proto.networks, vm_config.networks)
LOG.debug("extracting synced folder")
extract_synced_folders(config_vm_proto.synced_folders, vm_config.synced_folders)
LOG.debug("extracting provider")
extract_provider(config_vm_proto.providers, vm_config)
LOG.debug("done loading machine config for #{mach}")
plugin_configs = []
root_config.__internal_state["keys"].each do |name, config|
@ -105,6 +119,7 @@ module VagrantPlugins
current_version: Vagrant::Config::CURRENT_VERSION,
machine_configs: machine_configs,
)
LOG.debug("vagrantfile parsed!")
Hashicorp::Vagrant::ParseVagrantfileResponse.new(
vagrantfile: vagrantfile
)