def network_define(name, bridge, forward, **kwargs):
    '''
    Create libvirt network.

    :param name: Network name
    :param bridge: Bridge name
    :param forward: Forward mode(bridge, router, nat)
    :param vport: Virtualport type
    :param tag: Vlan tag
    :param autostart: Network autostart (default True)
    :param start: Network start (default True)
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    CLI Example:

    .. code-block:: bash

        salt '*' virt.network_define network main bridge openvswitch

    .. versionadded:: 2019.2.0
    '''
    conn = __get_conn(**kwargs)
    vport = kwargs.get('vport', None)
    tag = kwargs.get('tag', None)
    autostart = kwargs.get('autostart', True)
    starting = kwargs.get('start', True)
    net_xml = _gen_net_xml(
        name,
        bridge,
        forward,
        vport,
        tag,
    )
    try:
        conn.networkDefineXML(net_xml)
    except libvirtError as err:
        log.warning(err)
        conn.close()
        raise err  # a real error we should report upwards

    try:
        network = conn.networkLookupByName(name)
    except libvirtError as err:
        log.warning(err)
        conn.close()
        raise err  # a real error we should report upwards

    if network is None:
        conn.close()
        return False

    if (starting is True or autostart is True) and network.isActive() != 1:
        network.create()

    if autostart is True and network.autostart() != 1:
        network.setAutostart(int(autostart))
    elif autostart is False and network.autostart() == 1:
        network.setAutostart(int(autostart))

    conn.close()

    return True
def network_define ( name , bridge , forward , ** kwargs ) : conn = __get_conn ( ** kwargs ) vport = kwargs . get ( 'vport' , None ) tag = kwargs . get ( 'tag' , None ) autostart = kwargs . get ( 'autostart' , True ) starting = kwargs . get ( 'start' , True ) net_xml = _gen_net_xml ( name , bridge , forward , vport , tag , ) try : conn . networkDefineXML ( net_xml ) except libvirtError as err : log . warning ( err ) conn . close ( ) raise err try : network = conn . networkLookupByName ( name ) except libvirtError as err : log . warning ( err ) conn . close ( ) raise err if network is None : conn . close ( ) return False if ( starting is True or autostart is True ) and network . isActive ( ) != 1 : network . create ( ) if autostart is True and network . autostart ( ) != 1 : network . setAutostart ( int ( autostart ) ) elif autostart is False and network . autostart ( ) == 1 : network . setAutostart ( int ( autostart ) ) conn . close ( ) return True
Create libvirt network.

    :param name: Network name
    :param bridge: Bridge name
    :param forward: Forward mode(bridge, router, nat)
    :param vport: Virtualport type
    :param tag: Vlan tag
    :param autostart: Network autostart (default True)
    :param start: Network start (default True)
    :param connection: libvirt connection URI, overriding defaults
    :param username: username to connect with, overriding defaults
    :param password: password to connect with, overriding defaults

    CLI Example:

    .. code-block:: bash

        salt '*' virt.network_define network main bridge openvswitch

    .. versionadded:: 2019.2.0