func createServer(t *testing.T, client *gophercloud.ServiceClient, keyName string) *os.Server { if testing.Short() { t.Skip("Skipping test that requires server creation in short mode.") } options, err := optionsFromEnv() th.AssertNoErr(t, err) name := tools.RandomString("Gophercloud-", 8) opts := &servers.CreateOpts{ Name: name, ImageRef: options.imageID, FlavorRef: options.flavorID, DiskConfig: diskconfig.Manual, } if keyName != "" { opts.KeyPair = keyName } t.Logf("Creating server [%s].", name) s, err := servers.Create(client, opts).Extract() th.AssertNoErr(t, err) t.Logf("Creating server.") err = servers.WaitForStatus(client, s.ID, "ACTIVE", 300) th.AssertNoErr(t, err) t.Logf("Server created successfully.") return s }
func (sdk *RackspaceSDK) AllocateNewInstance() (id string) { prefix := "[RackspaceSDK AllocateNewInstance]" f := func() string { opt := servers.CreateOpts{ Name: sdk.InstanceName, ImageName: sdk.ImageName, FlavorName: sdk.FlavorName, KeyPair: sdk.SSHKeyName, } result := servers.Create(sdk.p, opt) one, err := result.Extract() if err != nil { fmt.Println(prefix, err) return "" } return one.ID } for i := 0; i < 12; i++ { id = f() if id != "" { break } else { fmt.Println(prefix, "retry", i) time.Sleep(time.Second * 10) } } return id }
func (command *commandCreate) Execute(resource *handler.Resource) { opts := resource.Params.(*paramsCreate).opts server, err := servers.Create(command.Ctx.ServiceClient, opts).Extract() if err != nil { resource.Err = err return } resource.Result = serverSingle(server) }
func findServer(t *testing.T) string { var serverIP string client, err := newComputeClient() th.AssertNoErr(t, err) err = servers.List(client, nil).EachPage(func(page pagination.Page) (bool, error) { sList, err := servers.ExtractServers(page) th.AssertNoErr(t, err) for _, s := range sList { serverIP = s.AccessIPv4 t.Logf("Found an existing server: ID [%s] Public IP [%s]", s.ID, serverIP) break } return true, nil }) th.AssertNoErr(t, err) if serverIP == "" { t.Log("No server found, creating one") imageRef := os.Getenv("RS_IMAGE_ID") if imageRef == "" { t.Fatalf("OS var RS_IMAGE_ID undefined") } flavorRef := os.Getenv("RS_FLAVOR_ID") if flavorRef == "" { t.Fatalf("OS var RS_FLAVOR_ID undefined") } opts := &servers.CreateOpts{ Name: tools.RandomString("lb_test_", 5), ImageRef: imageRef, FlavorRef: flavorRef, DiskConfig: diskconfig.Manual, } s, err := servers.Create(client, opts).Extract() th.AssertNoErr(t, err) serverIP = s.AccessIPv4 t.Logf("Created server %s, waiting for it to build", s.ID) err = servers.WaitForStatus(client, s.ID, "ACTIVE", 300) th.AssertNoErr(t, err) t.Logf("Server created successfully.") } return serverIP }
// create cloud servers instance and print out results to stdout (eg. password) func Create(c *cli.Context) { // assign vars from cli args user := c.String("user") key := c.String("key") region := c.String("region") // server create specific options newservername := c.String("name") imageid := c.String("image") flavorid := c.String("flavor") // 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) } // create the cloud server server, err3 := servers.Create(serviceClient, servers.CreateOpts{ Name: newservername, ImageRef: imageid, FlavorRef: flavorid, }).Extract() fmt.Println(server) if err3 != nil { fmt.Println(err3) } }
func createVAServer(t *testing.T, computeClient *gophercloud.ServiceClient, choices *serverOpts) (*osServers.Server, error) { if testing.Short() { t.Skip("Skipping test that requires server creation in short mode.") } name := tools.RandomString("ACPTTEST", 16) t.Logf("Attempting to create server: %s\n", name) pwd := tools.MakeNewPassword("") server, err := servers.Create(computeClient, osServers.CreateOpts{ Name: name, FlavorRef: choices.flavorID, ImageRef: choices.imageID, AdminPass: pwd, }).Extract() if err != nil { t.Fatalf("Unable to create server: %v", err) } th.AssertEquals(t, pwd, server.AdminPass) return server, err }