Commit 22e9fd1b authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis
Browse files

ci: Get flavor by name

The option flavor_name support a list of flavors to try.

Refs #4192
parent af241a62
...@@ -32,6 +32,7 @@ kamaki_cloud = ...@@ -32,6 +32,7 @@ kamaki_cloud =
# Server name to use for our machine # Server name to use for our machine
server_name = Synnefo Deployment server_name = Synnefo Deployment
# Flavor name (reg expression) to use # Flavor name (reg expression) to use
# This is a list of flavor_names (comma seperated) to try
flavor_name = C8R8...D100drbd flavor_name = C8R8...D100drbd
# Image to use (name must contain this) # Image to use (name must contain this)
image_name = OldStable image_name = OldStable
......
...@@ -284,19 +284,23 @@ class SynnefoCI(object): ...@@ -284,19 +284,23 @@ class SynnefoCI(object):
def _find_flavor(self, flavor_name): def _find_flavor(self, flavor_name):
"""Given a flavor_name (reg expression) find a flavor id to use""" """Given a flavor_name (reg expression) find a flavor id to use"""
if flavor_name is None: # Get a list of flavor names from config file
flavor_name = self.config.get('Deployment', 'flavor_name') flavor_names = self.config.get('Deployment', 'flavor_name').split(",")
self.logger.debug("Try to find a flavor with name \"%s\"" % flavor_name) if flavor_name is not None:
# If we have a flavor_name to use, add it to our list
flavor_names.insert(0, flavor_name)
flavors = self.compute_client.list_flavors() flavors = self.compute_client.list_flavors()
flavors = [f for f in flavors for flname in flavor_names:
if re.search(flavor_name, f['name']) is not None] sflname = flname.strip()
self.logger.debug("Try to find a flavor with name \"%s\"" % sflname)
if flavors: fls = [f for f in flavors
if re.search(sflname, f['name']) is not None]
if fls:
self.logger.debug("Will use %s with id %s" self.logger.debug("Will use %s with id %s"
% (flavors[0]['name'], flavors[0]['id'])) % (fls[0]['name'], fls[0]['id']))
return flavors[0]['id'] return fls[0]['id']
else:
self.logger.error("No matching flavor found.. aborting") self.logger.error("No matching flavor found.. aborting")
sys.exit(1) sys.exit(1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment