コード例 #1
0
    def _network_update_callback(self, network_uuid, callback):
        """
        Network Update Callback
        """
        response = (yield)
        DLOG.verbose("Network-Update callback response=%s." % response)
        if response['completed']:
            network_table = tables.tables_get_network_table()
            nfvi_network = response['result-data']
            network = network_table.get(nfvi_network.uuid, None)
            if network is None:
                network = objects.Network(
                    nfvi_network.uuid, nfvi_network.name,
                    nfvi_network.admin_state, nfvi_network.oper_state,
                    nfvi_network.avail_status, nfvi_network.is_shared,
                    nfvi_network.mtu, nfvi_network.provider_data)
                network_table[nfvi_network.uuid] = network
            else:
                network.admin_state = nfvi_network.admin_state
                network.oper_state = nfvi_network.oper_state
                network.avail_status = nfvi_network.avail_status
                network.is_shared = nfvi_network.is_shared
                network.provider_data = nfvi_network.provider_data

        callback(response['completed'], network_uuid)
コード例 #2
0
def vim_network_api_delete_network(connection, msg):
    """
    Handle Delete-Network API request
    """
    global _network_delete_operations

    network_table = tables.tables_get_network_table()

    if msg.by_uuid is not None:
        DLOG.verbose("Delete network, by_uuid=%s." % msg.by_uuid)
        network = network_table.get(msg.by_uuid, None)
    else:
        DLOG.verbose("Delete network, by_name=%s." % msg.by_name)
        network = network_table.get_by_name(msg.by_name)

    if network is not None:
        _network_delete_operations[network.uuid] = connection
        network_director = directors.get_network_director()
        network_director.network_delete(network.uuid, _delete_network_callback)
    else:
        response = rpc.APIResponseDeleteNetwork()
        response.result = rpc.RPC_MSG_RESULT.NOT_FOUND
        connection.send(response.serialize())
        DLOG.verbose("Sent response=%s" % response)
        connection.close()
コード例 #3
0
def vim_network_api_get_network(connection, msg):
    """
    Handle Get-Network API request
    """
    if msg.filter_by_uuid is not None:
        DLOG.verbose("Get network, filter_by_uuid=%s." % msg.filter_by_uuid)
    else:
        DLOG.verbose("Get network, filter_by_name=%s." % msg.filter_by_name)

    response = rpc.APIResponseGetNetwork()
    network_table = tables.tables_get_network_table()
    if msg.filter_by_uuid is not None:
        network = network_table.get(msg.filter_by_uuid, None)
    else:
        network = network_table.get_by_name(msg.filter_by_name)
    if network is not None:
        response.uuid = network.uuid
        response.name = network.name
        response.admin_state = network.admin_state
        response.oper_state = network.oper_state
        response.avail_status = network.avail_status
        response.is_shared = network.is_shared
        response.mtu = network.mtu
        response.network_type = network.provider_data.network_type
        response.segmentation_id = network.provider_data.segmentation_id
        response.physical_network = network.provider_data.physical_network
    else:
        response.result = rpc.RPC_MSG_RESULT.NOT_FOUND
    connection.send(response.serialize())
    DLOG.verbose("Sent response=%s" % response)
    connection.close()
コード例 #4
0
def _update_network_callback(success, network_uuid):
    """
    Handle Update-Network callback
    """
    DLOG.verbose("Update network callback, uuid=%s." % network_uuid)

    connection = _network_update_operations.get(network_uuid, None)
    if connection is not None:
        response = rpc.APIResponseUpdateNetwork()
        if success:
            network_table = tables.tables_get_network_table()
            network = network_table.get(network_uuid)
            if network is not None:
                response.uuid = network.uuid
                response.name = network.name
                response.admin_state = network.admin_state
                response.oper_state = network.oper_state
                response.avail_status = network.avail_status
                response.network_type = network.provider_data.network_type
                response.segmentation_id \
                    = network.provider_data.segmentation_id
                response.mtu = network.mtu
                response.physical_network \
                    = network.provider_data.physical_network
                response.is_shared = network.is_shared
            else:
                response.result = rpc.RPC_MSG_RESULT.NOT_FOUND
        else:
            response.result = rpc.RPC_MSG_RESULT.FAILED

        connection.send(response.serialize())
        connection.close()
        DLOG.verbose("Sent response=%s" % response)
        del _network_update_operations[network_uuid]
