From 43f59fc025b4decd02a78acbfd0cf654bc9cf0db Mon Sep 17 00:00:00 2001 From: Ilya Alekseyev Date: Fri, 24 Dec 2010 21:05:45 +0300 Subject: adding zones to api --- nova/api/ec2/cloud.py | 7 ++++++- nova/compute/api.py | 6 ++++-- nova/db/sqlalchemy/models.py | 2 +- nova/service.py | 3 ++- nova/tests/test_scheduler.py | 7 ++++--- nova/tests/test_service.py | 24 ++++++++++++++++-------- 6 files changed, 33 insertions(+), 16 deletions(-) (limited to 'nova') diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index e09261f00..66060bbfc 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -753,6 +753,10 @@ class CloudController(object): def run_instances(self, context, **kwargs): max_count = int(kwargs.get('max_count', 1)) + placement = kwargs.get('placement') + avzone = None + if placement is not None: + avzone = placement['availability_zone'] instances = self.compute_api.create_instances(context, instance_types.get_by_type(kwargs.get('instance_type', None)), kwargs['image_id'], @@ -765,7 +769,8 @@ class CloudController(object): key_name=kwargs.get('key_name'), user_data=kwargs.get('user_data'), security_group=kwargs.get('security_group'), - generate_hostname=internal_id_to_ec2_id) + generate_hostname=internal_id_to_ec2_id, + availability_zone=avzone) return self._format_run_instances(context, instances[0]['reservation_id']) diff --git a/nova/compute/api.py b/nova/compute/api.py index 4953fe559..cc377a1e4 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -75,7 +75,8 @@ class ComputeAPI(base.Base): display_name='', description='', key_name=None, key_data=None, security_group='default', user_data=None, - generate_hostname=generate_default_hostname): + generate_hostname=generate_default_hostname, + availability_zone=None): """Create the number of instances requested if quote and other arguments check out ok.""" @@ -175,7 +176,8 @@ class ComputeAPI(base.Base): FLAGS.scheduler_topic, {"method": "run_instance", "args": {"topic": FLAGS.compute_topic, - "instance_id": instance_id}}) + "instance_id": instance_id, + "availability_zone": availability_zone}}) return instances diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index 843675fe6..5a020a469 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -149,7 +149,7 @@ class Service(BASE, NovaBase): topic = Column(String(255)) report_count = Column(Integer, nullable=False, default=0) disabled = Column(Boolean, default=False) - availability_zone = Column(String(255)) + availability_zone = Column(String(255), default='nova') class Certificate(BASE, NovaBase): diff --git a/nova/service.py b/nova/service.py index f1f90742f..a612ac592 100644 --- a/nova/service.py +++ b/nova/service.py @@ -114,7 +114,8 @@ class Service(object): {'host': self.host, 'binary': self.binary, 'topic': self.topic, - 'report_count': 0}) + 'report_count': 0, + 'availability_zone': FLAGS.node_availability_zone}) self.service_id = service_ref['id'] def __getattr__(self, key): diff --git a/nova/tests/test_scheduler.py b/nova/tests/test_scheduler.py index 487e7b9e6..188e50aac 100644 --- a/nova/tests/test_scheduler.py +++ b/nova/tests/test_scheduler.py @@ -110,10 +110,11 @@ class ZoneSchedulerTestCase(test.TestCase): self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True) rpc.cast(ctxt, 'compute.host1', - {'method': 'create_instance', #TODO: check it - 'args': {'availability_zone': 'zone1'}}) + {'method': 'run_instance', + 'args':{'instance_id': 'i-ffffffff', + 'availability_zone': 'zone1'}}) self.mox.ReplayAll() - scheduler.create_instance(ctxt, 'compute', availability_zone='zone1') + scheduler.run_instance(ctxt, 'compute', instance_id='i-ffffffff', availability_zone='zone1') class SimpleDriverTestCase(test.TestCase): diff --git a/nova/tests/test_service.py b/nova/tests/test_service.py index b30838ad7..1400b88e5 100644 --- a/nova/tests/test_service.py +++ b/nova/tests/test_service.py @@ -107,11 +107,13 @@ class ServiceTestCase(test.TestCase): service_create = {'host': host, 'binary': binary, 'topic': topic, - 'report_count': 0} + 'report_count': 0, + 'availability_zone': 'nova'} service_ref = {'host': host, 'binary': binary, 'report_count': 0, - 'id': 1} + 'id': 1, + 'availability_zone': 'nova'} service.db.service_get_by_args(mox.IgnoreArg(), host, @@ -135,12 +137,14 @@ class ServiceTestCase(test.TestCase): service_create = {'host': host, 'binary': binary, 'topic': topic, - 'report_count': 0} + 'report_count': 0, + 'availability_zone': 'nova'} service_ref = {'host': host, 'binary': binary, 'topic': topic, 'report_count': 0, - 'id': 1} + 'id': 1, + 'availability_zone': 'nova'} service.db.service_get_by_args(mox.IgnoreArg(), host, @@ -167,12 +171,14 @@ class ServiceTestCase(test.TestCase): service_create = {'host': host, 'binary': binary, 'topic': topic, - 'report_count': 0} + 'report_count': 0, + 'availability_zone': 'nova'} service_ref = {'host': host, 'binary': binary, 'topic': topic, 'report_count': 0, - 'id': 1} + 'id': 1, + 'availability_zone': 'nova'} service.db.service_get_by_args(mox.IgnoreArg(), host, @@ -198,12 +204,14 @@ class ServiceTestCase(test.TestCase): service_create = {'host': host, 'binary': binary, 'topic': topic, - 'report_count': 0} + 'report_count': 0, + 'availability_zone': 'nova'} service_ref = {'host': host, 'binary': binary, 'topic': topic, 'report_count': 0, - 'id': 1} + 'id': 1, + 'availability_zone': 'nova'} service.db.service_get_by_args(mox.IgnoreArg(), host, -- cgit