retry error handling
This commit is contained in:
@@ -9,7 +9,8 @@ buildtime=$(TZ=Australia/Sydney date +%Y-%m-%dT%T%z)
|
|||||||
git_version=$(git describe --tags --always --long --dirty)
|
git_version=$(git describe --tags --always --long --dirty)
|
||||||
package_name=vctp
|
package_name=vctp
|
||||||
|
|
||||||
platforms=("linux/amd64" "darwin/amd64")
|
#platforms=("linux/amd64" "darwin/amd64")
|
||||||
|
platforms=("linux/amd64")
|
||||||
|
|
||||||
echo Building $package_name with git version: $git_version
|
echo Building $package_name with git version: $git_version
|
||||||
for platform in "${platforms[@]}"
|
for platform in "${platforms[@]}"
|
||||||
|
@@ -75,7 +75,7 @@ func (v *Vcenter) Login(vUrl string) error {
|
|||||||
|
|
||||||
v.client = c
|
v.client = c
|
||||||
|
|
||||||
v.Logger.Debug("successfully connected to vCenter")
|
v.Logger.Debug("successfully connected to vCenter", "url", vUrl, "username", username)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -115,6 +115,9 @@ func (v *Vcenter) FindVMByName(vmName string) ([]mo.VirtualMachine, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *Vcenter) FindVMByID(vmID string) (*VmProperties, error) {
|
func (v *Vcenter) FindVMByID(vmID string) (*VmProperties, error) {
|
||||||
|
|
||||||
|
v.Logger.Debug("searching for vm id", "vm_id", vmID)
|
||||||
|
|
||||||
finder := find.NewFinder(v.client.Client, true)
|
finder := find.NewFinder(v.client.Client, true)
|
||||||
|
|
||||||
// List all datacenters
|
// List all datacenters
|
||||||
@@ -138,18 +141,19 @@ func (v *Vcenter) FindVMByID(vmID string) (*VmProperties, error) {
|
|||||||
|
|
||||||
var vm mo.VirtualMachine
|
var vm mo.VirtualMachine
|
||||||
err := v.client.RetrieveOne(v.ctx, vmRef, []string{"config", "name"}, &vm)
|
err := v.client.RetrieveOne(v.ctx, vmRef, []string{"config", "name"}, &vm)
|
||||||
if err != nil {
|
|
||||||
|
if err == nil {
|
||||||
|
return &VmProperties{
|
||||||
|
Datacenter: dc.Name(),
|
||||||
|
Vm: vm,
|
||||||
|
}, nil
|
||||||
|
} else if _, ok := err.(*find.NotFoundError); !ok {
|
||||||
// If the error is not a NotFoundError, return it
|
// If the error is not a NotFoundError, return it
|
||||||
if err == err.(*find.NotFoundError) {
|
//return nil, fmt.Errorf("failed to retrieve VM with ID %s in datacenter %s: %w", vmID, dc.Name(), err)
|
||||||
return nil, fmt.Errorf("failed to retrieve VM with ID %s in datacenter %s: %w", vmID, dc.Name(), err)
|
v.Logger.Debug("Couldn't find vm in datacenter", "vm_id", vmID, "datacenter_name", dc.Name())
|
||||||
}
|
} else if err != nil {
|
||||||
return nil, fmt.Errorf("failed to retrieve VM: %w", err)
|
return nil, fmt.Errorf("failed to retrieve VM: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &VmProperties{
|
|
||||||
Datacenter: dc.Name(),
|
|
||||||
Vm: vm,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("VM with ID %s not found in any datacenter", vmID)
|
return nil, fmt.Errorf("VM with ID %s not found in any datacenter", vmID)
|
||||||
|
Reference in New Issue
Block a user