]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
heat : Make instance flavors consistent
authorSteven Hardy <shardy@redhat.com>
Thu, 2 Aug 2012 13:37:13 +0000 (14:37 +0100)
committerSteven Hardy <shardy@redhat.com>
Thu, 2 Aug 2012 16:52:24 +0000 (17:52 +0100)
Add additional instance flavors to align templates with
nova

Fixes #179

Change-Id: I586e57748c9b0a0c7594746399d5328da788efcd
Signed-off-by: Steven Hardy <shardy@redhat.com>
heat/engine/instance.py
heat/tests/test_instance.py
heat/tests/test_stacks.py
tools/nova_create_flavors.sh [new file with mode: 0755]
tools/openstack

index 70e89875d88b8e90e1a7003c58bf51519a36580b..179995558f6b4f46896ea706a75f893303d24802 100644 (file)
@@ -108,19 +108,6 @@ class Instance(resources.Resource):
         self.ipaddress = None
         self.mime_string = None
 
-        self.itype_oflavor = {'t1.micro': 'm1.tiny',
-            'm1.small': 'm1.small',
-            'm1.medium': 'm1.medium',
-            'm1.large': 'm1.large',
-            'm1.xlarge': 'm1.tiny',  # TODO(sdake)
-            'm2.xlarge': 'm1.xlarge',
-            'm2.2xlarge': 'm1.large',
-            'm2.4xlarge': 'm1.large',
-            'c1.medium': 'm1.medium',
-            'c1.4xlarge': 'm1.large',
-            'cc2.8xlarge': 'm1.large',
-            'cg1.4xlarge': 'm1.large'}
-
     def _set_ipaddress(self, networks):
         '''
         Read the server's IP address from a list of networks provided by Nova
@@ -202,7 +189,7 @@ class Instance(resources.Resource):
     def handle_create(self):
         security_groups = self.properties.get('SecurityGroups')
         userdata = self.properties['UserData']
-        flavor = self.itype_oflavor[self.properties['InstanceType']]
+        flavor = self.properties['InstanceType']
         key_name = self.properties['KeyName']
 
         keypairs = [k.name for k in self.nova().keypairs.list()]
index eb393ec1477083457857734bc6ef377c88c43dd5..6afde1f1318ff2096eafb75aadc0803793865e05 100644 (file)
@@ -68,7 +68,6 @@ class instancesTest(unittest.TestCase):
         instance = instances.Instance('test_resource_name',
                                       t['Resources']['WebServer'], stack)
 
-        instance.itype_oflavor['256 MB Server'] = '256 MB Server'
         instance.t = instance.stack.resolve_runtime_data(instance.t)
 
         # need to resolve the template functions
@@ -81,7 +80,6 @@ class instancesTest(unittest.TestCase):
                 meta=None).AndReturn(self.fc.servers.list()[1])
         self.m.ReplayAll()
 
-        instance.itype_oflavor['256 MB Server'] = '256 MB Server'
         instance.create()
 
         # this makes sure the auto increment worked on instance creation
@@ -114,7 +112,6 @@ class instancesTest(unittest.TestCase):
         instance = instances.Instance('test_resource_name',
                                       t['Resources']['WebServer'], stack)
 
-        instance.itype_oflavor['256 MB Server'] = '256 MB Server'
         instance.t = instance.stack.resolve_runtime_data(instance.t)
 
         # need to resolve the template functions
@@ -128,7 +125,6 @@ class instancesTest(unittest.TestCase):
         self.m.ReplayAll()
 
         instance.instance_id = 1234
-        instance.itype_oflavor['256 MB Server'] = '256 MB Server'
         instance.create()
 
         # this makes sure the auto increment worked on instance creation
index fa35fa45874ed4944fced0c45247572fa6b744dd..caa590d56834a358762297ac1e2f7e44d3b68fc5 100644 (file)
@@ -71,7 +71,6 @@ def setup_mocks(mocks, stack):
     instances.Instance.nova().MultipleTimes().AndReturn(fc)
 
     instance = stack.resources['WebServer']
-    instance.itype_oflavor['m1.large'] = 'm1.large'
     instance.calculate_properties()
     server_userdata = instance._build_userdata(instance.properties['UserData'])
     mocks.StubOutWithMock(fc.servers, 'create')
diff --git a/tools/nova_create_flavors.sh b/tools/nova_create_flavors.sh
new file mode 100755 (executable)
index 0000000..de62f2d
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/sh
+# Create additional nova instance types (flavors)
+# to map to the AWS instance types we have in the templates
+
+# Default nova install (via tools/openstack) gives this:
+# +----+-----------+-----------+------+-----------+------+-------+-------------+
+# | ID |    Name   | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor |
+# +----+-----------+-----------+------+-----------+------+-------+-------------+
+# | 1  | m1.tiny   | 512       | 0    | 0         |      | 1     | 1.0         |
+# | 2  | m1.small  | 2048      | 10   | 20        |      | 1     | 1.0         |
+# | 3  | m1.medium | 4096      | 10   | 40        |      | 2     | 1.0         |
+# | 4  | m1.large  | 8192      | 10   | 80        |      | 4     | 1.0         |
+# | 5  | m1.xlarge | 16384     | 10   | 160       |      | 8     | 1.0         |
+# +----+-----------+-----------+------+-----------+------+-------+-------------+
+
+# Templates define these as valid
+#      "t1.micro"    : { "Arch" : "32" },
+#      "m1.small"    : { "Arch" : "32" },
+#      "m1.large"    : { "Arch" : "64" },
+#      "m1.xlarge"   : { "Arch" : "64" },
+#      "m2.xlarge"   : { "Arch" : "64" },
+#      "m2.2xlarge"  : { "Arch" : "64" },
+#      "m2.4xlarge"  : { "Arch" : "64" },
+#      "c1.medium"   : { "Arch" : "32" },
+#      "c1.xlarge"   : { "Arch" : "64" },
+#      "cc1.4xlarge" : { "Arch" : "64" }
+
+# So for development purposes, we create all flavors, but with a maximum of
+# 2vcpus, 10G disk and 2G RAM (since we're all running on laptops..)
+
+for f in $(nova flavor-list | grep "^| [0-9]" | awk '{print $2}')
+do
+    nova flavor-delete $f
+done
+
+# Note, horrible sleep 1's are because nova starts failing requests due
+# to rate limiting without them..
+nova flavor-create --ephemeral 0 --swap 0 --rxtx-factor 1 t1.micro 1 256 0 1
+sleep 1
+nova flavor-create --ephemeral 0 --swap 0 --rxtx-factor 1 m1.tiny 2 256 0 1
+sleep 1
+nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m1.small 3 512 0 1
+sleep 1
+nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m1.medium 4 768 0 1
+sleep 1
+nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m1.large 5 1024 0 1
+sleep 1
+nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m1.xlarge 6 2048 0 1
+sleep 1
+nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m2.xlarge 7 2048 0 2
+sleep 1
+nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m2.2xlarge 8 2048 0 2
+sleep 1
+nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 m2.4xlarge 9 2048 0 2
+sleep 1
+nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 c1.medium 10 2048 0 2
+sleep 1
+nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 c1.xlarge 11 2048 0 2
+sleep 1
+nova flavor-create --ephemeral 10 --swap 0 --rxtx-factor 1 cc1.4xlarge 12 2048 0 2
index bcd1e342b454b2983a7e1406ee8ac7049fa82a29..7846a53513d42df2568675599e36c1e126bfb87f 100755 (executable)
@@ -160,6 +160,8 @@ EOF
     sleep 1
     echo "Installation Complete."
     echo "Testing nova and glance.  If any errors are displayed, the install failed..."
+    # Create additional flavors required by heat templates
+    ${BASE_DIR}/nova_create_flavors.sh
     nova flavor-list
     glance index
     echo