summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Behrens <cbehrens@codestud.com>2010-08-05 16:11:59 -0500
committerChris Behrens <cbehrens@codestud.com>2010-08-05 16:11:59 -0500
commitf42be0875d06a5d3ec0d5304d2f01a41b1f6a477 (patch)
tree45bc0dac48e7f61e33d066f68f53542ed07a1baf
parentbf0ea2deaf24419d85cae684e0700241e4c03f8c (diff)
downloadnova-f42be0875d06a5d3ec0d5304d2f01a41b1f6a477.tar.gz
nova-f42be0875d06a5d3ec0d5304d2f01a41b1f6a477.tar.xz
nova-f42be0875d06a5d3ec0d5304d2f01a41b1f6a477.zip
almost there on random scheduler. not pushing to correct compute node topic, yet, apparently...
-rwxr-xr-xbin/nova-scheduler32
-rw-r--r--nova/endpoint/cloud.py2
-rw-r--r--nova/flags.py1
-rw-r--r--nova/scheduler/__init__.py33
-rw-r--r--nova/scheduler/service.py87
5 files changed, 154 insertions, 1 deletions
diff --git a/bin/nova-scheduler b/bin/nova-scheduler
new file mode 100755
index 000000000..1ad41bbd3
--- /dev/null
+++ b/bin/nova-scheduler
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration.
+# 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.
+
+"""
+ Twistd daemon for the nova scheduler nodes.
+"""
+
+from nova import twistd
+from nova.scheduler import service
+
+
+if __name__ == '__main__':
+ twistd.serve(__file__)
+
+if __name__ == '__builtin__':
+ application = service.SchedulerService.create()
diff --git a/nova/endpoint/cloud.py b/nova/endpoint/cloud.py
index 0ee278f84..a808e54c3 100644
--- a/nova/endpoint/cloud.py
+++ b/nova/endpoint/cloud.py
@@ -576,7 +576,7 @@ class CloudController(object):
inst['private_dns_name'] = str(address)
# TODO: allocate expresses on the router node
inst.save()
- rpc.cast(FLAGS.compute_topic,
+ rpc.cast(FLAGS.scheduler_topic,
{"method": "run_instance",
"args": {"instance_id" : inst.instance_id}})
logging.debug("Casting to node for %s's instance with IP of %s" %
diff --git a/nova/flags.py b/nova/flags.py
index f35f5fa10..7f92e3f70 100644
--- a/nova/flags.py
+++ b/nova/flags.py
@@ -41,6 +41,7 @@ DEFINE_integer('s3_port', 3333, 's3 port')
DEFINE_string('s3_host', '127.0.0.1', 's3 host')
#DEFINE_string('cloud_topic', 'cloud', 'the topic clouds listen on')
DEFINE_string('compute_topic', 'compute', 'the topic compute nodes listen on')
+DEFINE_string('scheduler_topic', 'scheduler', 'the topic scheduler nodes listen on')
DEFINE_string('volume_topic', 'volume', 'the topic volume nodes listen on')
DEFINE_string('network_topic', 'network', 'the topic network nodes listen on')
diff --git a/nova/scheduler/__init__.py b/nova/scheduler/__init__.py
new file mode 100644
index 000000000..516ea61bc
--- /dev/null
+++ b/nova/scheduler/__init__.py
@@ -0,0 +1,33 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration.
+# 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.
+
+"""
+:mod:`nova.scheduler` -- Scheduler Nodes
+=====================================================
+
+.. automodule:: nova.scheduler
+ :platform: Unix
+ :synopsis: Daemon that picks a host for a VM instance.
+.. moduleauthor:: Jesse Andrews <jesse@ansolabs.com>
+.. moduleauthor:: Devin Carlen <devin.carlen@gmail.com>
+.. moduleauthor:: Vishvananda Ishaya <vishvananda@yahoo.com>
+.. moduleauthor:: Joshua McKenty <joshua@cognition.ca>
+.. moduleauthor:: Manish Singh <yosh@gimp.org>
+.. moduleauthor:: Andy Smith <andy@anarkystic.com>
+.. moduleauthor:: Chris Behrens <cbehrens@codestud.com>
+"""
diff --git a/nova/scheduler/service.py b/nova/scheduler/service.py
new file mode 100644
index 000000000..aca5b5db6
--- /dev/null
+++ b/nova/scheduler/service.py
@@ -0,0 +1,87 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration.
+# 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.
+
+"""
+Scheduler Service
+"""
+
+import logging
+import random
+import sys
+from twisted.internet import defer
+from twisted.internet import task
+
+from nova import exception
+from nova import flags
+from nova import process
+from nova import rpc
+from nova import service
+from nova import utils
+from nova.compute import model
+from nova.datastore import Redis
+
+FLAGS = flags.FLAGS
+
+
+class SchedulerService(service.Service):
+ """
+ Manages the running instances.
+ """
+ def __init__(self):
+ super(SchedulerService, self).__init__()
+ self.instdir = model.InstanceDirectory()
+
+ def noop(self):
+ """ simple test of an AMQP message call """
+ return defer.succeed('PONG')
+
+ @defer.inlineCallbacks
+ def report_state(self, nodename, daemon):
+ # TODO(termie): make this pattern be more elegant. -todd
+ try:
+ record = model.Daemon(nodename, daemon)
+ record.heartbeat()
+ if getattr(self, "model_disconnected", False):
+ self.model_disconnected = False
+ logging.error("Recovered model server connection!")
+
+ except model.ConnectionError, ex:
+ if not getattr(self, "model_disconnected", False):
+ self.model_disconnected = True
+ logging.exception("model server went away")
+ yield
+
+ @property
+ def compute_identifiers(self):
+ return [identifier for identifier in Redis.instance().smembers("daemons") if (identifier.split(':')[1] == "nova-compute")]
+
+ def pick_node(self, instance_id, **_kwargs):
+ identifiers = self.compute_identifiers
+ return identifiers[int(random.random() * len(identifiers))].split(':')[0]
+
+ @exception.wrap_exception
+ def run_instance(self, instance_id, **_kwargs):
+ node = self.pick_node(instance_id, **_kwargs)
+
+ rpc.cast('%s:%s' % (FLAGS.compute_topic, node),
+ {"method": "run_instance",
+ "args": {"instance_id" : instance_id}})
+ logging.debug("Casting to node %s for instance %s" %
+ (node, instance_id))
+
+