<commit_before>package main

import (
	"flag"
	"fmt"
	"log"
	"github.com/rackspace/gophercloud"
)

var region, serverName, imageRef, flavorRef *string
var adminPass = flag.String("a", "", "Administrator password (auto-assigned if none)")

func main() {
	provider, username, password := getCredentials()
	region = flag.String("r", "DFW", "Rackspace region in which to create the server")
	serverName = flag.String("n", randomString(16), "Server name (what you see in the control panel)")
	imageRef = flag.String("i", "", "ID of image to deploy onto the server")  // TODO(sfalvo): Make this work in -quiet mode.
	flavorRef = flag.String("f", "", "Flavor of server to deploy image upon") // TODO(sfalvo): Make this work in -quiet mode.

	flag.Parse()

	validations := map[string]string{
		"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))
		}
	}

	auth, err := gophercloud.Authenticate(
		provider,
		gophercloud.AuthOptions{
			Username: username,
			Password: password,
		},
	)
	if err != nil {
		panic(err)
	}

	servers, err := gophercloud.ServersApi(auth, gophercloud.ApiCriteria{
		Name:      "cloudServersOpenStack",
		Region:    *region,
		VersionId: "2",
		UrlChoice: gophercloud.PublicURL,
	})
	if err != nil {
		panic(err)
	}

	_, err = servers.CreateServer(gophercloud.NewServer{
		Name:      *serverName,
		ImageRef:  *imageRef,
		FlavorRef: *flavorRef,
		AdminPass: *adminPass,
	})
	if err != nil {
		panic(err)
	}

	allServers, err := servers.ListServers()
	if err != nil {
		panic(err)
	}

	fmt.Printf("ID,Name,Status,Progress\n")
	for _, i := range allServers {
		fmt.Printf("%s,\"%s\",%s,%d\n", i.Id, i.Name, i.Status, i.Progress)
	}
}<commit_msg>Finish acceptance test for CreateServer() function<commit_after>package main

import (
	"flag"
	"fmt"
	"github.com/rackspace/gophercloud"
)

var provider, username, password string

var region, serverName, imageRef, flavorRef *string
var adminPass = flag.String("a", "", "Administrator password (auto-assigned if none)")
var quiet = flag.Bool("quiet", false, "Quiet mode for acceptance tests.  $? non-zero if error.")

func configure() {
	provider, username, password = getCredentials()
	region = flag.String("r", "DFW", "Rackspace region in which to create the server")
	serverName = flag.String("n", randomString(16), "Server name (what you see in the control panel)")
	imageRef = flag.String("i", "", "ID of image to deploy onto the server")
	flavorRef = flag.String("f", "", "Flavor of server to deploy image upon")

	flag.Parse()
}

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 images[i].Id == "6a668bb8-fb5d-407a-9a89-6f957bced767" {
			return images[i].Id
		}
	}
	panic("Image 6a668bb8-fb5d-407a-9a89-6f957bced767 (Ubuntu 12.04 LTS) not found.")
}

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.")
}

func main() {
	configure()

	auth, err := gophercloud.Authenticate(
		provider,
		gophercloud.AuthOptions{
			Username: username,
			Password: password,
		},
	)
	if err != nil {
		panic(err)
	}

	servers, err := gophercloud.ServersApi(auth, gophercloud.ApiCriteria{
		Name:      "cloudServersOpenStack",
		Region:    *region,
		VersionId: "2",
		UrlChoice: gophercloud.PublicURL,
	})
	if err != nil {
		panic(err)
	}

	if *imageRef == "" {
		*imageRef = aSuitableImage(servers)
	}

	if *flavorRef == "" {
		*flavorRef = aSuitableFlavor(servers)
	}

	_, err = servers.CreateServer(gophercloud.NewServer{
		Name:      *serverName,
		ImageRef:  *imageRef,
		FlavorRef: *flavorRef,
		AdminPass: *adminPass,
	})
	if err != nil {
		panic(err)
	}

	allServers, err := servers.ListServers()
	if err != nil {
		panic(err)
	}

	if !*quiet {
		fmt.Printf("ID,Name,Status,Progress\n")
		for _, i := range allServers {
			fmt.Printf("%s,\"%s\",%s,%d\n", i.Id, i.Name, i.Status, i.Progress)
		}
	}
}
{'fraction_non_alphanumeric': 0.150074294205052, 'fraction_numerical': 0.014434302695818298, 'mean_word_length': 3.8081632653061224, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4487030', 'n_tokens_mistral': 1833, 'n_tokens_neox': 1695, 'n_words': 455}