コード例 #5
0
def vim_network_api_get_subnets(connection, msg):
    """
    Handle Get-Subnets API request
    """
    subnet_table = tables.tables_get_subnet_table()
    if msg.filter_by_network_uuid is not None:
        DLOG.verbose("Get subnet, all=%s, filter_by_network_uuid=%s." %
                     (msg.get_all, msg.filter_by_network_uuid))
        subnets = subnet_table.on_network(msg.filter_by_network_uuid)
    else:
        DLOG.verbose("Get subnet, all=%s, filter_by_network_name=%s." %
                     (msg.get_all, msg.filter_by_network_name))
        network_table = tables.tables_get_network_table()
        network = network_table.get_by_name(msg.filter_by_network_name)
        if network is not None:
            subnets = subnet_table.on_network(network.uuid)
        else:
            subnets = list()

    for subnet in subnets:
        response = rpc.APIResponseGetSubnet()
        response.uuid = subnet.uuid
        response.name = subnet.name
        response.ip_version = subnet.ip_version
        response.subnet_ip = subnet.subnet_ip
        response.subnet_prefix = subnet.subnet_prefix
        response.gateway_ip = subnet.gateway_ip
        response.network_uuid = subnet.network_uuid
        response.is_dhcp_enabled = subnet.is_dhcp_enabled
        connection.send(response.serialize())
        DLOG.verbose("Sent response=%s" % response)
    connection.close()
コード例 #6
0
def _delete_subnet_callback(success, network_uuid, subnet_uuid, subnet_name,
                            subnet_ip, subnet_prefix):
    """
    Handle Delete-Subnet callback
    """
    DLOG.verbose("Delete subnet callback, network_uuid=%s, name=%s, ip=%s, "
                 "prefix=%s." %
                 (network_uuid, subnet_name, subnet_ip, subnet_prefix))

    op_index = "%s.%s.%s" % (network_uuid, subnet_ip, subnet_prefix)
    connection = _subnet_delete_operations.get(op_index, None)
    if connection is not None:
        response = rpc.APIResponseDeleteSubnet()
        if success:
            network_table = tables.tables_get_network_table()
            network = network_table.get(network_uuid)
            response.network_name = network.name
            response.subnet_ip = subnet_ip
            response.subnet_prefix = subnet_prefix
        else:
            response.result = rpc.RPC_MSG_RESULT.FAILED

        connection.send(response.serialize())
        connection.close()
        DLOG.verbose("Sent response=%s" % response)
        del _subnet_delete_operations[op_index]
コード例 #7
0
 def _network_delete_callback(self, network_uuid, callback):
     """
     Network Delete Callback
     """
     response = (yield)
     DLOG.verbose("Network-Delete callback response=%s." % response)
     if response['completed']:
         network_table = tables.tables_get_network_table()
         network = network_table.get(network_uuid, None)
         if network is not None:
             subnet_uuids_to_delete = list()
             subnet_table = tables.tables_get_subnet_table()
             for subnet in subnet_table.on_network(network_uuid):
                 subnet_uuids_to_delete.append(subnet.uuid)
             for subnet_uuid in subnet_uuids_to_delete:
                 del subnet_table[subnet_uuid]
             del network_table[network_uuid]
     callback(response['completed'], network_uuid)
コード例 #8
0
def vim_network_api_get_networks(connection, msg):
    """
    Handle Get-Networks API request
    """
    DLOG.verbose("Get network, all=%s." % msg.get_all)
    network_table = tables.tables_get_network_table()
    for network in network_table.itervalues():
        response = rpc.APIResponseGetNetwork()
        response.uuid = network.uuid
        response.name = network.name
        response.admin_state = network.admin_state
        response.oper_state = network.oper_state
        response.avail_status = network.avail_status
        response.is_shared = network.is_shared
        response.mtu = network.mtu
        response.network_type = network.provider_data.network_type
        response.segmentation_id = network.provider_data.segmentation_id
        response.physical_network = network.provider_data.physical_network
        connection.send(response.serialize())
        DLOG.verbose("Sent response=%s" % response)
    connection.close()
コード例 #9
0
def _create_subnet_callback(success, network_uuid, subnet_name, subnet_ip,
                            subnet_prefix):
    """
    Handle Create-Subnet callback
    """
    DLOG.verbose("Create subnet callback, network_uuid=%s, name=%s, ip=%s, "
                 "prefix=%s." %
                 (network_uuid, subnet_name, subnet_ip, subnet_prefix))

    op_index = "%s.%s.%s" % (network_uuid, subnet_ip, subnet_prefix)
    connection = _subnet_create_operations.get(op_index, None)
    if connection is not None:
        response = rpc.APIResponseCreateSubnet()
        if success:
            network_table = tables.tables_get_network_table()
            network = network_table.get(network_uuid)
            subnet_table = tables.tables_get_subnet_table()
            subnet = subnet_table.get_by_network_and_ip(
                network_uuid, subnet_ip, subnet_prefix)
            if network is not None and subnet is not None:
                response.uuid = subnet.uuid
                response.name = subnet.name
                response.ip_version = subnet.ip_version
                response.subnet_ip = subnet.subnet_ip
                response.subnet_prefix = subnet.subnet_prefix
                response.gateway_ip = subnet.gateway_ip
                response.network_uuid = subnet.network_uuid
                response.network_name = network.name
                response.is_dhcp_enabled = subnet.is_dhcp_enabled
            else:
                response.result = rpc.RPC_MSG_RESULT.NOT_FOUND
        else:
            response.result = rpc.RPC_MSG_RESULT.FAILED

        connection.send(response.serialize())
        connection.close()
        DLOG.verbose("Sent response=%s" % response)
        del _subnet_create_operations[op_index]
