@@ -2485,38 +2485,6 @@ func (c *RestClient) LunOptions(
24852485 return result , nil
24862486}
24872487
2488- // pollLunCreate polls for the created LUN to appear, with backoff retry logic
2489- func (c * RestClient ) pollLunCreate (ctx context.Context , lunPath string ) error {
2490- checkCreateStatus := func () error {
2491- fields := []string {"" }
2492- lun , err := c .LunGetByName (ctx , lunPath , fields )
2493- if err != nil {
2494- return err
2495- }
2496- if lun == nil {
2497- return fmt .Errorf ("could not find LUN with name %v" , lunPath )
2498- }
2499- return nil
2500- }
2501- createStatusNotify := func (err error , duration time.Duration ) {
2502- Logc (ctx ).WithField ("increment" , duration ).Debug ("LUN creation not finished, waiting." )
2503- }
2504- createStatusBackoff := backoff .NewExponentialBackOff ()
2505- createStatusBackoff .InitialInterval = 1 * time .Second
2506- createStatusBackoff .Multiplier = 2
2507- createStatusBackoff .RandomizationFactor = 0.1
2508- createStatusBackoff .MaxElapsedTime = 2 * time .Minute
2509-
2510- // Run the creation check using an exponential backoff
2511- if err := backoff .RetryNotify (checkCreateStatus , createStatusBackoff , createStatusNotify ); err != nil {
2512- Logc (ctx ).WithField ("LUN" , lunPath ).Warnf ("LUN not found after %3.2f seconds." ,
2513- createStatusBackoff .MaxElapsedTime .Seconds ())
2514- return err
2515- }
2516-
2517- return nil
2518- }
2519-
25202488// LunCloneCreate creates a LUN clone
25212489func (c * RestClient ) LunCloneCreate (
25222490 ctx context.Context , lunPath , sourcePath string , sizeInBytes int64 , osType string , qosPolicyGroup QosPolicyGroup ,
@@ -2563,16 +2531,7 @@ func (c *RestClient) LunCloneCreate(
25632531
25642532 params .SetInfo (lunInfo )
25652533
2566- lunCreateCreated , lunCreateAccepted , err := c .api .San .LunCreate (params , c .authInfo )
2567- if err != nil {
2568- return err
2569- }
2570- if lunCreateCreated == nil && lunCreateAccepted == nil {
2571- return fmt .Errorf ("unexpected response from LUN create" )
2572- }
2573-
2574- // verify the created LUN can be found
2575- return c .pollLunCreate (ctx , lunPath )
2534+ return c .lunCreate (ctx , params , "failed to create lun clone" )
25762535}
25772536
25782537// LunCreate creates a LUN
@@ -2620,18 +2579,31 @@ func (c *RestClient) LunCreate(
26202579
26212580 params .SetInfo (lunInfo )
26222581
2623- lunCreateCreated , lunCreateAccepted , err := c .api .San .LunCreate (params , c .authInfo )
2582+ return c .lunCreate (ctx , params , "failed to create lun" )
2583+ }
2584+
2585+ func (c * RestClient ) lunCreate (ctx context.Context , params * san.LunCreateParams , customErrMsg string ) error {
2586+ lunCreateOk , lunCreateAccepted , err := c .api .San .LunCreate (params , c .authInfo )
26242587 if err != nil {
26252588 return err
26262589 }
26272590
26282591 // If both response parameter is nil, then it is unexpected.
2629- if lunCreateCreated == nil && lunCreateAccepted == nil {
2592+ if lunCreateOk == nil && lunCreateAccepted == nil {
26302593 return fmt .Errorf ("unexpected response from LUN create" )
26312594 }
26322595
2633- // verify the created LUN can be found
2634- return c .pollLunCreate (ctx , lunPath )
2596+ // Check for synchronous response and return status based on that
2597+ if lunCreateOk != nil {
2598+ if lunCreateOk .IsSuccess () {
2599+ return nil
2600+ }
2601+ return fmt .Errorf ("%s: %v" , customErrMsg , lunCreateOk .Error ())
2602+ }
2603+
2604+ // Else, wait for job to finish
2605+ jobLink := getGenericJobLinkFromLunJobLink (lunCreateAccepted .Payload )
2606+ return c .PollJobStatus (ctx , jobLink )
26352607}
26362608
26372609// LunGet gets the LUN with the specified uuid
0 commit comments