示例#1
0
文件: networks.py 项目: popbjc/kimchi
    def _create_linux_bridge(self, interface):
        # get xml definition of interface
        iface_xml = self._get_interface_desc_xml(interface)

        # Truncate the interface name if it exceeds 13 characters to make sure
        # the length of bridge name is less than 15 (its maximum value).
        br_name = KIMCHI_BRIDGE_PREFIX + interface[-13:]
        br_xml = create_linux_bridge_xml(br_name, interface, iface_xml)

        # drop network config from interface
        self._redefine_iface_no_network(interface)

        # create and start bridge
        self._create_bridge(br_name, br_xml)

        return br_name
示例#2
0
    def _create_linux_bridge(self, interface):
        # get xml definition of interface
        iface_xml = self._get_interface_desc_xml(interface)

        # Truncate the interface name if it exceeds 13 characters to make sure
        # the length of bridge name is less than 15 (its maximum value).
        br_name = KIMCHI_BRIDGE_PREFIX + interface[-13:]
        br_xml = create_linux_bridge_xml(br_name, interface, iface_xml)

        # drop network config from interface
        self._redefine_iface_no_network(interface)

        # create and start bridge
        self._create_bridge(br_name, br_xml)

        return br_name
示例#3
0
    def _create_linux_bridge(self, interface):
        # get xml definition of interface
        iface_xml = self._get_interface_desc_xml(interface)

        # interface not defined in libvirt: try to define it
        iface_defined = False
        conn = self.conn.get()
        if iface_xml is None:
            try:
                mac = netinfo.get_dev_macaddr(str(interface))
                iface_xml = get_iface_xml(
                    {
                        'type': 'ethernet',
                        'name': interface,
                        'mac': mac,
                        'startmode': 'onboot',
                    }
                )
                conn.interfaceDefineXML(iface_xml)
                iface_defined = True
            except libvirt.libvirtError as e:
                raise OperationFailed(
                    'KCHNET0024E', {'name': interface,
                                    'err': e.get_error_message()}
                )

        # Truncate the interface name if it exceeds 13 characters to make sure
        # the length of bridge name is less than 15 (its maximum value).
        br_name = KIMCHI_BRIDGE_PREFIX + interface[-13:]
        br_xml = create_linux_bridge_xml(br_name, interface, iface_xml)

        # drop network config from interface
        iface_defined or self._redefine_iface_no_network(interface, iface_xml)

        # create and start bridge
        self._create_bridge(br_name, br_xml)

        return br_name
示例#4
0
 def test_linux_bridge_no_ip(self):
     em1_xml = """
         <interface type='ethernet' name='em1'>
             <start mode='onboot'/>
             <protocol family='ipv4'>
                 <dhcp/>
             </protocol>
         </interface>
         """
     expected_xml = """
         <interface type='bridge' name='br10'>
             <start mode='onboot'/>
             <bridge>
                 <interface type='ethernet' name='em1' />
             </bridge>
             <protocol family='ipv4'>
                 <dhcp/>
             </protocol>
         </interface>
         """
     actual_xml = nxml.create_linux_bridge_xml('br10', 'em1',
                                               normalize_xml(em1_xml))
     self.assertEquals(actual_xml, normalize_xml(expected_xml))
示例#5
0
 def test_linux_bridge_no_ip(self):
     em1_xml = """
         <interface type='ethernet' name='em1'>
             <start mode='onboot'/>
             <protocol family='ipv4'>
                 <dhcp/>
             </protocol>
         </interface>
         """
     expected_xml = """
         <interface type='bridge' name='br10'>
             <start mode='onboot'/>
             <bridge>
                 <interface type='ethernet' name='em1' />
             </bridge>
             <protocol family='ipv4'>
                 <dhcp/>
             </protocol>
         </interface>
         """
     actual_xml = nxml.create_linux_bridge_xml(
         'br10', 'em1', normalize_xml(em1_xml))
     self.assertEqual(actual_xml, normalize_xml(expected_xml))
