File tree 1 file changed +26
-1
lines changed
1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package provision
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
ovhsdk "github.com/dirien/ovh-go-sdk/pkg/sdk"
6
7
)
7
8
@@ -75,8 +76,32 @@ func (o *OVHProvisioner) Status(id string) (*ProvisionedHost, error) {
75
76
}, nil
76
77
}
77
78
79
+ func (o * OVHProvisioner ) lookupID (request HostDeleteRequest ) (string , error ) {
80
+ instances , err := o .client .ListInstance (context .Background ())
81
+ if err != nil {
82
+ return "" , err
83
+ }
84
+ for _ , instance := range instances {
85
+ ip4 , _ := ovhsdk .IPv4 (& instance )
86
+ if ip4 == request .IP {
87
+ return instance .ID , nil
88
+ }
89
+ }
90
+ return "" , fmt .Errorf ("no host with ip: %s" , request .IP )
91
+ }
92
+
78
93
func (o * OVHProvisioner ) Delete (request HostDeleteRequest ) error {
79
- err := o .client .DeleteInstance (context .Background (), request .ID )
94
+ var id string
95
+ var err error
96
+ if len (request .ID ) > 0 {
97
+ id = request .ID
98
+ } else {
99
+ id , err = o .lookupID (request )
100
+ if err != nil {
101
+ return err
102
+ }
103
+ }
104
+ err = o .client .DeleteInstance (context .Background (), id )
80
105
if err != nil {
81
106
return err
82
107
}
You can’t perform that action at this time.
0 commit comments