Search in sources :

Example 1 with Networks

use of com.woorea.openstack.quantum.model.Networks in project so by onap.

the class MsoNeutronUtils method findNetworkByName.

/*
     * Find a network (or query its existence) by its Name. This method avoids an initial lookup by ID when it's known
     * that we have the network Name.
     *
     * Neutron does not support 'name=*' query parameter for Network query (show). The only way to query by name is to
     * retrieve all networks and look for the match. While inefficient, this capability will be provided as it is needed
     * by MSO, but should be avoided in favor of ID whenever possible.
     *
     * TODO: Network names are not required to be unique, though MSO will attempt to enforce uniqueness. This call
     * probably needs to return an error (instead of returning the first match).
     *
     * @param neutronClient an authenticated Quantum object
     * 
     * @param networkName the network name to query
     * 
     * @return a Network object or null if not found
     */
public Network findNetworkByName(Quantum neutronClient, String networkName) {
    if (networkName == null) {
        return null;
    }
    try {
        OpenStackRequest<Networks> request = neutronClient.networks().list();
        Networks networks = executeAndRecordOpenstackRequest(request);
        for (Network network : networks.getList()) {
            if (network.getName().equals(networkName)) {
                logger.debug("Found match on network name: {}", networkName);
                return network;
            }
        }
        logger.debug("findNetworkByName - no match found for {}", networkName);
        return null;
    } catch (OpenStackResponseException e) {
        if (e.getStatus() == 404) {
            return null;
        } else {
            logger.error("{} {} Openstack Error, GET Network By Name ({}): ", MessageEnum.RA_CONNECTION_EXCEPTION, ErrorCode.DataError.getValue(), networkName, e);
            throw e;
        }
    }
}
Also used : Networks(com.woorea.openstack.quantum.model.Networks) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) Network(com.woorea.openstack.quantum.model.Network)

Example 2 with Networks

use of com.woorea.openstack.quantum.model.Networks in project so by onap.

the class NeutronClientImpl method queryNetworks.

/**
 * Query Networks
 *
 * @param cloudSiteId the cloud site id
 * @param tenantId the tenant id
 * @param limit limits the number of records returned
 * @param marker the last viewed record
 * @param name of the newtork
 * @param id of the network
 * @return the list of networks in openstack
 * @throws MsoCloudSiteNotFound the mso cloud site not found
 * @throws NeutronClientException if the client cannot be built this is thrown
 */
public Networks queryNetworks(String cloudSiteId, String tenantId, int limit, String marker, String name, String id) throws MsoCloudSiteNotFound, NeutronClientException {
    try {
        String encodedName = null;
        if (name != null) {
            try {
                encodedName = URLEncoder.encode(name, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                logger.error("error encoding query parameter: {}", encodedName);
            }
        }
        Quantum neutronClient = getNeutronClient(cloudSiteId, tenantId);
        OpenStackRequest<Networks> request = neutronClient.networks().list().queryParam("id", id).queryParam("limit", limit).queryParam("marker", marker).queryParam("name", encodedName);
        return executeAndRecordOpenstackRequest(request, false);
    } catch (MsoException e) {
        logger.error("Error building Neutron Client", e);
        throw new NeutronClientException("Error building Neutron Client", e);
    }
}
Also used : Quantum(com.woorea.openstack.quantum.Quantum) Networks(com.woorea.openstack.quantum.model.Networks) MsoException(org.onap.so.openstack.exceptions.MsoException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Networks (com.woorea.openstack.quantum.model.Networks)2 OpenStackResponseException (com.woorea.openstack.base.client.OpenStackResponseException)1 Quantum (com.woorea.openstack.quantum.Quantum)1 Network (com.woorea.openstack.quantum.model.Network)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MsoException (org.onap.so.openstack.exceptions.MsoException)1