More cleanup and fixing nova + quantum using options instead of instances

This commit is contained in:
Joshua Harlow 2012-03-27 13:33:51 -07:00
parent bb614ceba5
commit 48ee64f4ff
6 changed files with 38 additions and 54 deletions

View File

@ -6,7 +6,7 @@ set -o errexit
# Create a small network # Create a small network
nova-manage --flagfile %CFG_FILE% network create private %FIXED_RANGE% 1 %FIXED_NETWORK_SIZE% nova-manage --flagfile %CFG_FILE% network create private %FIXED_RANGE% 1 %FIXED_NETWORK_SIZE%
if [[ "$ENABLED_SERVICES" =~ "quantum-server" ]]; then if [[ "$ENABLED_SERVICES" =~ "quantum" ]]; then
echo "Not creating floating IPs (not supported by quantum server)" echo "Not creating floating IPs (not supported by quantum server)"
else else
# Create some floating ips # Create some floating ips

View File

@ -20,7 +20,6 @@ from urlparse import urlunparse
from devstack import cfg from devstack import cfg
from devstack import component as comp from devstack import component as comp
from devstack import date
from devstack import log as logging from devstack import log as logging
from devstack import shell as sh from devstack import shell as sh
from devstack import utils from devstack import utils
@ -222,17 +221,7 @@ class KeystoneRuntime(comp.PythonRuntime):
setup_cmd = MANAGE_CMD_ROOT + [tgt_fn] setup_cmd = MANAGE_CMD_ROOT + [tgt_fn]
LOG.info("Running %r command to initialize keystone." % (" ".join(setup_cmd))) LOG.info("Running %r command to initialize keystone." % (" ".join(setup_cmd)))
sh.execute(*setup_cmd, env_overrides=env, run_as_root=False) sh.execute(*setup_cmd, env_overrides=env, run_as_root=False)
self._toggle_key_init(tgt_fn, env) utils.mark_unexecute_file(tgt_fn, env)
def _toggle_key_init(self, src_fn, env):
add_lines = list()
add_lines.append('')
add_lines.append('# Ran on %s by %s' % (date.rcf8222date(), sh.getuser()))
add_lines.append('# With environment:')
for (k, v) in env.items():
add_lines.append('# %s => %s' % (k, v))
sh.append_file(src_fn, utils.joinlinesep(*add_lines))
sh.chmod(src_fn, 0644)
def _get_apps_to_start(self): def _get_apps_to_start(self):
apps = list() apps = list()

View File

@ -363,16 +363,6 @@ class NovaRuntime(NovaMixin, comp.PythonRuntime):
self.wait_time = max(self.cfg.getint('default', 'service_wait_seconds'), 1) self.wait_time = max(self.cfg.getint('default', 'service_wait_seconds'), 1)
self.virsh = lv.Virsh(self.cfg, self.distro) self.virsh = lv.Virsh(self.cfg, self.distro)
def _toggle_network_init(self, src_fn, env):
add_lines = list()
add_lines.append('')
add_lines.append('# Ran on %s by %s' % (date.rcf8222date(), sh.getuser()))
add_lines.append('# With environment:')
for k, v in env.items():
add_lines.append('# %s => %s' % (k, v))
sh.append_file(src_fn, utils.joinlinesep(*add_lines))
sh.chmod(src_fn, 0644)
def _setup_network_init(self): def _setup_network_init(self):
tgt_fn = sh.joinpths(self.bin_dir, NET_INIT_CONF) tgt_fn = sh.joinpths(self.bin_dir, NET_INIT_CONF)
if sh.is_executable(tgt_fn): if sh.is_executable(tgt_fn):
@ -384,11 +374,11 @@ class NovaRuntime(NovaMixin, comp.PythonRuntime):
LOG.info("Waiting %s seconds so that quantum can start up before running first time init." % (self.wait_time)) LOG.info("Waiting %s seconds so that quantum can start up before running first time init." % (self.wait_time))
sh.sleep(self.wait_time) sh.sleep(self.wait_time)
env = dict() env = dict()
env['ENABLED_SERVICES'] = ",".join(self.instances.keys()) env['ENABLED_SERVICES'] = ",".join(self.options)
setup_cmd = NET_INIT_CMD_ROOT + [tgt_fn] setup_cmd = NET_INIT_CMD_ROOT + [tgt_fn]
LOG.info("Running %r command to initialize nova's network." % (" ".join(setup_cmd))) LOG.info("Running %r command to initialize nova's network." % (" ".join(setup_cmd)))
sh.execute(*setup_cmd, env_overrides=env, run_as_root=False) sh.execute(*setup_cmd, env_overrides=env, run_as_root=False)
self._toggle_network_init(tgt_fn, env) utils.mark_unexecute_file(tgt_fn, env)
def post_start(self): def post_start(self):
self._setup_network_init() self._setup_network_init()

View File

@ -15,6 +15,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import sys
def partition(fullname): def partition(fullname):
""" """
@ -40,3 +42,14 @@ def import_entry_point(fullname):
raise RuntimeError('Could not load entry point %s: %s' % raise RuntimeError('Could not load entry point %s: %s' %
(fullname, err)) (fullname, err))
return cls return cls
def import_module(module_name, quiet=True):
try:
__import__(module_name)
return sys.modules.get(module_name, None)
except ImportError:
if quiet:
return None
else:
raise

View File

