From 1121f33c7dd3648e0b6cf7fb9edcaeb6a00c9759 Mon Sep 17 00:00:00 2001 From: Yichen Wang Date: Sun, 18 Oct 2015 01:33:07 -0700 Subject: [PATCH] Enhance the flavor pick-up logic 1. Enhance the flavor pick-up logic; 2. Fix the force_cleanup script to be safer to run on production cloud; Change-Id: I737f7fd5fcea31be06d4347d91740ac4de65b8db --- kloudbuster/force_cleanup.sh | 2 +- kloudbuster/users.py | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/kloudbuster/force_cleanup.sh b/kloudbuster/force_cleanup.sh index 395fa10..7357e61 100755 --- a/kloudbuster/force_cleanup.sh +++ b/kloudbuster/force_cleanup.sh @@ -97,7 +97,7 @@ for line in $KEYPAIR_LIST; do nova keypair-delete "$line" done; -if [ "$FLOATINGIP_LIST" == "" ]; then +if [ "$FLOATINGIP_LIST" == "" ] && [ "$1" == "" ]; then echo -e "`neutron floatingip-list | grep -E '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'`" | while read line; do fid=`echo $line | cut -d'|' -f2 | xargs` portid=`echo $line | cut -d'|' -f5 | xargs` diff --git a/kloudbuster/users.py b/kloudbuster/users.py index 7d3d7dc..679e52c 100644 --- a/kloudbuster/users.py +++ b/kloudbuster/users.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +import sys + import base_compute import base_network from cinderclient.v2 import client as cinderclient @@ -135,17 +137,24 @@ class User(object): def check_resources_quota(self): # Flavor check flavor_manager = base_compute.Flavor(self.nova_client) - flavor_to_use = None + find_flag = False + fcand = {'vcpus': sys.maxint, 'ram': sys.maxint, 'disk': sys.maxint} for flavor in flavor_manager.list(): flavor = vars(flavor) if flavor['vcpus'] < 1 or flavor['ram'] < 1024 or flavor['disk'] < 10: continue - flavor_to_use = flavor - break - if flavor_to_use: - LOG.info('Automatically selects flavor %s to instantiate VMs.' % - (flavor_to_use['name'])) - self.tenant.kloud.flavor_to_use = flavor_to_use['name'] + if flavor['vcpus'] < fcand['vcpus']: + fcand = flavor + if flavor['vcpus'] == fcand['vcpus'] and flavor['ram'] < fcand['ram']: + fcand = flavor + if flavor['vcpus'] == fcand['vcpus'] and flavor['ram'] == fcand['ram'] and\ + flavor['disk'] < fcand['disk']: + fcand = flavor + find_flag = True + + if find_flag: + LOG.info('Automatically selects flavor %s to instantiate VMs.' % fcand['name']) + self.tenant.kloud.flavor_to_use = fcand['name'] else: LOG.error('Cannot find a flavor which meets the minimum ' 'requirements to instantiate VMs.')