Switch from FLAGS to CONF in bin
Use the global CONF variable instead of FLAGS. This is purely a cleanup since FLAGS is already just another reference to CONF. We leave the nova.flags imports until a later cleanup commit since removing them may cause unpredictable problems due to config options not being registered. Change-Id: Id0c59b2dc8002ec89ccbc5e5d7986fb68d3a693d
This commit is contained in:
14 changed files with 69 additions and 65 deletions
@@ -49,6 +49,7 @@ from nova import utils
from nova.vnc import xvp_proxy
CONF = config.CONF
LOG = logging.getLogger('nova.all')
if __name__ == '__main__':
@@ -58,7 +59,7 @@ if __name__ == '__main__':
launcher = service.ProcessLauncher()
# nova-api
for api in flags.FLAGS.enabled_apis:
for api in CONF.enabled_apis:
try:
server = service.WSGIService(api)
launcher.launch_server(server, workers=server.workers or 1)
@@ -42,12 +42,14 @@ from nova.openstack.common import log as logging
from nova import service
from nova import utils
CONF = config.CONF
if __name__ == '__main__':
config.parse_args(sys.argv)
logging.setup("nova")
utils.monkey_patch()
launcher = service.ProcessLauncher()
for api in flags.FLAGS.enabled_apis:
for api in CONF.enabled_apis:
server = service.WSGIService(api)
launcher.launch_server(server, workers=server.workers or 1)
launcher.wait()
@@ -38,11 +38,12 @@ from nova.openstack.common import log as logging
from nova import service
from nova import utils
CONF = config.CONF
if __name__ == '__main__':
config.parse_args(sys.argv)
FLAGS = flags.FLAGS
logging.setup("nova")
utils.monkey_patch()
server = service.Service.create(binary='nova-cert', topic=FLAGS.cert_topic)
server = service.Service.create(binary='nova-cert', topic=CONF.cert_topic)
service.serve(server)
service.wait()
@@ -53,8 +53,8 @@ delete_exchange_opt = cfg.BoolOpt('delete_exchange',
default=False,
help='delete nova exchange too.')
FLAGS = flags.FLAGS
FLAGS.register_cli_opt(delete_exchange_opt)
CONF = config.CONF
CONF.register_cli_opt(delete_exchange_opt)
def delete_exchange(exch):
@@ -73,5 +73,5 @@ if __name__ == '__main__':
args = config.parse_args(sys.argv)
logging.setup("nova")
delete_queues(args[1:])
if FLAGS.delete_exchange:
delete_exchange(FLAGS.control_exchange)
if CONF.delete_exchange:
delete_exchange(CONF.control_exchange)
@@ -40,12 +40,13 @@ from nova.openstack.common import log as logging
from nova import service
from nova import utils
CONF = config.CONF
if __name__ == '__main__':
config.parse_args(sys.argv)
FLAGS = flags.FLAGS
logging.setup('nova')
utils.monkey_patch()
server = service.Service.create(binary='nova-compute',
topic=FLAGS.compute_topic)
topic=CONF.compute_topic)
service.serve(server)
service.wait()
@@ -38,11 +38,12 @@ from nova import flags
from nova.openstack.common import log as logging
from nova import service
CONF = config.CONF
if __name__ == '__main__':
config.parse_args(sys.argv)
FLAGS = flags.FLAGS
logging.setup("nova")
server = service.Service.create(binary='nova-console',
topic=FLAGS.console_topic)
topic=CONF.console_topic)
service.serve(server)
service.wait()
@@ -37,12 +37,12 @@ from nova import flags
from nova.openstack.common import log as logging
from nova import service
CONF = config.CONF
if __name__ == "__main__":
config.parse_args(sys.argv)
FLAGS = flags.FLAGS
logging.setup("nova")
server = service.Service.create(binary='nova-consoleauth',
topic=FLAGS.consoleauth_topic)
topic=CONF.consoleauth_topic)
service.serve(server)
service.wait()
@@ -46,21 +46,20 @@ from nova.openstack.common import log as logging
from nova.openstack.common import rpc
from nova import utils
FLAGS = flags.FLAGS
CONF = config.CONF
LOG = logging.getLogger('nova.dhcpbridge')
def add_lease(mac, ip_address):
"""Set the IP that was assigned by the DHCP server."""
if FLAGS.fake_rabbit:
if CONF.fake_rabbit:
LOG.debug(_("leasing ip"))
network_manager = importutils.import_object(FLAGS.network_manager)
network_manager = importutils.import_object(CONF.network_manager)
network_manager.lease_fixed_ip(context.get_admin_context(),
ip_address)
else:
api = network_rpcapi.NetworkAPI()
api.lease_fixed_ip(context.get_admin_context(), ip_address, FLAGS.host)
api.lease_fixed_ip(context.get_admin_context(), ip_address, CONF.host)
def old_lease(mac, ip_address):
@@ -73,28 +72,28 @@ def old_lease(mac, ip_address):
def del_lease(mac, ip_address):
"""Called when a lease expires."""
if FLAGS.fake_rabbit:
if CONF.fake_rabbit:
LOG.debug(_("releasing ip"))
network_manager = importutils.import_object(FLAGS.network_manager)
network_manager = importutils.import_object(CONF.network_manager)
network_manager.release_fixed_ip(context.get_admin_context(),
ip_address)
else:
api = network_rpcapi.NetworkAPI()
api.release_fixed_ip(context.get_admin_context(), ip_address,
FLAGS.host)
CONF.host)
def init_leases(network_id):
"""Get the list of hosts for a network."""
ctxt = context.get_admin_context()
network_ref = db.network_get(ctxt, network_id)
network_manager = importutils.import_object(FLAGS.network_manager)
network_manager = importutils.import_object(CONF.network_manager)
return network_manager.get_dhcp_leases(ctxt, network_ref)
def main():
"""Parse environment and arguments and call the approproate action."""
flagfile = os.environ.get('FLAGFILE', FLAGS.dhcpbridge_flagfile)
flagfile = os.environ.get('FLAGFILE', CONF.dhcpbridge_flagfile)
argv = config.parse_args(sys.argv, default_config_files=[flagfile])
logging.setup("nova")
@@ -89,8 +89,6 @@ from nova.scheduler import rpcapi as scheduler_rpcapi
from nova import utils
from nova import version
FLAGS = flags.FLAGS
CONF = config.CONF
CONF.import_opt('flat_network_bridge', 'nova.network.manager')
CONF.import_opt('num_networks', 'nova.network.manager')
@@ -381,9 +379,9 @@ class FloatingIpCommands(object):
"""Creates floating ips for zone by range"""
admin_context = context.get_admin_context()
if not pool:
pool = FLAGS.default_floating_pool
pool = CONF.default_floating_pool
if not interface:
interface = FLAGS.public_interface
interface = CONF.public_interface
ips = ({'address': str(address), 'pool': pool, 'interface': interface}
for address in self.address_to_hosts(ip_range))
@@ -477,7 +475,7 @@ class NetworkCommands(object):
if v and k != "self"))
if multi_host is not None:
kwargs['multi_host'] = multi_host == 'T'
net_manager = importutils.import_object(FLAGS.network_manager)
net_manager = importutils.import_object(CONF.network_manager)
net_manager.create_networks(context.get_admin_context(), **kwargs)
def list(self):
@@ -521,8 +519,8 @@ class NetworkCommands(object):
if fixed_range is None and uuid is None:
raise Exception("Please specify either fixed_range or uuid")
net_manager = importutils.import_object(FLAGS.network_manager)
if "QuantumManager" in FLAGS.network_manager:
net_manager = importutils.import_object(CONF.network_manager)
if "QuantumManager" in CONF.network_manager:
if uuid is None:
raise Exception("UUID is required to delete Quantum Networks")
if fixed_range:
@@ -636,7 +634,7 @@ class ServiceCommands(object):
_('Updated_At'))
for svc in services:
delta = now - (svc['updated_at'] or svc['created_at'])
alive = abs(utils.total_seconds(delta)) <= FLAGS.service_down_time
alive = abs(utils.total_seconds(delta)) <= CONF.service_down_time
art = (alive and ":-)") or "XXX"
active = 'enabled'
if svc['disabled']:
@@ -1123,10 +1121,10 @@ class GetLogCommands(object):
def errors(self):
"""Get all of the errors from the log files"""
error_found = 0
if FLAGS.logdir:
logs = [x for x in os.listdir(FLAGS.logdir) if x.endswith('.log')]
if CONF.logdir:
logs = [x for x in os.listdir(CONF.logdir) if x.endswith('.log')]
for file in logs:
log_file = os.path.join(FLAGS.logdir, file)
log_file = os.path.join(CONF.logdir, file)
lines = [line.strip() for line in open(log_file, "r")]
lines.reverse()
print_name = 0
@@ -1226,7 +1224,7 @@ def main():
argv = config.parse_args(sys.argv)
logging.setup("nova")
except cfg.ConfigFilesNotFoundError:
cfgfile = FLAGS.config_file[-1] if FLAGS.config_file else None
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
@@ -40,12 +40,13 @@ from nova.openstack.common import log as logging
from nova import service
from nova import utils
CONF = config.CONF
if __name__ == '__main__':
config.parse_args(sys.argv)
FLAGS = flags.FLAGS
logging.setup("nova")
utils.monkey_patch()
server = service.Service.create(binary='nova-network',
topic=FLAGS.network_topic)
topic=CONF.network_topic)
service.serve(server)
service.wait()
@@ -67,8 +67,9 @@ opts = [
default=6080,
help='Port on which to listen for incoming requests'),
]
FLAGS = flags.FLAGS
FLAGS.register_cli_opts(opts)
CONF = config.CONF
CONF.register_cli_opts(opts)
LOG = logging.getLogger(__name__)
@@ -130,28 +131,28 @@ class NovaWebSocketProxy(websockify.WebSocketProxy):
if __name__ == '__main__':
if FLAGS.ssl_only and not os.path.exists(FLAGS.cert):
parser.error("SSL only and %s not found" % FLAGS.cert)
if CONF.ssl_only and not os.path.exists(CONF.cert):
parser.error("SSL only and %s not found" % CONF.cert)
# Setup flags
config.parse_args(sys.argv)
# Check to see if novnc html/js/css files are present
if not os.path.exists(FLAGS.web):
print "Can not find novnc html/js/css files at %s." % FLAGS.web
if not os.path.exists(CONF.web):
print "Can not find novnc html/js/css files at %s." % CONF.web
sys.exit(-1)
# Create and start the NovaWebSockets proxy
server = NovaWebSocketProxy(listen_host=FLAGS.novncproxy_host,
listen_port=FLAGS.novncproxy_port,
source_is_ipv6=FLAGS.source_is_ipv6,
verbose=FLAGS.verbose,
cert=FLAGS.cert,
key=FLAGS.key,
ssl_only=FLAGS.ssl_only,
daemon=FLAGS.daemon,
record=FLAGS.record,
web=FLAGS.web,
server = NovaWebSocketProxy(listen_host=CONF.novncproxy_host,
listen_port=CONF.novncproxy_port,
source_is_ipv6=CONF.source_is_ipv6,
verbose=CONF.verbose,
cert=CONF.cert,
key=CONF.key,
ssl_only=CONF.ssl_only,
daemon=CONF.daemon,
record=CONF.record,
web=CONF.web,
target_host='ignore',
target_port='ignore',
wrap_mode='exit',
@@ -40,9 +40,9 @@ from nova.openstack.common import rpc
from nova.openstack.common.rpc import impl_zmq
from nova import utils
FLAGS = flags.FLAGS
FLAGS.register_opts(rpc.rpc_opts)
FLAGS.register_opts(impl_zmq.zmq_opts)
CONF = config.CONF
CONF.register_opts(rpc.rpc_opts)
CONF.register_opts(impl_zmq.zmq_opts)
def main():
@@ -50,7 +50,7 @@ def main():
logging.setup("nova")
utils.monkey_patch()
ipc_dir = FLAGS.rpc_zmq_ipc_dir
ipc_dir = CONF.rpc_zmq_ipc_dir
# Create the necessary directories/files for this service.
if not os.path.isdir(ipc_dir):
@@ -63,10 +63,10 @@ def main():
logging.error(_("Could not create IPC socket directory."))
return
with contextlib.closing(impl_zmq.ZmqProxy(FLAGS)) as reactor:
with contextlib.closing(impl_zmq.ZmqProxy(CONF)) as reactor:
consume_in = "tcp://%s:%s" % \
(FLAGS.rpc_zmq_bind_address,
FLAGS.rpc_zmq_port)
(CONF.rpc_zmq_bind_address,
CONF.rpc_zmq_port)
consumption_proxy = impl_zmq.InternalContext(None)
reactor.register(consumption_proxy,
@@ -42,12 +42,13 @@ from nova.openstack.common import log as logging
from nova import service
from nova import utils
CONF = config.CONF
if __name__ == '__main__':
config.parse_args(sys.argv)
FLAGS = flags.FLAGS
logging.setup("nova")
utils.monkey_patch()
server = service.Service.create(binary='nova-scheduler',
topic=FLAGS.scheduler_topic)
topic=CONF.scheduler_topic)
service.serve(server)
service.wait()
@@ -38,8 +38,6 @@ from nova.openstack.common import rpc
from nova import service
from nova.vnc import xvp_proxy
FLAGS = flags.FLAGS
if __name__ == "__main__":
config.parse_args(sys.argv)
logging.setup("nova")
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.