Esempio n. 1
0
    def _update_attrs(cls, node_data):
        node_db = db().query(Node).get(node_data['id'])
        is_ether = lambda x: x['type'] == consts.NETWORK_INTERFACE_TYPES.ether
        is_bond = lambda x: x['type'] == consts.NETWORK_INTERFACE_TYPES.bond
        interfaces = filter(is_ether, node_data['interfaces'])
        bond_interfaces = filter(is_bond, node_data['interfaces'])

        interfaces_db = node_db.nic_interfaces
        bond_interfaces_db = node_db.bond_interfaces
        for iface in interfaces:
            current_iface = filter(
                lambda i: i.id == iface['id'],
                interfaces_db
            )[0]
            # Remove all old network's assignment for this interface.
            db().query(NetworkNICAssignment).filter_by(
                interface_id=current_iface.id
            ).delete()
            for net in iface['assigned_networks']:
                net_assignment = NetworkNICAssignment()
                net_assignment.network_id = net['id']
                net_assignment.interface_id = current_iface.id
                db().add(net_assignment)
            if 'interface_properties' in iface:
                current_iface.interface_properties = \
                    iface['interface_properties']
        map(db().delete, bond_interfaces_db)
        db().commit()

        for bond in bond_interfaces:
            bond_db = NodeBondInterface()
            bond_db.node_id = node_db.id
            db().add(bond_db)
            bond_db.name = bond['name']
            if bond.get('bond_properties', {}).get('mode'):
                bond_db.mode = bond['bond_properties']['mode']
            else:
                bond_db.mode = bond['mode']
            bond_db.mac = bond.get('mac')
            bond_db.bond_properties = bond.get('bond_properties', {})
            bond_db.interface_properties = bond.get('interface_properties', {})
            db().commit()
            db().refresh(bond_db)

            # Add new network assignment.
            map(bond_db.assigned_networks_list.append,
                [db().query(NetworkGroup).get(ng['id']) for ng
                 in bond['assigned_networks']])
            # Add new slaves.
            for nic in bond['slaves']:
                bond_db.slaves.append(
                    db().query(NodeNICInterface).filter_by(
                        name=nic['name']
                    ).filter_by(
                        node_id=node_db.id
                    ).first()
                )
            db().commit()

        return node_db.id
Esempio n. 2
0
    def _update_attrs(cls, node_data):
        node_db = db().query(Node).get(node_data['id'])
        is_ether = lambda x: x['type'] == consts.NETWORK_INTERFACE_TYPES.ether
        is_bond = lambda x: x['type'] == consts.NETWORK_INTERFACE_TYPES.bond
        interfaces = filter(is_ether, node_data['interfaces'])
        bond_interfaces = filter(is_bond, node_data['interfaces'])

        interfaces_db = node_db.nic_interfaces
        bond_interfaces_db = node_db.bond_interfaces
        for iface in interfaces:
            current_iface = filter(lambda i: i.id == iface['id'],
                                   interfaces_db)[0]
            # Remove all old network's assignment for this interface.
            db().query(NetworkNICAssignment).filter_by(
                interface_id=current_iface.id).delete()
            for net in iface['assigned_networks']:
                net_assignment = NetworkNICAssignment()
                net_assignment.network_id = net['id']
                net_assignment.interface_id = current_iface.id
                db().add(net_assignment)
            if 'interface_properties' in iface:
                current_iface.interface_properties = iface[
                    'interface_properties']
        map(db().delete, bond_interfaces_db)
        db().commit()

        for bond in bond_interfaces:
            bond_db = NodeBondInterface()
            bond_db.node_id = node_db.id
            db().add(bond_db)
            bond_db.name = bond['name']
            #bond_db.mode = bond['mode']
            bond_db.mac = bond.get('mac')
            #bond_db.flags = bond.get('flags', {})

            if bond.get('bond_properties', {}).get('mode'):
                bond_db.mode = bond['bond_properties']['mode']
            else:
                bond_db.mode = bond['mode']
            #bond_db.mode = consts.OVS_BOND_MODES[0]
            bond_db.bond_properties = bond.get('bond_properties', {})
            bond_db.interface_properties = bond.get('interface_properties', {})
            db().commit()
            db().refresh(bond_db)

            # Add new network assignment.
            map(bond_db.assigned_networks_list.append, [
                db().query(NetworkGroup).get(ng['id'])
                for ng in bond['assigned_networks']
            ])
            # Add new slaves.
            for nic in bond['slaves']:
                bond_db.slaves.append(db().query(NodeNICInterface).filter_by(
                    name=nic['name']).filter_by(node_id=node_db.id).first())
            db().commit()

        return node_db.id
