Find target in index by uuid or name

This commit is contained in:
sophia 2022-01-19 14:01:05 -06:00 committed by Paul Hinze
parent 9dbeca0492
commit 5ed50277bd
No known key found for this signature in database
GPG Key ID: B69DEDF2D55501C0

View File

@ -35,6 +35,7 @@ func (t *TargetIndex) Delete(uuid string) (err error) {
return target.(*Target).Destroy()
}
// Get target from entry by uuid or name
func (t *TargetIndex) Get(uuid string) (entry core.Target, err error) {
// Start with finding the target
result, err := t.client.FindTarget(t.ctx, &vagrant_server.FindTargetRequest{
@ -43,7 +44,15 @@ func (t *TargetIndex) Get(uuid string) (entry core.Target, err error) {
},
})
if err != nil {
return
// Search name if not found by uuid
result, err = t.client.FindTarget(t.ctx, &vagrant_server.FindTargetRequest{
Target: &vagrant_server.Target{
Name: uuid,
},
})
if err != nil {
return
}
}
return t.loadTarget(&vagrant_plugin_sdk.Ref_Target{
ResourceId: result.Target.ResourceId,