mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/yunionio/cloudpods.git
synced 2026-09-20 08:03:53 +08:00
fix: remove apiversion param from session
This commit is contained in:
@@ -68,9 +68,9 @@ type BaseOptions struct {
|
||||
OsRegionName string `default:"$OS_REGION_NAME" help:"Defaults to env[OS_REGION_NAME]"`
|
||||
OsZoneName string `default:"$OS_ZONE_NAME" help:"Defaults to env[OS_ZONE_NAME]"`
|
||||
OsEndpointType string `default:"$OS_ENDPOINT_TYPE|internalURL" help:"Defaults to env[OS_ENDPOINT_TYPE] or internalURL" choices:"publicURL|internalURL|adminURL"`
|
||||
ApiVersion string `default:"$API_VERSION" help:"override default modules service api version"`
|
||||
OutputFormat string `default:"$CLIMC_OUTPUT_FORMAT|table" choices:"table|kv|json|flatten-table|flatten-kv" help:"output format"`
|
||||
SUBCOMMAND string `help:"climc subcommand" subcommand:"true"`
|
||||
// ApiVersion string `default:"$API_VERSION" help:"override default modules service api version"`
|
||||
OutputFormat string `default:"$CLIMC_OUTPUT_FORMAT|table" choices:"table|kv|json|flatten-table|flatten-kv" help:"output format"`
|
||||
SUBCOMMAND string `help:"climc subcommand" subcommand:"true"`
|
||||
}
|
||||
|
||||
func getSubcommandsParser() (*structarg.ArgumentParser, error) {
|
||||
@@ -222,16 +222,13 @@ func newClientSession(options *BaseOptions) (*mcclient.ClientSession, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if options.ApiVersion != "" {
|
||||
mcclient.DisableApiVersionByModule()
|
||||
}
|
||||
session := client.NewSession(
|
||||
context.Background(),
|
||||
options.OsRegionName,
|
||||
options.OsZoneName,
|
||||
options.OsEndpointType,
|
||||
cacheToken,
|
||||
options.ApiVersion)
|
||||
)
|
||||
return session, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ func init() {
|
||||
svcUrl string
|
||||
)
|
||||
if len(opts.Service) > 0 {
|
||||
svcUrl, err = s.GetServiceURL(opts.Service, "")
|
||||
svcUrl, err = s.GetServiceURL(opts.Service, "", "")
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "get service %s url", opts.Service)
|
||||
}
|
||||
|
||||
@@ -62,9 +62,7 @@ func init() {
|
||||
if opts.All {
|
||||
resSets := sets.NewString()
|
||||
mods, _ := modulebase.GetRegisterdModules()
|
||||
for _, ress := range mods {
|
||||
resSets.Insert(ress...)
|
||||
}
|
||||
resSets.Insert(mods...)
|
||||
resources = resSets.List()
|
||||
}
|
||||
if len(resources) == 0 {
|
||||
|
||||
@@ -62,7 +62,7 @@ func newClientSession(options *options.CloudMonOptions) (*mcclient.ClientSession
|
||||
"",
|
||||
options.EndpointType,
|
||||
token,
|
||||
options.ApiVersion)
|
||||
)
|
||||
|
||||
return session, nil
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ var PlaybookWorker *workmanager.SWorkManager
|
||||
|
||||
func taskFailed(ctx context.Context, reason string) {
|
||||
if taskId := ctx.Value(appctx.APP_CONTEXT_KEY_TASK_ID); taskId != nil {
|
||||
session := auth.GetAdminSessionWithInternal(ctx, "", "")
|
||||
session := auth.GetAdminSessionWithInternal(ctx, "")
|
||||
modules.TaskFailed(&compute.DevtoolTasks, session, taskId.(string), reason)
|
||||
} else {
|
||||
log.Warningf("Reqeuest task failed missing task id, with reason: %s", reason)
|
||||
@@ -224,7 +224,7 @@ func taskFailed(ctx context.Context, reason string) {
|
||||
|
||||
func taskCompleted(ctx context.Context, data jsonutils.JSONObject) {
|
||||
if taskId := ctx.Value(appctx.APP_CONTEXT_KEY_TASK_ID); taskId != nil {
|
||||
session := auth.GetAdminSessionWithInternal(ctx, "", "")
|
||||
session := auth.GetAdminSessionWithInternal(ctx, "")
|
||||
modules.TaskComplete(&compute.DevtoolTasks, session, taskId.(string), data)
|
||||
} else {
|
||||
log.Warningf("Reqeuest task failed missing task id, with data: %v", data)
|
||||
|
||||
@@ -102,7 +102,7 @@ func (v *ValidatorAnsiblePlaybook) Validate(data *jsonutils.JSONDict) error {
|
||||
}
|
||||
|
||||
func (v *ValidatorAnsiblePlaybook) getHostAccessIp(name string) (string, error) {
|
||||
sess := mcclient_auth.GetSession(context.Background(), v.userCred, "", "")
|
||||
sess := mcclient_auth.GetSession(context.Background(), v.userCred, "")
|
||||
hostJson, err := compute.Hosts.Get(sess, name, nil)
|
||||
if err != nil {
|
||||
return "", httperrors.NewBadRequestError("cannot find host %s", name)
|
||||
@@ -118,7 +118,7 @@ func (v *ValidatorAnsiblePlaybook) getHostAccessIp(name string) (string, error)
|
||||
}
|
||||
|
||||
func (v *ValidatorAnsiblePlaybook) getServerIp(name string) (string, error) {
|
||||
sess := mcclient_auth.GetSession(context.Background(), v.userCred, "", "")
|
||||
sess := mcclient_auth.GetSession(context.Background(), v.userCred, "")
|
||||
serverJson, err := compute.Servers.Get(sess, name, nil)
|
||||
if err != nil {
|
||||
return "", httperrors.NewBadRequestError("find server %s: %v", name, err)
|
||||
|
||||
@@ -151,7 +151,7 @@ func (h *AuthHandlers) GetRegionsResponse(ctx context.Context, w http.ResponseWr
|
||||
EncryptPasswd: true,
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, regions[0], "")
|
||||
s := auth.GetAdminSession(ctx, regions[0])
|
||||
if options.Options.ReturnFullDomainList {
|
||||
filters := jsonutils.NewDict()
|
||||
if len(currentDomain) > 0 {
|
||||
@@ -228,7 +228,7 @@ func (h *AuthHandlers) getUser(ctx context.Context, w http.ResponseWriter, req *
|
||||
|
||||
func getStatsInfo(ctx context.Context, req *http.Request) (jsonutils.JSONObject, error) {
|
||||
token := AppContextToken(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(req), "")
|
||||
s := auth.GetSession(ctx, token, FetchRegion(req))
|
||||
params, _ := jsonutils.ParseQueryString(req.URL.RawQuery)
|
||||
|
||||
if params == nil {
|
||||
@@ -306,7 +306,7 @@ func doTenantLogin(ctx context.Context, req *http.Request, body jsonutils.JSONOb
|
||||
}
|
||||
|
||||
func fetchUserInfoFromToken(ctx context.Context, req *http.Request, token mcclient.TokenCredential) (jsonutils.JSONObject, error) {
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
return fetchUserInfoById(s, token.GetUserId())
|
||||
}
|
||||
|
||||
@@ -383,7 +383,7 @@ func (h *AuthHandlers) doCredentialLogin(ctx context.Context, req *http.Request,
|
||||
}
|
||||
uname := token.GetUserName()
|
||||
if len(tenant) > 0 {
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
jsonProj, e := modules.Projects.GetById(s, tenant, nil)
|
||||
if e != nil {
|
||||
log.Errorf("fail to find preset project %s, reset to empty", tenant)
|
||||
@@ -430,7 +430,7 @@ func (h *AuthHandlers) doCredentialLogin(ctx context.Context, req *http.Request,
|
||||
}
|
||||
}
|
||||
if len(tenant) == 0 {
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
projects, e := modules.UsersV3.GetProjects(s, token.GetUserId())
|
||||
if e == nil && len(projects.Data) > 0 {
|
||||
projectJson := projects.Data[0]
|
||||
@@ -584,7 +584,7 @@ func (h *AuthHandlers) doLogin(ctx context.Context, w http.ResponseWriter, req *
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
isTotpInit, err := isUserTotpCredInitialed(s, token.GetUserId())
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -844,7 +844,7 @@ func isHostAgentExists(s *mcclient.ClientSession) (bool, error) {
|
||||
|
||||
func getUserInfo(ctx context.Context, req *http.Request) (*jsonutils.JSONDict, error) {
|
||||
token := AppContextToken(ctx)
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
/*log.Infof("getUserInfo modules.UsersV3.Get")
|
||||
usr, err := modules.UsersV3.Get(s, token.GetUserId(), nil)
|
||||
if err != nil {
|
||||
@@ -1117,7 +1117,7 @@ func (h *AuthHandlers) doCreatePolicies(ctx context.Context, w http.ResponseWrit
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
return
|
||||
}
|
||||
s := auth.GetSession(ctx, t, FetchRegion(req), "")
|
||||
s := auth.GetSession(ctx, t, FetchRegion(req))
|
||||
result, err := policytool.PolicyCreate(s, body)
|
||||
if err != nil {
|
||||
httperrors.GeneralServerError(ctx, w, err)
|
||||
@@ -1137,7 +1137,7 @@ func (h *AuthHandlers) doPatchPolicy(ctx context.Context, w http.ResponseWriter,
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
return
|
||||
}
|
||||
s := auth.GetSession(ctx, t, FetchRegion(req), "")
|
||||
s := auth.GetSession(ctx, t, FetchRegion(req))
|
||||
result, err := policytool.PolicyPatch(s, params["<policy_id>"], body)
|
||||
if err != nil {
|
||||
httperrors.GeneralServerError(ctx, w, err)
|
||||
@@ -1153,7 +1153,7 @@ func (h *AuthHandlers) doDeletePolicies(ctx context.Context, w http.ResponseWrit
|
||||
// return
|
||||
// }
|
||||
_, query, _ := appsrv.FetchEnv(ctx, w, req)
|
||||
s := auth.GetSession(ctx, t, FetchRegion(req), "")
|
||||
s := auth.GetSession(ctx, t, FetchRegion(req))
|
||||
|
||||
idlist, e := query.GetArray("id")
|
||||
if e != nil || len(idlist) == 0 {
|
||||
@@ -1245,7 +1245,7 @@ func (h *AuthHandlers) resetUserPassword(ctx context.Context, w http.ResponseWri
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
// 2.如果已开启MFA,验证 随机密码正确
|
||||
if isMfaEnabled(user) {
|
||||
err = authToken.VerifyTotpPasscode(s, t.GetUserId(), input.Passcode)
|
||||
|
||||
@@ -214,7 +214,7 @@ func initTotpSecrets(ctx context.Context, w http.ResponseWriter, req *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
code, err := doCreateUserTotpCred(s, t)
|
||||
if err != nil {
|
||||
httperrors.GeneralServerError(ctx, w, err)
|
||||
@@ -237,7 +237,7 @@ func validatePasscodeHandler(ctx context.Context, w http.ResponseWriter, req *ht
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
_, _, body := appsrv.FetchEnv(ctx, w, req)
|
||||
if body == nil {
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
@@ -276,7 +276,7 @@ func resetTotpSecrets(ctx context.Context, w http.ResponseWriter, req *http.Requ
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
_, _, body := appsrv.FetchEnv(ctx, w, req)
|
||||
if body == nil {
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
@@ -314,7 +314,7 @@ func listTotpRecoveryQuestions(ctx context.Context, w http.ResponseWriter, req *
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
// 做缓存?
|
||||
ss, err := modules.Credentials.GetRecoverySecrets(s, t.GetUserId())
|
||||
if len(ss) == 0 {
|
||||
@@ -340,7 +340,7 @@ func resetTotpRecoveryQuestions(ctx context.Context, w http.ResponseWriter, req
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
_, _, body := appsrv.FetchEnv(ctx, w, req)
|
||||
if body == nil {
|
||||
httperrors.InvalidInputError(ctx, w, "request body is empty")
|
||||
|
||||
@@ -68,8 +68,8 @@ func (h *SBackendServiceProxyHandler) fetchReverseEndpoint() *proxy.SEndpointFac
|
||||
return "", httperrors.NewBadRequestError("no service")
|
||||
}
|
||||
endpointType := "internalURL"
|
||||
session := auth.GetAdminSession(ctx, FetchRegion(r), "")
|
||||
ep, err := session.GetServiceURL(serviceName, endpointType)
|
||||
session := auth.GetAdminSession(ctx, FetchRegion(r))
|
||||
ep, err := session.GetServiceURL(serviceName, endpointType, "")
|
||||
if err != nil {
|
||||
return "", httperrors.NewBadRequestError("invalid service %s: %s", serviceName, err)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func (h *CSRFResourceHandler) Bind(app *appsrv.Application) {
|
||||
h.SHandlers.Bind(app)
|
||||
}
|
||||
|
||||
func getAdminSession(ctx context.Context, apiVer string, region string, w http.ResponseWriter) *mcclient.ClientSession {
|
||||
func getAdminSession(ctx context.Context, region string, w http.ResponseWriter) *mcclient.ClientSession {
|
||||
adminToken := auth.AdminCredential()
|
||||
if adminToken == nil {
|
||||
httperrors.NotFoundError(ctx, w, "get admin credential is nil")
|
||||
@@ -60,7 +60,7 @@ func getAdminSession(ctx context.Context, apiVer string, region string, w http.R
|
||||
if !ret {
|
||||
httperrors.NotFoundError(ctx, w, "illegal region %s, please contact admin", region)
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, region, apiVer)
|
||||
s := auth.GetAdminSession(ctx, region)
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ func fetchEnvCsrf0(ctx context.Context, w http.ResponseWriter, r *http.Request)
|
||||
return nil, nil, nil, nil
|
||||
}
|
||||
log.Infof("csrf region from url: %s", region)
|
||||
session := getAdminSession(ctx, params[APIVer], region, w)
|
||||
session := getAdminSession(ctx, region, w)
|
||||
log.Infof("csrf got session: %s", region)
|
||||
if session == nil {
|
||||
return nil, nil, nil, nil
|
||||
|
||||
@@ -49,7 +49,7 @@ func getSsoBaseCallbackUrl() string {
|
||||
|
||||
func getSsoCallbackUrl(ctx context.Context, req *http.Request, idpId string) string {
|
||||
baseUrl := getSsoBaseCallbackUrl()
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
input := api.GetIdpSsoCallbackUriInput{
|
||||
RedirectUri: baseUrl,
|
||||
}
|
||||
@@ -110,7 +110,7 @@ func (h *AuthHandlers) getIdpSsoRedirectUri(ctx context.Context, w http.Response
|
||||
query.(*jsonutils.JSONDict).Set("idp_nonce", jsonutils.NewString(utils.GenRequestId(4)))
|
||||
state := base64.URLEncoding.EncodeToString([]byte(query.String()))
|
||||
redirectUri := getSsoCallbackUrl(ctx, req, idpId)
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
input := api.GetIdpSsoRedirectUriInput{
|
||||
RedirectUri: redirectUri,
|
||||
State: state,
|
||||
@@ -145,7 +145,7 @@ func findExtUserId(input string) string {
|
||||
func (h *AuthHandlers) handleIdpInitSsoLogin(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
params := appctx.AppContextParams(ctx)
|
||||
idpId := params["<idp_id>"]
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
resp, err := modules.IdentityProviders.Get(s, idpId, nil)
|
||||
if err != nil {
|
||||
httperrors.GeneralServerError(ctx, w, err)
|
||||
@@ -383,7 +383,7 @@ func linkWithExistingUser(ctx context.Context, req *http.Request, idpId, idpLink
|
||||
IdpId: idpId,
|
||||
IdpEntityId: extUserId,
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
_, err = modules.UsersV3.PerformAction(s, t.GetUserId(), "link-idp", jsonutils.Marshal(linkInput))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "link-idp")
|
||||
@@ -413,7 +413,7 @@ func handleUnlinkIdp(ctx context.Context, w http.ResponseWriter, req *http.Reque
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
input := api.UserUnlinkIdpInput{
|
||||
IdpId: idpId,
|
||||
IdpEntityId: idpEntityId,
|
||||
@@ -438,7 +438,7 @@ func fetchIdpBasicConfig(ctx context.Context, w http.ResponseWriter, req *http.R
|
||||
}
|
||||
|
||||
func getIdpBasicConfig(ctx context.Context, req *http.Request, idpId string) (jsonutils.JSONObject, error) {
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
baseUrl := getSsoBaseCallbackUrl()
|
||||
input := api.GetIdpSsoCallbackUriInput{
|
||||
RedirectUri: baseUrl,
|
||||
@@ -468,7 +468,7 @@ func getIdpBasicConfig(ctx context.Context, req *http.Request, idpId string) (js
|
||||
}
|
||||
|
||||
func fetchIdpSAMLMetadata(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
params := appctx.AppContextParams(ctx)
|
||||
idpId := params["<idp_id>"]
|
||||
query := jsonutils.NewDict()
|
||||
|
||||
@@ -130,7 +130,7 @@ func imageUploadHandler(ctx context.Context, w http.ResponseWriter, r *http.Requ
|
||||
}
|
||||
|
||||
token := AppContextToken(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(r), "")
|
||||
s := auth.GetSession(ctx, token, FetchRegion(r))
|
||||
|
||||
res, e := modules.Images.Upload(s, params, f, imageSize)
|
||||
if e != nil {
|
||||
@@ -213,7 +213,7 @@ func imageDownload(ctx context.Context, w http.ResponseWriter, s *mcclient.Clien
|
||||
func imageDownloadHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
params, query, _ := appsrv.FetchEnv(ctx, w, r)
|
||||
token := AppContextToken(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(r), "")
|
||||
s := auth.GetSession(ctx, token, FetchRegion(r))
|
||||
// input params
|
||||
imageId, ok := params["<image_id>"]
|
||||
if !ok || len(imageId) == 0 {
|
||||
@@ -273,7 +273,7 @@ func imageDownloadByUrlHandler(ctx context.Context, w http.ResponseWriter, r *ht
|
||||
return
|
||||
}
|
||||
format, _ := d.GetString("format")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
imageDownload(ctx, w, s, id, format)
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ func (h *K8sResourceHandler) fetchEnv(ctx context.Context, req *http.Request) (*
|
||||
namespace, _ := params.GetString("namespace")
|
||||
cluster, _ := params.GetString("cluster")
|
||||
token := AppContextToken(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(req), "")
|
||||
s := auth.GetSession(ctx, token, FetchRegion(req))
|
||||
return &k8sResourceEnv{
|
||||
session: s,
|
||||
cluster: cluster,
|
||||
|
||||
@@ -70,9 +70,9 @@ var (
|
||||
BatchHostPXERegisterTemplate = []string{HOST_NAME, HOST_IPMI_ADDR, HOST_IPMI_USERNAME, HOST_IPMI_PASSWORD, HOST_MNG_MAC_ADDR_OPTIONAL, HOST_MNG_IP_ADDR_OPTIONAL}
|
||||
)
|
||||
|
||||
func FetchSession(ctx context.Context, r *http.Request, apiVersion string) *mcclient.ClientSession {
|
||||
func FetchSession(ctx context.Context, r *http.Request) *mcclient.ClientSession {
|
||||
token := AppContextToken(ctx)
|
||||
session := auth.GetSession(ctx, token, FetchRegion(r), apiVersion)
|
||||
session := auth.GetSession(ctx, token, FetchRegion(r))
|
||||
return session
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ func (mh *MiscHandler) DoBatchHostRegister(ctx context.Context, w http.ResponseW
|
||||
}
|
||||
|
||||
params := jsonutils.NewDict()
|
||||
s := FetchSession(ctx, req, "")
|
||||
s := FetchSession(ctx, req)
|
||||
params.Set("hosts", jsonutils.NewString(hosts.String()))
|
||||
|
||||
// extra params
|
||||
@@ -301,8 +301,8 @@ func (mh *MiscHandler) DoBatchHostRegister(ctx context.Context, w http.ResponseW
|
||||
}
|
||||
|
||||
func (mh *MiscHandler) DoBatchUserRegister(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
adminS := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := FetchSession(ctx, req, "")
|
||||
adminS := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
s := FetchSession(ctx, req)
|
||||
files := req.MultipartForm.File
|
||||
|
||||
userfiles, ok := files["users"]
|
||||
@@ -543,7 +543,7 @@ func (mh *MiscHandler) postS3UploadHandler(ctx context.Context, w http.ResponseW
|
||||
acl, _ := p["acl"]
|
||||
|
||||
token := AppContextToken(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(r), "")
|
||||
s := auth.GetSession(ctx, token, FetchRegion(r))
|
||||
|
||||
meta := http.Header{}
|
||||
meta.Set("Content-Type", "application/octet-stream")
|
||||
|
||||
@@ -107,7 +107,7 @@ func handleOIDCAuth(ctx context.Context, w http.ResponseWriter, req *http.Reques
|
||||
|
||||
func fetchOIDCCredential(ctx context.Context, req *http.Request, clientId string) (modules.SOpenIDConnectCredential, error) {
|
||||
var oidcSecret modules.SOpenIDConnectCredential
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req), "")
|
||||
s := auth.GetAdminSession(ctx, FetchRegion(req))
|
||||
secret, err := modules.Credentials.GetById(s, clientId, nil)
|
||||
if err != nil {
|
||||
return oidcSecret, errors.Wrap(err, "Request Credential")
|
||||
@@ -405,7 +405,7 @@ func handleOIDCUserInfo(ctx context.Context, w http.ResponseWriter, req *http.Re
|
||||
return
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, token.Info.Region, "")
|
||||
s := auth.GetAdminSession(ctx, token.Info.Region)
|
||||
data, err := getUserInfo2(s, token.Info.UserId, token.Info.ProjectId, token.Info.Ip.String())
|
||||
if err != nil {
|
||||
httperrors.NotFoundError(ctx, w, "%v", err)
|
||||
|
||||
@@ -68,8 +68,8 @@ func getEndpointSchemeHost(endpoint string) (string, error) {
|
||||
func fetchReverseEndpoint(serviceName string) *proxy.SEndpointFactory {
|
||||
f := func(ctx context.Context, r *http.Request) (string, error) {
|
||||
endpointType := "internalURL"
|
||||
session := auth.GetAdminSession(ctx, FetchRegion(r), "")
|
||||
ep, err := session.GetServiceURL(serviceName, endpointType)
|
||||
session := auth.GetAdminSession(ctx, FetchRegion(r))
|
||||
ep, err := session.GetServiceURL(serviceName, endpointType, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ type Request struct {
|
||||
func newRequest(ctx context.Context, w http.ResponseWriter, r *http.Request) *Request {
|
||||
params := appctx.AppContextParams(ctx)
|
||||
token := AppContextToken(ctx)
|
||||
session := auth.GetSession(ctx, token, FetchRegion(r), params[APIVer])
|
||||
session := auth.GetSession(ctx, token, FetchRegion(r))
|
||||
query, err := jsonutils.ParseQueryString(r.URL.RawQuery)
|
||||
req := &Request{
|
||||
ctx: ctx,
|
||||
|
||||
@@ -83,8 +83,8 @@ func RpcHandler(ctx context.Context, w http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
token := AppContextToken(ctx)
|
||||
pathParams := appctx.AppContextParams(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(req), pathParams["<apiver>"])
|
||||
// pathParams := appctx.AppContextParams(ctx)
|
||||
s := auth.GetSession(ctx, token, FetchRegion(req))
|
||||
funcname := verb + utils.Kebab2Camel(callName, "-")
|
||||
mod, e := modulebase.GetModule(s, resType)
|
||||
if e != nil || mod == nil {
|
||||
|
||||
@@ -156,7 +156,7 @@ func fetchSyslogMessage(r *http.Request) jsonutils.JSONObject {
|
||||
params.Add(jsonutils.NewString(moduleType), "service")
|
||||
}
|
||||
|
||||
sess := auth.GetAdminSession(nil, "", "")
|
||||
sess := auth.GetAdminSession(nil, "")
|
||||
logs, err := modules.Actions.List(sess, params)
|
||||
if err != nil {
|
||||
ret.Code = 2
|
||||
|
||||
@@ -69,7 +69,7 @@ func Report(ctx context.Context, userCred mcclient.TokenCredential, isStart bool
|
||||
getFunc := func() (*sReport, error) {
|
||||
ret := &sReport{}
|
||||
ret.Version = version.GetShortString()
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
system := jsonutils.Marshal(map[string]string{"scope": "system"})
|
||||
user, err := identity.UsersV3.Get(s, idapi.SystemAdminUser, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -31,7 +31,6 @@ import (
|
||||
app_common "yunion.io/x/onecloud/pkg/cloudcommon/app"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/cronman"
|
||||
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
func StartService() {
|
||||
@@ -46,10 +45,6 @@ func StartService() {
|
||||
|
||||
common_options.StartOptionManager(opts, opts.ConfigSyncPeriodSeconds, api.SERVICE_TYPE, api.SERVICE_VERSION, options.OnOptionsChange)
|
||||
|
||||
if opts.DisableModuleApiVersion {
|
||||
mcclient.DisableApiVersionByModule()
|
||||
}
|
||||
|
||||
if err := clientman.InitClient(); err != nil {
|
||||
log.Fatalf("Init client token manager: %v", err)
|
||||
}
|
||||
|
||||
@@ -128,7 +128,6 @@ func (h *APIHelper) adminClientSession(ctx context.Context) *mcclient.ClientSess
|
||||
}
|
||||
|
||||
region := h.opts.CommonOptions.Region
|
||||
apiVersion := "v2"
|
||||
h.mcclientSession = auth.GetAdminSession(ctx, region, apiVersion)
|
||||
h.mcclientSession = auth.GetAdminSession(ctx, region)
|
||||
return h.mcclientSession
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ func (agent *SBaremetalAgent) GetZoneId() string {
|
||||
}
|
||||
|
||||
func (agent *SBaremetalAgent) GetAdminSession() *mcclient.ClientSession {
|
||||
return auth.GetAdminSession(context.TODO(), o.Options.Region, "v2")
|
||||
return auth.GetAdminSession(context.TODO(), o.Options.Region)
|
||||
}
|
||||
|
||||
func (agent *SBaremetalAgent) GetListenIP() (net.IP, error) {
|
||||
|
||||
@@ -138,7 +138,7 @@ func eventToJson(e redfish.SEvent) *jsonutils.JSONDict {
|
||||
|
||||
func fetchLogs(baremetal *SBaremetalInstance, ctx context.Context, logType string) error {
|
||||
params := jsonutils.NewDict()
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
params.Add(jsonutils.NewInt(1), "limit")
|
||||
params.Add(jsonutils.NewString(baremetal.GetId()), "host_id")
|
||||
params.Add(jsonutils.NewString(logType), "type")
|
||||
@@ -216,8 +216,8 @@ func (job *SSendMetricsJob) Name() string {
|
||||
}
|
||||
|
||||
func (job *SSendMetricsJob) Do(ctx context.Context, now time.Time) error {
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "")
|
||||
urls, err := s.GetServiceURLs("influxdb", o.Options.SessionEndpointType)
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
urls, err := s.GetServiceURLs("influxdb", o.Options.SessionEndpointType, "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "s.GetServiceURLs")
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ func NewBaremetalRegisterTask(
|
||||
}
|
||||
|
||||
func (s *sBaremetalRegisterTask) getSession() *mcclient.ClientSession {
|
||||
return auth.GetSession(context.Background(), s.userCred, o.Options.Region, "v2")
|
||||
return auth.GetSession(context.Background(), s.userCred, o.Options.Region)
|
||||
}
|
||||
|
||||
func (s *sBaremetalRegisterTask) getAccessDevMacAddr(ip string) (string, error) {
|
||||
|
||||
@@ -100,7 +100,7 @@ func InitBaseAuth(options *common_options.BaseOptions) {
|
||||
}
|
||||
|
||||
func FetchEtcdServiceInfo() (*identity.EndpointDetails, error) {
|
||||
s := auth.GetAdminSession(context.Background(), "", "")
|
||||
s := auth.GetAdminSession(context.Background(), "")
|
||||
return s.GetCommonEtcdEndpoint()
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ func (res *SEncryptedResource) GetEncryptInfo(
|
||||
userCred mcclient.TokenCredential,
|
||||
) (apis.SEncryptInfo, error) {
|
||||
ret := apis.SEncryptInfo{}
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion(), "")
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion())
|
||||
secKey, err := identity_modules.Credentials.GetEncryptKey(session, res.EncryptKeyId)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "GetEncryptKey")
|
||||
@@ -82,7 +82,7 @@ func (manager *SEncryptedResourceManager) ValidateCreateData(
|
||||
input apis.EncryptedResourceCreateInput,
|
||||
) (apis.EncryptedResourceCreateInput, error) {
|
||||
if input.EncryptKeyId != nil && len(*input.EncryptKeyId) > 0 {
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion(), "v1")
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion())
|
||||
keyObj, err := identity_modules.Credentials.Get(session, *input.EncryptKeyId, nil)
|
||||
if err != nil {
|
||||
return input, errors.Wrap(err, "Credentials get key")
|
||||
@@ -103,7 +103,7 @@ func (manager *SEncryptedResourceManager) ValidateCreateData(
|
||||
func (res *SEncryptedResource) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, data jsonutils.JSONObject, nameHint string) error {
|
||||
if len(res.EncryptKeyId) == 0 && jsonutils.QueryBoolean(data, "encrypt_key_new", false) && !jsonutils.QueryBoolean(data, "dry_run", false) {
|
||||
// create new encrypt key
|
||||
session := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
session := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
now := time.Now()
|
||||
keyName := "key-" + nameHint + "-" + timeutils.ShortDate(now)
|
||||
algName, _ := data.GetString("encrypt_key_alg")
|
||||
@@ -127,7 +127,7 @@ func (manager *SEncryptedResourceManager) FetchCustomizeColumns(
|
||||
) []apis.EncryptedResourceDetails {
|
||||
rets := make([]apis.EncryptedResourceDetails, len(objs))
|
||||
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion(), "")
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion())
|
||||
encKeyMap := make(map[string]identity_modules.SEncryptKeySecret)
|
||||
for i := range objs {
|
||||
var base *SEncryptedResource
|
||||
|
||||
@@ -123,7 +123,7 @@ func (manager *SRoleCacheManager) FetchRoleFromKeystone(ctx context.Context, idS
|
||||
query.Set("scope", jsonutils.NewString("system"))
|
||||
query.Set("system", jsonutils.JSONTrue)
|
||||
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
role, err := modules.RolesV3.GetById(s, idStr, query)
|
||||
if err != nil {
|
||||
if je, ok := err.(*httputils.JSONClientError); ok && je.Code == 404 {
|
||||
@@ -263,7 +263,7 @@ func (manager *SRoleCacheManager) StartWatchRoleInKeystone() error {
|
||||
return nil
|
||||
}
|
||||
ctx := context.Background()
|
||||
s := auth.GetAdminSession(ctx, "", "")
|
||||
s := auth.GetAdminSession(ctx, "")
|
||||
watchMan, err := informer.NewWatchManagerBySession(s)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -231,7 +231,7 @@ func (manager *STenantCacheManager) fetchTenantFromKeystone(ctx context.Context,
|
||||
query := jsonutils.NewDict()
|
||||
query.Set("scope", jsonutils.NewString("system"))
|
||||
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
tenant, err := modules.Projects.GetById(s, idStr, query)
|
||||
if err != nil {
|
||||
if je, ok := err.(*httputils.JSONClientError); ok && je.Code == 404 {
|
||||
@@ -286,7 +286,7 @@ func (manager *STenantCacheManager) fetchDomainFromKeystone(ctx context.Context,
|
||||
log.Debugf("fetch empty domain!!!!\n%s", debug.Stack())
|
||||
return nil, fmt.Errorf("Empty idStr")
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
tenant, err := modules.Domains.GetById(s, idStr, nil)
|
||||
if err != nil {
|
||||
if je, ok := err.(*httputils.JSONClientError); ok && je.Code == 404 {
|
||||
@@ -421,7 +421,7 @@ func (manager *STenantCacheManager) fetchDomainTenantsFromKeystone(ctx context.C
|
||||
return fmt.Errorf("Empty domainId")
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(domainId), "domain_id")
|
||||
params.Add(jsonutils.JSONTrue, "details")
|
||||
|
||||
@@ -69,7 +69,7 @@ func (w *tenantCacheSyncWorker) Dump() string {
|
||||
}
|
||||
|
||||
func syncDomains(ctx context.Context) error {
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
query := jsonutils.NewDict()
|
||||
query.Add(jsonutils.NewInt(1024), "limit")
|
||||
query.Add(jsonutils.NewString(string(rbacutils.ScopeSystem)), "scope")
|
||||
@@ -98,7 +98,7 @@ func syncDomains(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func syncProjects(ctx context.Context) error {
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
query := jsonutils.NewDict()
|
||||
query.Add(jsonutils.NewInt(1024), "limit")
|
||||
query.Add(jsonutils.NewString(string(rbacutils.ScopeSystem)), "scope")
|
||||
|
||||
@@ -125,7 +125,7 @@ func (manager *SUserCacheManager) FetchUserFromKeystone(ctx context.Context, idS
|
||||
query.Set("scope", jsonutils.NewString("system"))
|
||||
query.Set("system", jsonutils.JSONTrue)
|
||||
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
user, err := modules.UsersV3.GetById(s, idStr, query)
|
||||
if err != nil {
|
||||
if je, ok := err.(*httputils.JSONClientError); ok && je.Code == 404 {
|
||||
|
||||
@@ -237,7 +237,7 @@ func (t *eventTask) Dump() string {
|
||||
}
|
||||
|
||||
func (t *eventTask) Run() {
|
||||
s, err := AdminSessionGenerator(context.Background(), "", "")
|
||||
s, err := AdminSessionGenerator(context.Background(), "")
|
||||
if err != nil {
|
||||
log.Errorf("unable to get admin session: %v", err)
|
||||
return
|
||||
@@ -361,7 +361,7 @@ func IntelliNotify(ctx context.Context, recipientId []string, isGroup bool, chan
|
||||
}
|
||||
|
||||
func FetchNotifyAdminRecipients(ctx context.Context, region string, users []string, groups []string) {
|
||||
s, err := AdminSessionGenerator(ctx, region, "v1")
|
||||
s, err := AdminSessionGenerator(ctx, region)
|
||||
if err != nil {
|
||||
log.Errorf("unable to get admin session: %v", err)
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func systemNotify(ctx context.Context, priority npk.TNotifyPriority, event strin
|
||||
}
|
||||
|
||||
func notifyAll(ctx context.Context, recipientId []string, isGroup bool, priority npk.TNotifyPriority, event string, data jsonutils.JSONObject) error {
|
||||
s, err := AdminSessionGenerator(ctx, consts.GetRegion(), "")
|
||||
s, err := AdminSessionGenerator(ctx, consts.GetRegion())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func lang(ctx context.Context, contactType npk.TNotifyChannel, reIds []string, c
|
||||
|
||||
func genMsgViaLang(ctx context.Context, p sNotifyParams) ([]npk.SNotifyMessage, error) {
|
||||
reIds := make([]string, 0)
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion(), "")
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -359,7 +359,7 @@ func (t *notifyTask) Dump() string {
|
||||
}
|
||||
|
||||
func (t *notifyTask) Run() {
|
||||
s, err := AdminSessionGenerator(t.ctx, consts.GetRegion(), "")
|
||||
s, err := AdminSessionGenerator(t.ctx, consts.GetRegion())
|
||||
if err != nil {
|
||||
log.Errorf("fail to get session: %v", err)
|
||||
}
|
||||
|
||||
@@ -46,15 +46,15 @@ var (
|
||||
checkTemplates bool
|
||||
)
|
||||
|
||||
type SAdminSessionGenerator func(ctx context.Context, region string, apiVersion string) (*mcclient.ClientSession, error)
|
||||
type SAdminSessionGenerator func(ctx context.Context, region string) (*mcclient.ClientSession, error)
|
||||
type SUserLangFetcher func(uids []string) (map[string]string, error)
|
||||
|
||||
func getAdminSesion(ctx context.Context, region string, apiVersion string) (*mcclient.ClientSession, error) {
|
||||
return auth.GetAdminSession(ctx, region, apiVersion), nil
|
||||
func getAdminSesion(ctx context.Context, region string) (*mcclient.ClientSession, error) {
|
||||
return auth.GetAdminSession(ctx, region), nil
|
||||
}
|
||||
|
||||
func getUserLang(uids []string) (map[string]string, error) {
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion(), "")
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func getUserLang(uids []string) (map[string]string, error) {
|
||||
}
|
||||
|
||||
func getRobotLang(robots []string) (map[string]string, error) {
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion(), "")
|
||||
s, err := AdminSessionGenerator(context.Background(), consts.GetRegion())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func (s *mcclientServiceConfigSession) Merge(opts interface{}, serviceType strin
|
||||
s.config = jsonutils.Marshal(opts).(*jsonutils.JSONDict)
|
||||
region, _ := s.config.GetString("region")
|
||||
// epType, _ := s.config.GetString("session_endpoint_type")
|
||||
s.session = auth.GetAdminSession(context.Background(), region, "")
|
||||
s.session = auth.GetAdminSession(context.Background(), region)
|
||||
s.serviceId, _ = getServiceIdByType(s.session, serviceType, serviceVersion)
|
||||
if len(s.serviceId) > 0 {
|
||||
serviceConf, err := getServiceConfig(s.session, s.serviceId)
|
||||
|
||||
@@ -400,7 +400,7 @@ func explainPolicy(userCred mcclient.TokenCredential, policyReq jsonutils.JSONOb
|
||||
}
|
||||
|
||||
func fetchPolicyDataByIdOrName(ctx context.Context, id string) (*sPolicyData, error) {
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
data, err := identity.Policies.Get(s, id, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "modules.Policies.Get")
|
||||
|
||||
@@ -81,7 +81,7 @@ func (manager *SInformerSyncManager) StartWatching(resMan informer.IResourceMana
|
||||
func (manager *SInformerSyncManager) startWatcher() error {
|
||||
log.Infof("[%s] Start resource informer watcher for %s", manager.Name(), manager.resourceManager.GetKeyword())
|
||||
ctx := context.Background()
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
informer.NewWatchManagerBySessionBg(s, func(watchMan *informer.SWatchManager) error {
|
||||
if err := watchMan.For(manager.resourceManager).AddEventHandler(ctx, manager); err != nil {
|
||||
return errors.Wrapf(err, "watch resource %s", manager.resourceManager.GetKeyword())
|
||||
|
||||
@@ -329,7 +329,7 @@ type SCloudproviderDelegate struct {
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetDelegate() (*SCloudproviderDelegate, error) {
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region, "")
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region)
|
||||
result, err := modules.Cloudproviders.Get(s, self.Id, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "modules.Cloudproviders.Get")
|
||||
|
||||
@@ -88,7 +88,7 @@ func (manager *SCloudaccountManager) GetResourceCount() ([]db.SScopeResourceCoun
|
||||
}
|
||||
|
||||
func (manager *SCloudaccountManager) GetICloudaccounts() ([]SCloudaccount, error) {
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region, "")
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region)
|
||||
|
||||
data := []jsonutils.JSONObject{}
|
||||
offset := int64(0)
|
||||
@@ -449,7 +449,7 @@ func (manager *SCloudaccountManager) FetchAccount(ctx context.Context, id string
|
||||
account, err := manager.FetchById(id)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
session := auth.GetAdminSession(context.Background(), options.Options.Region, "")
|
||||
session := auth.GetAdminSession(context.Background(), options.Options.Region)
|
||||
result, err := modules.Cloudaccounts.Get(session, id, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Cloudaccounts.Get")
|
||||
@@ -493,7 +493,7 @@ type SCloudDelegate struct {
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) getCloudDelegate(ctx context.Context) (*SCloudDelegate, error) {
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
result, err := modules.Cloudaccounts.Get(s, self.Id, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Cloudaccounts.Get")
|
||||
@@ -515,7 +515,7 @@ func (self *SCloudaccount) GetProvider() (cloudprovider.ICloudProvider, error) {
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) GetCloudDelegaes(ctx context.Context) ([]SCloudDelegate, error) {
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
params := map[string]string{"cloudaccount": self.Id}
|
||||
result, err := modules.Cloudproviders.List(s, jsonutils.Marshal(params))
|
||||
if err != nil {
|
||||
@@ -860,7 +860,7 @@ func (self *SCloudaccount) SyncSystemCloudpoliciesFromCloud(ctx context.Context,
|
||||
return nil
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region, "")
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region)
|
||||
transport := httputils.GetTransport(true)
|
||||
transport.Proxy = options.Options.HttpTransportProxyFunc()
|
||||
client := &http.Client{Transport: transport}
|
||||
@@ -982,7 +982,7 @@ func (self *SCloudaccount) GetCloudproviders() ([]SCloudprovider, error) {
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) GetICloudprovider() ([]SCloudprovider, error) {
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region, "")
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region)
|
||||
data := []jsonutils.JSONObject{}
|
||||
offset := int64(0)
|
||||
params := map[string]interface{}{
|
||||
@@ -1895,7 +1895,7 @@ func (self *SCloudaccount) GetUserCloudgroups(userId string) ([]string, error) {
|
||||
if len(cache.ExternalId) > 0 {
|
||||
ret = append(ret, cache.Name)
|
||||
} else {
|
||||
s := auth.GetAdminSession(context.TODO(), options.Options.Region, "")
|
||||
s := auth.GetAdminSession(context.TODO(), options.Options.Region)
|
||||
_, err = cache.GetOrCreateICloudgroup(context.TODO(), s.GetToken())
|
||||
if err != nil {
|
||||
return []string{}, errors.Wrapf(err, "GetOrCreateICloudgroup")
|
||||
|
||||
@@ -83,7 +83,7 @@ func (manager *SCloudproviderManager) FetchProvider(ctx context.Context, id stri
|
||||
provider, err := manager.FetchById(id)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
session := auth.GetAdminSession(context.Background(), options.Options.Region, "")
|
||||
session := auth.GetAdminSession(context.Background(), options.Options.Region)
|
||||
result, err := modules.Cloudproviders.Get(session, id, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Cloudproviders.Get")
|
||||
@@ -105,7 +105,7 @@ func (manager *SCloudproviderManager) FetchProvider(ctx context.Context, id stri
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) getCloudDelegate(ctx context.Context) (*SCloudDelegate, error) {
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
result, err := modules.Cloudproviders.Get(s, self.Id, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Cloudproviders.Get")
|
||||
|
||||
@@ -205,7 +205,7 @@ func (self *SSamluser) SyncAzureGroup() error {
|
||||
return errors.Wrapf(err, "group cache Register")
|
||||
}
|
||||
if len(cache.ExternalId) == 0 {
|
||||
s := auth.GetAdminSession(context.TODO(), options.Options.Region, "")
|
||||
s := auth.GetAdminSession(context.TODO(), options.Options.Region)
|
||||
_, err = cache.GetOrCreateICloudgroup(context.TODO(), s.GetToken())
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "GetOrCreateICloudgroup")
|
||||
|
||||
@@ -451,7 +451,7 @@ func JsonToMetric(obj *jsonutils.JSONDict, name string, tags map[string]string,
|
||||
}
|
||||
|
||||
func SendMetrics(s *mcclient.ClientSession, metrics []influxdb.SMetricData, debug bool, database string) error {
|
||||
urls, err := s.GetServiceURLs("influxdb", o.Options.SessionEndpointType)
|
||||
urls, err := s.GetServiceURLs("influxdb", o.Options.SessionEndpointType, "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "GetServiceURLs")
|
||||
}
|
||||
@@ -596,7 +596,7 @@ func MakePullMetricRoutineWithDur(ctx context.Context, factory ICloudReportFacto
|
||||
go func() {
|
||||
timer := time.NewTimer(0)
|
||||
for {
|
||||
session := auth.GetAdminSession(ctx, "", "")
|
||||
session := auth.GetAdminSession(ctx, "")
|
||||
select {
|
||||
case <-closeChan:
|
||||
log.Warningf("closed provider: %s,name: %s. pull metric", provider.Name, provider.Name)
|
||||
@@ -618,7 +618,7 @@ func MakePullMetricRoutineAtZeroPoint(ctx context.Context, factory ICloudReportF
|
||||
next := now.Add(time.Hour * 24 * interval)
|
||||
date := time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
|
||||
timer.Reset(date.Sub(now))
|
||||
session := auth.GetAdminSession(ctx, "", "")
|
||||
session := auth.GetAdminSession(ctx, "")
|
||||
select {
|
||||
case <-closeChan:
|
||||
log.Warningf("closed provider: %s,brand: %s. pull metric", provider.Name, provider.Brand)
|
||||
|
||||
@@ -52,7 +52,7 @@ func jsonToMetric(obj *jsonutils.JSONDict, name string, tags []string, metrics [
|
||||
}
|
||||
|
||||
func sendMetrics(s *mcclient.ClientSession, metrics []influxdb.SMetricData, debug bool) error {
|
||||
urls, err := s.GetServiceURLs("influxdb", o.Options.SessionEndpointType)
|
||||
urls, err := s.GetServiceURLs("influxdb", o.Options.SessionEndpointType, "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "GetServiceURLs")
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func StartService() {
|
||||
}
|
||||
|
||||
func getCloudproviderList(ctx context.Context) ([]jsonutils.JSONObject, error) {
|
||||
session := auth.GetAdminSessionWithPublic(context.Background(), "", "")
|
||||
session := auth.GetAdminSessionWithPublic(context.Background(), "")
|
||||
query := jsonutils.NewDict()
|
||||
query.Add(jsonutils.NewString("10"), common.KEY_LIMIT)
|
||||
query.Add(jsonutils.NewString("true"), common.KEY_ADMIN)
|
||||
|
||||
@@ -72,7 +72,7 @@ func (router *SRouter) realize(ctx context.Context, userCred mcclient.TokenCrede
|
||||
params.Set("inventory", jsonutils.NewString(inv.String()))
|
||||
params.Set("playbook", jsonutils.NewString(pb.String()))
|
||||
params.Set("files", jsonutils.NewString(files))
|
||||
cliSess := auth.GetSession(ctx, userCred, "", "")
|
||||
cliSess := auth.GetSession(ctx, userCred, "")
|
||||
if _, err := ansible.AnsiblePlaybooksV2.Create(cliSess, params); err != nil {
|
||||
return errors.WithMessagef(err, "create ansible task")
|
||||
}
|
||||
|
||||
@@ -71,7 +71,6 @@ func NewWorker(commonOpts *common_options.CommonOptions, opts *agentoptions.Opti
|
||||
clientSet: agentssh.NewClientSet(),
|
||||
sessionCache: &auth.SessionCache{
|
||||
Region: commonOpts.Region,
|
||||
APIVersion: "v2",
|
||||
UseAdminToken: true,
|
||||
EarlyRefresh: time.Hour,
|
||||
},
|
||||
|
||||
@@ -154,7 +154,7 @@ func (proxyendpoint *SProxyEndpoint) remoteConfigure(ctx context.Context, userCr
|
||||
},
|
||||
}
|
||||
|
||||
cliSess := auth.GetSession(ctx, userCred, "", "")
|
||||
cliSess := auth.GetSession(ctx, userCred, "")
|
||||
pbId := ""
|
||||
pbName := "pe-remote-configure-" + proxyendpoint.Name
|
||||
_, err := ansible_modules.AnsiblePlaybooks.UpdateOrCreatePbModel(
|
||||
|
||||
@@ -60,7 +60,7 @@ func getServerInfo(
|
||||
userCred mcclient.TokenCredential,
|
||||
serverId string,
|
||||
) (*serverInfo, error) {
|
||||
sess := auth.GetSession(ctx, userCred, "", "")
|
||||
sess := auth.GetSession(ctx, userCred, "")
|
||||
serverJson, err := compute_modules.Servers.Get(sess, serverId, nil)
|
||||
if err != nil {
|
||||
return nil, httperrors.NewGeneralError(err)
|
||||
|
||||
@@ -125,7 +125,7 @@ func (self *SAzureGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *mo
|
||||
|
||||
func (self *SAzureGuestDriver) ValidateImage(ctx context.Context, image *cloudprovider.SImage) error {
|
||||
if len(image.ExternalId) == 0 {
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
result, err := modules.Images.GetSpecific(s, image.Id, "subformats", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get subformats")
|
||||
|
||||
@@ -207,7 +207,7 @@ func (self *SCachedimage) GetImage() (*cloudprovider.SImage, error) {
|
||||
}
|
||||
|
||||
func (self *SCachedimage) syncClassMetadata(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
session := auth.GetSessionWithInternal(ctx, userCred, "", "")
|
||||
session := auth.GetSessionWithInternal(ctx, userCred, "")
|
||||
ret, err := image.Images.GetSpecific(session, self.Id, "class-metadata", nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to get class_metadata")
|
||||
@@ -321,7 +321,7 @@ func (manager *SCachedimageManager) GetCachedimageById(ctx context.Context, user
|
||||
if err != nil && errors.Cause(err) != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
obj, err := image.Images.Get(s, imageId, nil)
|
||||
if err != nil {
|
||||
log.Errorf("GetImageById %s error %s", imageId, err)
|
||||
@@ -347,7 +347,7 @@ func (manager *SCachedimageManager) GetImageById(ctx context.Context, userCred m
|
||||
return cachedImage.requestRefreshExternalImage(ctx, userCred)
|
||||
}
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
obj, err := image.Images.Get(s, imageId, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "modules.Images.Get")
|
||||
@@ -371,7 +371,7 @@ func (manager *SCachedimageManager) getImageByName(ctx context.Context, userCred
|
||||
return cachedImage.requestRefreshExternalImage(ctx, userCred)
|
||||
}
|
||||
}
|
||||
s := auth.GetSession(ctx, userCred, options.Options.Region, "")
|
||||
s := auth.GetSession(ctx, userCred, options.Options.Region)
|
||||
obj, err := image.Images.GetByName(s, imageId, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "modules.Images.GetByName")
|
||||
@@ -448,7 +448,7 @@ func (self *SCachedimageManager) PerformCacheImage(ctx context.Context, userCred
|
||||
if len(input.ImageId) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("image_id")
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
obj, err := image.Images.Get(s, input.ImageId, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "modules.Images.Get")
|
||||
@@ -871,7 +871,7 @@ func (manager *SCachedimageManager) AutoCleanImageCaches(ctx context.Context, us
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
for i := range caches {
|
||||
_, err := image.Images.Get(s, caches[i].Id, nil)
|
||||
if err != nil {
|
||||
|
||||
@@ -49,7 +49,7 @@ func (account *SCloudaccount) GetDetailsSaml(ctx context.Context, userCred mccli
|
||||
output.RedirectLoginUrl = httputils.JoinPath(options.Options.ApiServer, cloudid.SAML_IDP_PREFIX, "redirect/login", account.Id)
|
||||
output.RedirectLogoutUrl = httputils.JoinPath(options.Options.ApiServer, cloudid.SAML_IDP_PREFIX, "redirect/logout", account.Id)
|
||||
output.MetadataUrl = httputils.JoinPath(options.Options.ApiServer, cloudid.SAML_IDP_PREFIX, "metadata", account.Id)
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
params := map[string]string{
|
||||
"scope": "system",
|
||||
"cloudaccount_id": account.Id,
|
||||
|
||||
@@ -398,7 +398,7 @@ func getTenant(ctx context.Context, projectId string, name string) (*db.STenant,
|
||||
}
|
||||
|
||||
func createTenant(ctx context.Context, name, domainId, desc string) (string, string, error) {
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(name), "generate_name")
|
||||
|
||||
|
||||
@@ -1032,7 +1032,7 @@ func syncSkusFromPrivateCloud(ctx context.Context, userCred mcclient.TokenCreden
|
||||
if result.IsError() {
|
||||
return
|
||||
}
|
||||
s := auth.GetSession(ctx, userCred, "", "")
|
||||
s := auth.GetSession(ctx, userCred, "")
|
||||
if _, err := scheduler.SchedManager.SyncSku(s, true); err != nil {
|
||||
log.Errorf("Sync scheduler sku cache error: %v", err)
|
||||
}
|
||||
|
||||
@@ -1098,7 +1098,7 @@ func (self *SDisk) PrepareSaveImage(ctx context.Context, userCred mcclient.Token
|
||||
return "", httperrors.NewResourceNotFoundError("No zone for this disk")
|
||||
}
|
||||
if len(input.GenerateName) == 0 {
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
imageList, err := image.Images.List(s, jsonutils.Marshal(map[string]string{"name": input.Name, "admin": "true"}))
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -1150,7 +1150,7 @@ func (self *SDisk) PrepareSaveImage(ctx context.Context, userCred mcclient.Token
|
||||
if _, err := image.ImageQuotas.DoQuotaCheck(session, jsonutils.Marshal("a)); err != nil {
|
||||
return "", err
|
||||
}*/
|
||||
us := auth.GetSession(ctx, userCred, options.Options.Region, "")
|
||||
us := auth.GetSession(ctx, userCred, options.Options.Region)
|
||||
result, err := image.Images.Create(us, jsonutils.Marshal(opts))
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -237,7 +237,7 @@ func (self *SExternalProject) syncRemoveCloudProject(ctx context.Context, userCr
|
||||
}
|
||||
|
||||
func (self *SExternalProject) SyncWithCloudProject(ctx context.Context, userCred mcclient.TokenCredential, account *SCloudaccount, ext cloudprovider.ICloudProject) error {
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
providers := account.GetCloudproviders()
|
||||
providerMaps := map[string]string{}
|
||||
for _, provider := range providers {
|
||||
@@ -323,7 +323,7 @@ func (self *SCloudaccount) getOrCreateDomain(ctx context.Context, userCred mccli
|
||||
if errors.Cause(err) != sql.ErrNoRows {
|
||||
return "", errors.Wrapf(err, "FetchDomainByIdOrName")
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(name), "generate_name")
|
||||
|
||||
@@ -412,7 +412,7 @@ func (manager *SExternalProjectManager) newFromCloudProject(ctx context.Context,
|
||||
|
||||
tags, _ := extProject.GetTags()
|
||||
if len(tags) > 0 {
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion(), "v1")
|
||||
s := auth.GetAdminSession(ctx, consts.GetRegion())
|
||||
identity.Projects.PerformAction(s, project.ProjectId, "user-metadata", jsonutils.Marshal(tags))
|
||||
}
|
||||
|
||||
|
||||
@@ -265,7 +265,7 @@ func (self *SGuest) PerformSaveGuestImage(ctx context.Context, userCred mcclient
|
||||
kwargs.OsArch = self.OsArch
|
||||
}
|
||||
|
||||
s := auth.GetSession(ctx, userCred, consts.GetRegion(), "")
|
||||
s := auth.GetSession(ctx, userCred, consts.GetRegion())
|
||||
ret, err := image.GuestImages.Create(s, jsonutils.Marshal(kwargs))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -474,7 +474,7 @@ func (self *SGuest) PerformMigrateForecast(ctx context.Context, userCred mcclien
|
||||
schedParams.Hypervisor = api.HYPERVISOR_KVM
|
||||
}
|
||||
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
_, res, err := scheduler.SchedManager.DoScheduleForecast(s, schedParams, 1)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Do schedule migrate forecast")
|
||||
@@ -2667,7 +2667,7 @@ func (self *SGuest) PerformChangeConfig(ctx context.Context, userCred mcclient.T
|
||||
// schedulr forecast
|
||||
schedDesc := self.changeConfToSchedDesc(addCpu, addMem, schedInputDisks)
|
||||
confs.Set("sched_desc", jsonutils.Marshal(schedDesc))
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
canChangeConf, res, err := scheduler.SchedManager.DoScheduleForecast(s, schedDesc, 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -165,7 +165,7 @@ func (guest *SGuest) sshableTryEach(
|
||||
}
|
||||
}
|
||||
|
||||
sess := auth.GetSession(ctx, userCred, "", "")
|
||||
sess := auth.GetSession(ctx, userCred, "")
|
||||
// - check existing proxy forward
|
||||
proxyforwardTried := false
|
||||
for i := range gnInfos {
|
||||
@@ -488,7 +488,7 @@ func (guest *SGuest) PerformMakeSshable(
|
||||
host.SetVar("ansible_password", input.Password)
|
||||
}
|
||||
|
||||
cliSess := auth.GetSession(ctx, userCred, "", "")
|
||||
cliSess := auth.GetSession(ctx, userCred, "")
|
||||
pbId := ""
|
||||
pbName := "make-sshable-" + guest.Id
|
||||
pbModel, err := ansible_modules.AnsiblePlaybooks.UpdateOrCreatePbModel(
|
||||
|
||||
@@ -466,7 +466,7 @@ func (gt *SGuestTemplate) getMoreDetails(ctx context.Context, userCred mcclient.
|
||||
configInfo.Image = gt.ImageId
|
||||
}
|
||||
case IMAGE_TYPE_GUEST:
|
||||
s := auth.GetSession(ctx, userCred, options.Options.Region, "")
|
||||
s := auth.GetSession(ctx, userCred, options.Options.Region)
|
||||
ret, err := image.GuestImages.Get(s, gt.ImageId, jsonutils.JSONNull)
|
||||
if err != nil || !ret.Contains("id") {
|
||||
configInfo.Image = gt.ImageId
|
||||
@@ -561,7 +561,7 @@ func (gt *SGuestTemplate) PerformPublic(
|
||||
}
|
||||
isPublic, publicScope = image.IsPublic, image.PublicScope
|
||||
case IMAGE_TYPE_GUEST:
|
||||
s := auth.GetSession(ctx, userCred, options.Options.Region, "")
|
||||
s := auth.GetSession(ctx, userCred, options.Options.Region)
|
||||
ret, err := image.GuestImages.Get(s, gt.ImageId, jsonutils.JSONNull)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "fail to fetch guest image %s descripted by guest template", gt.ImageId)
|
||||
|
||||
@@ -5837,7 +5837,7 @@ func (self *SGuestManager) checkGuestImage(ctx context.Context, input *api.Serve
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.JSONTrue, "details")
|
||||
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
ret, err := image.GuestImages.Get(s, guestImageId, params)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get guest image from glance error")
|
||||
|
||||
@@ -1170,7 +1170,7 @@ func (self *SHostManager) ClearSchedDescCache(hostId string) error {
|
||||
}
|
||||
|
||||
func (self *SHostManager) ClearSchedDescSessionCache(hostId, sessionId string) error {
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region, "")
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region)
|
||||
return scheduler.SchedManager.CleanCache(s, hostId, sessionId, false)
|
||||
}
|
||||
|
||||
@@ -1184,7 +1184,7 @@ func (self *SHost) ClearSchedDescSessionCache(sessionId string) error {
|
||||
|
||||
// sync clear sched desc on scheduler side
|
||||
func (self *SHostManager) SyncClearSchedDescSessionCache(hostId, sessionId string) error {
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region, "")
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region)
|
||||
return scheduler.SchedManager.CleanCache(s, hostId, sessionId, true)
|
||||
}
|
||||
|
||||
@@ -3238,7 +3238,7 @@ func (manager *SHostManager) GetHostsByManagerAndRegion(managerId string, region
|
||||
}
|
||||
|
||||
func (self *SHost) Request(ctx context.Context, userCred mcclient.TokenCredential, method httputils.THttpMethod, url string, headers http.Header, body jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
s := auth.GetSession(ctx, userCred, "", "")
|
||||
s := auth.GetSession(ctx, userCred, "")
|
||||
_, ret, err := s.JSONRequest(self.ManagerUri, "", method, url, headers, body)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
@@ -617,7 +617,7 @@ func (ib *SInstanceBackup) FillFromPackMetadata(ctx context.Context, userCred mc
|
||||
ib.SetAllMetadata(ctx, meta, userCred)
|
||||
}
|
||||
if len(metadata.EncryptKeyId) > 0 {
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion(), "")
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion())
|
||||
_, err := identity_modules.Credentials.GetEncryptKey(session, metadata.EncryptKeyId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetEncryptKey")
|
||||
|
||||
@@ -224,7 +224,7 @@ func (self *SKubeCluster) doRemoteImport(ctx context.Context, userCred mcclient.
|
||||
"kubeconfig": config.Config,
|
||||
},
|
||||
}
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
resp, err := k8s.KubeClusters.Create(s, jsonutils.Marshal(params))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Create")
|
||||
|
||||
@@ -274,7 +274,7 @@ func (lbagent *SLoadbalancerAgent) validateHost(ctx context.Context, userCred mc
|
||||
|
||||
// Better make this explicit in the API
|
||||
if guest.SrcIpCheck.Bool() || guest.SrcMacCheck.Bool() {
|
||||
sess := auth.GetSession(ctx, userCred, "", "")
|
||||
sess := auth.GetSession(ctx, userCred, "")
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("src_ip_check", jsonutils.JSONFalse)
|
||||
params.Set("src_mac_check", jsonutils.JSONFalse)
|
||||
@@ -363,7 +363,7 @@ func (lbagent *SLoadbalancerAgent) updateOrCreatePbModel(ctx context.Context,
|
||||
pbName string,
|
||||
pb *ansible.Playbook,
|
||||
) (*ansible_model.AnsiblePlaybook, error) {
|
||||
cliSess := auth.GetSession(ctx, userCred, "", "")
|
||||
cliSess := auth.GetSession(ctx, userCred, "")
|
||||
pbModel, err := ansible_modules.AnsiblePlaybooks.UpdateOrCreatePbModel(
|
||||
ctx, cliSess, pbId, pbName, pb,
|
||||
)
|
||||
|
||||
@@ -275,7 +275,7 @@ func (sa *SScalingAlarm) Register(ctx context.Context, userCred mcclient.TokenCr
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
session := auth.GetSession(ctx, userCred, "", "")
|
||||
session := auth.GetSession(ctx, userCred, "")
|
||||
notificationID, err := ScalingPolicyManager.NotificationID(session)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "ScalingPolicyManager.NotificationID")
|
||||
@@ -357,7 +357,7 @@ func (sa *SScalingAlarm) generateAlertConfig(sp *SScalingPolicy) (*monitor.Alert
|
||||
}
|
||||
|
||||
func (sa *SScalingAlarm) UnRegister(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
session := auth.GetSession(ctx, userCred, "", "")
|
||||
session := auth.GetSession(ctx, userCred, "")
|
||||
_, err := monitor.Alerts.Delete(session, sa.AlarmId, jsonutils.NewDict())
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Alerts.Delete")
|
||||
|
||||
@@ -156,7 +156,7 @@ func (sc *SServiceCatalog) PerformDeploy(ctx context.Context, userCred mcclient.
|
||||
input.Count = 1
|
||||
}
|
||||
contentDict.Add(jsonutils.NewInt(int64(input.Count)), "count")
|
||||
s := auth.GetSession(ctx, userCred, options.Options.Region, "")
|
||||
s := auth.GetSession(ctx, userCred, options.Options.Region)
|
||||
_, err = compute.Servers.Create(s, content)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "fail to create guest")
|
||||
|
||||
@@ -387,7 +387,7 @@ func (self *SServerSku) GetPrivateCloudproviders() ([]SCloudprovider, error) {
|
||||
}
|
||||
|
||||
func (self *SServerSkuManager) ClearSchedDescCache(wait bool) error {
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region, "")
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region)
|
||||
_, err := scheduler.SchedManager.SyncSku(s, true)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "chedManager.SyncSku")
|
||||
@@ -1215,7 +1215,7 @@ func (manager *SServerSkuManager) SyncServerSkus(ctx context.Context, userCred m
|
||||
}
|
||||
|
||||
// notfiy sched manager
|
||||
_, err = scheduler.SchedManager.SyncSku(auth.GetAdminSession(ctx, options.Options.Region, ""), false)
|
||||
_, err = scheduler.SchedManager.SyncSku(auth.GetAdminSession(ctx, options.Options.Region), false)
|
||||
if err != nil {
|
||||
log.Errorf("SchedManager SyncSku %s", err)
|
||||
}
|
||||
|
||||
@@ -582,7 +582,7 @@ func SyncServerSkusByRegion(ctx context.Context, userCred mcclient.TokenCredenti
|
||||
}
|
||||
|
||||
func FetchSkuResourcesMeta() (*SSkuResourcesMeta, error) {
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region, "")
|
||||
s := auth.GetAdminSession(context.Background(), options.Options.Region)
|
||||
transport := httputils.GetTransport(true)
|
||||
transport.Proxy = options.Options.HttpTransportProxyFunc()
|
||||
client := &http.Client{Transport: transport}
|
||||
|
||||
@@ -56,7 +56,7 @@ func (self *DiskSaveTask) taskFailed(ctx context.Context, disk *models.SDisk, er
|
||||
disk.SetDiskReady(ctx, self.GetUserCred(), err.Error())
|
||||
db.OpsLog.LogEvent(disk, db.ACT_SAVE_FAIL, err.Error(), self.GetUserCred())
|
||||
if imageId, _ := self.GetParams().GetString("image_id"); len(imageId) > 0 {
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region, "")
|
||||
s := auth.GetAdminSession(ctx, options.Options.Region)
|
||||
image.Images.PerformAction(s, imageId, "status", jsonutils.Marshal(map[string]string{"status": "killed", "reason": err.Error()}))
|
||||
}
|
||||
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
|
||||
|
||||
@@ -45,7 +45,7 @@ func (self *GuestRestartNetworkTask) OnCloseIpMacSrcCheckComplete(ctx context.Co
|
||||
guest := obj.(*models.SGuest)
|
||||
|
||||
ip, _ := self.Params.GetString("ip")
|
||||
session := auth.GetAdminSession(ctx, "", "")
|
||||
session := auth.GetAdminSession(ctx, "")
|
||||
sshable, clean, err := self.checkSshable(ctx, guest, ip)
|
||||
log.Infof("start to CheckSshableForYunionCloud")
|
||||
if err != nil {
|
||||
|
||||
@@ -63,7 +63,7 @@ func (self *GuestSaveTemplateTask) OnInit(ctx context.Context, obj db.IStandalon
|
||||
}
|
||||
dict.Set("description", jsonutils.NewString(fmt.Sprintf("Save from Guest '%s'", g.Name)))
|
||||
dict.Set("content", jsonutils.Marshal(ci))
|
||||
session := auth.GetSession(ctx, self.UserCred, "", "")
|
||||
session := auth.GetSession(ctx, self.UserCred, "")
|
||||
_, err := compute.GuestTemplate.Create(session, dict)
|
||||
if err != nil {
|
||||
self.taskFailed(ctx, g, jsonutils.NewString(err.Error()))
|
||||
|
||||
@@ -126,7 +126,7 @@ func doScheduleWithInput(
|
||||
params = jsonutils.Marshal(schedInput).(*jsonutils.JSONDict)
|
||||
}
|
||||
task.SetStage("OnScheduleComplete", params)
|
||||
s := auth.GetSession(ctx, task.GetUserCred(), options.Options.Region, "")
|
||||
s := auth.GetSession(ctx, task.GetUserCred(), options.Options.Region)
|
||||
return scheduler.SchedManager.DoSchedule(s, schedInput, count)
|
||||
}
|
||||
|
||||
|
||||
@@ -328,7 +328,7 @@ func (asc *SASController) DetachInstances(ctx context.Context, userCred mcclient
|
||||
removeParams.Set("scaling_group", jsonutils.NewString(sg.Id))
|
||||
removeParams.Set("delete_server", jsonutils.JSONTrue)
|
||||
removeParams.Set("auto", jsonutils.JSONTrue)
|
||||
session := auth.GetSession(ctx, userCred, "", "")
|
||||
session := auth.GetSession(ctx, userCred, "")
|
||||
failedList := make([]string, 0)
|
||||
waitList := make([]string, 0, len(instances))
|
||||
instanceMap := make(map[string]SInstance, len(instances))
|
||||
@@ -484,7 +484,7 @@ func (asc *SASController) CreateInstances(
|
||||
countPR, requests := asc.countPRAndRequests(num)
|
||||
log.Debugf("countPR: %d, requests: %d", countPR, requests)
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
session := auth.GetSession(ctx, userCred, "", "")
|
||||
session := auth.GetSession(ctx, userCred, "")
|
||||
|
||||
failedList := make([]string, 0)
|
||||
succeedList := make([]SInstance, 0, num/2)
|
||||
|
||||
@@ -103,7 +103,7 @@ func (asc *SASController) CheckInstanceHealth(ctx context.Context, userCred mccl
|
||||
removeParams := jsonutils.NewDict()
|
||||
removeParams.Set("delete_server", jsonutils.JSONTrue)
|
||||
removeParams.Set("auto", jsonutils.JSONTrue)
|
||||
session := auth.GetSession(ctx, userCred, "", "")
|
||||
session := auth.GetSession(ctx, userCred, "")
|
||||
for i := range unnormalGuests {
|
||||
ug := unnormalGuests[i]
|
||||
if ug.CreateCompleteTime.Add(time.Duration(scalingGroupMap[ug.ScalngGroupId].HealthCheckGov) * time.Second).After(now) {
|
||||
|
||||
@@ -60,7 +60,7 @@ func (asc *SASController) Timer(ctx context.Context, userCred mcclient.TokenCred
|
||||
}
|
||||
log.Debugf("total %d need to exec, %v", len(scalingTimers), scalingTimers)
|
||||
log.Debugf("timeScope: start: %s, end: %s", timeScope.Start, timeScope.End)
|
||||
session := auth.GetSession(ctx, userCred, "", "")
|
||||
session := auth.GetSession(ctx, userCred, "")
|
||||
triggerParams := jsonutils.NewDict()
|
||||
for i := range scalingTimers {
|
||||
scalingTimer := scalingTimers[i]
|
||||
|
||||
@@ -61,8 +61,8 @@ func getServerAttrs(ID string, s *mcclient.ClientSession) (map[string]string, er
|
||||
|
||||
func getInfluxdbURL() (string, error) {
|
||||
|
||||
s := auth.GetAdminSessionWithPublic(nil, "", "")
|
||||
url, err := s.GetServiceURL("influxdb", apiidentity.EndpointInterfacePublic)
|
||||
s := auth.GetAdminSessionWithPublic(nil, "")
|
||||
url, err := s.GetServiceURL("influxdb", apiidentity.EndpointInterfacePublic, "")
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("get influxdb Endpoint error %s", err)
|
||||
@@ -116,7 +116,7 @@ func (obj *SDevtoolTemplate) Binding(ctx context.Context, userCred mcclient.Toke
|
||||
// * create playbook
|
||||
|
||||
template := obj
|
||||
s := auth.GetSession(ctx, userCred, "", "")
|
||||
s := auth.GetSession(ctx, userCred, "")
|
||||
ServerID, err := data.GetString("server_id")
|
||||
|
||||
attrs, err := getServerAttrs(ServerID, s)
|
||||
@@ -189,7 +189,7 @@ func (obj *SDevtoolTemplate) Unbinding(ctx context.Context, userCred mcclient.To
|
||||
// * get cronjob struct and create obj
|
||||
// * create playbook
|
||||
template := obj
|
||||
s := auth.GetSession(ctx, userCred, "", "")
|
||||
s := auth.GetSession(ctx, userCred, "")
|
||||
ServerID, err := data.GetString("server_id")
|
||||
|
||||
newPlaybookName := template.Name + "-" + template.Id[0:8] + "-" + ServerID[0:8]
|
||||
|
||||
@@ -113,7 +113,7 @@ func AddOneCronjob(item *SCronjob, s *mcclient.ClientSession) error {
|
||||
func InitializeCronjobs() error {
|
||||
DevToolCronManager = cronman.InitCronJobManager(true, 8)
|
||||
DevToolCronManager.Start()
|
||||
Session := auth.GetAdminSession(nil, "", "")
|
||||
Session := auth.GetAdminSession(nil, "")
|
||||
|
||||
go func() {
|
||||
items := make([]SCronjob, 0)
|
||||
@@ -131,7 +131,7 @@ func InitializeCronjobs() error {
|
||||
}
|
||||
|
||||
func (job *SCronjob) PostCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerID mcclient.IIdentityProvider, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
Session := auth.GetAdminSession(nil, "", "")
|
||||
Session := auth.GetAdminSession(nil, "")
|
||||
job.SStandaloneResourceBase.PostCreate(ctx, userCred, nil, query, data)
|
||||
AddOneCronjob(job, Session)
|
||||
}
|
||||
@@ -141,7 +141,7 @@ func (job *SCronjob) PostDelete(ctx context.Context, userCred mcclient.TokenCred
|
||||
}
|
||||
|
||||
func (job *SCronjob) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) {
|
||||
Session := auth.GetAdminSession(nil, "", "")
|
||||
Session := auth.GetAdminSession(nil, "")
|
||||
job.SStandaloneResourceBase.PostUpdate(ctx, userCred, query, data)
|
||||
DevToolCronManager.Remove(job.Id)
|
||||
AddOneCronjob(job, Session)
|
||||
|
||||
@@ -84,7 +84,7 @@ func (sm *SScriptManager) InitializeData() error {
|
||||
|
||||
func (sm *SScriptManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input api.ScriptCreateInput) (api.ScriptCreateInput, error) {
|
||||
// check ansible playbook reference
|
||||
session := auth.GetSessionWithInternal(ctx, userCred, "", "")
|
||||
session := auth.GetSessionWithInternal(ctx, userCred, "")
|
||||
pr, err := ansible.AnsiblePlaybookReference.Get(session, input.PlaybookReference, nil)
|
||||
if err != nil {
|
||||
return input, errors.Wrapf(err, "unable to get AnsiblePlaybookReference %q", input.PlaybookReference)
|
||||
|
||||
@@ -106,7 +106,7 @@ func (self *ApplyScriptTask) OnInit(ctx context.Context, obj db.IStandaloneModel
|
||||
self.taskFailed(ctx, sa, sar, err)
|
||||
return
|
||||
}
|
||||
session := auth.GetAdminSession(ctx, "", "")
|
||||
session := auth.GetAdminSession(ctx, "")
|
||||
sshable, cleanFunc, err := utils.CheckSSHable(session, sa.GuestId)
|
||||
// check sshable
|
||||
if err != nil {
|
||||
@@ -180,7 +180,7 @@ const (
|
||||
|
||||
func (self *ApplyScriptTask) OnAnsiblePlaybookComplete(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) {
|
||||
// try to delete local forward
|
||||
session := auth.GetAdminSession(ctx, "", "")
|
||||
session := auth.GetAdminSession(ctx, "")
|
||||
|
||||
sa := obj.(*models.SScriptApply)
|
||||
// try to set metadata for guest
|
||||
|
||||
@@ -40,7 +40,7 @@ func init() {
|
||||
func (self *SshInfoCreateTask) OnInit(ctx context.Context, obj db.IStandaloneModel, body jsonutils.JSONObject) {
|
||||
sshInfo := obj.(*models.SSshInfo)
|
||||
serverId := sshInfo.ServerId
|
||||
session := auth.GetSession(ctx, self.GetUserCred(), "", "")
|
||||
session := auth.GetSession(ctx, self.GetUserCred(), "")
|
||||
sshable, cleanFunc, err := utils.CheckSSHable(session, serverId)
|
||||
if err != nil {
|
||||
sshInfo.MarkCreateFailed(err.Error())
|
||||
|
||||
@@ -41,7 +41,7 @@ func (self *SshInfoDeleteTask) OnInit(ctx context.Context, obj db.IStandaloneMod
|
||||
self.SetStageComplete(ctx, nil)
|
||||
return
|
||||
}
|
||||
session := auth.GetSession(ctx, self.GetUserCred(), "", "")
|
||||
session := auth.GetSession(ctx, self.GetUserCred(), "")
|
||||
clean := utils.GetCleanFunc(session, sshInfo.ServerHypervisor, sshInfo.ServerId, sshInfo.Host, sshInfo.ForwardId, sshInfo.Port)
|
||||
err := clean()
|
||||
if err != nil {
|
||||
|
||||
@@ -68,7 +68,7 @@ func serviceComplete2(service Service) (completeUrl string, expectedCode int) {
|
||||
|
||||
func proxyEndpoints(ctx context.Context, proxyEndpointId string, info sServerInfo) ([]sProxyEndpoint, error) {
|
||||
pes := make([]sProxyEndpoint, 0)
|
||||
session := auth.GetAdminSession(ctx, "", "")
|
||||
session := auth.GetAdminSession(ctx, "")
|
||||
if len(proxyEndpointId) > 0 {
|
||||
ep, err := cloudproxy.ProxyEndpoints.Get(session, proxyEndpointId, nil)
|
||||
if err != nil {
|
||||
@@ -130,7 +130,7 @@ func serviceUrlDirect(ctx context.Context, service Service, proxyEndpointId stri
|
||||
|
||||
func GetServerInfo(ctx context.Context, serverId string) (sServerInfo, error) {
|
||||
// check server
|
||||
session := auth.GetAdminSession(ctx, "", "")
|
||||
session := auth.GetAdminSession(ctx, "")
|
||||
data, err := compute.Servers.Get(session, serverId, nil)
|
||||
if err != nil {
|
||||
if httputils.ErrorCode(err) == 404 {
|
||||
@@ -243,7 +243,7 @@ func GetServiceUrl(ctx context.Context, serviceName string) (string, error) {
|
||||
if url, ok := serviceUrls[serviceName]; ok {
|
||||
return url, nil
|
||||
}
|
||||
session := auth.GetAdminSession(ctx, "", "")
|
||||
session := auth.GetAdminSession(ctx, "")
|
||||
params := jsonutils.NewDict()
|
||||
params.Set("interface", jsonutils.NewString("public"))
|
||||
params.Set("service", jsonutils.NewString(serviceName))
|
||||
@@ -262,7 +262,7 @@ func GetServiceUrl(ctx context.Context, serviceName string) (string, error) {
|
||||
}
|
||||
|
||||
func convertServiceUrl(ctx context.Context, service Service, endpointId string) (port int64, recycle func() error, err error) {
|
||||
session := auth.AdminSessionWithInternal(ctx, "", "", "")
|
||||
session := auth.AdminSessionWithInternal(ctx, "", "")
|
||||
filter := jsonutils.NewDict()
|
||||
filter.Set("proxy_endpoint_id", jsonutils.NewString(endpointId))
|
||||
filter.Set("opaque", jsonutils.NewString(service.Url))
|
||||
@@ -328,7 +328,7 @@ func convertServiceUrl(ctx context.Context, service Service, endpointId string)
|
||||
}
|
||||
|
||||
func checkUrl(ctx context.Context, completeUrl string, expectedCode int, host *ansible_api.AnsibleHost) (bool, error) {
|
||||
session := auth.GetAdminSession(ctx, "", "")
|
||||
session := auth.GetAdminSession(ctx, "")
|
||||
ahost := ansible.Host{}
|
||||
ahost.Name = host.IP
|
||||
ahost.Vars = map[string]string{
|
||||
|
||||
@@ -124,7 +124,7 @@ func (r *SRegionDNS) initK8s() {
|
||||
}
|
||||
|
||||
func (r *SRegionDNS) getAdminSession(ctx context.Context) *mcclient.ClientSession {
|
||||
return auth.GetAdminSession(ctx, r.Region, "")
|
||||
return auth.GetAdminSession(ctx, r.Region)
|
||||
}
|
||||
|
||||
func (r *SRegionDNS) initAuth() {
|
||||
|
||||
@@ -85,7 +85,7 @@ func (ea *SEsxiAgent) GetZoneId() string {
|
||||
}
|
||||
|
||||
func (ea *SEsxiAgent) GetAdminSession() *mcclient.ClientSession {
|
||||
return auth.GetAdminSession(context.TODO(), options.Options.Region, "v2")
|
||||
return auth.GetAdminSession(context.TODO(), options.Options.Region)
|
||||
}
|
||||
|
||||
func (ea *SEsxiAgent) TuneSystem() error {
|
||||
|
||||
@@ -222,7 +222,7 @@ func (s *SKVMGuestInstance) getEncryptKey(ctx context.Context, userCred mcclient
|
||||
if userCred == nil {
|
||||
return ret, errors.Wrap(httperrors.ErrUnauthorized, "no credential to fetch encrypt key")
|
||||
}
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion(), "")
|
||||
session := auth.GetSession(ctx, userCred, consts.GetRegion())
|
||||
secKey, err := identity_modules.Credentials.GetEncryptKey(session, encKeyId)
|
||||
if err != nil {
|
||||
return ret, errors.Wrap(err, "GetEncryptKey")
|
||||
|
||||
@@ -62,15 +62,15 @@ type IHost interface {
|
||||
}
|
||||
|
||||
func GetComputeSession(ctx context.Context) *mcclient.ClientSession {
|
||||
return auth.GetAdminSessionWithInternal(ctx, options.HostOptions.Region, "v2")
|
||||
return auth.GetAdminSessionWithInternal(ctx, options.HostOptions.Region)
|
||||
}
|
||||
|
||||
func GetK8sSession(ctx context.Context) *mcclient.ClientSession {
|
||||
return auth.GetAdminSessionWithInternal(ctx, options.HostOptions.Region, "")
|
||||
return auth.GetAdminSessionWithInternal(ctx, options.HostOptions.Region)
|
||||
}
|
||||
|
||||
func GetImageSession(ctx context.Context, zone string) *mcclient.ClientSession {
|
||||
return auth.AdminSessionWithInternal(ctx, options.HostOptions.Region, "", "v1")
|
||||
return auth.AdminSessionWithInternal(ctx, options.HostOptions.Region, "")
|
||||
}
|
||||
|
||||
func TaskFailed(ctx context.Context, reason string) {
|
||||
|
||||
@@ -406,7 +406,7 @@ func (d *SLocalDisk) DiskBackup(ctx context.Context, params interface{}) (jsonut
|
||||
|
||||
encKey := ""
|
||||
if len(diskBackup.EncryptKeyId) > 0 {
|
||||
session := auth.GetSession(ctx, diskBackup.UserCred, consts.GetRegion(), "")
|
||||
session := auth.GetSession(ctx, diskBackup.UserCred, consts.GetRegion())
|
||||
secKey, err := identity_modules.Credentials.GetEncryptKey(session, diskBackup.EncryptKeyId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetEncryptKey")
|
||||
|
||||
@@ -370,7 +370,7 @@ func (s *SLocalStorage) SaveToGlance(ctx context.Context, params interface{}) (j
|
||||
encAlg seclib2.TSymEncAlg
|
||||
)
|
||||
if len(encKeyId) > 0 {
|
||||
session := auth.GetSession(ctx, info.UserCred, consts.GetRegion(), "")
|
||||
session := auth.GetSession(ctx, info.UserCred, consts.GetRegion())
|
||||
key, err := identity_modules.Credentials.GetEncryptKey(session, encKeyId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "GetEncryptKey")
|
||||
|
||||
@@ -1923,7 +1923,7 @@ func (img *SImage) doEncrypt(ctx context.Context, userCred mcclient.TokenCredent
|
||||
if img.EncryptStatus == api.IMAGE_ENCRYPT_STATUS_ENCRYPTED {
|
||||
return false, nil
|
||||
}
|
||||
session := auth.GetSession(ctx, userCred, options.Options.Region, "v1")
|
||||
session := auth.GetSession(ctx, userCred, options.Options.Region)
|
||||
keyObj, err := identity_modules.Credentials.GetById(session, img.EncryptKeyId, nil)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "GetByEncryptKeyId")
|
||||
|
||||
@@ -45,7 +45,7 @@ func (self *ImageSyncClassMetadataTask) OnInit(ctx context.Context, obj db.IStan
|
||||
self.taskFailed(ctx, img, jsonutils.NewString(err.Error()))
|
||||
return
|
||||
}
|
||||
session := auth.GetAdminSession(ctx, "", "")
|
||||
session := auth.GetAdminSession(ctx, "")
|
||||
_, err = compute.Cachedimages.PerformAction(session, img.Id, "set-class-metadata", jsonutils.Marshal(cm))
|
||||
if err == nil {
|
||||
self.taskSuccess(ctx, img)
|
||||
|
||||
@@ -71,6 +71,6 @@ func getDefaultAdminCred() *mcclient.SSimpleToken {
|
||||
return &token
|
||||
}
|
||||
|
||||
func GetDefaultClientSession(ctx context.Context, token mcclient.TokenCredential, region, apiVersion string) *mcclient.ClientSession {
|
||||
return GetDefaultClient().NewSession(ctx, region, "", "", token, apiVersion)
|
||||
func GetDefaultClientSession(ctx context.Context, token mcclient.TokenCredential, region string) *mcclient.ClientSession {
|
||||
return GetDefaultClient().NewSession(ctx, region, "", "", token)
|
||||
}
|
||||
|
||||
@@ -22,6 +22,6 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
func GetDefaulAdminSession(ctx context.Context, region, apiVersion string) (*mcclient.ClientSession, error) {
|
||||
return models.GetDefaultClientSession(ctx, tokens.GetDefaultAdminCredToken(), region, apiVersion), nil
|
||||
func GetDefaulAdminSession(ctx context.Context, region string) (*mcclient.ClientSession, error) {
|
||||
return models.GetDefaultClientSession(ctx, tokens.GetDefaultAdminCredToken(), region), nil
|
||||
}
|
||||
|
||||
@@ -171,8 +171,8 @@ func (h *ApiHelper) adminClientSession(ctx context.Context) *mcclient.ClientSess
|
||||
}
|
||||
|
||||
region := h.opts.CommonOptions.Region
|
||||
apiVersion := "v2"
|
||||
h.mcclientSession = auth.GetAdminSession(ctx, region, apiVersion)
|
||||
// apiVersion := "v2"
|
||||
h.mcclientSession = auth.GetAdminSession(ctx, region)
|
||||
return h.mcclientSession
|
||||
}
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ func AdminCredential() mcclient.TokenCredential {
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func AdminSession(ctx context.Context, region, zone, endpointType, apiVersion string) *mcclient.ClientSession {
|
||||
func AdminSession(ctx context.Context, region, zone, endpointType string) *mcclient.ClientSession {
|
||||
cli := Client()
|
||||
if cli == nil {
|
||||
return nil
|
||||
@@ -334,17 +334,17 @@ func AdminSession(ctx context.Context, region, zone, endpointType, apiVersion st
|
||||
if endpointType == "" && globalEndpointType != "" {
|
||||
endpointType = globalEndpointType
|
||||
}
|
||||
return cli.NewSession(ctx, region, zone, endpointType, AdminCredential(), apiVersion)
|
||||
return cli.NewSession(ctx, region, zone, endpointType, AdminCredential())
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func AdminSessionWithInternal(ctx context.Context, region, zone, apiVersion string) *mcclient.ClientSession {
|
||||
return AdminSession(ctx, region, zone, "internal", apiVersion)
|
||||
func AdminSessionWithInternal(ctx context.Context, region, zone string) *mcclient.ClientSession {
|
||||
return AdminSession(ctx, region, zone, "internal")
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func AdminSessionWithPublic(ctx context.Context, region, zone, apiVersion string) *mcclient.ClientSession {
|
||||
return AdminSession(ctx, region, zone, "public", apiVersion)
|
||||
func AdminSessionWithPublic(ctx context.Context, region, zone string) *mcclient.ClientSession {
|
||||
return AdminSession(ctx, region, zone, "public")
|
||||
}
|
||||
|
||||
type AuthCompletedCallback func()
|
||||
@@ -368,38 +368,35 @@ func ReAuth() {
|
||||
manager.reAuth()
|
||||
}
|
||||
|
||||
func GetAdminSession(ctx context.Context, region string,
|
||||
apiVersion string) *mcclient.ClientSession {
|
||||
return GetSession(ctx, manager.adminCredential, region, apiVersion)
|
||||
func GetAdminSession(ctx context.Context, region string) *mcclient.ClientSession {
|
||||
return GetSession(ctx, manager.adminCredential, region)
|
||||
}
|
||||
|
||||
func GetAdminSessionWithPublic(ctx context.Context, region string,
|
||||
apiVersion string) *mcclient.ClientSession {
|
||||
return GetSessionWithPublic(ctx, manager.adminCredential, region, apiVersion)
|
||||
func GetAdminSessionWithPublic(ctx context.Context, region string) *mcclient.ClientSession {
|
||||
return GetSessionWithPublic(ctx, manager.adminCredential, region)
|
||||
}
|
||||
|
||||
func GetAdminSessionWithInternal(
|
||||
ctx context.Context, region string, apiVersion string) *mcclient.ClientSession {
|
||||
return GetSessionWithInternal(ctx, manager.adminCredential, region, apiVersion)
|
||||
func GetAdminSessionWithInternal(ctx context.Context, region string) *mcclient.ClientSession {
|
||||
return GetSessionWithInternal(ctx, manager.adminCredential, region)
|
||||
}
|
||||
|
||||
func GetSession(ctx context.Context, token mcclient.TokenCredential, region string, apiVersion string) *mcclient.ClientSession {
|
||||
func GetSession(ctx context.Context, token mcclient.TokenCredential, region string) *mcclient.ClientSession {
|
||||
if len(globalEndpointType) != 0 {
|
||||
return getSessionByType(ctx, token, region, apiVersion, globalEndpointType)
|
||||
return getSessionByType(ctx, token, region, globalEndpointType)
|
||||
}
|
||||
return GetSessionWithInternal(ctx, token, region, apiVersion)
|
||||
return GetSessionWithInternal(ctx, token, region)
|
||||
}
|
||||
|
||||
func GetSessionWithInternal(ctx context.Context, token mcclient.TokenCredential, region string, apiVersion string) *mcclient.ClientSession {
|
||||
return getSessionByType(ctx, token, region, apiVersion, identity.EndpointInterfaceInternal)
|
||||
func GetSessionWithInternal(ctx context.Context, token mcclient.TokenCredential, region string) *mcclient.ClientSession {
|
||||
return getSessionByType(ctx, token, region, identity.EndpointInterfaceInternal)
|
||||
}
|
||||
|
||||
func GetSessionWithPublic(ctx context.Context, token mcclient.TokenCredential, region string, apiVersion string) *mcclient.ClientSession {
|
||||
return getSessionByType(ctx, token, region, apiVersion, identity.EndpointInterfacePublic)
|
||||
func GetSessionWithPublic(ctx context.Context, token mcclient.TokenCredential, region string) *mcclient.ClientSession {
|
||||
return getSessionByType(ctx, token, region, identity.EndpointInterfacePublic)
|
||||
}
|
||||
|
||||
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)
|
||||
func getSessionByType(ctx context.Context, token mcclient.TokenCredential, region string, epType string) *mcclient.ClientSession {
|
||||
return manager.client.NewSession(ctx, region, "", epType, token)
|
||||
}
|
||||
|
||||
// use for climc test only
|
||||
|
||||
@@ -26,8 +26,8 @@ type SessionCache struct {
|
||||
mu sync.RWMutex
|
||||
session *mcclient.ClientSession
|
||||
|
||||
Region string
|
||||
APIVersion string
|
||||
Region string
|
||||
// APIVersion string
|
||||
|
||||
// EarlyRefresh tells the cache how early to fetch a new session before
|
||||
// actual expiration of the old
|
||||
@@ -67,6 +67,6 @@ func (sc *SessionCache) Get(ctx context.Context) *mcclient.ClientSession {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
token := sc.getToken()
|
||||
sc.session = GetSession(ctx, token, sc.Region, sc.APIVersion)
|
||||
sc.session = GetSession(ctx, token, sc.Region)
|
||||
return sc.session
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func getSession() (*mcclient.ClientSession, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return client.NewSession(context.Background(), Region, "", EndpointType, token, "v2"), nil
|
||||
return client.NewSession(context.Background(), Region, "", EndpointType, token), nil
|
||||
}
|
||||
|
||||
func CreateServerExample() error {
|
||||
|
||||
@@ -401,7 +401,7 @@ func (this *Client) GetCommonEtcdTLSConfig(endpoint *api.EndpointDetails) (*tls.
|
||||
return seclib2.InitTLSConfigByData(caData, certData, keyData)
|
||||
}
|
||||
|
||||
func (this *Client) NewSession(ctx context.Context, region, zone, endpointType string, token TokenCredential, apiVersion string) *ClientSession {
|
||||
func (this *Client) NewSession(ctx context.Context, region, zone, endpointType string, token TokenCredential) *ClientSession {
|
||||
cata := token.GetServiceCatalog()
|
||||
if this.GetServiceCatalog() == nil {
|
||||
if cata == nil || cata.Len() == 0 {
|
||||
@@ -420,7 +420,6 @@ func (this *Client) NewSession(ctx context.Context, region, zone, endpointType s
|
||||
zone: zone,
|
||||
endpointType: endpointType,
|
||||
token: token,
|
||||
defaultApiVersion: apiVersion,
|
||||
Header: http.Header{},
|
||||
customizeServiceUrl: map[string]string{},
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
func GetAppOptions(s *mcclient.ClientSession, serviceType string) (jsonutils.JSONObject, error) {
|
||||
man := NewBaseManager(serviceType, "", "", nil, nil)
|
||||
man := NewBaseManager(serviceType, "", "", nil, nil, "")
|
||||
_, resp, err := man.jsonRequest(s, "GET", "/app-options", nil, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "rawBaseUrlRequest")
|
||||
|
||||
@@ -39,11 +39,12 @@ type BaseManager struct {
|
||||
adminColumns []string
|
||||
}
|
||||
|
||||
func NewBaseManager(serviceType, endpointType, version string, columns, adminColumns []string) *BaseManager {
|
||||
func NewBaseManager(serviceType, endpointType, version string, columns, adminColumns []string, apiVersion string) *BaseManager {
|
||||
return &BaseManager{
|
||||
serviceType: serviceType,
|
||||
endpointType: endpointType,
|
||||
version: version,
|
||||
apiVersion: apiVersion,
|
||||
columns: columns,
|
||||
adminColumns: adminColumns,
|
||||
}
|
||||
@@ -61,10 +62,6 @@ func (this *BaseManager) SetVersion(v string) {
|
||||
this.version = v
|
||||
}
|
||||
|
||||
func (this *BaseManager) SetApiVersion(v string) {
|
||||
this.apiVersion = v
|
||||
}
|
||||
|
||||
func (this *BaseManager) GetApiVersion() string {
|
||||
return this.apiVersion
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
func GetVersion(s *mcclient.ClientSession, serviceType string) (string, error) {
|
||||
man := NewBaseManager(serviceType, "", "", nil, nil)
|
||||
man := NewBaseManager(serviceType, "", "", nil, nil, "")
|
||||
resp, err := man.rawBaseUrlRequest(s, "GET", "/version", nil, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -37,7 +37,7 @@ func GetVersion(s *mcclient.ClientSession, serviceType string) (string, error) {
|
||||
}
|
||||
|
||||
func ListWorkers(s *mcclient.ClientSession, serviceType string) (*ListResult, error) {
|
||||
man := NewBaseManager(serviceType, "", "", nil, nil)
|
||||
man := NewBaseManager(serviceType, "", "", nil, nil, "")
|
||||
resp, err := man.rawBaseUrlRequest(s, "GET", "/worker_stats", nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -35,7 +35,6 @@ type IBaseManager interface {
|
||||
EndpointType() string
|
||||
GetColumns(session *mcclient.ClientSession) []string
|
||||
List(session *mcclient.ClientSession, params jsonutils.JSONObject) (*ListResult, error)
|
||||
SetApiVersion(string)
|
||||
}
|
||||
|
||||
type ManagerContext struct {
|
||||
@@ -171,8 +170,8 @@ type JointManager interface {
|
||||
}
|
||||
|
||||
var (
|
||||
modules map[string]map[string][]IBaseManager
|
||||
jointModules map[string]map[string][]JointManager
|
||||
modules map[string][]IBaseManager
|
||||
jointModules map[string][]JointManager
|
||||
)
|
||||
|
||||
func _getJointKey(mod1 Manager, mod2 Manager) string {
|
||||
@@ -190,16 +189,11 @@ func ensureModuleNotRegistered(mod, newMod IBaseManager) {
|
||||
}
|
||||
}
|
||||
|
||||
func Register(version string, mod IBaseManager) {
|
||||
func Register(mod IBaseManager) {
|
||||
if modules == nil {
|
||||
modules = make(map[string]map[string][]IBaseManager)
|
||||
modules = make(map[string][]IBaseManager)
|
||||
}
|
||||
modtable, ok := modules[version]
|
||||
if !ok {
|
||||
modtable = make(map[string][]IBaseManager)
|
||||
modules[version] = modtable
|
||||
}
|
||||
mods, ok := modtable[mod.KeyString()]
|
||||
mods, ok := modules[mod.KeyString()]
|
||||
if !ok {
|
||||
mods = make([]IBaseManager, 0)
|
||||
}
|
||||
@@ -207,21 +201,16 @@ func Register(version string, mod IBaseManager) {
|
||||
ensureModuleNotRegistered(mods[i], mod)
|
||||
}
|
||||
mods = append(mods, mod)
|
||||
modules[version][mod.KeyString()] = mods
|
||||
modules[mod.KeyString()] = mods
|
||||
// modtable[mod.KeyString()] = append(mods, mod)
|
||||
}
|
||||
|
||||
func RegisterJointModule(version string, mod IBaseManager) {
|
||||
func RegisterJointModule(mod IBaseManager) {
|
||||
jointMod, ok := mod.(JointManager)
|
||||
if ok { // also a joint manager
|
||||
jointKey := _getJointKey(jointMod.MasterManager(), jointMod.SlaveManager())
|
||||
// log.Printf("%s(%s) is also a joint module", mod.KeyString(), jointKey)
|
||||
modtable, ok := jointModules[version]
|
||||
if !ok {
|
||||
modtable = make(map[string][]JointManager)
|
||||
jointModules[version] = modtable
|
||||
}
|
||||
jointMods, ok := modtable[jointKey]
|
||||
jointMods, ok := jointModules[jointKey]
|
||||
if !ok {
|
||||
jointMods = make([]JointManager, 0)
|
||||
}
|
||||
@@ -231,31 +220,25 @@ func RegisterJointModule(version string, mod IBaseManager) {
|
||||
//}
|
||||
}
|
||||
// modtable[jointKey] = append(jointMods, jointMod)
|
||||
jointModules[version][jointKey] = append(jointMods, jointMod)
|
||||
jointModules[jointKey] = append(jointMods, jointMod)
|
||||
}
|
||||
}
|
||||
|
||||
func registerAllJointModules() {
|
||||
if jointModules == nil {
|
||||
jointModules = make(map[string]map[string][]JointManager)
|
||||
for version := range modules {
|
||||
for modname := range modules[version] {
|
||||
for i := range modules[version][modname] {
|
||||
RegisterJointModule(version, modules[version][modname][i])
|
||||
}
|
||||
jointModules = make(map[string][]JointManager)
|
||||
for modname := range modules {
|
||||
for i := range modules[modname] {
|
||||
RegisterJointModule(modules[modname][i])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func _getModule(session *mcclient.ClientSession, name string) (IBaseManager, error) {
|
||||
modtable, ok := modules[session.GetApiVersion()]
|
||||
mods, ok := modules[name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("No such version: %s", session.GetApiVersion())
|
||||
}
|
||||
mods, ok := modtable[name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("No such module %s for version %s", name, session.GetApiVersion())
|
||||
return nil, fmt.Errorf("No such module %s", name)
|
||||
}
|
||||
|
||||
if len(mods) == 1 {
|
||||
@@ -263,7 +246,7 @@ func _getModule(session *mcclient.ClientSession, name string) (IBaseManager, err
|
||||
}
|
||||
|
||||
for _, mod := range mods {
|
||||
url, e := session.GetServiceURL(mod.ServiceType(), mod.EndpointType())
|
||||
url, e := session.GetServiceURL(mod.ServiceType(), mod.EndpointType(), mod.GetApiVersion())
|
||||
if e != nil {
|
||||
return nil, errors.Wrap(e, "session.GetServiceURL")
|
||||
}
|
||||
@@ -305,11 +288,7 @@ func GetJointModule(session *mcclient.ClientSession, name string) (JointManager,
|
||||
func GetJointModule2(session *mcclient.ClientSession, mod1 Manager, mod2 Manager) (JointManager, error) {
|
||||
registerAllJointModules()
|
||||
key := _getJointKey(mod1, mod2)
|
||||
modtable, ok := jointModules[session.GetApiVersion()]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("No such version: %s", session.GetApiVersion())
|
||||
}
|
||||
mods, ok := modtable[key]
|
||||
mods, ok := jointModules[key]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("No such joint module: %s", key)
|
||||
}
|
||||
@@ -326,28 +305,18 @@ func GetJointModule2(session *mcclient.ClientSession, mod1 Manager, mod2 Manager
|
||||
return nil, fmt.Errorf("Version mismatch")
|
||||
}
|
||||
|
||||
func GetRegisterdModules() (map[string][]string, map[string][]string) {
|
||||
func GetRegisterdModules() ([]string, []string) {
|
||||
registerAllJointModules()
|
||||
|
||||
ret := make(map[string][]string)
|
||||
for k, v := range modules {
|
||||
ret[k] = make([]string, 0)
|
||||
for m := range v {
|
||||
ret[k] = append(ret[k], m)
|
||||
}
|
||||
ret := make([]string, 0)
|
||||
for k := range modules {
|
||||
ret = append(ret, k)
|
||||
}
|
||||
for k := range ret {
|
||||
sort.Strings(ret[k])
|
||||
}
|
||||
ret2 := make(map[string][]string)
|
||||
for k, v := range jointModules {
|
||||
ret2[k] = make([]string, 0)
|
||||
for m := range v {
|
||||
ret2[k] = append(ret2[k], m)
|
||||
}
|
||||
}
|
||||
for k := range ret2 {
|
||||
sort.Strings(ret2[k])
|
||||
sort.Strings(ret)
|
||||
ret2 := make([]string, 0)
|
||||
for k := range jointModules {
|
||||
ret2 = append(ret2, k)
|
||||
}
|
||||
sort.Strings(ret2)
|
||||
return ret, ret2
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user