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 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") 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", "old"]: 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(): """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 test_cleanup(self, mock_NOTIFIER, mock_LEGACY_NOTIFIER, mock_NOTIFICATION_TRANSPORT, mock_TRANSPORT): rpc.cleanup() mock_TRANSPORT.cleanup.assert_called_once_with() mock_NOTIFICATION_TRANSPORT.cleanup.assert_called_once_with() self.assertIsNone(rpc.TRANSPORT) self.assertIsNone(rpc.NOTIFICATION_TRANSPORT) self.assertIsNone(rpc.LEGACY_NOTIFIER) self.assertIsNone(rpc.NOTIFIER)
def wait(): LOG.debug(_('Full set of FLAGS:')) for flag in FLAGS: flag_get = FLAGS.get(flag, None) # hide flag contents from log if contains a password # should use secret flag when switch over to openstack-common if ("_password" in flag or "_key" in flag or (flag == "sql_connection" and "mysql:" in flag_get)): LOG.debug(_('%(flag)s : FLAG SET ') % locals()) else: LOG.debug('%(flag)s : %(flag_get)s' % locals()) try: _launcher.wait() except KeyboardInterrupt: _launcher.stop() rpc.cleanup()
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(): """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 test_cleanup(self): rpc.LEGACY_NOTIFIER = mock.Mock() rpc.NOTIFIER = mock.Mock() rpc.NOTIFICATION_TRANSPORT = mock.Mock() rpc.TRANSPORT = mock.Mock() trans_cleanup = mock.Mock() not_trans_cleanup = mock.Mock() rpc.TRANSPORT.cleanup = trans_cleanup rpc.NOTIFICATION_TRANSPORT.cleanup = not_trans_cleanup rpc.cleanup() trans_cleanup.assert_called_once_with() not_trans_cleanup.assert_called_once_with() self.assertIsNone(rpc.TRANSPORT) self.assertIsNone(rpc.NOTIFICATION_TRANSPORT) self.assertIsNone(rpc.LEGACY_NOTIFIER) self.assertIsNone(rpc.NOTIFIER)
def main(): """Parse options and call the appropriate class/method.""" CONF.register_cli_opt(category_opt) try: config.parse_args(sys.argv) logging.setup("nova") except cfg.ConfigFilesNotFoundError: cfgfile = CONF.config_file[-1] if CONF.config_file else None if cfgfile and not os.access(cfgfile, os.R_OK): st = os.stat(cfgfile) print(_("Could not read %s. Re-running with sudo") % cfgfile) try: os.execvp('sudo', ['sudo', '-u', '#%s' % st.st_uid] + sys.argv) except Exception: print(_('sudo failed, continuing as if nothing happened')) print(_('Please re-run nova-manage as root.')) return(2) objects.register_all() if CONF.category.name == "version": print(version.version_string_with_package()) return(0) if CONF.category.name == "bash-completion": if not CONF.category.query_category: print(" ".join(CATEGORIES.keys())) elif CONF.category.query_category in CATEGORIES: fn = CATEGORIES[CONF.category.query_category] command_object = fn() actions = methods_of(command_object) print(" ".join([k for (k, v) in actions])) return(0) fn = CONF.category.action_fn fn_args = [arg.decode('utf-8') for arg in CONF.category.action_args] fn_kwargs = {} for k in CONF.category.action_kwargs: v = getattr(CONF.category, 'action_kwarg_' + k) if v is None: continue if isinstance(v, six.string_types): v = v.decode('utf-8') fn_kwargs[k] = v # call the action with the remaining arguments # check arguments try: cliutils.validate_args(fn, *fn_args, **fn_kwargs) except cliutils.MissingArgs as e: # NOTE(mikal): this isn't the most helpful error message ever. It is # long, and tells you a lot of things you probably don't want to know # if you just got a single arg wrong. print(fn.__doc__) CONF.print_help() print(e) return(1) try: ret = fn(*fn_args, **fn_kwargs) rpc.cleanup() return(ret) except Exception: print(_("Command failed, please check log for more info")) raise
def main(): """Parse options and call the appropriate class/method.""" CONF.register_cli_opt(category_opt) try: config.parse_args(sys.argv) logging.setup("nova") except cfg.ConfigFilesNotFoundError: cfgfile = CONF.config_file[-1] if CONF.config_file else None if cfgfile and not os.access(cfgfile, os.R_OK): st = os.stat(cfgfile) print(_("Could not read %s. Re-running with sudo") % cfgfile) try: os.execvp('sudo', ['sudo', '-u', '#%s' % st.st_uid] + sys.argv) except Exception: print(_('sudo failed, continuing as if nothing happened')) print(_('Please re-run nova-manage as root.')) return (2) objects.register_all() if CONF.category.name == "version": print(version.version_string_with_package()) return (0) if CONF.category.name == "bash-completion": if not CONF.category.query_category: print(" ".join(CATEGORIES.keys())) elif CONF.category.query_category in CATEGORIES: fn = CATEGORIES[CONF.category.query_category] command_object = fn() actions = methods_of(command_object) print(" ".join([k for (k, v) in actions])) return (0) fn = CONF.category.action_fn fn_args = [arg.decode('utf-8') for arg in CONF.category.action_args] fn_kwargs = {} for k in CONF.category.action_kwargs: v = getattr(CONF.category, 'action_kwarg_' + k) if v is None: continue if isinstance(v, six.string_types): v = v.decode('utf-8') fn_kwargs[k] = v # call the action with the remaining arguments # check arguments try: cliutils.validate_args(fn, *fn_args, **fn_kwargs) except cliutils.MissingArgs as e: # NOTE(mikal): this isn't the most helpful error message ever. It is # long, and tells you a lot of things you probably don't want to know # if you just got a single arg wrong. print(fn.__doc__) CONF.print_help() print(e) return (1) try: ret = fn(*fn_args, **fn_kwargs) rpc.cleanup() return (ret) except Exception: print(_("Command failed, please check log for more info")) raise