From aae6f1e6b91486d8d0cb849f091412c21c96c394 Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Tue, 17 Sep 2019 16:20:01 +0800 Subject: [PATCH] host: use public endpoint --- pkg/hostman/hostutils/hostutils.go | 6 ++--- pkg/hostman/storageman/imagecache_local.go | 2 +- pkg/mcclient/auth/auth.go | 27 +++++++++++++++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/pkg/hostman/hostutils/hostutils.go b/pkg/hostman/hostutils/hostutils.go index 1c202f2534..6de4686f6a 100644 --- a/pkg/hostman/hostutils/hostutils.go +++ b/pkg/hostman/hostutils/hostutils.go @@ -52,15 +52,15 @@ type IHost interface { } func GetComputeSession(ctx context.Context) *mcclient.ClientSession { - return auth.GetAdminSession(ctx, options.HostOptions.Region, "v2") + return auth.GetAdminSessionWithPublic(ctx, options.HostOptions.Region, "v2") } func GetK8sSession(ctx context.Context) *mcclient.ClientSession { - return auth.GetAdminSession(ctx, options.HostOptions.Region, "") + return auth.GetAdminSessionWithPublic(ctx, options.HostOptions.Region, "") } func GetImageSession(ctx context.Context, zone string) *mcclient.ClientSession { - return auth.AdminSession(ctx, options.HostOptions.Region, zone, "internal", "v1") + return auth.AdminSessionWithPublic(ctx, options.HostOptions.Region, zone, "v1") } func TaskFailed(ctx context.Context, reason string) { diff --git a/pkg/hostman/storageman/imagecache_local.go b/pkg/hostman/storageman/imagecache_local.go index 0157fa2f37..2ec757cd8c 100644 --- a/pkg/hostman/storageman/imagecache_local.go +++ b/pkg/hostman/storageman/imagecache_local.go @@ -171,7 +171,7 @@ func (l *SLocalImageCache) prepare(ctx context.Context, zone, srcUrl, format str l.consumerCount++ return true, true } - url, err := auth.GetServiceURL("image", "", zone, "internal") + url, err := auth.GetServiceURL("image", "", zone, "public") if err != nil { log.Errorf("Failed to acquire image %s", err) return false, true diff --git a/pkg/mcclient/auth/auth.go b/pkg/mcclient/auth/auth.go index 41c90b5f80..4ad36c7154 100644 --- a/pkg/mcclient/auth/auth.go +++ b/pkg/mcclient/auth/auth.go @@ -279,6 +279,14 @@ func AdminSession(ctx context.Context, region, zone, endpointType, apiVersion st return cli.NewSession(ctx, region, zone, endpointType, AdminCredential(), apiVersion) } +func AdminSessionWithInternal(ctx context.Context, region, zone, apiVersion string) *mcclient.ClientSession { + return AdminSession(ctx, region, zone, "internal", apiVersion) +} + +func AdminSessionWithPublic(ctx context.Context, region, zone, apiVersion string) *mcclient.ClientSession { + return AdminSession(ctx, region, zone, "public", apiVersion) +} + type AuthCompletedCallback func() func (callback *AuthCompletedCallback) Run() { @@ -317,8 +325,25 @@ func GetAdminSession(ctx context.Context, region string, return GetSession(ctx, manager.adminCredential, region, apiVersion) } +func GetAdminSessionWithPublic(ctx context.Context, region string, + apiVersion string) *mcclient.ClientSession { + return GetSessionWithPublic(ctx, manager.adminCredential, region, apiVersion) +} + func GetSession(ctx context.Context, token mcclient.TokenCredential, region string, apiVersion string) *mcclient.ClientSession { - return manager.client.NewSession(ctx, region, "", "internal", token, apiVersion) + return GetSessionWithInternal(ctx, token, region, apiVersion) +} + +func GetSessionWithInternal(ctx context.Context, token mcclient.TokenCredential, region string, apiVersion string) *mcclient.ClientSession { + return getSessionByType(ctx, token, region, apiVersion, "internal") +} + +func GetSessionWithPublic(ctx context.Context, token mcclient.TokenCredential, region string, apiVersion string) *mcclient.ClientSession { + return getSessionByType(ctx, token, region, apiVersion, "public") +} + +func getSessionByType(ctx context.Context, token mcclient.TokenCredential, region string, apiVersion string, epType string) *mcclient.ClientSession { + return manager.client.NewSession(ctx, region, "", epType, token, apiVersion) } // use for climc test only