fix: 增加openstack兼容性 (#7492)

Co-authored-by: Qu Xuan <quxuan@yunionyun.com>
This commit is contained in:
屈轩
2020-08-06 11:56:18 +08:00
committed by GitHub
co-authored by Qu Xuan
parent d988b41a39
commit 327b60baf6
3 changed files with 18 additions and 8 deletions
+1 -1
View File
@@ -100,7 +100,7 @@ func (host *SHypervisor) GetIWires() ([]cloudprovider.ICloudWire, error) {
func (host *SHypervisor) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
istorages := []cloudprovider.ICloudStorage{}
storages, err := host.zone.region.GetStorageTypes()
if err != nil {
if err != nil && errors.Cause(err) != ErrNoEndpoint {
return nil, errors.Wrap(err, "GetStorageTypes")
}
for i := range storages {
+16 -6
View File
@@ -45,6 +45,8 @@ const (
OPENSTACK_SERVICE_VOLUMEV2 = "volumev2"
OPENSTACK_SERVICE_VOLUME = "volume"
OPENSTACK_SERVICE_IMAGE = "image"
ErrNoEndpoint = errors.Error("no valid endpoint")
)
type OpenstackClientConfig struct {
@@ -256,12 +258,20 @@ func jsonReuest(token mcclient.TokenCredential, service, region, endpointType st
}
}
requestUrl := resource
if !strings.HasPrefix(resource, serviceUrl) {
requestUrl = fmt.Sprintf("%s/%s", serviceUrl, resource)
if service == OPENSTACK_SERVICE_IDENTITY {
if strings.HasSuffix(serviceUrl, "/v3/") {
serviceUrl = strings.TrimSuffix(serviceUrl, "/v3/")
} else if strings.HasSuffix(serviceUrl, "/v3") {
serviceUrl = strings.TrimSuffix(serviceUrl, "/v3")
}
}
if query != nil {
requestUrl := resource
if !strings.HasPrefix(resource, serviceUrl) {
requestUrl = fmt.Sprintf("%s/%s", strings.TrimSuffix(serviceUrl, "/"), strings.TrimPrefix(resource, "/"))
}
if query != nil && len(query) > 0 {
requestUrl = fmt.Sprintf("%s?%s", requestUrl, query.Encode())
}
@@ -333,7 +343,7 @@ func (cli *SOpenStackClient) bsRequest(region string, method httputils.THttpMeth
return jsonReuest(cli.tokenCredential, service, region, cli.endpointType, method, resource, query, body, cli.debug)
}
}
return nil, fmt.Errorf("no valid volume service endpoint")
return nil, errors.Wrap(ErrNoEndpoint, "cinder service")
}
func (cli *SOpenStackClient) bsCreate(projectId, region, resource string, body interface{}) (jsonutils.JSONObject, error) {
@@ -351,7 +361,7 @@ func (cli *SOpenStackClient) bsCreate(projectId, region, resource string, body i
return jsonReuest(token, service, region, cli.endpointType, httputils.POST, resource, nil, body, cli.debug)
}
}
return nil, fmt.Errorf("no valid volume service endpoint")
return nil, errors.Wrap(ErrNoEndpoint, "cinder service")
}
func (cli *SOpenStackClient) imageUpload(region, url string, body io.Reader) (*http.Response, error) {
+1 -1
View File
@@ -112,7 +112,7 @@ func (zone *SZone) getStorageByCategory(category, host string) (*SStorage, error
func (zone *SZone) GetIStorages() ([]cloudprovider.ICloudStorage, error) {
storages, err := zone.region.GetStorageTypes()
if err != nil {
if err != nil && errors.Cause(err) != ErrNoEndpoint {
return nil, errors.Wrap(err, "GetStorageTypes")
}
istorages := []cloudprovider.ICloudStorage{}