Merge trunk and handle flagfiles with kid-gloves in nova-api. Rename some flags for clarity.

This commit is contained in:
Todd Willey
2011-01-12 17:35:09 -05:00
5 changed files with 49 additions and 58 deletions

View File

@@ -21,6 +21,7 @@ Jesse Andrews <anotherjesse@gmail.com>
Joe Heck <heckj@mac.com> Joe Heck <heckj@mac.com>
Joel Moore <joelbm24@gmail.com> Joel Moore <joelbm24@gmail.com>
Jonathan Bryce <jbryce@jbryce.com> Jonathan Bryce <jbryce@jbryce.com>
Josh Durgin <joshd@hq.newdream.net>
Josh Kearney <josh.kearney@rackspace.com> Josh Kearney <josh.kearney@rackspace.com>
Joshua McKenty <jmckenty@gmail.com> Joshua McKenty <jmckenty@gmail.com>
Justin Santa Barbara <justin@fathomdb.com> Justin Santa Barbara <justin@fathomdb.com>

View File

@@ -40,59 +40,48 @@ from nova import flags
from nova import log as logging from nova import log as logging
from nova import wsgi from nova import wsgi
logging.basicConfig()
LOG = logging.getLogger('nova.api') LOG = logging.getLogger('nova.api')
LOG.setLevel(logging.DEBUG)
LOG.addHandler(logging.StreamHandler())
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
API_ENDPOINTS = ['ec2', 'openstack'] API_ENDPOINTS = ['ec2', 'osapi']
def load_configuration(paste_config): def load_configuration(paste_config, name):
"""Load the paste configuration from the config file and return it.""" """Load the paste configuration from the config file and return it."""
config = None config = None
# Try each known name to get the global DEFAULTS, which will give ports try:
for name in API_ENDPOINTS: config = deploy.appconfig("config:%s" % paste_config, name=name)
try: return config
config = deploy.appconfig("config:%s" % paste_config, name=name) except LookupError:
except LookupError: return None
pass
if config:
verbose = config.get('verbose', None)
if verbose:
FLAGS.verbose = int(verbose) == 1
if FLAGS.verbose:
logging.getLogger().setLevel(logging.DEBUG)
return config
LOG.debug(_("Paste config at %s has no secion for known apis"),
paste_config)
print _("Paste config at %s has no secion for any known apis") % \
paste_config
os.exit(1)
def launch_api(paste_config_file, section, server, port, host):
"""Launch an api server from the specified port and IP."""
LOG.debug(_("Launching %s api on %s:%s"), section, host, port)
app = deploy.loadapp('config:%s' % paste_config_file, name=section)
server.start(app, int(port), host)
def run_app(paste_config_file): def run_app(paste_config_file):
LOG.debug(_("Using paste.deploy config at: %s"), configfile) LOG.debug(_("Using paste.deploy config at: %s"), configfile)
config = load_configuration(paste_config_file)
LOG.debug(_("Configuration: %r"), config)
server = wsgi.Server() server = wsgi.Server()
ip = config.get('host', '0.0.0.0') apps = []
for api in API_ENDPOINTS: for api in API_ENDPOINTS:
port = config.get("%s_port" % api, None) config = load_configuration(paste_config_file, api)
if not port: if config is None:
continue continue
host = config.get("%s_host" % api, ip) if int(config.get('verbose', 0)) == 1:
launch_api(configfile, api, server, port, host) FLAGS.verbose = True
LOG.debug(_("All api servers launched, now waiting")) host = config.get("%s_host" % api, config.get('host', '0.0.0.0'))
server.wait() port = config.get("%s_port" % api, getattr(FLAGS, "%s_port" % api))
setattr(FLAGS, "%s_host" % api, host)
setattr(FLAGS, "%s_port" % api, port)
LOG.info(_("Running %s API"), api)
app = deploy.loadapp('config:%s' % paste_config_file, name=api)
apps.append((app, int(port), host))
if len(apps) == 0:
LOG.error(_("No known API applications configured in %s."),
paste_config_file)
else:
for app in apps:
server.start(*app)
server.wait()
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -44,7 +44,6 @@ from nova import wsgi
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
flags.DEFINE_integer('osapi_port', 8774, 'OpenStack API port')
flags.DEFINE_string('osapi_host', '0.0.0.0', 'OpenStack API host') flags.DEFINE_string('osapi_host', '0.0.0.0', 'OpenStack API host')
flags.DEFINE_integer('ec2api_port', 8773, 'EC2 API port') flags.DEFINE_integer('ec2api_port', 8773, 'EC2 API port')
flags.DEFINE_string('ec2api_host', '0.0.0.0', 'EC2 API host') flags.DEFINE_string('ec2api_host', '0.0.0.0', 'EC2 API host')

