def _audit_nfvi_subnets_callback(timer_id):
    """
    Audit Subnets
    """
    global _main_audit_inprogress
    global _deletable_subnets, _nfvi_subnets_paging

    response = (yield)
    DLOG.verbose("Audit-Subnets callback, response=%s." % response)
    if response['completed']:
        if response['page-request-id'] == _nfvi_subnets_paging.page_request_id:
            subnet_table = tables.tables_get_subnet_table()

            if _deletable_subnets is None:
                _deletable_subnets = subnet_table.keys()

            for nfvi_subnet in response['result-data']:
                subnet = subnet_table.get(nfvi_subnet.uuid, None)
                if subnet is None:
                    subnet = objects.Subnet(nfvi_subnet.uuid, nfvi_subnet.name,
                                            nfvi_subnet.ip_version,
                                            nfvi_subnet.subnet_ip,
                                            nfvi_subnet.subnet_prefix,
                                            nfvi_subnet.gateway_ip,
                                            nfvi_subnet.network_uuid,
                                            nfvi_subnet.is_dhcp_enabled)
                    subnet_table[nfvi_subnet.uuid] = subnet
                else:
                    subnet.is_dhcp_enabled = nfvi_subnet.is_dhcp_enabled
                    if nfvi_subnet.uuid in _deletable_subnets:
                        _deletable_subnets.remove(nfvi_subnet.uuid)

            if _nfvi_subnets_paging.done:
                for subnet_uuid in _deletable_subnets:
                    if subnet_uuid in subnet_table.keys():
                        del subnet_table[subnet_uuid]

                _deletable_subnets = subnet_table.keys()
                _nfvi_subnets_paging.first_page()
        else:
            DLOG.error("Audit-Subnets callback, page-request-id mismatch, "
                       "responses=%s, page-request-id=%s."
                       % (response, _nfvi_subnets_paging.page_request_id))
            subnet_table = tables.tables_get_subnet_table()
            _deletable_subnets = subnet_table.keys()
            _nfvi_subnets_paging.first_page()
    else:
        DLOG.error("Audit-Subnets callback, not completed, responses=%s."
                   % response)
        subnet_table = tables.tables_get_subnet_table()
        _deletable_subnets = subnet_table.keys()
        _nfvi_subnets_paging.first_page()

    _nfvi_subnets_paging.set_page_request_id()
    _main_audit_inprogress = False
    timers.timers_reschedule_timer(timer_id, 2)  # 2 seconds later
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()
Example #3
0
 def _subnet_delete_callback(self, network_uuid, subnet_uuid, subnet_name,
                             subnet_ip, subnet_prefix, callback):
     """
     Subnet Delete Callback
     """
     response = (yield)
     DLOG.verbose("Subnet-Delete callback response=%s." % response)
     if response['completed']:
         subnet_table = tables.tables_get_subnet_table()
         subnet = subnet_table.get(subnet_uuid, None)
         if subnet is not None:
             del subnet_table[subnet_uuid]
     callback(response['completed'], network_uuid, subnet_uuid, subnet_name,
              subnet_ip, subnet_prefix)
Example #4
0
    def _subnet_update_callback(self, network_uuid, subnet_uuid, subnet_name,
                                subnet_ip, subnet_prefix, callback):
        """
        Subnet Update Callback
        """
        response = (yield)
        DLOG.verbose("Subnet-Update callback response=%s." % response)
        if response['completed']:
            nfvi_subnet = response['result-data']
            subnet_table = tables.tables_get_subnet_table()
            subnet = subnet_table.get(nfvi_subnet.uuid, None)
            if subnet is not None:
                subnet.is_dhcp_enabled = nfvi_subnet.is_dhcp_enabled

        callback(response['completed'], network_uuid, subnet_uuid, subnet_name,
                 subnet_ip, subnet_prefix)
Example #5
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)
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]
Example #7
0
    def _subnet_create_callback(self, network_uuid, subnet_name, subnet_ip,
                                subnet_prefix, callback):
        """
        Subnet Create Callback
        """
        response = (yield)
        DLOG.verbose("Subnet-Create callback response=%s." % response)
        if response['completed']:
            nfvi_subnet = response['result-data']
            subnet_table = tables.tables_get_subnet_table()
            subnet = subnet_table.get(nfvi_subnet.uuid, None)
            if subnet is None:
                subnet = objects.Subnet(
                    nfvi_subnet.uuid, nfvi_subnet.name, nfvi_subnet.ip_version,
                    nfvi_subnet.subnet_ip, nfvi_subnet.subnet_prefix,
                    nfvi_subnet.gateway_ip, nfvi_subnet.network_uuid,
                    nfvi_subnet.is_dhcp_enabled)
                subnet_table[nfvi_subnet.uuid] = subnet
            else:
                subnet.is_dhcp_enabled = nfvi_subnet.is_dhcp_enabled

        callback(response['completed'], network_uuid, subnet_name, subnet_ip,
                 subnet_prefix)
def vim_network_api_get_subnet(connection, msg):
    """
    Handle Get-Subnet API request
    """
    DLOG.verbose("Get subnet, filter_by_uuid=%s." % msg.filter_by_uuid)

    subnet_table = tables.tables_get_subnet_table()
    response = rpc.APIResponseGetSubnet()
    subnet = subnet_table.get(msg.filter_by_uuid, None)
    if 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.is_dhcp_enabled = subnet.is_dhcp_enabled
    else:
        response.result = rpc.RPC_MSG_RESULT.NOT_FOUND
    connection.send(response.serialize())
    DLOG.verbose("Sent response=%s" % response)
    connection.close()
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()