コード例 #10
0
def vim_network_api_create_network(connection, msg):
    """
    Handle Create-Network API request
    """
    global _network_create_operations

    DLOG.verbose("Create network, name=%s." % msg.name)

    network_table = tables.tables_get_network_table()
    network = network_table.get_by_name(msg.name)
    if network is None:
        _network_create_operations[msg.name] = connection
        network_director = directors.get_network_director()
        network_director.network_create(msg.name, msg.network_type,
                                        msg.segmentation_id,
                                        msg.physical_network, msg.is_shared,
                                        _create_network_callback)
    else:
        response = rpc.APIResponseCreateNetwork()
        response.result = rpc.RPC_MSG_RESULT.CONFLICT
        connection.send(response.serialize())
        DLOG.verbose("Sent response=%s" % response)
        connection.close()
コード例 #11
0
def vim_network_api_create_subnet(connection, msg):
    """
    Handle Create-Subnet API request
    """
    global _subnet_create_operations

    DLOG.verbose("Create subnet, ip=%s, prefix=%s for network %s." %
                 (msg.subnet_ip, msg.subnet_prefix, msg.network_name))
    network_table = tables.tables_get_network_table()
    network = network_table.get_by_name(msg.network_name)
    if network is not None:
        subnet_table = tables.tables_get_subnet_table()
        subnet = subnet_table.get_by_network_and_ip(network.uuid,
                                                    msg.subnet_ip,
                                                    msg.subnet_prefix)
        if subnet is None:
            op_index = "%s.%s.%s" % (network.uuid, msg.subnet_ip,
                                     msg.subnet_prefix)
            _subnet_create_operations[op_index] = connection
            network_director = directors.get_network_director()
            network_director.subnet_create(network.uuid, None, msg.ip_version,
                                           msg.subnet_ip, msg.subnet_prefix,
                                           msg.gateway_ip, msg.is_dhcp_enabled,
                                           _create_subnet_callback)
        else:
            response = rpc.APIResponseCreateNetwork()
            response.result = rpc.RPC_MSG_RESULT.CONFLICT
            connection.send(response.serialize())
            DLOG.verbose("Sent response=%s" % response)
            connection.close()
    else:
        response = rpc.APIResponseCreateSubnet()
        response.result = rpc.RPC_MSG_RESULT.NOT_FOUND
        connection.send(response.serialize())
        DLOG.verbose("Sent response=%s" % response)
        connection.close()
コード例 #12
0
def _audit_nfvi_networks_callback(timer_id):
    """
    Audit Networks
    """
    global _main_audit_inprogress
    global _deletable_networks, _nfvi_networks_paging

    response = (yield)
    DLOG.verbose("Audit-Networks callback, response=%s." % response)

    if response['completed']:
        if response[
                'page-request-id'] == _nfvi_networks_paging.page_request_id:
            network_table = tables.tables_get_network_table()

            if _deletable_networks is None:
                _deletable_networks = list(network_table)

            for nfvi_network in response['result-data']:
                network = network_table.get(nfvi_network.uuid, None)
                if network is None:
                    network = objects.Network(
                        nfvi_network.uuid, nfvi_network.name,
                        nfvi_network.admin_state, nfvi_network.oper_state,
                        nfvi_network.avail_status, nfvi_network.is_shared,
                        nfvi_network.mtu, nfvi_network.provider_data)
                    network_table[nfvi_network.uuid] = network
                else:
                    network.admin_state = nfvi_network.admin_state
                    network.oper_state = nfvi_network.oper_state
                    network.avail_status = nfvi_network.avail_status
                    network.is_shared = nfvi_network.is_shared
                    network.provider_data = nfvi_network.provider_data

                    if nfvi_network.uuid in _deletable_networks:
                        _deletable_networks.remove(nfvi_network.uuid)

            if _nfvi_networks_paging.done:
                for network_uuid in _deletable_networks:
                    if network_uuid in list(network_table):
                        del network_table[network_uuid]

                _deletable_networks = list(network_table)
                _nfvi_networks_paging.first_page()
        else:
            DLOG.error("Audit-Networks callback, page-request-id mismatch, "
                       "responses=%s, page-request-id=%s." %
                       (response, _nfvi_networks_paging.page_request_id))
            network_table = tables.tables_get_network_table()
            _deletable_networks = list(network_table)
            _nfvi_networks_paging.first_page()
    else:
        DLOG.error("Audit-Networks callback, not completed, responses=%s." %
                   response)
        network_table = tables.tables_get_network_table()
        _deletable_networks = list(network_table)
        _nfvi_networks_paging.first_page()

    _nfvi_networks_paging.set_page_request_id()
    _main_audit_inprogress = False
    timers.timers_reschedule_timer(timer_id, 20)  # 20 seconds later