From 044887521ec2c38231458c3928af6956dc16119a Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Thu, 2 Aug 2012 14:37:13 +0100 Subject: [PATCH] heat : Make instance flavors consistent Add additional instance flavors to align templates with nova Fixes #179 Change-Id: I586e57748c9b0a0c7594746399d5328da788efcd Signed-off-by: Steven Hardy --- heat/engine/instance.py | 15 +-------- heat/tests/test_instance.py | 4 --- heat/tests/test_stacks.py | 1 - tools/nova_create_flavors.sh | 60 ++++++++++++++++++++++++++++++++++++ tools/openstack | 2 ++ 5 files changed, 63 insertions(+), 19 deletions(-) create mode 100755 tools/nova_create_flavors.sh diff --git a/heat/engine/instance.py b/heat/engine/instance.py index 70e89875..17999555 100644 --- a/heat/engine/instance.py +++ b/heat/engine/instance.py @@ -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()] diff --git a/heat/tests/test_instance.py b/heat/tests/test_instance.py index eb393ec1..6afde1f1 100644 --- a/heat/tests/test_instance.py +++ b/heat/tests/test_instance.py @@ -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 diff --git a/heat/tests/test_stacks.py b/heat/tests/test_stacks.py index fa35fa45..caa590d5 100644 --- a/heat/tests/test_stacks.py +++ b/heat/tests/test_stacks.py @@ -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 index 00000000..de62f2d9 --- /dev/null +++ b/tools/nova_create_flavors.sh @@ -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 diff --git a/tools/openstack b/tools/openstack index bcd1e342..7846a535 100755 --- a/tools/openstack +++ b/tools/openstack @@ -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 -- 2.45.2