示例#6
0
    def _create_linux_bridge(self, interface):
        # get xml definition of interface
        iface_xml = self._get_interface_desc_xml(interface)

        # interface not defined in libvirt: try to define it
        iface_defined = False
        conn = self.conn.get()
        if iface_xml is None:
            try:
                mac = netinfo.get_dev_macaddr(str(interface))
                iface_xml = get_iface_xml({
                    'type': 'ethernet',
                    'name': interface,
                    'mac': mac,
                    'startmode': 'onboot',
                })
                conn.interfaceDefineXML(iface_xml)
                iface_defined = True
            except libvirt.libvirtError as e:
                raise OperationFailed('KCHNET0024E', {
                    'name': interface,
                    'err': e.get_error_message()
                })

        # Truncate the interface name if it exceeds 13 characters to make sure
        # the length of bridge name is less than 15 (its maximum value).
        br_name = KIMCHI_BRIDGE_PREFIX + interface[-13:]
        br_xml = create_linux_bridge_xml(br_name, interface, iface_xml)

        # drop network config from interface
        iface_defined or self._redefine_iface_no_network(interface, iface_xml)

        # create and start bridge
        self._create_bridge(br_name, br_xml)

        return br_name
示例#7
0
                    'name': interface,
                    'mac': mac,
                    'startmode': "onboot"
                })
                conn.interfaceDefineXML(iface_xml.encode("utf-8"))
                iface_defined = True
            except libvirt.libvirtError, e:
                raise OperationFailed("KCHNET0024E", {
                    'name': interface,
                    'err': e.get_error_message()
                })

        # Truncate the interface name if it exceeds 13 characters to make sure
        # the length of bridge name is less than 15 (its maximum value).
        br_name = KIMCHI_BRIDGE_PREFIX + interface[-13:]
        br_xml = create_linux_bridge_xml(br_name, interface, iface_xml)

        # drop network config from interface
        iface_defined or self._redefine_iface_no_network(interface, iface_xml)

        # create and start bridge
        self._create_bridge(br_name, br_xml)

        return br_name

    def _create_vlan_tagged_bridge(self, interface, vlan_id):
        # Truncate the interface name if it exceeds 8 characters to make sure
        # the length of bridge name is less than 15 (its maximum value).
        br_name = KIMCHI_BRIDGE_PREFIX + interface[-8:] + '-' + vlan_id
        br_xml = create_vlan_tagged_bridge_xml(br_name, interface, vlan_id)
示例#8
0
            try:
                mac = knetwork.get_dev_macaddr(str(interface))
                iface_xml = get_iface_xml({'type': 'ethernet',
                                           'name': interface,
                                           'mac': mac,
                                           'startmode': "onboot"})
                conn.interfaceDefineXML(iface_xml.encode("utf-8"))
                iface_defined = True
            except libvirt.libvirtError, e:
                raise OperationFailed("KCHNET0024E", {'name': interface,
                                      'err': e.get_error_message()})

        # Truncate the interface name if it exceeds 13 characters to make sure
        # the length of bridge name is less than 15 (its maximum value).
        br_name = KIMCHI_BRIDGE_PREFIX + interface[-13:]
        br_xml = create_linux_bridge_xml(br_name, interface, iface_xml)

        # drop network config from interface
        iface_defined or self._redefine_iface_no_network(interface, iface_xml)

        # create and start bridge
        self._create_bridge(br_name, br_xml)

        return br_name

    def _create_vlan_tagged_bridge(self, interface, vlan_id):
        # Truncate the interface name if it exceeds 8 characters to make sure
        # the length of bridge name is less than 15 (its maximum value).
        br_name = KIMCHI_BRIDGE_PREFIX + interface[-8:] + '-' + vlan_id
        br_xml = create_vlan_tagged_bridge_xml(br_name, interface, vlan_id)