Skip to content

Commit

Permalink
Updated to clear out old domains and fixing some pylint/pep8 warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Harlow committed Feb 8, 2012
1 parent 91e4fbf commit 0dd2895
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
36 changes: 36 additions & 0 deletions devstack/components/nova.py
Expand Up @@ -184,6 +184,12 @@
#pip files that nova requires
REQ_PIPS = ['general.json', 'nova.json']

#used to clear out old domains that may be stuck around
LIBVIRT_PROTOCOL_MAP = {
'qemu': "qemu:///system",
'kvm': "qemu:///system",
}


class NovaUninstaller(comp.PythonUninstallComponent):
def __init__(self, *args, **kargs):
Expand Down Expand Up @@ -420,6 +426,36 @@ def _get_param_map(self, app_name):
def _get_app_options(self, app):
return APP_OPTIONS.get(app)

def _clear_domains(self):
libvirt_type = self.cfg.get('nova', 'libvirt_type')
inst_prefix = self.cfg.get('nova', 'instance_name_prefix')
virt_protocol = LIBVIRT_PROTOCOL_MAP.get(libvirt_type)
if virt_protocol and inst_prefix:
#attempt to clear out dead domains
#late import so this is not always required
try:
import libvirt
with sh.Rooted(True):
conn = None
try:
conn = libvirt.open(virt_protocol)
except libvirt.libvirtError:
LOG.warn("Could not connect to libvirt using protocol [%s]" % (virt_protocol))
if conn:
try:
definedDomains = conn.listDefinedDomains()
for domain in definedDomains:
if domain.startswith(inst_prefix):
LOG.info("Found old domain %s" % (domain))
dom = conn.lookupByName(domain)
LOG.info("Clearing domain id %d running %s" % (dom.ID(), dom.OSType()))
dom.undefine()
except libvirt.libvirtError, e:
LOG.warn("Could not clear out libvirt domains due to [%s]" % (e.message))
except ImportError:
#LOG it?
pass


# This class has the smarts to build the configuration file based on
# various runtime values. A useful reference for figuring out this
Expand Down
9 changes: 2 additions & 7 deletions devstack/env_rc.py
Expand Up @@ -110,9 +110,7 @@ def _generate_os_env(fh, cfg):
_write_line("", fh)


def generate_local_rc(fn=None, cfg=None):
if not fn:
fn = DEF_FN
def generate_local_rc(fn, cfg=None):
if not cfg:
cfg = common.get_config()
with open(fn, "w") as fh:
Expand All @@ -129,9 +127,7 @@ def generate_local_rc(fn=None, cfg=None):
_generate_os_env(fh, cfg)


def load_local_rc(fn=None, cfg=None):
if not fn:
fn = DEF_FN
def load_local_rc(fn, cfg=None):
if not cfg:
cfg = common.get_config()
am_set = 0
Expand All @@ -145,4 +141,3 @@ def load_local_rc(fn=None, cfg=None):
os.environ[var] = value
am_set += 1
return am_set

2 changes: 1 addition & 1 deletion devstack/shell.py
Expand Up @@ -487,7 +487,7 @@ def root_mode():
LOG.debug("Escalating permissions to (user=%s, group=%s)" % (root_uid, root_gid))
os.setreuid(0, root_uid)
os.setregid(0, root_gid)
except:
except OSError:
LOG.warn("Cannot escalate permissions to (user=%s, group=%s)" % (root_uid, root_gid))


Expand Down

0 comments on commit 0dd2895

Please sign in to comment.