Ejemplo n.º 1
0
 def __add_new_interface(cls, node, interface_attrs):
     interface = NodeNICInterface()
     interface.node_id = node.id
     cls.__set_interface_attributes(interface, interface_attrs)
     db().add(interface)
     db().commit()
     node.interfaces.append(interface)
Ejemplo n.º 2
0
 def __add_new_interface(cls, node, interface_attrs):
     interface = NodeNICInterface()
     interface.node_id = node.id
     cls.__set_interface_attributes(interface, interface_attrs)
     db().add(interface)
     db().commit()
     node.interfaces.append(interface)
Ejemplo n.º 3
0
 def test_offloading_modes_as_flat_dict(self):
     self.assertDictEqual(
         self.expected_result,
         NodeNICInterface.offloading_modes_as_flat_dict(self.changed_modes))
     self.assertDictEqual(
         self.expected_result_deep,
         NodeNICInterface.offloading_modes_as_flat_dict(
             self.deep_structure))
Ejemplo n.º 4
0
 def test_offloading_modes_as_flat_dict(self):
     self.assertDictEqual(
         self.expected_result,
         NodeNICInterface.offloading_modes_as_flat_dict(
             self.changed_modes))
     self.assertDictEqual(
         self.expected_result_deep,
         NodeNICInterface.offloading_modes_as_flat_dict(
             self.deep_structure))
Ejemplo n.º 5
0
    def _add_interfaces_to_node(self, node_id, count=1):
        interfaces = []
        node = self.db.query(Node).get(node_id)
        networks_to_assign = \
            list(node.cluster.network_groups) if node.cluster else []

        for i in xrange(count):
            interface = NodeNICInterface({
                'node_id':
                node_id,
                'name':
                'eth{0}'.format(i),
                'mac':
                self.generate_random_mac(),
                'current_speed':
                100,
                'max_speed':
                1000,
                'assigned_networks':
                networks_to_assign
            })
            self.db.add(interface)
            self.db.commit()

            interfaces.append(interface)
            # assign all networks to first NIC
            networks_to_assign = []

        return interfaces
Ejemplo n.º 6
0
    def _add_interfaces_to_node(self, node_id, count=1):
        interfaces = []
        node = self.db.query(Node).get(node_id)
        ng_ids = [
            ng.id
            for ng in self.network_manager.get_all_cluster_networkgroups(node)
        ]
        allowed_networks = list(
            self.db.query(NetworkGroup).filter(NetworkGroup.id.in_(ng_ids)))

        for i in xrange(count):
            nic_dict = {
                'node_id': node_id,
                'name': 'eth{0}'.format(i),
                'mac': self._generate_random_mac(),
                'current_speed': 100,
                'max_speed': 1000,
                'assigned_networks': allowed_networks
            }

            interface = NodeNICInterface()
            for k, v in nic_dict.iteritems():
                setattr(interface, k, v)

            self.db.add(interface)
            self.db.commit()

            interfaces.append(interface)

        return interfaces
Ejemplo n.º 7
0
    def _create_interfaces_from_meta(self, node):
        # Create interfaces from meta
        for interface in node.meta['interfaces']:
            interface = NodeNICInterface(
                mac=interface.get('mac'),
                name=interface.get('name'),
                ip_addr=interface.get('ip'),
                netmask=interface.get('netmask'))

            self.db.add(interface)
            node.interfaces.append(interface)

        # If node in a cluster then add
        # allowed_networks for all interfaces
        # and assigned_networks for first interface
        if node.cluster_id:
            ng_ids = [ng.id for ng in
                      self.network_manager.get_all_cluster_networkgroups(node)]
            allowed_networks = list(self.db.query(NetworkGroup).filter(
                NetworkGroup.id.in_(ng_ids)))

            for interface in node.interfaces:
                interface.allowed_networks_list = allowed_networks

            node.interfaces[0].assigned_networks_list = allowed_networks

        self.db.commit()
        # At least one interface should have
        # same ip as mac in meta
        if node.interfaces and not \
           filter(lambda i: node.mac == i.mac, node.interfaces):

            node.interfaces[0].mac = node.mac
            self.db.commit()
Ejemplo n.º 8
0
    def _create_interfaces_from_meta(self, node):
        # Create interfaces from meta
        for interface in node.meta["interfaces"]:
            interface = NodeNICInterface(
                mac=interface.get("mac"),
                name=interface.get("name"),
                ip_addr=interface.get("ip"),
                netmask=interface.get("netmask"),
            )
            self.db.add(interface)
            node.nic_interfaces.append(interface)

        self.db.flush()
        # If node in a cluster then assign networks for all interfaces
        if node.cluster_id:
            self.network_manager.assign_networks_by_default(node)
        # At least one interface should have
        # same ip as mac in meta
        if node.nic_interfaces and not filter(lambda i: node.mac == i.mac, node.nic_interfaces):

            node.nic_interfaces[0].mac = node.mac
        self.db.commit()
