Last active
September 17, 2021 08:52
-
-
Save pierreprinetti/c2011ba2d41a9efc51576963f57b9b0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"github.com/gophercloud/gophercloud" | |
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers" | |
"github.com/gophercloud/utils/openstack/clientconfig" | |
) | |
const ( | |
serviceCompute = "compute" | |
serverNoSG = "cec5b2ee-deb2-4c15-be03-4c7a732e24cb" | |
serverWithSG = "e53bfe24-e183-45e4-9507-5e1e4e9c1a56" | |
microversionLow = "2.60" | |
microversionHigh = "2.71" | |
) | |
// client generates a Gophercloud client for the given service. Available | |
// services are exposed from this file as constants. | |
func client(service string) (*gophercloud.ServiceClient, error) { | |
opts := &clientconfig.ClientOpts{ | |
Cloud: os.Getenv("OS_CLOUD"), | |
} | |
return clientconfig.NewServiceClient(service, opts) | |
} | |
func printResult(computeClient *gophercloud.ServiceClient, serverWithGroup bool, microversion string) { | |
defer func(baseMicroversion string) { | |
computeClient.Microversion = baseMicroversion | |
}(computeClient.Microversion) | |
computeClient.Microversion = microversion | |
var serverID string | |
if serverWithGroup { | |
serverID = serverWithSG | |
} else { | |
serverID = serverNoSG | |
} | |
s, err := servers.Get(computeClient, serverID).Extract() | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("|%s|%t|%t|%d|\n", computeClient.Microversion, serverWithGroup, s.ServerGroups == nil, len(s.ServerGroups)) | |
} | |
func main() { | |
computeClient, err := client(serviceCompute) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("|call microversion|server has SG|ServerGroups is nil |len(ServerGroups)|\n|-|-|-|-|\n") | |
for _, microversion := range [...]string{microversionLow, microversionHigh} { | |
for _, hasServerGroup := range [...]bool{false, true} { | |
printResult(computeClient, hasServerGroup, microversion) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment