def _create_domain(self, xml=None, domain=None, instance=None, launch_flags=0, power_on=True):
    'Create a domain.\n\n        Either domain or xml must be passed in. If both are passed, then\n        the domain definition is overwritten from the xml.\n        '
    err = None
    if (instance and (CONF.libvirt.virt_type == 'lxc')):
        self._create_domain_setup_lxc(instance)
    try:
        if xml:
            err = (_LE('Error defining a domain with XML: %s') % xml)
            domain = self._conn.defineXML(xml)
        if power_on:
            err = (_LE('Error launching a defined domain with XML: %s') % domain.XMLDesc(0))
            domain.createWithFlags(launch_flags)
        if (not utils.is_neutron()):
            err = (_LE('Error enabling hairpin mode with XML: %s') % domain.XMLDesc(0))
            self._enable_hairpin(domain.XMLDesc(0))
    except Exception:
        with excutils.save_and_reraise_exception():
            if err:
                LOG.error(err)
    finally:
        if (instance and (CONF.libvirt.virt_type == 'lxc')):
            self._create_domain_cleanup_lxc(instance)
    return domain
Create a domain.

Either domain or xml must be passed in. If both are passed, then
the domain definition is overwritten from the xml.
def _create_domain(self, xml=None, domain=None, instance=None, launch_flags=0, power_on=True):
    'Create a domain.\n\n        Either domain or xml must be passed in. If both are passed, then\n        the domain definition is overwritten from the xml.\n        '
    err = None
    if (instance and (CONF.libvirt.virt_type == 'lxc')):
        self._create_domain_setup_lxc(instance)
    try:
        if xml:
            err = (_LE('Error defining a domain with XML: %s') % xml)
            domain = self._conn.defineXML(xml)
        if power_on:
            err = (_LE('Error launching a defined domain with XML: %s') % domain.XMLDesc(0))
            domain.createWithFlags(launch_flags)
        if (not utils.is_neutron()):
            err = (_LE('Error enabling hairpin mode with XML: %s') % domain.XMLDesc(0))
            self._enable_hairpin(domain.XMLDesc(0))
    except Exception:
        with excutils.save_and_reraise_exception():
            if err:
                LOG.error(err)
    finally:
        if (instance and (CONF.libvirt.virt_type == 'lxc')):
            self._create_domain_cleanup_lxc(instance)
    return domain