Ejemplo n.º 9
0
    def test_update_offloading_modes_for_bond_interface(self):
        different_modes = [
            [{
                'name': 'mode_for_nic1',
                'state': None,
                'sub': [
                    {
                        'name': 'sub_mode_for_nic1',
                        'state': None,
                        'sub': []
                    }
                ]
            }],
            [{
                'name': 'mode_for_nic2',
                'state': None,
                'sub': []
            }],

        ]

        nics = []
        for i in xrange(2):
            nic_data = copy.deepcopy(self.sample_nic_interface_data)
            nic_data['offloading_modes'] = \
                self.unchanged_modes + different_modes[i]
            nics.append(NodeNICInterface(**nic_data))

        sample_bond_data = {
            'node_id': 1,
            'name': 'test_bond_interface',
            'mode': 'active-backup',
            'bond_properties': jsonutils.dumps(
                {'test_property': 'test_value'})
        }

        bond = NodeBondInterface(**sample_bond_data)
        bond.slaves = nics

        bond_modes = bond.offloading_modes
        self.assertListEqual(self.unchanged_modes, bond_modes)

        bond.offloading_modes = self.changed_modes

        bond_modes = bond.offloading_modes
        self.assertListEqual(self.changed_modes, bond_modes)

        for i in xrange(2):
            self.assertListEqual(self.changed_modes + different_modes[i],
                                 nics[i].offloading_modes)
Ejemplo n.º 10
0
    def _add_interfaces_to_node(self, node_id, count=1):
        interfaces = []
        node = self.db.query(Node.model).get(node_id)
        networks_to_assign = \
            list(node.cluster.network_groups) if node.cluster else []

        for i in xrange(count):
            interface = NodeNICInterface(node_id=node_id,
                                         name='eth{0}'.format(i),
                                         mac=self.generate_random_mac(),
                                         current_speed=100,
                                         max_speed=1000,
                                         assigned_networks=networks_to_assign)
            self.db.add(interface)
            self.db.commit()

            interfaces.append(interface)
            # assign all networks to first NIC
            networks_to_assign = []

        return interfaces
Ejemplo n.º 11
0
    def _create_interfaces_from_meta(self, node):
        # Create interfaces from meta
        for interface in node.meta['interfaces']:
            interface = NodeNICInterface(mac=interface.get('mac'),
                                         name=interface.get('name'),
                                         ip_addr=interface.get('ip'),
                                         netmask=interface.get('netmask'))

            self.db.add(interface)
            node.interfaces.append(interface)

        # If node in a cluster then add
        # allowed_networks for all interfaces
        # and assigned_networks for first interface
        if node.cluster_id:
            ng_ids = [
                ng.id for ng in
                self.network_manager.get_all_cluster_networkgroups(node)
            ]
            allowed_networks = list(
                self.db.query(NetworkGroup).filter(
                    NetworkGroup.id.in_(ng_ids)))

            for interface in node.interfaces:
                interface.allowed_networks_list = allowed_networks

            node.interfaces[0].assigned_networks_list = allowed_networks

        self.db.commit()
        # At least one interface should have
        # same ip as mac in meta
        if node.interfaces and not \
           filter(lambda i: node.mac == i.mac, node.interfaces):

            node.interfaces[0].mac = node.mac
            self.db.commit()
Ejemplo n.º 12
0
    def _create_interfaces_from_meta(self, node):
        # Create interfaces from meta
        for interface in node.meta['interfaces']:
            interface = NodeNICInterface(mac=interface.get('mac'),
                                         name=interface.get('name'),
                                         ip_addr=interface.get('ip'),
                                         netmask=interface.get('netmask'))
            self.db.add(interface)
            node.nic_interfaces.append(interface)

        self.db.flush()
        # If node in a cluster then assign networks for all interfaces
        if node.cluster_id:
            self.network_manager.assign_networks_by_default(node)
        # At least one interface should have
        # same ip as mac in meta
        if node.nic_interfaces and not \
           filter(lambda i: node.mac == i.mac, node.nic_interfaces):

            node.nic_interfaces[0].mac = node.mac
        self.db.commit()
Ejemplo n.º 13
0
 def __add_new_interface(cls, node, interface_attrs):
     interface = NodeNICInterface()
     interface.node_id = node.id
     cls.__set_interface_attributes(interface, interface_attrs)
     db().add(interface)
     db().flush()
Ejemplo n.º 14
0
 def __add_new_interface(cls, node, interface_attrs):
     interface = NodeNICInterface()
     interface.node_id = node.id
     cls.__set_interface_attributes(interface, interface_attrs)
     db().add(interface)
     db().flush()