func main() { if len(os.Args) < 3 { log.Fatal("Usage: I need both username and API key on CLI, in that order.") } username := os.Args[1] password := os.Args[2] id := identity.NewIdentity(username, password, "") err := id.Authenticate() if err != nil { log.Fatal(err) } region, err := servers.RegionByName(id, "dfw") if err != nil { log.Fatal(err) } images, err := region.Images() if err != nil { log.Fatal(err) } fmt.Printf("ID,Name\n") for _, i := range images { fmt.Printf("%s,\"%s\"\n", i.Id, i.Name) } }
func main() { flag.Parse() validations := map[string]string{ "a username (-u flag)": *userName, "a password (-p flag)": *passWord, "a server ID (-i flag)": *serverId, } for flag, value := range validations { if value == "" { log.Fatal(fmt.Sprintf("You must provide %s", flag)) } } id := identity.NewIdentity(*userName, *passWord, *region) err := id.Authenticate() if err != nil { log.Fatal(err) } region, err := servers.RegionByName(id, *region) if err != nil { log.Fatal(err) } err = region.RebootServer(*serverId, *hard) if err != nil { log.Fatal(err) } }
func main() { if len(os.Args) < 3 { log.Fatal("Usage: I need both username and API key on CLI, in that order.") } username := os.Args[1] password := os.Args[2] id := identity.NewIdentity(username, password, "") err := id.Authenticate() if err != nil { log.Fatal(err) } region, err := servers.RegionByName(id, "dfw") if err != nil { log.Fatal(err) } servers, err := region.Servers() if err != nil { log.Fatal(err) } fmt.Printf("ID,Name,IPv4,Status,Progress\n") for _, i := range servers { fmt.Printf("%s,\"%s\",%s,%s,%d\n", i.Id, i.Name, i.AccessIPv4, i.Status, i.Progress) } }
func main() { var err error flag.Parse() if *pUserName == "" { log.Fatal("You must specify a username with the -u flag.") } if *pPassword == "" { log.Fatal("You must specify an API password with the -p flag.") } if *pId == "" { log.Fatal("You must specify the server ID to delete with the -i flag.") } id := identity.NewIdentity(*pUserName, *pPassword, *pRegion) err = id.Authenticate() if err != nil { log.Fatal(err) } region, err := servers.RegionByName(id, *pRegion) if err != nil { log.Fatal(err) } err = region.DeleteServerById(*pId) if err != nil { log.Fatal(err) } }
// withAuthentication abstracts common set-up code for authenticating an identity. func withAuthentication(c *http.Client, f func(e error, id identity.Identity)) { id := identity.NewIdentity("unused", "fields", "") id.UseClient(c) err := id.Authenticate() if err != nil { f(err, nil) return } f(nil, id) }
func main() { var err error flag.Parse() if *pUserName == "" { log.Fatal("You must specify a username with the -u flag.") } if *pPassword == "" { log.Fatal("You must specify an API password with the -p flag.") } if *pId == "" { log.Fatal("You must specify the server ID to get information on with the -i flag.") } id := identity.NewIdentity(*pUserName, *pPassword, *pRegion) err = id.Authenticate() if err != nil { log.Fatal(err) } region, err := servers.RegionByName(id, *pRegion) if err != nil { log.Fatal(err) } s, err := region.ServerInfoById(*pId) if err != nil { log.Fatal(err) } fields := map[string]string{ "Access IPv4: %s": s.AccessIPv4, "Access IPv6: %s": s.AccessIPv6, "Created: %s": s.Created, "Flavor: %s": s.Flavor.Id, "Host ID: %s": s.HostId, "ID: %s": s.Id, "Image: %s": s.Image.Id, "Name: %s": s.Name, "Progress: %s": fmt.Sprintf("%d", s.Progress), "Status: %s": s.Status, "Tenant ID: %s": s.TenantId, "Updated: %s": s.Updated, "User ID: %s": s.UserId, } fmt.Printf("Server info:\n") for k, v := range fields { fmt.Printf(k, v) fmt.Println() } }
func main() { flag.Parse() validations := map[string]string{ "a username (-u flag)": *userName, "a password (-p flag)": *passWord, "a server name (-n flag)": *serverName, "an image reference (-i flag)": *imageRef, "a server flavor (-f flag)": *flavorRef, } for flag, value := range validations { if value == "" { log.Fatal(fmt.Sprintf("You must provide %s", flag)) } } id := identity.NewIdentity(*userName, *passWord, *region) err := id.Authenticate() if err != nil { log.Fatal(err) } region, err := servers.RegionByName(id, *region) if err != nil { log.Fatal(err) } nsr, err := region.CreateServer(servers.NewServer{ Name: *serverName, ImageRef: *imageRef, FlavorRef: *flavorRef, AdminPass: *adminPass, }) if err != nil { log.Fatal(err) } nscJson, err := json.MarshalIndent(nsr, "", " ") if err != nil { log.Fatal(err) } fmt.Printf("%s\n", string(nscJson)) servers, err := region.Servers() if err != nil { log.Fatal(err) } fmt.Printf("ID,Name\n") for _, i := range servers { fmt.Printf("%s,\"%s\"\n", i.Id, i.Name) } }
func main() { flag.Parse() validations := map[string]string{ "a username (-u flag)": *userName, "a password (-p flag)": *passWord, "a server ID (-i flag)": *serverId, } for flag, value := range validations { if value == "" { log.Fatal(fmt.Sprintf("You must provide %s", flag)) } } id := identity.NewIdentity(*userName, *passWord, *region) err := id.Authenticate() if err != nil { log.Fatal(err) } region, err := servers.RegionByName(id, *region) if err != nil { log.Fatal(err) } if *wait { // TODO(sfalvo): // // I, or someone, will need to find out why this call is not // reliable. On many occasions, I've observed that Rackspace // will set the server in ACTIVE status, despite it still being // in the rebuild operation per the mycloud.rackspace.com UI. // This will cause the call to ConfirmResizeServer() to respond // with a 409 error instead of a 204, as expected. While // inconvenient, it doesn't appear to harm anything, so the // solution for now is to just re-run the command again. err = waitForServer(region, *serverId) if err != nil { log.Fatal(err) } } if *revert { err = region.RevertResizeServer(*serverId) } else { err = region.ConfirmResizeServer(*serverId) } if err != nil { log.Fatal(err) } }
func main() { flag.Parse() validations := map[string]string{ "a username (-u flag)": *userName, "a password (-p flag)": *passWord, "a flavor ID (-f flag)": *flavorId, "a server name (-n flag)": *serverName, "a server ID (-i flag)": *serverId, } for flag, value := range validations { if value == "" { log.Fatal(fmt.Sprintf("You must provide %s", flag)) } } config := strings.ToUpper(*diskConfig) if (config != "") && (config != "AUTO") && (config != "MANUAL") { log.Printf("The disk configuration must be one of the following values:\n") log.Printf(" (unspecifed) - Leave it the same.") log.Printf(" AUTO - The server is built with a single partition the size of the target flavor disk.") log.Fatal(" MANUAL - The server is built using whatever partition scheme and file system is in the source image.") } id := identity.NewIdentity(*userName, *passWord, *region) err := id.Authenticate() if err != nil { log.Fatal(err) } region, err := servers.RegionByName(id, *region) if err != nil { log.Fatal(err) } err = region.ResizeServer(*serverId, *serverName, *flavorId, config) if err != nil { log.Fatal(err) } }
func ExampleRegionByName() { id := identity.NewIdentity(USERNAME, APIKEY, "") err := id.Authenticate() if err != nil { panic(err) } region, err := RegionByName(id, "dfw") if err != nil { panic(err) } images, err := region.Images() if err != nil { panic(err) } fmt.Printf("%20s Name\n", "UUID") for _, i := range images { fmt.Printf("%20s %s\n", string(i.Id[0:20]), i.Name) } }
func main() { flag.Parse() validations := map[string]string{ "a username (-u flag)": *userName, "a password (-p flag)": *passWord, "a server name (-n flag)": *serverName, "an image ID (-I flag)": *imageId, "a flavor ID (-f flag)": *flavorId, "an administrator password (-w flag)": *adminPassword, } for flag, value := range validations { if value == "" { log.Fatal(fmt.Sprintf("You must provide %s", flag)) } } id := identity.NewIdentity(*userName, *passWord, *region) err := id.Authenticate() if err != nil { log.Fatal(err) } region, err := servers.RegionByName(id, *region) if err != nil { log.Fatal(err) } _, err = region.RebuildServer(*serverId, servers.NewServer{ Name: *serverName, ImageRef: *imageId, FlavorRef: *flavorId, AdminPass: *adminPassword, }) if err != nil { log.Fatal(err) } }