Skip to content

Instantly share code, notes, and snippets.

@holmboe
Last active January 23, 2019 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holmboe/ddcccef0fd8b1c47434cca5b1fcaa76a to your computer and use it in GitHub Desktop.
Save holmboe/ddcccef0fd8b1c47434cca5b1fcaa76a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Generate OpenStack flavor permutations
# The flavor name can be generated easily with Bash, but then we wouldn't get
# the corresponding RAM in MB, etc that is required by the `openstack flavor`
# command.
#
# Roughly equivalent:
# echo {1C,2C,4C,8C}-{0.5GB,1GB,2GB,4GB,8GB,16GB,32GB,64GB,128GB}-{5GB,10GB,20GB,40GB}
import itertools
CORE = [
"1C",
"2C",
"4C",
# "6C",
"8C",
# "12C",
# "16C",
]
MEM = [
"0.5GB",
"1GB",
"2GB",
"4GB",
"8GB",
"16GB",
"32GB",
"64GB",
# "96GB",
"128GB",
# "192GB",
# "256GB",
]
DISK = [
"5GB",
"10GB",
"20GB",
"40GB",
# "80GB",
# "160GB",
# "320GB",
]
combinations = list(itertools.product(CORE, MEM, DISK))
for combination in combinations:
name = "{}-{}-{}".format(combination[0], combination[1], combination[2])
cpu = combination[0].rstrip("C")
mem = int(float(combination[1].rstrip("GB")) * 1024)
disk = combination[2].rstrip("GB")
print(
"openstack flavor show {0} || "
"openstack flavor create --public --vcpus {1} --ram {2} --disk {3} "
"{0}".format(name, cpu, mem, disk)
)
print("Permutations: {}".format(len(combinations)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment