From f36b90ad11b02119e09792ceff8c32b714e66e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Tue, 29 Dec 2015 16:19:15 -0500 Subject: [PATCH] Disk key give the size of the disk Disk key should give the size of the first disk in GB, not the number of hard drive. During the nova boot, nova will compare this value with the minimal mandatory size associated with the Glance image. Without this patch, nova will always fail and returns the "no valid host was found" message as soon as the size is greater than 1. --- README.md | 6 +++--- main.go | 23 +++++++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 51ef76b..38f33e1 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ yields (without logging output): ], "cpu": "12", "memory": "98304", - "disk": "7", + "disk": "500", "arch": "x86_64" }, { @@ -41,7 +41,7 @@ yields (without logging output): ], "cpu": "16", "memory": "131072", - "disk": "0", + "disk": "500", "arch": "x86_64" }, { @@ -59,7 +59,7 @@ yields (without logging output): ], "cpu": "20", "memory": "98304", - "disk": "1", + "disk": "1200", "arch": "x86_64" } ] diff --git a/main.go b/main.go index afbcd30..18b05f8 100644 --- a/main.go +++ b/main.go @@ -113,8 +113,19 @@ func getDisk(client *wsman.Client) string { log.Printf("Error getting disks: %v\n", err) return "-1" } - vds := search.All(search.Tag("DCIM_VirtualDiskView", "*"), res.AllBodyElements()) - return strconv.Itoa(len(vds)) + vd := search.First(search.Tag("DCIM_VirtualDiskView", "*"), res.AllBodyElements()) + if vd == nil { + log.Printf("Error getting first disk information\n") + return "-1" + } + sizeBytes := search.First(search.Tag("SizeInBytes", "*"), vd.Children()) + if sizeBytes == nil { + log.Printf("Error getting first disk size\n") + return "-1" + } + count, err := strconv.Atoi(string(sizeBytes.Content)) + sizeGBytes := count / (1024 * 1024 * 1024) + return strconv.Itoa(sizeGBytes) } func getCPU(client *wsman.Client) string { @@ -152,15 +163,15 @@ func getBootNic(client *wsman.Client, nics []*dom.Element) *dom.Element { os.Exit(1) } fqdd := string(n.Content) // Only care about integrated nics - if ! strings.HasPrefix(fqdd, "NIC.Integrated.") { - log.Printf("%s is not integrated, skipping\n",fqdd) + if !strings.HasPrefix(fqdd, "NIC.Integrated.") { + log.Printf("%s is not integrated, skipping\n", fqdd) continue } - speed := search.First(search.Tag("LinkSpeed","*"),nic.Children()) + speed := search.First(search.Tag("LinkSpeed", "*"), nic.Children()) // If there is not speed setting, then the server is too old to report it. // Happily enough, that also means it is too old for 10 gig ports to be a thing. if speed != nil && string(speed.Content) != "3" { - log.Printf("%s is not a gigabit Ethernet port\n",fqdd) + log.Printf("%s is not a gigabit Ethernet port\n", fqdd) continue } fqdds = append(fqdds, fqdd)