From c71eb9ea0ea5b782f4312b911bca57648e8b957c Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 11 Aug 2021 12:37:24 -0400 Subject: [PATCH] UQuery machine index by uuid --- lib/vagrant/environment/remote.rb | 1 - lib/vagrant/machine_index/remote.rb | 32 +++++++++---------- .../proto/vagrant_plugin_sdk/plugin_pb.rb | 4 +++ .../vagrant_plugin_sdk/plugin_services_pb.rb | 6 ++-- .../commands/serve/client/machine_index.rb | 6 ++-- plugins/commands/serve/client/project.rb | 5 --- 6 files changed, 25 insertions(+), 29 deletions(-) diff --git a/lib/vagrant/environment/remote.rb b/lib/vagrant/environment/remote.rb index dd07c41e3..9f653cc77 100644 --- a/lib/vagrant/environment/remote.rb +++ b/lib/vagrant/environment/remote.rb @@ -36,7 +36,6 @@ module Vagrant machine_index_client = @client.machine_index @machine_index ||= Vagrant::MachineIndex.new() @machine_index.client = machine_index_client - @machine_index.project_ref = @client.ref end @machine_index end diff --git a/lib/vagrant/machine_index/remote.rb b/lib/vagrant/machine_index/remote.rb index 6b4abfbaa..8747a6966 100644 --- a/lib/vagrant/machine_index/remote.rb +++ b/lib/vagrant/machine_index/remote.rb @@ -5,8 +5,6 @@ module Vagrant attr_accessor :client - attr_accessor :project_ref - # Add an attribute reader for the client # when applied to the MachineIndex class def self.prepended(klass) @@ -23,22 +21,23 @@ module Vagrant # Deletes a machine by UUID. # - # @param [Entry] entry The entry to delete. + # @param [Stinrg] The uuid for the entry to delete. # @return [Boolean] true if delete is successful - def delete(entry) - @machines.delete(entry.id) - machine = entry.machine_client.ref - @client.delete(machine) + def delete(uuid) + @machines.delete(uuid) + ref = Hashicorp::Vagrant::Sdk::TargetIndex::TargetIdentifier.new( + id: uuid + ) + @client.delete(ref) end # Accesses a machine by UUID # - # @param [String] name for the machine to access. + # @param [String] uuid for the machine to access. # @return [MachineIndex::Entry] - def get(name) - ref = Hashicorp::Vagrant::Sdk::Ref::Target.new( - name: name, - project: @project_ref + def get(uuid) + ref = Hashicorp::Vagrant::Sdk::TargetIndex::TargetIdentifier.new( + id: uuid ) get_response = @client.get(ref) entry = machine_to_entry(get_response) @@ -47,12 +46,11 @@ module Vagrant # Tests if the index has the given UUID. # - # @param [String] name + # @param [String] uuid # @return [Boolean] - def include?(name) - ref = Hashicorp::Vagrant::Sdk::Ref::Target.new( - name: name, - project: @project_ref + def include?(uuid) + ref = Hashicorp::Vagrant::Sdk::TargetIndex::TargetIdentifier.new( + id: uuid ) @client.include?(ref) end diff --git a/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb b/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb index 984f5492a..205ccd4b8 100644 --- a/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb +++ b/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_pb.rb @@ -698,6 +698,9 @@ Google::Protobuf::DescriptorPool.generated_pool.build do end add_message "hashicorp.vagrant.sdk.TargetIndex" do end + add_message "hashicorp.vagrant.sdk.TargetIndex.TargetIdentifier" do + optional :id, :string, 1 + end add_message "hashicorp.vagrant.sdk.TargetIndex.AllResponse" do repeated :targets, :message, 1, "hashicorp.vagrant.sdk.Args.Target" end @@ -872,6 +875,7 @@ module Hashicorp Vagrantfile::SyncedFolder = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Vagrantfile.SyncedFolder").msgclass Vagrantfile::Vagrantfile = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.Vagrantfile.Vagrantfile").msgclass TargetIndex = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.TargetIndex").msgclass + TargetIndex::TargetIdentifier = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.TargetIndex.TargetIdentifier").msgclass TargetIndex::AllResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.TargetIndex.AllResponse").msgclass TargetIndex::IncludesResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("hashicorp.vagrant.sdk.TargetIndex.IncludesResponse").msgclass end diff --git a/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_services_pb.rb b/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_services_pb.rb index 9fe99a7da..d6240f278 100644 --- a/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_services_pb.rb +++ b/lib/vagrant/protobufs/proto/vagrant_plugin_sdk/plugin_services_pb.rb @@ -453,9 +453,9 @@ module Hashicorp self.unmarshal_class_method = :decode self.service_name = 'hashicorp.vagrant.sdk.TargetIndexService' - rpc :Delete, ::Hashicorp::Vagrant::Sdk::Ref::Target, ::Google::Protobuf::Empty - rpc :Get, ::Hashicorp::Vagrant::Sdk::Ref::Target, ::Hashicorp::Vagrant::Sdk::Args::Target - rpc :Includes, ::Hashicorp::Vagrant::Sdk::Ref::Target, ::Hashicorp::Vagrant::Sdk::TargetIndex::IncludesResponse + rpc :Delete, ::Hashicorp::Vagrant::Sdk::TargetIndex::TargetIdentifier, ::Google::Protobuf::Empty + rpc :Get, ::Hashicorp::Vagrant::Sdk::TargetIndex::TargetIdentifier, ::Hashicorp::Vagrant::Sdk::Args::Target + rpc :Includes, ::Hashicorp::Vagrant::Sdk::TargetIndex::TargetIdentifier, ::Hashicorp::Vagrant::Sdk::TargetIndex::IncludesResponse rpc :Set, ::Hashicorp::Vagrant::Sdk::Args::Target, ::Hashicorp::Vagrant::Sdk::Args::Target rpc :All, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::TargetIndex::AllResponse end diff --git a/plugins/commands/serve/client/machine_index.rb b/plugins/commands/serve/client/machine_index.rb index 8d88d1e35..42f411e7f 100644 --- a/plugins/commands/serve/client/machine_index.rb +++ b/plugins/commands/serve/client/machine_index.rb @@ -20,7 +20,7 @@ module VagrantPlugins @broker = broker end - # @param [Hashicorp::Vagrant::Sdk::Args::Target] + # @param [Hashicorp::Vagrant::Sdk::TargetIndex::TargetIdentifier] # @return [Boolean] true if delete is successful def delete(target) @logger.debug("deleting machine #{target} from index") @@ -28,7 +28,7 @@ module VagrantPlugins true end - # @param [Hashicorp::Vagrant::Sdk::Ref::Target] a ref for the machine to access. + # @param [Hashicorp::Vagrant::Sdk::TargetIndex::TargetIdentifier] # @return [Hashicorp::Vagrant::Sdk::Ref::Target] def get(ref) @logger.debug("getting machine with ref #{ref} from index") @@ -36,7 +36,7 @@ module VagrantPlugins return resp end - # @param [Hashicorp::Vagrant::Sdk::Ref::Target] + # @param [Hashicorp::Vagrant::Sdk::TargetIndex::TargetIdentifier] # @return [Boolean] def include?(ref) @logger.debug("checking for machine with ref #{ref} in index") diff --git a/plugins/commands/serve/client/project.rb b/plugins/commands/serve/client/project.rb index 2e2cb3fed..547d3043b 100644 --- a/plugins/commands/serve/client/project.rb +++ b/plugins/commands/serve/client/project.rb @@ -17,11 +17,6 @@ module VagrantPlugins self.new(conn.to_s, broker) end - def ref - req = Google::Protobuf::Empty.new - @client.ref(req) - end - # Returns a machine client for the given name # return [VagrantPlugins::CommandServe::Client::Machine] def target(name)