本文整理汇总了Golang中github.com/polvi/coreup/Godeps/_workspace/src/github.com/rackspace/gophercloud.CloudServersProvider类的典型用法代码示例。如果您正苦于以下问题:Golang CloudServersProvider类的具体用法?Golang CloudServersProvider怎么用?Golang CloudServersProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CloudServersProvider类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createServer
// createServer creates a new server in a manner compatible with acceptance testing.
// In particular, it ensures that the name of the server always starts with "ACPTTEST--",
// which the delete servers acceptance test relies on to identify servers to delete.
// Passing in empty image and flavor references will force the use of reasonable defaults.
// An empty name string will result in a dynamically created name prefixed with "ACPTTEST--".
// A blank admin password will cause a password to be automatically generated; however,
// at present no means of recovering this password exists, as no acceptance tests yet require
// this data.
func createServer(servers gophercloud.CloudServersProvider, imageRef, flavorRef, name, adminPass string) (string, error) {
if imageRef == "" {
imageRef = aSuitableImage(servers)
}
if flavorRef == "" {
flavorRef = aSuitableFlavor(servers)
}
if len(name) < 1 {
name = randomString("ACPTTEST", 16)
}
if (len(name) < 8) || (name[0:8] != "ACPTTEST") {
name = fmt.Sprintf("ACPTTEST--%s", name)
}
newServer, err := servers.CreateServer(gophercloud.NewServer{
Name: name,
ImageRef: imageRef,
FlavorRef: flavorRef,
AdminPass: adminPass,
})
if err != nil {
return "", err
}
return newServer.Id, nil
}
示例2: tryLinksOnly
func tryLinksOnly(api gophercloud.CloudServersProvider) {
servers, err := api.ListServersLinksOnly()
if err != nil {
panic(err)
}
if !*quiet {
fmt.Println("Id,Name")
for _, s := range servers {
if s.AccessIPv4 != "" {
panic("IPv4 not expected")
}
if s.Status != "" {
panic("Status not expected")
}
if s.Progress != 0 {
panic("Progress not expected")
}
fmt.Printf("%s,\"%s\"\n", s.Id, s.Name)
}
}
}
示例3: withServer
func withServer(api gophercloud.CloudServersProvider, f func(string)) {
id, err := createServer(api, "", "", "", "")
if err != nil {
panic(err)
}
for {
s, err := api.ServerById(id)
if err != nil {
panic(err)
}
if s.Status == "ACTIVE" {
break
}
time.Sleep(10 * time.Second)
}
f(id)
// I've learned that resizing an instance can fail if a delete request
// comes in prior to its completion. This ends up leaving the server
// in an error state, and neither the resize NOR the delete complete.
// This is a bug in OpenStack, as far as I'm concerned, but thankfully,
// there's an easy work-around -- just wait for your server to return to
// active state first!
waitForServerState(api, id, "ACTIVE")
err = api.DeleteServerById(id)
if err != nil {
panic(err)
}
}
示例4: waitForImageState
// waitForImageState polls, every 10 seconds, for a given image to appear in the indicated state.
// This call will block forever if it never appears in the desired state, so if a timeout is required,
// make sure to call this function in a goroutine.
func waitForImageState(api gophercloud.CloudServersProvider, id, state string) error {
for {
s, err := api.ImageById(id)
if err != nil {
return err
}
if s.Status == state {
return nil
}
time.Sleep(10 * time.Second)
}
panic("Impossible")
}
示例5: tryFullDetails
func tryFullDetails(api gophercloud.CloudServersProvider) {
servers, err := api.ListServers()
if err != nil {
panic(err)
}
if !*quiet {
fmt.Println("Id,Name,AccessIPv4,Status,Progress")
for _, s := range servers {
fmt.Printf("%s,\"%s\",%s,%s,%d\n", s.Id, s.Name, s.AccessIPv4, s.Status, s.Progress)
}
}
}
示例6: tryAddressesByNetwork
func tryAddressesByNetwork(networkLabel string, id string, api gophercloud.CloudServersProvider) {
log("Getting list of addresses on", networkLabel, "network...")
network, err := api.ListAddressesByNetwork(id, networkLabel)
if (err != nil) && (err != gophercloud.WarnUnauthoritative) {
panic(err)
}
if err == gophercloud.WarnUnauthoritative {
log("Uh oh -- got a response back, but it's not authoritative for some reason.")
}
for _, addr := range network[networkLabel] {
log("Address:", addr.Addr, " IPv", addr.Version)
}
}
示例7: tryAllAddresses
func tryAllAddresses(id string, api gophercloud.CloudServersProvider) {
log("Getting list of all addresses...")
addresses, err := api.ListAddresses(id)
if (err != nil) && (err != gophercloud.WarnUnauthoritative) {
panic(err)
}
if err == gophercloud.WarnUnauthoritative {
log("Uh oh -- got a response back, but it's not authoritative for some reason.")
}
if !*quiet {
fmt.Println("Addresses:")
fmt.Printf("%+v\n", addresses)
}
}
示例8: resizeAcceptTest
// Perform the resize test, but accept the resize request.
func resizeAcceptTest(api gophercloud.CloudServersProvider, done chan bool) {
withServer(api, func(id string) {
newFlavorId := findAlternativeFlavor()
err := api.ResizeServer(id, randomString("ACPTTEST", 24), newFlavorId, "")
if err != nil {
panic(err)
}
waitForServerState(api, id, "VERIFY_RESIZE")
err = api.ConfirmResize(id)
if err != nil {
panic(err)
}
})
done <- true
}
示例9: aSuitableFlavor
// aSuitableFlavor finds the minimum flavor capable of running the test image
// chosen by aSuitableImage. If none can be found, this function will panic.
func aSuitableFlavor(api gophercloud.CloudServersProvider) string {
flavors, err := api.ListFlavors()
if err != nil {
panic(err)
}
// TODO(sfalvo):
// Works for Rackspace, might not work for your provider!
// Need to figure out why ListFlavors() provides 0 values for
// Ram and Disk fields.
//
// Until then, just return Ubuntu 12.04 LTS.
for i := 0; i < len(flavors); i++ {
if flavors[i].Id == "2" {
return flavors[i].Id
}
}
panic("Flavor 2 (512MB 1-core 20GB machine) not found.")
}
示例10: aSuitableImage
// aSuitableImage finds a minimal image for use in dynamically creating servers.
// If none can be found, this function will panic.
func aSuitableImage(api gophercloud.CloudServersProvider) string {
images, err := api.ListImages()
if err != nil {
panic(err)
}
// TODO(sfalvo):
// Works for Rackspace, might not work for your provider!
// Need to figure out why ListImages() provides 0 values for
// Ram and Disk fields.
//
// Until then, just return Ubuntu 12.04 LTS.
for i := 0; i < len(images); i++ {
if strings.Contains(images[i].Name, "Ubuntu 12.04 LTS") {
return images[i].Id
}
}
panic("Image for Ubuntu 12.04 LTS not found.")
}
示例11: locateAServer
// locateAServer queries the set of servers owned by the user. If at least one
// exists, the first found is picked, and its ID is returned. Otherwise, a new
// server will be created, and its ID returned.
//
// deleteAfter will be true if the caller should schedule a call to DeleteServerById()
// to clean up.
func locateAServer(servers gophercloud.CloudServersProvider) (deleteAfter bool, id string, err error) {
ss, err := servers.ListServers()
if err != nil {
return false, "", err
}
if len(ss) > 0 {
// We could just cheat and dump the server details from ss[0].
// But, that tests ListServers(), and not ServerById(). So, we
// elect not to cheat.
return false, ss[0].Id, nil
}
serverId, err := createServer(servers, "", "", "", "")
if err != nil {
return false, "", err
}
err = waitForServerState(servers, serverId, "ACTIVE")
return true, serverId, err
}
示例12: tryAllAddresses
func tryAllAddresses(id string, api gophercloud.CloudServersProvider) {
log("Getting the server instance")
s, err := api.ServerById(id)
if err != nil {
panic(err)
}
log("Getting the complete set of pools")
ps, err := s.AllAddressPools()
if err != nil {
panic(err)
}
log("Listing IPs for each pool")
for k, v := range ps {
log(fmt.Sprintf(" Pool %s", k))
for _, a := range v {
log(fmt.Sprintf(" IP: %s, Version: %d", a.Addr, a.Version))
}
}
}