Allow loading of product/vendor/package info from external file

Currently the version.py file hardcodes some basic info for
the NOVA_PRODUCT, NOVA_VENDOR and NOVA_PACKAGE constants. It
is desirable that OS distro vendors can override/extend this
data in packages they ship. Cloud providers may also desire
to do the same. This allows Nova to optionally load this
data from a /etc/nova/release file. That file should contain
the data in a trivial "ini" format. For example:

  [Nova]
  vendor = Fedora Project
  package = 1.fc18

Note that vendor sare not required to override all strings.
In this example, the 'product' field is not set, leaving
it on the default 'OpenStack Nova' value.

Change-Id: I3d8d32eaf35268c4b0908b0a93b7c9a2ea9c580a
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange
2012-12-13 20:07:36 +00:00
parent 481d6ff142
commit 4aa45d2900
3 changed files with 82 additions and 0 deletions

View File

@@ -21,16 +21,63 @@ NOVA_VERSION = ['2013', '1', None]
YEAR, COUNT, REVISION = NOVA_VERSION
FINAL = False # This becomes true at Release Candidate time
loaded = False
def _load_config():
# Don't load in global context, since we can't assume
# these modules are accessible when distutils uses
# this module
import ConfigParser
from nova.openstack.common import cfg
from nova.openstack.common import log as logging
global loaded, NOVA_VENDOR, NOVA_PRODUCT, NOVA_PACKAGE
if loaded:
return
loaded = True
cfgfile = cfg.CONF.find_file("release")
if cfgfile is None:
return
try:
cfg = ConfigParser.RawConfigParser()
cfg.read(cfgfile)
NOVA_VENDOR = cfg.get("Nova", "vendor")
if cfg.has_option("Nova", "vendor"):
NOVA_VENDOR = cfg.get("Nova", "vendor")
NOVA_PRODUCT = cfg.get("Nova", "product")
if cfg.has_option("Nova", "product"):
NOVA_PRODUCT = cfg.get("Nova", "product")
NOVA_PACKAGE = cfg.get("Nova", "package")
if cfg.has_option("Nova", "package"):
NOVA_PACKAGE = cfg.get("Nova", "package")
except Exception, ex:
LOG = logging.getLogger(__name__)
LOG.error("Failed to load %(cfgfile)s: %(ex)s" % locals())
def vendor_string():
_load_config()
return NOVA_VENDOR
def product_string():
_load_config()
return NOVA_PRODUCT
def package_string():
_load_config()
return NOVA_PACKAGE