Esempio n. 3
0
    def _update_attrs(cls, node_data):
        node_db = db().query(Node).get(node_data['id'])
        is_ether = lambda x: x['type'] == consts.NETWORK_INTERFACE_TYPES.ether
        is_bond = lambda x: x['type'] == consts.NETWORK_INTERFACE_TYPES.bond
        interfaces = filter(is_ether, node_data['interfaces'])
        bond_interfaces = filter(is_bond, node_data['interfaces'])

        interfaces_db = node_db.nic_interfaces
        bond_interfaces_db = node_db.bond_interfaces
        for iface in interfaces:
            current_iface = filter(
                lambda i: i.id == iface['id'],
                interfaces_db
            )[0]
            # Remove all old network's assignment for this interface.
            db().query(NetworkNICAssignment).filter_by(
                interface_id=current_iface.id
            ).delete()
            for net in iface['assigned_networks']:
                net_assignment = NetworkNICAssignment()
                net_assignment.network_id = net['id']
                net_assignment.interface_id = current_iface.id
                db().add(net_assignment)
        db().commit()
        # Remove bonds from DB if they are not in a received data.
        received_bond_ids = [x['id'] for x in bond_interfaces if 'id' in x]
        unused_bonds = filter(lambda x: x.id not in received_bond_ids,
                              bond_interfaces_db)
        map(db().delete, unused_bonds)
        db().commit()

        for bond in bond_interfaces:
            if 'id' in bond:
                bond_db = filter(
                    lambda i: i.id == bond['id'],
                    bond_interfaces_db
                )[0]
                # Clear all previous assigned networks.
                map(bond_db.assigned_networks_list.remove,
                    list(bond_db.assigned_networks_list))
                # Clear all previous assigned slaves.
                map(bond_db.slaves.remove, list(bond_db.slaves))
            else:
                # Create a bond if not exists.
                bond_db = NodeBondInterface()
                bond_db.node_id = node_db.id
                db().add(bond_db)
            bond_db.name = bond['name']
            if 'mode' in bond:
                bond_db.mode = bond['mode']
            bond_db.mac = bond.get('mac')
            bond_db.flags = bond.get('flags', {})
            db().commit()
            db().refresh(bond_db)

            # Add new network assignment.
            map(bond_db.assigned_networks_list.append,
                [db().query(NetworkGroup).get(ng['id']) for ng
                 in bond['assigned_networks']])
            # Add new slaves.
            for nic in bond['slaves']:
                bond_db.slaves.append(
                    db().query(NodeNICInterface).filter_by(
                        name=nic['name']
                    ).filter_by(
                        node_id=node_db.id
                    ).first()
                )
            db().commit()

        return node_db.id
Esempio n. 4
0
    def _update_attrs(cls, node_data):
        node_db = db().query(Node).get(node_data['id'])
        is_ether = lambda x: x['type'] == consts.NETWORK_INTERFACE_TYPES.ether
        is_bond = lambda x: x['type'] == consts.NETWORK_INTERFACE_TYPES.bond
        interfaces = filter(is_ether, node_data['interfaces'])
        bond_interfaces = filter(is_bond, node_data['interfaces'])

        interfaces_db = node_db.nic_interfaces
        bond_interfaces_db = node_db.bond_interfaces
        for iface in interfaces:
            current_iface = filter(lambda i: i.id == iface['id'],
                                   interfaces_db)[0]
            # Remove all old network's assignment for this interface.
            db().query(NetworkNICAssignment).filter_by(
                interface_id=current_iface.id).delete()
            for net in iface['assigned_networks']:
                net_assignment = NetworkNICAssignment()
                net_assignment.network_id = net['id']
                net_assignment.interface_id = current_iface.id
                db().add(net_assignment)
        db().commit()
        # Remove bonds from DB if they are not in a received data.
        received_bond_ids = [x['id'] for x in bond_interfaces if 'id' in x]
        unused_bonds = filter(lambda x: x.id not in received_bond_ids,
                              bond_interfaces_db)
        map(db().delete, unused_bonds)
        db().commit()

        for bond in bond_interfaces:
            if 'id' in bond:
                bond_db = filter(lambda i: i.id == bond['id'],
                                 bond_interfaces_db)[0]
                # Clear all previous assigned networks.
                map(bond_db.assigned_networks_list.remove,
                    list(bond_db.assigned_networks_list))
                # Clear all previous assigned slaves.
                map(bond_db.slaves.remove, list(bond_db.slaves))
            else:
                # Create a bond if not exists.
                bond_db = NodeBondInterface()
                bond_db.node_id = node_db.id
                db().add(bond_db)
            bond_db.name = bond['name']
            if 'mode' in bond:
                bond_db.mode = bond['mode']
            bond_db.mac = bond.get('mac')
            bond_db.flags = bond.get('flags', {})
            db().commit()
            db().refresh(bond_db)

            # Add new network assignment.
            map(bond_db.assigned_networks_list.append, [
                db().query(NetworkGroup).get(ng['id'])
                for ng in bond['assigned_networks']
            ])
            # Add new slaves.
            for nic in bond['slaves']:
                bond_db.slaves.append(db().query(NodeNICInterface).filter_by(
                    name=nic['name']).filter_by(node_id=node_db.id).first())
            db().commit()

        return node_db.id