jclouds-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Raj <...@apache.org>
Subject Re: [Neutron API] What is the efficient way to get the port by its fixed IP?
Date Mon, 17 Nov 2014 03:13:54 GMT
Or we can do the same with predicates;

    private Iterable<Port> getPortByFixedIP(final String fixedIP) {
        Iterable<Port> port =
Iterables.filter(portApi.list().concat().toList(),
                new Predicate<Port>() {
            @Override
            public boolean apply(Port input) {
                for (IP ip : input.getFixedIps()) {
                    if (ip.getIpAddress()!= null
                            && ip.getIpAddress().equals(fixedIP)){
                        return true;
                    }
                }
                return false;
            }
        });
        return port;
    }

This will return the list of ports which is associated with the given fixed
IP right?

Am I correct?

Thanks.

On Sun, Nov 16, 2014 at 2:00 PM, Raj <raj@apache.org> wrote:

> Hi,
>
> If I know the fixed IP, what is efficient way of getting the port which is
> associated with this IP, using neutron api?
>
> Currently I am doing like below, but it is not efficient.
>
>    - List all the ports using port API
>    - go through each port and get all fixed IPs
>    - go through each fixed IP and check whether it is equal to my fixed
>    IP.
>
>           List<Port> ports = api.list().concat().toList();
>           for (Iterator<Port> iterator = ports.iterator();
> iterator.hasNext();) {
>                 Port port = (Port) iterator.next();
>                 for (IP ip : port.getFixedIps()) {
>                     if (ip.getIpAddress().equals(myFixedIP)) {
>                         // so this "port" is what I am searching
>                     }
>                 }
>           }
>
> Is there any efficient way to do this?
>
> Thanks.
>
> --
> Rajkumar Rajaratnam
> Committer & PMC Member, Apache Stratos
> Software Engineer, WSO2
>



-- 
Rajkumar Rajaratnam
Committer & PMC Member, Apache Stratos
Software Engineer, WSO2

Mime
View raw message