You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jclouds.apache.org by Raj <ra...@apache.org> on 2014/11/16 09:30:55 UTC
[Neutron API] What is the efficient way to get the port by its fixed IP?
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
Re: [Neutron API] What is the efficient way to get the port by its
fixed IP?
Posted by Raj <ra...@apache.org>.
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 <ra...@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