本文整理汇总了Golang中github.com/rackspace/gophercloud/openstack.AuthenticatedClient函数的典型用法代码示例。如果您正苦于以下问题:Golang AuthenticatedClient函数的具体用法?Golang AuthenticatedClient怎么用?Golang AuthenticatedClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AuthenticatedClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: newOpenstackClient
func newOpenstackClient(config *authConfig) (*OpenstackClient, error) {
if config == nil {
err := errors.New("no OpenStack cloud provider config file given")
return nil, err
}
opts := gophercloud.AuthOptions{
IdentityEndpoint: config.AuthUrl,
Username: config.Username,
Password: config.Password,
TenantName: config.Tenant,
TenantID: config.TenantID,
AllowReauth: false,
}
provider, err := openstack.AuthenticatedClient(opts)
if err != nil {
glog.Info("Failed: Starting openstack authenticate client")
return nil, err
}
authClient := openstack.NewIdentityV2(provider)
return &OpenstackClient{
provider,
authClient,
config,
}, nil
}
示例2: newCinderClient
func newCinderClient(configFile string) (*cinderClient, error) {
cfg, err := readConfig(configFile)
if err != nil {
return nil, err
}
provider, err := openstack.AuthenticatedClient(cfg.toAuthOptions())
if err != nil {
return nil, err
}
client, err := openstack.NewBlockStorageV2(provider, gophercloud.EndpointOpts{
Region: cfg.Global.Region,
})
if err != nil {
return nil, err
}
cc := cinderClient{
cinder: client,
keyring: cfg.RBD.Keyring,
}
return &cc, nil
}
示例3: TestAuthenticatedClient
func TestAuthenticatedClient(t *testing.T) {
// Obtain credentials from the environment.
ao, err := openstack.AuthOptionsFromEnv()
if err != nil {
t.Fatalf("Unable to acquire credentials: %v", err)
}
client, err := openstack.AuthenticatedClient(ao)
if err != nil {
t.Fatalf("Unable to authenticate: %v", err)
}
if client.TokenID == "" {
t.Errorf("No token ID assigned to the client")
}
t.Logf("Client successfully acquired a token: %v", client.TokenID)
// Find the storage service in the service catalog.
storage, err := openstack.NewObjectStorageV1(client, gophercloud.EndpointOpts{
Region: os.Getenv("OS_REGION_NAME"),
})
if err != nil {
t.Errorf("Unable to locate a storage service: %v", err)
} else {
t.Logf("Located a storage service at endpoint: [%s]", storage.Endpoint)
}
}
示例4: client
func (c *Config) client() (*gophercloud.ProviderClient, error) {
options := gophercloud.AuthOptions{
IdentityEndpoint: fmt.Sprintf("https://identity.%s.conoha.io/v2.0", c.Region),
Username: c.Username,
Password: c.Password,
TenantName: c.TenantName,
}
return openstack.AuthenticatedClient(options)
}
示例5: Init
func (d *driver) Init(context types.Context, config gofig.Config) error {
d.config = config
fields := eff(map[string]interface{}{})
var err error
if d.instanceID, err = d.getInstanceID(); err != nil {
return err
}
fields["moduleName"] = context
fields["instanceId"] = d.instanceID
if d.region, err = d.getInstanceRegion(); err != nil {
return err
}
fields["region"] = d.region
d.region = strings.ToUpper(d.region)
authOpts := d.getAuthOptions()
fields["identityEndpoint"] = d.authURL()
fields["userId"] = d.userID()
fields["userName"] = d.userName()
if d.password() == "" {
fields["password"] = ""
} else {
fields["password"] = "******"
}
fields["tenantId"] = d.tenantID()
fields["tenantName"] = d.tenantName()
fields["domainId"] = d.domainID()
fields["domainName"] = d.domainName()
if d.provider, err = openstack.AuthenticatedClient(authOpts); err != nil {
return goof.WithFieldsE(fields,
"error getting authenticated client", err)
}
if d.client, err = openstack.NewComputeV2(d.provider,
gophercloud.EndpointOpts{Region: d.region}); err != nil {
goof.WithFieldsE(fields, "error getting newComputeV2", err)
}
if d.clientBlockStorage, err = openstack.NewBlockStorageV1(d.provider,
gophercloud.EndpointOpts{Region: d.region}); err != nil {
return goof.WithFieldsE(fields,
"error getting newBlockStorageV1", err)
}
log.WithFields(fields).Info("storage driver initialized")
return nil
}
示例6: newClient
func newClient(t *testing.T) (*gophercloud.ServiceClient, error) {
ao, err := openstack.AuthOptionsFromEnv()
th.AssertNoErr(t, err)
client, err := openstack.AuthenticatedClient(ao)
th.AssertNoErr(t, err)
return openstack.NewBlockStorageV2(client, gophercloud.EndpointOpts{
Region: os.Getenv("OS_REGION_NAME"),
})
}
示例7: Init
func (d *driver) Init(r *core.RexRay) error {
d.r = r
fields := ef()
var err error
if d.instanceID, err = getInstanceID(d.r.Config); err != nil {
return err
}
fields["instanceId"] = d.instanceID
if d.region, err = getInstanceRegion(d.r.Config); err != nil {
return err
}
fields["region"] = d.region
d.region = strings.ToUpper(d.region)
authOpts := getAuthOptions(d.r.Config)
fields["identityEndpoint"] = d.r.Config.RackspaceAuthURL
fields["userId"] = d.r.Config.RackspaceUserID
fields["userName"] = d.r.Config.RackspaceUserName
if d.r.Config.RackspacePassword == "" {
fields["password"] = ""
} else {
fields["password"] = "******"
}
fields["tenantId"] = d.r.Config.RackspaceTenantID
fields["tenantName"] = d.r.Config.RackspaceTenantName
fields["domainId"] = d.r.Config.RackspaceDomainID
fields["domainName"] = d.r.Config.RackspaceDomainName
if d.provider, err = openstack.AuthenticatedClient(authOpts); err != nil {
return errors.WithFieldsE(fields,
"error getting authenticated client", err)
}
if d.client, err = openstack.NewComputeV2(d.provider,
gophercloud.EndpointOpts{Region: d.region}); err != nil {
errors.WithFieldsE(fields, "error getting newComputeV2", err)
}
if d.clientBlockStorage, err = openstack.NewBlockStorageV1(d.provider,
gophercloud.EndpointOpts{Region: d.region}); err != nil {
return errors.WithFieldsE(fields,
"error getting newBlockStorageV1", err)
}
log.WithField("provider", providerName).Info("storage driver initialized")
return nil
}
示例8: getProviderClient
func getProviderClient() (*gophercloud.ProviderClient, error) {
opts, err := openstack.AuthOptionsFromEnv()
if err != nil {
return nil, err
}
provider, err := openstack.AuthenticatedClient(opts)
if err != nil {
if strings.Contains(err.Error(), "provide exactly one of Domain") {
return nil, fmt.Errorf(envVariablesNotSetError, keystoneDomainIDKey, keystoneDomainNameKey)
}
}
return provider, err
}
示例9: newClient
func newClient(t *testing.T) *gophercloud.ServiceClient {
ao, err := openstack.AuthOptionsFromEnv()
th.AssertNoErr(t, err)
client, err := openstack.AuthenticatedClient(ao)
th.AssertNoErr(t, err)
c, err := openstack.NewOrchestrationV1(client, gophercloud.EndpointOpts{
Region: os.Getenv("OS_REGION_NAME"),
})
th.AssertNoErr(t, err)
return c
}
示例10: initIdentityClient
// initIdentityClient initializes openstack api using
// gophercloud which handles auth tokens keeping api calls
// simpler. Currently it uses environment variables for
// authenticating with openstack identity.
func initIdentityClient() (*gophercloud.ServiceClient, error) {
opts, err := openstack.AuthOptionsFromEnv()
if err != nil {
log.Println("Error fetching openstack env vars: ", err)
return nil, err
}
provider, err := openstack.AuthenticatedClient(opts)
if err != nil {
log.Println("Error authenticating with openstack: ", err)
return nil, err
}
return openstack.NewIdentityV2(provider), nil
}
示例11: NewKeystoneClient
// NewKeystoneClient initilizes a keystone client with the provided configuration.
func NewKeystoneClient(config Config) (KeystoneClient, error) {
opts := config.AuthOptions
provider, err := openstack.AuthenticatedClient(opts)
if err != nil {
return nil, err
}
client := openstack.NewIdentityV3(provider)
// build a closure for ksClient reauthentication
client.ReauthFunc = func() error {
return openstack.AuthenticateV3(client.ProviderClient, opts)
}
return &KeystoneClientImpl{client: client, opts: opts, token: nil, monascaURL: nil}, nil
}
示例12: newOpenStack
func newOpenStack(cfg Config) (*OpenStack, error) {
provider, err := openstack.AuthenticatedClient(cfg.toAuthOptions())
if err != nil {
return nil, err
}
os := OpenStack{
provider: provider,
region: cfg.Global.Region,
lbOpts: cfg.LoadBalancer,
}
return &os, nil
}
示例13: initClient
func initClient(config *Config) (*gophercloud.ProviderClient, error) {
opts := gophercloud.AuthOptions{
IdentityEndpoint: config.Auth_Url,
Username: config.User,
Password: config.Password,
TenantName: config.Tenant,
}
client, err := openstack.AuthenticatedClient(opts)
if err != nil {
return nil, err
}
return client, nil
}
示例14: New
func New(cfgFile string) CinderDriver {
conf, err := processConfig(cfgFile)
isV3 := strings.Contains(conf.Endpoint, "v3")
if err != nil {
log.Fatal("Error processing cinder driver config file: ", err)
}
_, err = os.Lstat(conf.MountPoint)
if os.IsNotExist(err) {
if err := os.MkdirAll(conf.MountPoint, 0755); err != nil {
log.Fatal("Failed to create Mount directory during driver init: %v", err)
}
}
auth := gophercloud.AuthOptions{
IdentityEndpoint: conf.Endpoint,
Username: conf.Username,
Password: conf.Password,
TenantID: conf.TenantID,
AllowReauth: true,
}
if isV3 == true && conf.DomainName == "" {
log.Warning("V3 endpoint specified, but DomainName not set!")
log.Warning("Setting to \"Default\", maybe it'll work.")
auth.DomainName = "Default"
}
if conf.DomainName != "" && isV3 == true {
log.Info("Authorizing to a V3 Endpoint")
auth.DomainName = conf.DomainName
}
providerClient, err := openstack.AuthenticatedClient(auth)
if err != nil {
log.Fatal("Error initiating gophercloud provider client: ", err)
}
client, err := openstack.NewBlockStorageV2(providerClient,
gophercloud.EndpointOpts{Region: "RegionOne"})
if err != nil {
log.Fatal("Error initiating gophercloud cinder client: ", err)
}
d := CinderDriver{
Conf: &conf,
Mutex: &sync.Mutex{},
Client: client,
}
return d
}
示例15: networkingClient
func networkingClient() (*gophercloud.ServiceClient, error) {
opts, err := openstack.AuthOptionsFromEnv()
if err != nil {
return nil, err
}
provider, err := openstack.AuthenticatedClient(opts)
if err != nil {
return nil, err
}
return openstack.NewNetworkV2(provider, gophercloud.EndpointOpts{
Region: os.Getenv("OS_REGION_NAME"),
})
}