def main(): config.parse_args(sys.argv) logging.setup(CONF, "nova") if not CONF.cells.enable: LOG.error( _LE('Nova network is deprecated and not supported ' 'except as required for CellsV1 deployments.')) return 1 utils.monkey_patch() objects.register_all() gmr.TextGuruMeditation.setup_autorun(version) cmd_common.block_db_access('nova-network') objects_base.NovaObject.indirection_api = conductor_rpcapi.ConductorAPI() LOG.warning( _LW('Nova network is deprecated and will be removed ' 'in the future')) server = service.Service.create(binary='nova-network', topic=CONF.network_topic) service.serve(server) service.wait()
def main(): config.parse_args(sys.argv) logging.setup(CONF, "nova") # NOTE(stephenfin): Yes, this is silly, but the whole thing is being # removed and we want to make the diff in individual changes as small as # possible if True: LOG.error('Nova network is deprecated and not supported ' 'except as required for CellsV1 deployments.') return 1 objects.register_all() gmr_opts.set_defaults(CONF) gmr.TextGuruMeditation.setup_autorun(version, conf=CONF) cmd_common.block_db_access('nova-network') objects_base.NovaObject.indirection_api = conductor_rpcapi.ConductorAPI() LOG.warning('Nova network is deprecated and will be removed ' 'in the future') server = service.Service.create(binary='nova-network', topic=network_rpcapi.RPC_TOPIC, manager=CONF.network_manager) service.serve(server) service.wait()
def main(): """Parse environment and arguments and call the appropriate action.""" config.parse_args(sys.argv, default_config_files=jsonutils.loads( os.environ['CONFIG_FILE'])) logging.setup("nova") global LOG LOG = logging.getLogger('nova.dhcpbridge') objects.register_all() if not CONF.conductor.use_local: block_db_access() objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI() if CONF.action.name in ['add', 'del', 'old']: msg = (_("Called '%(action)s' for mac '%(mac)s' with ip '%(ip)s'") % { "action": CONF.action.name, "mac": CONF.action.mac, "ip": CONF.action.ip }) LOG.debug(msg) CONF.action.func(CONF.action.mac, CONF.action.ip) else: try: network_id = int(os.environ.get('NETWORK_ID')) except TypeError: LOG.error(_("Environment variable 'NETWORK_ID' must be set.")) return (1) print(init_leases(network_id)) rpc.cleanup()
def _testable_conductor(self): self.conductor_service = self.start_service( 'conductor', manager='nova.conductor.manager.ConductorManager') self.remote_object_calls = list() orig_object_class_action = \ self.conductor_service.manager.object_class_action orig_object_action = \ self.conductor_service.manager.object_action def fake_object_class_action(*args, **kwargs): self.remote_object_calls.append((kwargs.get('objname'), kwargs.get('objmethod'))) with things_temporarily_local(): result = orig_object_class_action(*args, **kwargs) return result self.stubs.Set(self.conductor_service.manager, 'object_class_action', fake_object_class_action) def fake_object_action(*args, **kwargs): self.remote_object_calls.append((kwargs.get('objinst'), kwargs.get('objmethod'))) with things_temporarily_local(): result = orig_object_action(*args, **kwargs) return result self.stubs.Set(self.conductor_service.manager, 'object_action', fake_object_action) # Things are remoted by default in this session base.NovaObject.indirection_api = conductor_rpcapi.ConductorAPI()
def main(): config.parse_args(sys.argv) logging.setup(CONF, "nova") utils.monkey_patch() objects.register_all() gmr.TextGuruMeditation.setup_autorun(version) if not CONF.conductor.use_local: block_db_access() objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI() else: LOG.warning( _LW('Conductor local mode is deprecated and will ' 'be removed in a subsequent release')) LOG.warning( _LW('Nova network is deprecated and will be removed ' 'in the future')) server = service.Service.create(binary='nova-network', topic=CONF.network_topic, db_allowed=CONF.conductor.use_local) service.serve(server) service.wait()
def main(): """加载和设置配置参数,有两点需要注意: 1. 调用rpc.set_defaults设置默认的exchange为nova,如果不设置则为 openstack 2. 调用rpc.init设置Transport和Notifier,Transport是 oslo_messaging/transport.py/Transport实例,我采用的是默认的 rpc_backend=rabbit,所以Transport采用的driver=oslo_messaging/ _drivers/impl_rabbit.py/RabbitDriver;Notifier是一个通知消息发 送器,它借助Transport完成通知消息的发送 """ config.parse_args(sys.argv) logging.setup('nova') utils.monkey_patch() objects.register_all() gmr.TextGuruMeditation.setup_autorun(version) if not CONF.conductor.use_local: block_db_access() objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI() """调用类方法nova/service.py/Service.create创建Service服务对象 输入参数topic = compute, db_allowd = false;`create`方法是一个 类方法(@classmethod),它首先基于输入参数和(/etc/nova.conf中的选 项)设置配置,然后创建一个Service对象并返回给调用者 """ server = service.Service.create(binary='nova-compute', topic=CONF.compute_topic, db_allowed=CONF.conductor.use_local) """调用server方法启动服务并调用wait方法等待服务启动完成,serve方法创 建Launcher服务启动实例对象(这里是ServiceLauncher)来启动服务, 但最终会调用server.start方法启动服务。 """ service.serve(server) service.wait()
def main(): lock_filename = '/tmp/locking.lock' lock_file = open(lock_filename, 'w') try: fcntl.lockf(lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError: print('Cannot lock: ' + lock_filename) sys.exit(1) if len(sys.argv) < 3 or sys.argv[1] != '--config-file': usage() exit(1) detection_only = False if '--detection-only' in sys.argv: detection_only = True sys.argv.remove('--detection-only') out, err = utils.execute('which', 'multipath', check_exit_code=False) if 'multipath' not in out: print('Info: Multipath tools not installed. No cleanup need be done.') exit(0) multipath_flush_on_last_del = False multipath_conf_path = "/etc/multipath.conf" if os.path.exists(multipath_conf_path): flush_on_last_del_yes = re.compile(r'\s*flush_on_last_del.*yes') for line in open(multipath_conf_path, "r"): if flush_on_last_del_yes.match(line): multipath_flush_on_last_del = True break if not multipath_flush_on_last_del: print("Warning: 'flush_on_last_del yes' is not seen in" " /etc/multipath.conf." " 'map in use' failure may show up during cleanup.") CONF(sys.argv[1:]) rpc.set_defaults(control_exchange='nova') rpc.init(CONF) utils.monkey_patch() objects.register_all() objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI() # connect_volume and disconnect_volume in nova/virt/libvirt/volume.py # need be adjusted to take the same 'external=True' lock for # synchronization @utils.synchronized('connect_volume', external=True) def do_cleanup(detection_only): cleaner = FaultyDevicesCleaner(detection_only) cleaner.cleanup() do_cleanup(detection_only) os.unlink('/tmp/locking.lock')
def main(): config.parse_args(sys.argv) logging.setup("nova") utils.monkey_patch() if not CONF.conductor.use_local: objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI() should_use_ssl = 'metadata' in CONF.enabled_ssl_apis server = service.WSGIService('metadata', use_ssl=should_use_ssl) service.serve(server, workers=server.workers) service.wait()
def main(): config.parse_args(sys.argv) logging.setup("nova") utils.monkey_patch() if not CONF.conductor.use_local: objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI() server = service.Service.create(binary='nova-network', topic=CONF.network_topic, db_allowed=CONF.conductor.use_local) service.serve(server) service.wait()
def main(): config.parse_args(sys.argv) logging.setup(CONF, "nova") utils.monkey_patch() objects.register_all() gmr.TextGuruMeditation.setup_autorun(version) objects_base.NovaObject.indirection_api = conductor_rpcapi.ConductorAPI() should_use_ssl = 'metadata' in CONF.enabled_ssl_apis server = service.WSGIService('metadata', use_ssl=should_use_ssl) service.serve(server, workers=server.workers) service.wait()
def main(): objects.register_all() config.parse_args(sys.argv) logging.setup('nova') utils.monkey_patch() if not CONF.conductor.use_local: block_db_access() objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI() server = service.Service.create(binary='nova-compute', topic=CONF.compute_topic, db_allowed=False) service.serve(server) service.wait()
def main(): """Parse environment and arguments and call the appropriate action.""" config.parse_args(sys.argv, default_config_files=jsonutils.loads( os.environ['CONFIG_FILE'])) logging.setup(CONF, "nova") global LOG LOG = logging.getLogger('nova.dhcpbridge') if CONF.action.name == 'old': # NOTE(sdague): old is the most frequent message sent, and # it's a noop. We should just exit immediately otherwise we # can stack up a bunch of requests in dnsmasq. A SIGHUP seems # to dump this list, so actions queued up get lost. return objects.register_all() if not CONF.conductor.use_local: block_db_access() objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI() else: LOG.warning( _LW('Conductor local mode is deprecated and will ' 'be removed in a subsequent release')) if CONF.action.name in ['add', 'del']: LOG.debug( "Called '%(action)s' for mac '%(mac)s' with IP '%(ip)s'", { "action": CONF.action.name, "mac": CONF.action.mac, "ip": CONF.action.ip }) CONF.action.func(CONF.action.mac, CONF.action.ip) else: try: network_id = int(os.environ.get('NETWORK_ID')) except TypeError: LOG.error(_LE("Environment variable 'NETWORK_ID' must be set.")) return (1) print(init_leases(network_id)) rpc.cleanup()
def main(): config.parse_args(sys.argv) logging.setup(CONF, 'nova') priv_context.init(root_helper=shlex.split(utils.get_root_helper())) objects.register_all() gmr_opts.set_defaults(CONF) # Ensure os-vif objects are registered and plugins loaded os_vif.initialize() gmr.TextGuruMeditation.setup_autorun(version, conf=CONF) cmd_common.block_db_access('nova-compute') objects_base.NovaObject.indirection_api = conductor_rpcapi.ConductorAPI() objects.Service.enable_min_version_cache() server = service.Service.create(binary='nova-compute', topic=compute_rpcapi.RPC_TOPIC) service.serve(server) service.wait()
def main(): config.parse_args(sys.argv) logging.setup("nova") utils.monkey_patch() objects.register_all() gmr.TextGuruMeditation.setup_autorun(version) if not CONF.conductor.use_local: block_db_access() objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI() server = service.Service.create(binary='nova-network', topic=CONF.network_topic, db_allowed=CONF.conductor.use_local) service.serve(server) service.wait()
def main(): objects.register_all() config.parse_args(sys.argv) logging.setup('nova') utils.monkey_patch() gmr.TextGuruMeditation.setup_autorun(version) if not CONF.conductor.use_local: # NOTE(Sunny): For HPUXDriver, allow compute to access db directly. if 'hpux.HPUXDriver' not in CONF.compute_driver: block_db_access() objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI() server = service.Service.create(binary='nova-compute', topic=CONF.compute_topic, db_allowed=CONF.conductor.use_local) service.serve(server) service.wait()
def _testable_conductor(self): self.conductor_service = self.start_service( 'conductor', manager='nova.conductor.manager.ConductorManager') self.remote_object_calls = list() orig_object_class_action = \ self.conductor_service.manager.object_class_action orig_object_action = \ self.conductor_service.manager.object_action def fake_object_class_action(*args, **kwargs): self.remote_object_calls.append( (kwargs.get('objname'), kwargs.get('objmethod'))) with things_temporarily_local(): result = orig_object_class_action(*args, **kwargs) return (base.NovaObject.obj_from_primitive(result, context=args[0]) if isinstance(result, base.NovaObject) else result) self.stubs.Set(self.conductor_service.manager, 'object_class_action', fake_object_class_action) def fake_object_action(*args, **kwargs): self.remote_object_calls.append( (kwargs.get('objinst'), kwargs.get('objmethod'))) with things_temporarily_local(): result = orig_object_action(*args, **kwargs) return result self.stubs.Set(self.conductor_service.manager, 'object_action', fake_object_action) # Things are remoted by default in this session base.NovaObject.indirection_api = conductor_rpcapi.ConductorAPI() # To make sure local and remote contexts match self.stubs.Set(rpc.RequestContextSerializer, 'serialize_context', lambda s, c: c) self.stubs.Set(rpc.RequestContextSerializer, 'deserialize_context', lambda s, c: c)
def main(): config.parse_args(sys.argv) logging.setup('nova') utils.monkey_patch() objects.register_all() #special process for nova-compute-ironic and nova-compute setup on same host new_value = "baremetal" + CONF.host_postfix CONF.set_default("host", new_value) gmr.TextGuruMeditation.setup_autorun(version) if not CONF.conductor.use_local: block_db_access() objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI() server = service.Service.create(binary='nova-compute', topic=CONF.compute_topic, db_allowed=CONF.conductor.use_local) service.serve(server) service.wait()
def main(): config.parse_args(sys.argv) logging.setup(CONF, 'nova') priv_context.init(root_helper=shlex.split(utils.get_root_helper())) utils.monkey_patch() objects.register_all() gmr.TextGuruMeditation.setup_autorun(version) if not CONF.conductor.use_local: block_db_access() objects_base.NovaObject.indirection_api = \ conductor_rpcapi.ConductorAPI() else: LOG.warning(_LW('Conductor local mode is deprecated and will ' 'be removed in a subsequent release')) server = service.Service.create(binary='nova-compute', topic=CONF.compute_topic, db_allowed=CONF.conductor.use_local) service.serve(server) service.wait()
def __init__(self): self.conductor_rpcapi = rpcapi.ConductorAPI() self.base_rpcapi = baserpc.BaseAPI(topic=rpcapi.RPC_TOPIC)
def __init__(self): self._manager = rpcapi.ConductorAPI() self.base_rpcapi = baserpc.BaseAPI(topic=CONF.conductor.topic)
def __init__(self): self.conductor_rpcapi = rpcapi.ConductorAPI()
def setUp(self): super(ConductorRPCAPITestCase, self).setUp() self.conductor_service = self.start_service( 'conductor', manager='nova.conductor.manager.ConductorManager') self.conductor = conductor_rpcapi.ConductorAPI()
def _start_compute_worker(self): # All the subprocess should do this re-init job to enable rpc clients rpc.init(CONF) objects_base.NovaObject.indirection_api =\ conductor_rpcapi.ConductorAPI() self.__init__(self.host, self.binary, self.topic, self.manager_class_name, self.report_interval, self.periodic_enable, self.periodic_fuzzy_delay, self.periodic_interval_max, db_allowed=False) driver_class = self.servicegroup_api._driver_name_class_mapping['db'] self.servicegroup_api._driver = importutils.import_object( driver_class, db_allowed=False) # Some subprocess only start RPC servers to answer the requests if self._is_main_worker() is False: LOG.debug("Creating RPC server for service %s", self.topic) if self.backdoor_port is not None: self.manager.backdoor_port = self.backdoor_port target = messaging.Target(topic=self.topic, server=self.host) endpoints = [ self.manager, baserpc.BaseRPCAPI(self.manager.service_name, self.backdoor_port) ] endpoints.extend(self.manager.additional_endpoints) serializer = objects_base.NovaObjectSerializer() self.rpcserver = rpc.get_server(target, endpoints, serializer) self.rpcserver.start() return # Main subprocess do the initial and period jobs verstr = version.version_string_with_package() LOG.audit(_('Starting %(topic)s node (version %(version)s)'), { 'topic': self.topic, 'version': verstr }) self.basic_config_check() self.manager.init_host() self.model_disconnected = False ctxt = context.get_admin_context() try: self.service_ref = self.conductor_api.service_get_by_args( ctxt, self.host, self.binary) self.service_id = self.service_ref['id'] except exception.NotFound: try: self.service_ref = self._create_service_ref(ctxt) except (exception.ServiceTopicExists, exception.ServiceBinaryExists): # NOTE(danms): If we race to create a record with a sibling # worker, don't fail here. self.service_ref = self.conductor_api.service_get_by_args( ctxt, self.host, self.binary) self.manager.pre_start_hook() self.manager.post_start_hook() # Add service to the ServiceGroup membership group. LOG.debug("Join ServiceGroup membership for this service %s", self.topic) self.servicegroup_api.join(self.host, self.topic, self) if self.periodic_enable: if self.periodic_fuzzy_delay: initial_delay = random.randint(0, self.periodic_fuzzy_delay) else: initial_delay = None self.tg.add_dynamic_timer( self.periodic_tasks, initial_delay=initial_delay, periodic_interval_max=self.periodic_interval_max)