本文整理汇总了Golang中github.com/rackspace/gophercloud/rackspace.AuthenticatedClient函数的典型用法代码示例。如果您正苦于以下问题:Golang AuthenticatedClient函数的具体用法?Golang AuthenticatedClient怎么用?Golang AuthenticatedClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AuthenticatedClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Delete
// delete cloud files object from container
func Delete(c *cli.Context) {
// assign vars from cli args
user := c.String("user")
key := c.String("key")
region := c.String("region")
containerName := c.String("container")
objectName := c.String("name")
// step 1, set up auth options
ao := gophercloud.AuthOptions{
Username: user,
APIKey: key,
}
// step 2, rax auth to get back provider instance
provider, err := rackspace.AuthenticatedClient(ao)
if err != nil {
fmt.Println(err)
}
// set rax region
serviceClient, err := rackspace.NewObjectStorageV1(provider, gophercloud.EndpointOpts{
Region: region,
})
if err != nil {
fmt.Println(err)
}
_, err2 := objects.Delete(serviceClient, containerName, objectName, nil).Extract()
if err2 != nil {
fmt.Println(err2)
}
fmt.Printf("%v Deleted.", objectName)
}
开发者ID:rackeric,项目名称:erack,代码行数:34,代码来源:delete.go
示例2: Show
// print list of cloud block storage volumes to stdout
func Show(c *cli.Context) {
// assign vars from cli args
user := c.String("user")
key := c.String("key")
region := c.String("region")
volumeId := c.Args().First()
if c.String("uuid") != "" { volumeId = c.String("uuid") }
// step 1, set up auth options
ao := gophercloud.AuthOptions{
Username: user,
APIKey: key,
}
// step 2, rax auth to get back provider instance
provider, err := rackspace.AuthenticatedClient(ao)
if err != nil { fmt.Println(err) }
// set rax region
serviceClient, err2 := rackspace.NewBlockStorageV1(provider, gophercloud.EndpointOpts{
Region: region,
})
if err2 != nil { fmt.Println(err2) }
v, err3 := volumes.Get(serviceClient, volumeId).Extract()
if err3 != nil { fmt.Println(err3) }
fmt.Println("Name: ", v.Name)
fmt.Println("ID: ", v.ID)
fmt.Println("Size: ", v.Size)
fmt.Println("Status: ", v.Status)
fmt.Println("Type: ", v.VolumeType)
fmt.Println("Created: ", v.CreatedAt)
}
开发者ID:rackeric,项目名称:erack,代码行数:33,代码来源:show.go
示例3: Delete
// delete a cloud block storage snapshots from volume uuid
func Delete(c *cli.Context) {
// assign vars from cli args
user := c.String("user")
key := c.String("key")
region := c.String("region")
volumeId := c.Args().First()
if c.String("uuid") != "" {
volumeId = c.String("uuid")
}
// step 1, set up auth options
ao := gophercloud.AuthOptions{
Username: user,
APIKey: key,
}
// step 2, rax auth to get back provider instance
provider, err := rackspace.AuthenticatedClient(ao)
if err != nil {
fmt.Println(err)
}
// set rax region
serviceClient, err2 := rackspace.NewBlockStorageV1(provider, gophercloud.EndpointOpts{
Region: region,
})
if err2 != nil {
fmt.Println(err2)
}
// delete snapshot from uuid
err3 := snapshots.Delete(serviceClient, volumeId).ExtractErr()
if err3 != nil {
fmt.Println(err3)
}
}
开发者ID:rackeric,项目名称:erack,代码行数:36,代码来源:delete.go
示例4: Create
// create a cloud files container
func Create(c *cli.Context) {
// assign vars from cli args
user := c.String("user")
key := c.String("key")
region := c.String("region")
containerName := c.Args().First()
if c.String("name") != "" {
containerName = c.String("name")
}
// step 1, set up auth options
ao := gophercloud.AuthOptions{
Username: user,
APIKey: key,
}
// step 2, rax auth to get back provider instance
provider, err := rackspace.AuthenticatedClient(ao)
if err != nil {
fmt.Println(err)
}
// set rax region
serviceClient, err := rackspace.NewObjectStorageV1(provider, gophercloud.EndpointOpts{
Region: region,
})
if err != nil {
fmt.Println(err)
}
err2 := containers.Create(serviceClient, containerName, nil)
fmt.Println(err2)
}
开发者ID:rackeric,项目名称:erack,代码行数:33,代码来源:create.go
示例5: newClient
func newClient() (*gophercloud.ServiceClient, error) {
// Obtain credentials from the environment.
options, err := rackspace.AuthOptionsFromEnv()
if err != nil {
return nil, err
}
options = tools.OnlyRS(options)
region := os.Getenv("RS_REGION")
if options.Username == "" {
return nil, errors.New("Please provide a Rackspace username as RS_USERNAME.")
}
if options.APIKey == "" {
return nil, errors.New("Please provide a Rackspace API key as RS_API_KEY.")
}
if region == "" {
return nil, errors.New("Please provide a Rackspace region as RS_REGION.")
}
client, err := rackspace.AuthenticatedClient(options)
if err != nil {
return nil, err
}
return rackspace.NewComputeV2(client, gophercloud.EndpointOpts{
Region: region,
})
}
开发者ID:RomainVabre,项目名称:origin,代码行数:28,代码来源:compute_test.go
示例6: NewRackspaceSDK
func NewRackspaceSDK(username, apiKey, SSHKeyName string) *RackspaceSDK {
if SSHKeyName == "" {
panic("Empty SSHKeyName of instance don't allow!")
}
sdk := &RackspaceSDK{
Username: username,
APIKey: apiKey,
SSHKeyName: SSHKeyName,
Region: "HKG",
InstanceName: "kmg-RackspaceSDK-auto-build",
ImageName: "Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)",
FlavorName: "4 GB General Purpose v1",
}
ao := gophercloud.AuthOptions{
Username: sdk.Username,
APIKey: sdk.APIKey,
}
provider, err := rackspace.AuthenticatedClient(ao)
handleErr(err)
serviceClient, err := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
Region: sdk.Region,
})
handleErr(err)
sdk.p = serviceClient
return sdk
}
开发者ID:keysonZZZ,项目名称:kmg,代码行数:26,代码来源:SDKRackspace.go
示例7: GetList
func GetList(c *cli.Context) {
// assign vars from cli args
user := c.String("user")
key := c.String("key")
region := c.String("region")
// step 1, set up auth options
ao := gophercloud.AuthOptions{
Username: user,
APIKey: key,
}
// step 2, rax auth to get back provider instance
provider, err := rackspace.AuthenticatedClient(ao)
if err != nil {
fmt.Println(err)
}
// set rax region
serviceClient, err2 := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
Region: region,
})
if err2 != nil {
fmt.Println(err2)
}
// Retrieve a pager (i.e. a paginated collection)
server_pager := servers.List(serviceClient, nil)
// Define an anonymous function to be executed on each page's iteration
err6 := server_pager.EachPage(func(page pagination.Page) (bool, error) {
serverList, err7 := servers.ExtractServers(page)
if err7 != nil {
fmt.Println(err7)
}
for _, s := range serverList {
// "s" will be a servers.Server
// https://github.com/rackspace/gophercloud/blob/master/openstack/compute/v2/servers/results.go
fmt.Println("Name: ", s.Name)
fmt.Println("UUID: ", s.ID)
fmt.Println("Created: ", s.Created)
fmt.Println("Updated: ", s.Updated)
fmt.Println("Progress: ", s.Progress)
fmt.Println("HostID: ", s.HostID)
fmt.Println("Image: ", s.Image["id"])
fmt.Println("Flavor ID: ", s.Flavor["id"])
fmt.Println("Status: ", s.Status)
fmt.Println("Access: ", s.AccessIPv4)
fmt.Println("Public: ", s.Addresses["public"])
fmt.Println("Addresses: ", s.Addresses)
fmt.Println("\n")
}
return true, nil
})
if err6 != nil {
fmt.Println(err6)
}
}
开发者ID:rackeric,项目名称:erack,代码行数:57,代码来源:list.go
示例8: newProvider
func newProvider() (*gophercloud.ProviderClient, error) {
opts, err := rackspace.AuthOptionsFromEnv()
if err != nil {
return nil, err
}
opts = tools.OnlyRS(opts)
return rackspace.AuthenticatedClient(opts)
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:9,代码来源:common.go
示例9: newBlockClient
func newBlockClient(t *testing.T) (*gophercloud.ServiceClient, error) {
ao, err := rackspace.AuthOptionsFromEnv()
th.AssertNoErr(t, err)
client, err := rackspace.AuthenticatedClient(ao)
th.AssertNoErr(t, err)
return openstack.NewBlockStorageV1(client, gophercloud.EndpointOpts{
Region: os.Getenv("RS_REGION_NAME"),
})
}
开发者ID:RomainVabre,项目名称:origin,代码行数:11,代码来源:volumeattach_test.go
示例10: newClient
func newClient(t *testing.T) *gophercloud.ServiceClient {
ao, err := rackspace.AuthOptionsFromEnv()
th.AssertNoErr(t, err)
client, err := rackspace.AuthenticatedClient(ao)
th.AssertNoErr(t, err)
c, err := rackspace.NewCDNV1(client, gophercloud.EndpointOpts{})
th.AssertNoErr(t, err)
return c
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:11,代码来源:common.go
示例11: newRackspace
func newRackspace(cfg Config) (*Rackspace, error) {
provider, err := rackspace.AuthenticatedClient(cfg.toAuthOptions())
if err != nil {
return nil, err
}
os := Rackspace{
provider: provider,
region: cfg.Global.Region,
lbOpts: cfg.LoadBalancer,
}
return &os, nil
}
开发者ID:ethernetdan,项目名称:kubernetes,代码行数:13,代码来源:rackspace.go
示例12: newClient
func newClient(t *testing.T) *gophercloud.ServiceClient {
ao, err := rackspace.AuthOptionsFromEnv()
th.AssertNoErr(t, err)
client, err := rackspace.AuthenticatedClient(ao)
th.AssertNoErr(t, err)
c, err := rackspace.NewOrchestrationV1(client, gophercloud.EndpointOpts{
Region: os.Getenv("RS_REGION_NAME"),
})
th.AssertNoErr(t, err)
return c
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:13,代码来源:common.go
示例13: newClusterClient
func newClusterClient(endpoint string, ao gophercloud.AuthOptions) (*ClusterClient, error) {
provider, err := rackspace.AuthenticatedClient(ao)
if err != nil {
return nil, err
}
return &ClusterClient{
Client: &http.Client{},
Username: ao.Username,
Token: provider.TokenID,
Endpoint: endpoint,
}, nil
}
开发者ID:getcarina,项目名称:libcarina,代码行数:13,代码来源:libcarina.go
示例14: Create
// create cloud block storage volume in rackspace public cloud
func Create(c *cli.Context) {
// assign vars from cli args
user := c.String("user")
key := c.String("key")
region := c.String("region")
name := c.String("name")
size := c.Int("size")
var volType string
if c.String("type") != "" {
volType = c.String("type")
}
// step 1, set up auth options
ao := gophercloud.AuthOptions{
Username: user,
APIKey: key,
}
// step 2, rax auth to get back provider instance
provider, err := rackspace.AuthenticatedClient(ao)
if err != nil {
fmt.Println(err)
}
// set rax region
serviceClient, err2 := rackspace.NewBlockStorageV1(provider, gophercloud.EndpointOpts{
Region: region,
})
if err2 != nil {
fmt.Println(err2)
}
// https://github.com/rackspace/gophercloud/blob/master/openstack/blockstorage/v1/volumes/requests.go
opts := osvolumes.CreateOpts{
Name: name,
Size: size,
VolumeType: volType,
}
if volType == "" {
opts = osvolumes.CreateOpts{
Name: name,
Size: size,
}
}
vol, err3 := volumes.Create(serviceClient, opts).Extract()
if err3 != nil {
fmt.Println(err3)
}
fmt.Println(vol)
}
开发者ID:rackeric,项目名称:erack,代码行数:52,代码来源:create.go
示例15: Get
// print list of cloud servers images to stdout
func Get(c *cli.Context) {
// assign vars from cli args
user := c.String("user")
key := c.String("key")
region := c.String("region")
// step 1, set up auth options
ao := gophercloud.AuthOptions{
Username: user,
APIKey: key,
}
// step 2, rax auth to get back provider instance
provider, err := rackspace.AuthenticatedClient(ao)
if err != nil {
fmt.Println(err)
}
// set rax region
serviceClient, err := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
Region: region,
})
if err != nil {
fmt.Println(err)
}
//opts3 := images.ListOpts{}
cmdErr := images.ListDetail(serviceClient, nil).EachPage(func(page pagination.Page) (bool, error) {
images, err := images.ExtractImages(page)
if err != nil {
fmt.Println(err)
}
// Use the page of []images.Image
// https://github.com/rackspace/gophercloud/blob/master/openstack/compute/v2/images/results.go
for _, i := range images {
fmt.Println("Name: ", i.Name)
fmt.Println("ID: ", i.ID)
fmt.Println("Created: ", i.Created)
fmt.Println("Updated: ", i.Updated)
fmt.Println("MinDisk: ", i.MinDisk)
fmt.Println("MinRAM: ", i.MinRAM)
fmt.Println("Progress: ", i.Progress)
fmt.Println("Status: ", i.Status)
fmt.Println("\n")
}
return true, nil
})
if cmdErr != nil {
fmt.Println(cmdErr)
}
}
开发者ID:rackeric,项目名称:erack,代码行数:51,代码来源:list.go
示例16: Details
// print details of cloud servers instance to stdout
func Details(c *cli.Context) {
// assign vars from cli args
user := c.String("user")
key := c.String("key")
region := c.String("region")
// server create specific options
// check both options and arguments for server uuid
serverid := c.Args().First()
if c.String("uuid") != "" {
serverid = c.String("uuid")
}
// step 1, set up auth options
ao := gophercloud.AuthOptions{
Username: user,
APIKey: key,
}
// step 2, rax auth to get back provider instance
provider, err := rackspace.AuthenticatedClient(ao)
if err != nil {
fmt.Println(err)
}
// set rax region
serviceClient, err2 := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
Region: region,
})
if err2 != nil {
fmt.Println(err2)
}
// get cloud server
s, id := servers.Get(serviceClient, serverid).Extract()
fmt.Println("Name: ", s.Name)
fmt.Println("UUID: ", s.ID)
fmt.Println("Created: ", s.Created)
fmt.Println("Updated: ", s.Updated)
fmt.Println("Progress: ", s.Progress)
fmt.Println("HostID: ", s.HostID)
fmt.Println("Image: ", s.Image["id"])
fmt.Println("Flavor ID: ", s.Flavor["id"])
fmt.Println("Status: ", s.Status)
fmt.Println("Access: ", s.AccessIPv4)
fmt.Println("Public: ", s.Addresses["public"])
fmt.Println("Addresses: ", s.Addresses)
if id != nil {
fmt.Println(id)
}
}
开发者ID:rackeric,项目名称:erack,代码行数:50,代码来源:details.go
示例17: List
func List(c *cli.Context) {
// assign vars from cli args
user := c.String("user")
key := c.String("key")
region := c.String("region")
// step 1, set up auth options
ao := gophercloud.AuthOptions{
Username: user,
APIKey: key,
}
// step 2, rax auth to get back provider instance
//provider, err := rackspace.AuthenticatedClient(ao)
provider, err := rackspace.AuthenticatedClient(ao)
if err != nil {
fmt.Println(err)
}
// set rax region
serviceClient, err2 := rackspace.NewNetworkV2(provider, gophercloud.EndpointOpts{
Name: "cloudNetworks",
//Type: "network",
Region: region,
})
if err2 != nil {
fmt.Println(err2)
}
// Retrieve a pager (i.e. a paginated collection)
networks_pager := networks.List(serviceClient)
fmt.Println("networks_pager: ", networks_pager)
// Define an anonymous function to be executed on each page's iteration
err6 := networks_pager.EachPage(func(page pagination.Page) (bool, error) {
networkList, err7 := networks.ExtractNetworks(page)
if err7 != nil {
fmt.Println(err7)
}
for _, n := range networkList {
// "s" will be a servers.Server
// https://github.com/rackspace/gophercloud/blob/master/openstack/compute/v2/servers/results.go
fmt.Println(n)
}
return true, nil
})
if err6 != nil {
fmt.Println(err6)
}
}
开发者ID:rackeric,项目名称:erack,代码行数:49,代码来源:list.go
示例18: DeleteAll
// delete all cloud files object from container
func DeleteAll(c *cli.Context) {
// assign vars from cli args
user := c.String("user")
key := c.String("key")
region := c.String("region")
containerName := c.String("container")
useConcurrency := c.String("concurrency")
// step 1, set up auth options
ao := gophercloud.AuthOptions{
Username: user,
APIKey: key,
}
// step 2, rax auth to get back provider instance
provider, err := rackspace.AuthenticatedClient(ao)
if err != nil {
fmt.Println(err)
}
// set rax region
serviceClient, err := rackspace.NewObjectStorageV1(provider, gophercloud.EndpointOpts{
Region: region,
})
if err != nil {
fmt.Println(err)
}
// get objects List and delete each
err3 := objects.List(serviceClient, containerName, nil).EachPage(func(page pagination.Page) (bool, error) {
objectList, err4 := objects.ExtractNames(page)
// https://github.com/rackspace/gophercloud/blob/master/openstack/blockstorage/v1/volumes/results.go
for _, objectName := range objectList {
// now delete each object here
// fmt.Println(objName)
if strings.Compare(useConcurrency, "TRUE") == 0 {
go deleteObj(serviceClient, containerName, objectName)
} else {
deleteObj(serviceClient, containerName, objectName)
}
}
if err4 != nil {
fmt.Println(err4)
}
return true, nil
})
if err3 != nil {
fmt.Println(err3)
}
}
开发者ID:rackeric,项目名称:erack,代码行数:50,代码来源:deleteall.go
示例19: newClient
func newClient(t *testing.T) *gophercloud.ServiceClient {
opts, err := rackspace.AuthOptionsFromEnv()
th.AssertNoErr(t, err)
opts = tools.OnlyRS(opts)
client, err := rackspace.AuthenticatedClient(opts)
th.AssertNoErr(t, err)
c, err := rackspace.NewDBV1(client, gophercloud.EndpointOpts{
Region: "IAD",
})
th.AssertNoErr(t, err)
return c
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:15,代码来源:common.go
示例20: TestAuthenticatedClient
func TestAuthenticatedClient(t *testing.T) {
// Obtain credentials from the environment.
ao, err := rackspace.AuthOptionsFromEnv()
th.AssertNoErr(t, err)
client, err := rackspace.AuthenticatedClient(tools.OnlyRS(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)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:16,代码来源:client_test.go
注:本文中的github.com/rackspace/gophercloud/rackspace.AuthenticatedClient函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论