@ -17,6 +17,7 @@
import contextlib import contextlib
from devstack import exceptions as excp from devstack import exceptions as excp
from devstack import importer
from devstack import log as logging from devstack import log as logging
from devstack import shell as sh from devstack import shell as sh
from devstack import utils from devstack import utils
@ -50,12 +51,6 @@ def canon_libvirt_type(virt_type):
return virt_type return virt_type
def _get_virt_lib():
# Late import so that we don't always need this library to be active
# ie if u aren't using libvirt in the first place...
return utils.import_module('libvirt')
class Virsh(object): class Virsh(object):
def __init__(self, config, distro): def __init__(self, config, distro):
@ -73,7 +68,7 @@ class Virsh(object):
return _DEAD return _DEAD
def _destroy_domain(self, conn, dom_name): def _destroy_domain(self, conn, dom_name):
libvirt = _get_virt_lib() libvirt = importer.import_module('libvirt')
try: try:
dom = conn.lookupByName(dom_name) dom = conn.lookupByName(dom_name)
LOG.debug("Destroying domain (%r) (id=%s) running %r" % (dom_name, dom.ID(), dom.OSType())) LOG.debug("Destroying domain (%r) (id=%s) running %r" % (dom_name, dom.ID(), dom.OSType()))
@ -103,7 +98,7 @@ class Virsh(object):
utils.execute_template(*cmds, params=mp) utils.execute_template(*cmds, params=mp)
def clear_domains(self, virt_type, inst_prefix): def clear_domains(self, virt_type, inst_prefix):
libvirt = _get_virt_lib() libvirt = importer.import_module('libvirt')
if not libvirt: if not libvirt:
LOG.warn("Could not clear out libvirt domains, libvirt not available for python.") LOG.warn("Could not clear out libvirt domains, libvirt not available for python.")
return return

View File

@ -100,9 +100,8 @@ def configure_logging(verbosity_level=1, dry_run=False):
def load_template(component, template_name): def load_template(component, template_name):
full_pth = sh.joinpths(settings.STACK_TEMPLATE_DIR, component, template_name) templ_pth = sh.joinpths(settings.STACK_TEMPLATE_DIR, component, template_name)
contents = sh.load_file(full_pth) return (templ_pth, sh.load_file(templ_pth))
return (full_pth, contents)
def execute_template(*cmds, **kargs): def execute_template(*cmds, **kargs):
@ -143,6 +142,17 @@ def to_bytes(text):
return byte_val return byte_val
def mark_unexecute_file(fn, kvs, comment_start='#'):
add_lines = list()
add_lines.append('')
add_lines.append(comment_start + ' Ran on %s by %s' % (date.rcf8222date(), sh.getuser()))
add_lines.append(comment_start + ' With data:')
for (k, v) in kvs.items():
add_lines.append(comment_start + ' %s => %s' % (k, v))
sh.append_file(fn, joinlinesep(*add_lines))
sh.chmod(fn, 0644)
@contextlib.contextmanager @contextlib.contextmanager
def progress_bar(name, max_am, reverse=False): def progress_bar(name, max_am, reverse=False):
widgets = list() widgets = list()
@ -167,6 +177,7 @@ def progress_bar(name, max_am, reverse=False):
def tempdir(): def tempdir():
# This seems like it was only added in python 3.2 # This seems like it was only added in python 3.2
# Make it since its useful... # Make it since its useful...
# See: http://bugs.python.org/file12970/tempdir.patch
tdir = tempfile.mkdtemp() tdir = tempfile.mkdtemp()
try: try:
yield tdir yield tdir
@ -174,17 +185,6 @@ def tempdir():
sh.deldir(tdir) sh.deldir(tdir)
def import_module(module_name, quiet=True):
try:
__import__(module_name)
return sys.modules.get(module_name, None)
except ImportError:
if quiet:
return None
else:
raise
def versionize(input_version): def versionize(input_version):
segments = input_version.split(".") segments = input_version.split(".")
cleaned_segments = list() cleaned_segments = list()
@ -262,9 +262,7 @@ def get_host_ip():
def is_interface(intfc): def is_interface(intfc):
if intfc in get_interfaces(): return intfc in get_interfaces()
return True
return False
def get_interfaces(): def get_interfaces():
@ -273,11 +271,11 @@ def get_interfaces():
interface_info = dict() interface_info = dict()
interface_addresses = netifaces.ifaddresses(intfc) interface_addresses = netifaces.ifaddresses(intfc)
ip6 = interface_addresses.get(netifaces.AF_INET6) ip6 = interface_addresses.get(netifaces.AF_INET6)
if ip6 and len(ip6): if ip6:
# Just take the first # Just take the first
interface_info[settings.IPV6] = ip6[0] interface_info[settings.IPV6] = ip6[0]
ip4 = interface_addresses.get(netifaces.AF_INET) ip4 = interface_addresses.get(netifaces.AF_INET)
if ip4 and len(ip4): if ip4:
# Just take the first # Just take the first
interface_info[settings.IPV4] = ip4[0] interface_info[settings.IPV4] = ip4[0]
# Note: there are others but this is good for now.. # Note: there are others but this is good for now..
@ -418,8 +416,7 @@ ____ ___ ____ _ _ ____ ___ ____ ____ _ _
def center_text(text, fill, max_len): def center_text(text, fill, max_len):
centered_str = '{0:{fill}{align}{size}}'.format(text, fill=fill, align="^", size=max_len) return '{0:{fill}{align}{size}}'.format(text, fill=fill, align="^", size=max_len)
return centered_str
def _welcome_slang(): def _welcome_slang():