1 Star 0 Fork 0

zhuchance / kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
global_context.go 2.65 KB
一键复制 编辑 原始数据 按行查看 历史
package gophercloud
import (
"github.com/racker/perigee"
)
// globalContext is the, well, "global context."
// Most of this SDK is written in a manner to facilitate easier testing,
// which doesn't require all the configuration a real-world application would require.
// However, for real-world deployments, applications should be able to rely on a consistent configuration of providers, etc.
var globalContext *Context
// providers is the set of supported providers.
var providers = map[string]Provider{
"rackspace-us": {
AuthEndpoint: "https://identity.api.rackspacecloud.com/v2.0/tokens",
},
"rackspace-uk": {
AuthEndpoint: "https://lon.identity.api.rackspacecloud.com/v2.0/tokens",
},
}
// Initialize the global context to sane configuration.
// The Go runtime ensures this function is called before main(),
// thus guaranteeing proper configuration before your application ever runs.
func init() {
globalContext = TestContext()
for name, descriptor := range providers {
globalContext.RegisterProvider(name, descriptor)
}
}
// Authenticate() grants access to the OpenStack-compatible provider API.
//
// Providers are identified through a unique key string.
// Specifying an unsupported provider will result in an ErrProvider error.
// However, you may also specify a custom Identity API URL.
// Any provider name that contains the characters "://", in that order, will be treated as a custom Identity API URL.
// Custom URLs, important for private cloud deployments, overrides all provider configurations.
//
// The supplied AuthOptions instance allows the client to specify only those credentials
// relevant for the authentication request. At present, support exists for OpenStack
// Identity V2 API only; support for V3 will become available as soon as documentation for it
// becomes readily available.
//
// For Identity V2 API requirements, you must provide at least the Username and Password
// options. The TenantId field is optional, and defaults to "".
func Authenticate(provider string, options AuthOptions) (*Access, error) {
return globalContext.Authenticate(provider, options)
}
// Instantiates a Cloud Servers object for the provider given.
func ServersApi(acc AccessProvider, criteria ApiCriteria) (CloudServersProvider, error) {
return globalContext.ServersApi(acc, criteria)
}
// ActualResponseCode inspects a returned error, and discovers the actual response actual
// response code that caused the error to be raised.
func ActualResponseCode(e error) (int, error) {
if err, typeOk := e.(*perigee.UnexpectedResponseCodeError); typeOk {
return err.Actual, nil
} else if err, typeOk := e.(*AuthError); typeOk{
return err.StatusCode, nil
}
return 0, ErrError
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v0.7.4

搜索帮助

344bd9b3 5694891 D2dac590 5694891