Use uuid as Target Index identifier

This commit is contained in:
sophia 2021-08-11 12:21:52 -04:00 committed by Paul Hinze
parent 466c692d1c
commit 154a4e56f0
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0
2 changed files with 10 additions and 30 deletions

View File

@ -5,9 +5,9 @@ import (
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/vagrant-plugin-sdk/core"
"github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk"
"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
"github.com/hashicorp/vagrant/internal/serverclient"
"github.com/mitchellh/mapstructure"
)
// TargetIndex represents
@ -21,43 +21,26 @@ type TargetIndex struct {
closers []func() error
}
func (t *TargetIndex) Delete(ref *core.TargetRef) (err error) {
func (t *TargetIndex) Delete(uuid string) (err error) {
_, err = t.client.DeleteTarget(
t.ctx,
&vagrant_server.DeleteTargetRequest{
Target: ref.Ref(),
Target: &vagrant_plugin_sdk.Ref_Target{ResourceId: uuid},
},
)
return
}
func (t *TargetIndex) Get(ref *core.TargetRef) (entry core.Target, err error) {
entry, err = t.project.Target(ref.Name)
if err != nil {
entry, err = t.project.Target(ref.ResourceId)
return
}
return
func (t *TargetIndex) Get(uuid string) (entry core.Target, err error) {
return t.project.Target(uuid)
}
func (t *TargetIndex) Includes(ref *core.TargetRef) (exists bool, err error) {
var req *vagrant_server.Target
mapstructure.Decode(ref, &req)
// TODO: Not sure if this interface is going to change,
// would be neat if FindTarget accepted a Ref_Target
_, err = t.client.FindTarget(
t.ctx,
&vagrant_server.FindTargetRequest{
Target: req,
},
)
// TODO: Not sure what should be returned by the api
// if there is not Target found. For now assuming that
// if a target is not found an error is returned
if err != nil {
return false, err
func (t *TargetIndex) Includes(uuid string) (exists bool, err error) {
_, err = t.project.Target(uuid)
if err == nil {
return true, nil
}
return true, err
return false, nil
}
func (t *TargetIndex) Set(entry core.Target) (updatedEntry core.Target, err error) {

View File

@ -341,7 +341,6 @@ module Hashicorp
rpc :VagrantfilePath, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Target::VagrantfilePathResponse
rpc :UpdatedAt, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Target::UpdatedAtResponse
rpc :Communicate, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Args::Communicator
rpc :Ref, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Ref::Target
rpc :Save, ::Google::Protobuf::Empty, ::Google::Protobuf::Empty
end
@ -372,7 +371,6 @@ module Hashicorp
rpc :VagrantfilePath, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Target::VagrantfilePathResponse
rpc :UpdatedAt, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Target::UpdatedAtResponse
rpc :Communicate, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Args::Communicator
rpc :Ref, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Ref::Target
rpc :Save, ::Google::Protobuf::Empty, ::Google::Protobuf::Empty
# Machine specific
rpc :SetID, ::Hashicorp::Vagrant::Sdk::Target::Machine::SetIDRequest, ::Google::Protobuf::Empty
@ -418,7 +416,6 @@ module Hashicorp
rpc :Target, ::Hashicorp::Vagrant::Sdk::Project::TargetRequest, ::Hashicorp::Vagrant::Sdk::Args::Target
rpc :TargetNames, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Project::TargetNamesResponse
rpc :TargetIds, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Project::TargetIdsResponse
rpc :Ref, ::Google::Protobuf::Empty, ::Hashicorp::Vagrant::Sdk::Ref::Project
end
Stub = Service.rpc_stub_class