From f7d3948b2395fcee7e9826f567ededffc50305db Mon Sep 17 00:00:00 2001
From: Chmouel Boudjnah <chmouel@enovance.com>
Date: Wed, 7 Aug 2013 14:55:53 +0200
Subject: [PATCH] Do not restrict flavor to only ID and integers

- Flavors with strings and not just ID/UUID strings are valid.
- Closes-Bug: 1209060

Change-Id: Idee389fce40f8982b263e1a4349a8565140b6584
---
 novaclient/tests/v1_1/test_flavors.py | 38 +++++++++++++++++++++++++++
 novaclient/v1_1/flavors.py            |  7 -----
 2 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/novaclient/tests/v1_1/test_flavors.py b/novaclient/tests/v1_1/test_flavors.py
index eb7be2a4c..9adeda8ec 100644
--- a/novaclient/tests/v1_1/test_flavors.py
+++ b/novaclient/tests/v1_1/test_flavors.py
@@ -1,3 +1,18 @@
+# Copyright (c) 2013, OpenStack
+# All Rights Reserved.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
 from novaclient import exceptions
 from novaclient.v1_1 import flavors
 from novaclient.tests import utils
@@ -85,6 +100,29 @@ class FlavorsTest(utils.TestCase):
         cs.assert_called('POST', '/flavors', body)
         self.assertTrue(isinstance(f, flavors.Flavor))
 
+    def test_create_with_id_as_string(self):
+        flavor_id = 'foobar'
+        f = cs.flavors.create("flavorcreate", 512,
+                              1, 10, flavor_id, ephemeral=10,
+                              is_public=False)
+
+        body = {
+            "flavor": {
+                "name": "flavorcreate",
+                "ram": 512,
+                "vcpus": 1,
+                "disk": 10,
+                "OS-FLV-EXT-DATA:ephemeral": 10,
+                "id": flavor_id,
+                "swap": 0,
+                "rxtx_factor": 1.0,
+                "os-flavor-access:is_public": False,
+            }
+        }
+
+        cs.assert_called('POST', '/flavors', body)
+        self.assertTrue(isinstance(f, flavors.Flavor))
+
     def test_create_ephemeral_ispublic_defaults(self):
         f = cs.flavors.create("flavorcreate", 512, 1, 10, 1234)
 
diff --git a/novaclient/v1_1/flavors.py b/novaclient/v1_1/flavors.py
index 0f244bc18..02ca76cb4 100644
--- a/novaclient/v1_1/flavors.py
+++ b/novaclient/v1_1/flavors.py
@@ -7,7 +7,6 @@ import urllib
 from novaclient import base
 from novaclient import exceptions
 from novaclient import utils
-from novaclient.openstack.common import uuidutils
 
 
 class Flavor(base.Resource):
@@ -148,12 +147,6 @@ class FlavorManager(base.ManagerWithFind):
 
         if flavorid == "auto":
             flavorid = None
-        elif not uuidutils.is_uuid_like(flavorid):
-            try:
-                flavorid = int(flavorid)
-            except (TypeError, ValueError):
-                raise exceptions.CommandError("Flavor ID must be an integer "
-                                              "or a UUID or auto.")
 
         try:
             swap = int(swap)