Beispiel #1
0
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)
	}
}
Beispiel #2
0
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)
	}
}
Beispiel #3
0
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)
	}
}
Beispiel #4
0
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)
	}
}
Beispiel #5
0
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()
	}
}
Beispiel #6
0
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)
	}
}
Beispiel #7
0
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)
	}
}
Beispiel #8
0
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)
	}
}
Beispiel #9
0
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)
	}
}