View File

@@ -682,7 +682,7 @@ class AuthManager(object):
region, _sep, region_host = item.partition("=") region, _sep, region_host = item.partition("=")
regions[region] = region_host regions[region] = region_host
else: else:
regions = {'nova': FLAGS.cc_host} regions = {'nova': FLAGS.ec2_host}
for region, host in regions.iteritems(): for region, host in regions.iteritems():
rc = self.__generate_rc(user, rc = self.__generate_rc(user,
pid, pid,
@@ -727,28 +727,28 @@ class AuthManager(object):
def __generate_rc(user, pid, use_dmz=True, host=None): def __generate_rc(user, pid, use_dmz=True, host=None):
"""Generate rc file for user""" """Generate rc file for user"""
if use_dmz: if use_dmz:
cc_host = FLAGS.cc_dmz ec2_host = FLAGS.ec2_dmz_host
else: else:
cc_host = FLAGS.cc_host ec2_host = FLAGS.ec2_host
# NOTE(vish): Always use the dmz since it is used from inside the # NOTE(vish): Always use the dmz since it is used from inside the
# instance # instance
s3_host = FLAGS.s3_dmz s3_host = FLAGS.s3_dmz
if host: if host:
s3_host = host s3_host = host
cc_host = host ec2_host = host
rc = open(FLAGS.credentials_template).read() rc = open(FLAGS.credentials_template).read()
rc = rc % {'access': user.access, rc = rc % {'access': user.access,
'project': pid, 'project': pid,
'secret': user.secret, 'secret': user.secret,
'ec2': '%s://%s:%s%s' % (FLAGS.ec2_prefix, 'ec2': '%s://%s:%s%s' % (FLAGS.ec2_scheme,
cc_host, ec2_host,
FLAGS.cc_port, FLAGS.ec2_port,
FLAGS.ec2_suffix), FLAGS.ec2_path),
's3': 'http://%s:%s' % (s3_host, FLAGS.s3_port), 's3': 'http://%s:%s' % (s3_host, FLAGS.s3_port),
'os': '%s://%s:%s%s' % (FLAGS.os_prefix, 'os': '%s://%s:%s%s' % (FLAGS.osapi_scheme,
cc_host, ec2_host,
FLAGS.cc_port, FLAGS.osapi_port,
FLAGS.os_suffix), FLAGS.osapi_path),
'user': user.name, 'user': user.name,
'nova': FLAGS.ca_file, 'nova': FLAGS.ca_file,
'cert': FLAGS.credential_cert_file, 'cert': FLAGS.credential_cert_file,

View File

@@ -254,13 +254,15 @@ DEFINE_string('rabbit_virtual_host', '/', 'rabbit virtual host')
DEFINE_integer('rabbit_retry_interval', 10, 'rabbit connection retry interval') DEFINE_integer('rabbit_retry_interval', 10, 'rabbit connection retry interval')
DEFINE_integer('rabbit_max_retries', 12, 'rabbit connection attempts') DEFINE_integer('rabbit_max_retries', 12, 'rabbit connection attempts')
DEFINE_string('control_exchange', 'nova', 'the main exchange to connect to') DEFINE_string('control_exchange', 'nova', 'the main exchange to connect to')
DEFINE_string('ec2_prefix', 'http', 'prefix for ec2') DEFINE_string('ec2_host', '$my_ip', 'ip of api server')
DEFINE_string('os_prefix', 'http', 'prefix for openstack') DEFINE_string('ec2_dmz_host', '$my_ip', 'internal ip of api server')
DEFINE_string('cc_host', '$my_ip', 'ip of api server') DEFINE_integer('ec2_port', 8773, 'cloud controller port')
DEFINE_string('cc_dmz', '$my_ip', 'internal ip of api server') DEFINE_string('ec2_scheme', 'http', 'prefix for ec2')
DEFINE_integer('cc_port', 8773, 'cloud controller port') DEFINE_string('ec2_path', '/services/Cloud', 'suffix for ec2')
DEFINE_string('ec2_suffix', '/services/Cloud', 'suffix for ec2') DEFINE_string('osapi_host', '$my_ip', 'ip of api server')
DEFINE_string('os_suffix', '/v1.0/', 'suffix for openstack') DEFINE_string('osapi_scheme', 'http', 'prefix for openstack')
DEFINE_integer('osapi_port', 8774, 'OpenStack API port')
DEFINE_string('osapi_path', '/v1.0/', 'suffix for openstack')
DEFINE_string('default_project', 'openstack', 'default project for openstack') DEFINE_string('default_project', 'openstack', 'default project for openstack')
DEFINE_string('default_image', 'ami-11111', DEFINE_string('default_image', 'ami-11111',