almost there on random scheduler. not pushing to correct compute node topic, yet, apparently...
This commit is contained in:
		
							
								
								
									
										32
									
								
								bin/nova-scheduler
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										32
									
								
								bin/nova-scheduler
									
									
									
									
									
										Executable file
									
								
							@@ -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()
 | 
			
		||||
@@ -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" %
 | 
			
		||||
 
 | 
			
		||||
@@ -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')
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										33
									
								
								nova/scheduler/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								nova/scheduler/__init__.py
									
									
									
									
									
										Normal file
									
								
							@@ -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>
 | 
			
		||||
"""
 | 
			
		||||
							
								
								
									
										87
									
								
								nova/scheduler/service.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								nova/scheduler/service.py
									
									
									
									
									
										Normal file
									
								
							@@ -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))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user