@@ -24,13 +24,11 @@ import (
2424 "io/ioutil"
2525 "net/http"
2626 "regexp"
27- "sort"
2827 "strings"
2928 "time"
3029
3130 "github.com/gophercloud/gophercloud"
3231 "github.com/gophercloud/gophercloud/openstack"
33- apiversions_v1 "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/apiversions"
3432 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces"
3533 "github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
3634 "github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts"
@@ -644,49 +642,6 @@ func (os *OpenStack) Routes() (cloudprovider.Routes, bool) {
644642 return r , true
645643}
646644
647- // Implementation of sort interface for blockstorage version probing
648- type APIVersionsByID []apiversions_v1.APIVersion
649-
650- func (apiVersions APIVersionsByID ) Len () int {
651- return len (apiVersions )
652- }
653-
654- func (apiVersions APIVersionsByID ) Swap (i , j int ) {
655- apiVersions [i ], apiVersions [j ] = apiVersions [j ], apiVersions [i ]
656- }
657-
658- func (apiVersions APIVersionsByID ) Less (i , j int ) bool {
659- return apiVersions [i ].ID > apiVersions [j ].ID
660- }
661-
662- func autoVersionSelector (apiVersion * apiversions_v1.APIVersion ) string {
663- switch strings .ToLower (apiVersion .ID ) {
664- case "v2.0" :
665- return "v2"
666- case "v1.0" :
667- return "v1"
668- default :
669- return ""
670- }
671- }
672-
673- func doBsApiVersionAutodetect (availableApiVersions []apiversions_v1.APIVersion ) string {
674- sort .Sort (APIVersionsByID (availableApiVersions ))
675- for _ , status := range []string {"CURRENT" , "SUPPORTED" } {
676- for _ , version := range availableApiVersions {
677- if strings .ToUpper (version .Status ) == status {
678- if detectedApiVersion := autoVersionSelector (& version ); detectedApiVersion != "" {
679- glog .V (3 ).Infof ("Blockstorage API version probing has found a suitable %s api version: %s" , status , detectedApiVersion )
680- return detectedApiVersion
681- }
682- }
683- }
684- }
685-
686- return ""
687-
688- }
689-
690645func (os * OpenStack ) volumeService (forceVersion string ) (volumeService , error ) {
691646 bsVersion := ""
692647 if forceVersion == "" {
@@ -701,43 +656,36 @@ func (os *OpenStack) volumeService(forceVersion string) (volumeService, error) {
701656 if err != nil {
702657 return nil , err
703658 }
659+ glog .V (3 ).Infof ("Using Blockstorage API V1" )
704660 return & VolumesV1 {sClient , os .bsOpts }, nil
705661 case "v2" :
706662 sClient , err := os .NewBlockStorageV2 ()
707663 if err != nil {
708664 return nil , err
709665 }
666+ glog .V (3 ).Infof ("Using Blockstorage API V2" )
710667 return & VolumesV2 {sClient , os .bsOpts }, nil
711668 case "auto" :
712- sClient , err := os .NewBlockStorageV1 ()
669+ // Currently kubernetes just support Cinder v1 and Cinder v2.
670+ // Choose Cinder v2 firstly, if kubernetes can't initialize cinder v2 client, try to initialize cinder v1 client.
671+ // Return appropriate message when kubernetes can't initialize them.
672+ // TODO(FengyunPan): revisit 'auto' after supporting Cinder v3.
673+ sClient , err := os .NewBlockStorageV2 ()
713674 if err != nil {
714- return nil , err
715- }
716- availableApiVersions := []apiversions_v1.APIVersion {}
717- err = apiversions_v1 .List (sClient ).EachPage (func (page pagination.Page ) (bool , error ) {
718- // returning false from this handler stops page iteration, error is propagated to the upper function
719- apiversions , err := apiversions_v1 .ExtractAPIVersions (page )
675+ sClient , err = os .NewBlockStorageV1 ()
720676 if err != nil {
721- glog .Errorf ("Unable to extract api versions from page: %v" , err )
722- return false , err
677+ // Nothing suitable found, failed autodetection, just exit with appropriate message
678+ err_txt := "BlockStorage API version autodetection failed. " +
679+ "Please set it explicitly in cloud.conf in section [BlockStorage] with key `bs-version`"
680+ return nil , errors .New (err_txt )
681+ } else {
682+ glog .V (3 ).Infof ("Using Blockstorage API V1" )
683+ return & VolumesV1 {sClient , os .bsOpts }, nil
723684 }
724- availableApiVersions = append (availableApiVersions , apiversions ... )
725- return true , nil
726- })
727-
728- if err != nil {
729- glog .Errorf ("Error when retrieving list of supported blockstorage api versions: %v" , err )
730- return nil , err
731- }
732- if autodetectedVersion := doBsApiVersionAutodetect (availableApiVersions ); autodetectedVersion != "" {
733- return os .volumeService (autodetectedVersion )
734685 } else {
735- // Nothing suitable found, failed autodetection, just exit with appropriate message
736- err_txt := "BlockStorage API version autodetection failed. " +
737- "Please set it explicitly in cloud.conf in section [BlockStorage] with key `bs-version`"
738- return nil , errors .New (err_txt )
686+ glog .V (3 ).Infof ("Using Blockstorage API V2" )
687+ return & VolumesV2 {sClient , os .bsOpts }, nil
739688 }
740-
741689 default :
742690 err_txt := fmt .Sprintf ("Config error: unrecognised bs-version \" %v\" " , os .bsOpts .BSVersion )
743691 glog .Warningf (err_txt )
0 commit comments