Beispiel #1
0
    def ensure_legal_operation(self, nic, op_type, channel):
        # get the network attachments for <nic> from the database
        table = model.NetworkAttachment
        query = db.session.query(table).filter(table.nic_id == nic.id)

        if channel != 'vlan/native' and op_type == 'connect' and \
           query.filter(table.channel == 'vlan/native').count() == 0:
            # checks if it is trying to attach a trunked network, and then in
            # in the db see if nic does not have any networks attached natively
            raise BlockedError("Please attach a native network first")
        elif channel == 'vlan/native' and op_type == 'detach' and \
                query.filter(table.channel != 'vlan/native').count() > 0:
            # if it is detaching a network, then check in the database if there
            # are any trunked vlans.
            raise BlockedError("Please remove all trunked Vlans"
                               " before removing the native vlan")
        else:
            return
Beispiel #2
0
def check_native_networks(nic, op_type, channel):
    """Check to ensure that native network is the first one to be added
    and last one to be removed
    """
    table = model.NetworkAttachment
    query = db.session.query(table).filter(table.nic_id == nic.id)

    if channel != 'vlan/native' and op_type == 'connect' and \
       query.filter(table.channel == 'vlan/native').count() == 0:
        # checks if it is trying to attach a trunked network, and then in
        # in the db see if nic does not have any networks attached natively
        raise BlockedError("Please attach a native network first")
    elif channel == 'vlan/native' and op_type == 'detach' and \
            query.filter(table.channel != 'vlan/native').count() > 0:
        # if it is detaching a network, then check in the database if there
        # are any trunked vlans.
        raise BlockedError("Please remove all trunked Vlans"
                           " before removing the native vlan")
Beispiel #3
0
 def claim_network_id(self, net_id):
     vlan = Vlan.query.filter_by(vlan_no=net_id).first()
     if vlan is None:
         return
     elif vlan.available:
         vlan.available = False
     else:
         raise BlockedError("Network ID is not available."
                            " Please choose a different ID.")