@@ -72,6 +72,56 @@ func (e *exponentialBackoff) InspectInstance(instanceID string) (*cloudops.Insta
7272
7373}
7474
75+ func (e * exponentialBackoff ) CreateInstance (template interface {}) (* cloudops.InstanceInfo , error ) {
76+ var (
77+ instanceInfo * cloudops.InstanceInfo
78+ origErr error
79+ )
80+ conditionFn := func () (bool , error ) {
81+ instanceInfo , origErr = e .cloudOps .CreateInstance (template )
82+ msg := fmt .Sprintf ("Failed to create instance: %v." , template )
83+ return e .handleError (origErr , msg )
84+ }
85+ expErr := wait .ExponentialBackoff (e .backoff , conditionFn )
86+ if expErr == wait .ErrWaitTimeout {
87+ return nil , cloudops .NewStorageError (cloudops .ErrExponentialTimeout , origErr .Error (), "" )
88+ }
89+ return instanceInfo , origErr
90+ }
91+
92+ func (e * exponentialBackoff ) ListInstances (opts * cloudops.ListInstancesOpts ) (
93+ []* cloudops.InstanceInfo , error ) {
94+
95+ var (
96+ instanceInfos []* cloudops.InstanceInfo
97+ origErr error
98+ )
99+ conditionFn := func () (bool , error ) {
100+ instanceInfos , origErr = e .cloudOps .ListInstances (opts )
101+ msg := fmt .Sprintf ("Failed to list instances with options: %v." , opts )
102+ return e .handleError (origErr , msg )
103+ }
104+ expErr := wait .ExponentialBackoff (e .backoff , conditionFn )
105+ if expErr == wait .ErrWaitTimeout {
106+ return nil , cloudops .NewStorageError (cloudops .ErrExponentialTimeout , origErr .Error (), "" )
107+ }
108+ return instanceInfos , origErr
109+ }
110+
111+ func (e * exponentialBackoff ) DeleteInstance (instanceID string , zone string ) error {
112+ var origErr error
113+ conditionFn := func () (bool , error ) {
114+ origErr = e .cloudOps .DeleteInstance (instanceID , zone )
115+ msg := fmt .Sprintf ("Failed to inspect instance: %v." , instanceID )
116+ return e .handleError (origErr , msg )
117+ }
118+ expErr := wait .ExponentialBackoff (e .backoff , conditionFn )
119+ if expErr == wait .ErrWaitTimeout {
120+ return cloudops .NewStorageError (cloudops .ErrExponentialTimeout , origErr .Error (), "" )
121+ }
122+ return origErr
123+ }
124+
75125func (e * exponentialBackoff ) InspectInstanceGroupForInstance (instanceID string ) (* cloudops.InstanceGroupInfo , error ) {
76126 var (
77127 instanceGroupInfo * cloudops.InstanceGroupInfo
@@ -140,23 +190,6 @@ func (e *exponentialBackoff) GetClusterSizeForInstance(instanceID string) (int64
140190
141191}
142192
143- func (e * exponentialBackoff ) DeleteInstance (instanceID string , zone string , timeout time.Duration ) error {
144- var (
145- origErr error
146- )
147- conditionFn := func () (bool , error ) {
148- origErr = e .cloudOps .DeleteInstance (instanceID , zone , timeout )
149- msg := fmt .Sprintf ("Failed to delete instance: %v." , instanceID )
150- return e .handleError (origErr , msg )
151- }
152- expErr := wait .ExponentialBackoff (e .backoff , conditionFn )
153- if expErr == wait .ErrWaitTimeout {
154- return cloudops .NewStorageError (cloudops .ErrExponentialTimeout , origErr .Error (), "" )
155- }
156- return origErr
157-
158- }
159-
160193// Create volume based on input template volume and also apply given labels.
161194func (e * exponentialBackoff ) Create (template interface {}, labels map [string ]string ) (interface {}, error ) {
162195 var (
@@ -183,13 +216,13 @@ func (e *exponentialBackoff) GetDeviceID(template interface{}) (string, error) {
183216
184217// Attach volumeID.
185218// Return attach path.
186- func (e * exponentialBackoff ) Attach (volumeID string ) (string , error ) {
219+ func (e * exponentialBackoff ) Attach (volumeID string , options map [ string ] string ) (string , error ) {
187220 var (
188221 devPath string
189222 origErr error
190223 )
191224 conditionFn := func () (bool , error ) {
192- devPath , origErr = e .cloudOps .Attach (volumeID )
225+ devPath , origErr = e .cloudOps .Attach (volumeID , options )
193226 msg := fmt .Sprintf ("Failed to attach drive (%v)." , volumeID )
194227 return e .handleError (origErr , msg )
195228 }
@@ -200,11 +233,28 @@ func (e *exponentialBackoff) Attach(volumeID string) (string, error) {
200233 return devPath , origErr
201234}
202235
203- // Detach volumeID.
204- func (e * exponentialBackoff ) Detach (volumeID string ) error {
236+ func (e * exponentialBackoff ) AttachByInstanceID (
237+ instanceID , volumeID string ,
238+ options map [string ]string ) (string , error ) {
205239 var (
240+ devPath string
206241 origErr error
207242 )
243+ conditionFn := func () (bool , error ) {
244+ devPath , origErr = e .cloudOps .AttachByInstanceID (instanceID , volumeID , options )
245+ msg := fmt .Sprintf ("Failed to attach drive (%v) on %s" , volumeID , instanceID )
246+ return e .handleError (origErr , msg )
247+ }
248+ expErr := wait .ExponentialBackoff (e .backoff , conditionFn )
249+ if expErr == wait .ErrWaitTimeout {
250+ return "" , cloudops .NewStorageError (cloudops .ErrExponentialTimeout , origErr .Error (), "" )
251+ }
252+ return devPath , origErr
253+ }
254+
255+ // Detach volumeID.
256+ func (e * exponentialBackoff ) Detach (volumeID string ) error {
257+ var origErr error
208258 conditionFn := func () (bool , error ) {
209259 origErr = e .cloudOps .Detach (volumeID )
210260 msg := fmt .Sprintf ("Failed to detach drive (%v)." , volumeID )
@@ -312,13 +362,13 @@ func (e *exponentialBackoff) Inspect(volumeIds []*string) ([]interface{}, error)
312362}
313363
314364// DeviceMappings returns map[local_attached_volume_path]->volume ID/NAME
315- func (e * exponentialBackoff ) DeviceMappings () (map [string ]string , error ) {
365+ func (e * exponentialBackoff ) DeviceMappings (instanceID string ) (map [string ]string , error ) {
316366 var (
317367 mappings map [string ]string
318368 origErr error
319369 )
320370 conditionFn := func () (bool , error ) {
321- mappings , origErr = e .cloudOps .DeviceMappings ()
371+ mappings , origErr = e .cloudOps .DeviceMappings (instanceID )
322372 msg := fmt .Sprintf ("Failed to get device mappings." )
323373 return e .handleError (origErr , msg )
324374 }
0 commit comments