예제 #1
0
def _safe_get_network_interface(interface_uuid):
    ni = db.get_interface(interface_uuid)
    if not ni:
        return None, None, error(404, 'interface not found')

    n = net.from_db(ni['network_uuid'])
    if not n:
        logutil.info([
            net.ThinNetwork(ni['network_uuid']),
            net.ThinNetworkInterface(ni['uuid'])
        ], 'Network not found or deleted')
        return None, None, error(404, 'interface network not found')

    if get_jwt_identity() not in [n.namespace, 'system']:
        logutil.info([n, net.ThinNetworkInterface(ni['uuid'])],
                     'Interface not found, ownership test')
        return None, None, error(404, 'interface not found')

    i = virt.from_db(ni['instance_uuid'])
    if get_jwt_identity() not in [i.db_entry['namespace'], 'system']:
        logutil.info([n, i, net.ThinNetworkInterface(ni['uuid'])],
                     'Instance not found, ownership test')
        return None, None, error(404, 'interface not found')

    return ni, n, None
예제 #2
0
    def post(self, interface_uuid=None):
        ni = db.get_interface(interface_uuid)
        if not ni:
            return error(404, 'network interface not found')

        if not ni['floating']:
            return error(409, 'this interface does not have a floating ip')

        n = net.from_db(ni['network_uuid'])
        if not n:
            LOG.info('network(%s): network not found, genuinely missing' %
                     ni['network_uuid'])
            return error(404, 'network not found')

        if get_jwt_identity() not in [n.namespace, 'system']:
            LOG.info('%s: network not found, ownership test' % n)
            return error(404, 'network not found')

        i = virt.from_db(ni['instance_uuid'])
        if get_jwt_identity() not in [i.db_entry['namespace'], 'system']:
            LOG.info('%s: instance not found, ownership test' % i)
            return error(404, 'instance not found')

        float_net = net.from_db('floating')
        if not float_net:
            return error(404, 'floating network not found')

        db.add_event('interface', interface_uuid, 'api', 'defloat', None, None)
        with db.get_lock('sf/ipmanager/floating', ttl=120) as _:
            ipm = db.get_ipmanager('floating')
            ipm.release(ni['floating'])
            db.persist_ipmanager('floating', ipm.save())

        db.remove_floating_from_interface(ni['uuid'])
        n.remove_floating_ip(ni['floating'], ni['ipv4'])
예제 #3
0
    def get(self, interface_uuid=None):
        ni = db.get_interface(interface_uuid)
        if not ni:
            return error(404, 'interface not found')

        n = net.from_db(ni['network_uuid'])
        if not n:
            LOG.info('network(%s): network not found, genuinely missing' %
                     ni['network_uuid'])
            return error(404, 'interface network not found')

        if get_jwt_identity() not in [n.namespace, 'system']:
            LOG.info('%s: interface not found, ownership test' % n)
            return error(404, 'interface not found')

        i = virt.from_db(ni['instance_uuid'])
        if get_jwt_identity() not in [i.db_entry['namespace'], 'system']:
            LOG.info('%s: instance not found, ownership test' % i)
            return error(404, 'interface not found')

        return ni
예제 #4
0
    def post(self, interface_uuid=None):
        db.add_event('interface', interface_uuid,
                     'API DEFLOAT', None, None, None)
        ni = db.get_interface(interface_uuid)
        if not ni:
            return error(404, 'network interface not found')

        if not ni['floating']:
            return error(409, 'this interface does not have a floating ip')

        n = net.from_db(ni['network_uuid'])
        if not n:
            return error(404, 'network not found')

        float_net = net.from_db('floating')
        if not float_net:
            return error(404, 'floating network not found')

        float_net.ipmanager.release(ni['floating'])
        float_net.persist_ipmanager()
        db.remove_floating_from_interface(ni['uuid'])
        n.remove_floating_ip(ni['floating'], ni['ipv4'])
예제 #5
0
    def post(self, interface_uuid=None):
        db.add_event('interface', interface_uuid,
                     'API FLOAT', None, None, None)
        ni = db.get_interface(interface_uuid)
        if not ni:
            return error(404, 'network interface not found')

        if ni['floating']:
            return error(409, 'this interface already has a floating ip')

        n = net.from_db(ni['network_uuid'])
        if not n:
            return error(404, 'network not found')

        float_net = net.from_db('floating')
        if not float_net:
            return error(404, 'floating network not found')

        addr = float_net.ipmanager.get_random_free_address()
        float_net.persist_ipmanager()
        db.add_floating_to_interface(ni['uuid'], addr)
        n.add_floating_ip(addr, ni['ipv4'])