org.openstack4j.openstack.networking.internal.FloatingIPServiceImpl Maven / Gradle / Ivy
package org.openstack4j.openstack.networking.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import java.util.Map;
import org.openstack4j.api.networking.NetFloatingIPService;
import org.openstack4j.core.transport.ExecutionOptions;
import org.openstack4j.core.transport.propagation.PropagateOnStatus;
import org.openstack4j.model.common.ActionResponse;
import org.openstack4j.model.network.NetFloatingIP;
import org.openstack4j.openstack.networking.domain.NeutronFloatingIP;
import org.openstack4j.openstack.networking.domain.NeutronFloatingIP.FloatingIPs;
/**
* FloatingIPService implementation that provides Neutron Floating-IP based Service Operations.
*
* @author Nathan Anderson
*/
public class FloatingIPServiceImpl extends BaseNetworkingServices implements NetFloatingIPService {
/**
* {@inheritDoc}
*/
@Override
public List extends NetFloatingIP> list() {
return get(FloatingIPs.class, uri("/floatingips")).execute().getList();
}
/**
* {@inheritDoc}
*/
@Override
public List extends NetFloatingIP> list(Map filteringParams) {
Invocation fIPsInvocation = get(FloatingIPs.class, "/floatingips");
if (filteringParams != null) {
for (Map.Entry entry : filteringParams.entrySet()) {
fIPsInvocation = fIPsInvocation.param(entry.getKey(), entry.getValue());
}
}
return fIPsInvocation.execute().getList();
}
/**
* {@inheritDoc}
*/
@Override
public NetFloatingIP get(String id) {
checkNotNull(id);
return get(NeutronFloatingIP.class, uri("/floatingips/%s", id)).execute();
}
/**
* {@inheritDoc}
*/
@Override
public ActionResponse delete(String id) {
checkNotNull(id);
return deleteWithResponse(uri("/floatingips/%s", id)).execute();
}
/**
* {@inheritDoc}
*/
@Override
public NetFloatingIP create(NetFloatingIP floatingIp) {
checkNotNull(floatingIp);
checkNotNull(floatingIp.getFloatingNetworkId());
return post(NeutronFloatingIP.class, uri("/floatingips")).entity(floatingIp).execute();
}
/**
* {@inheritDoc}
*/
@Override
public NetFloatingIP associateToPort(String id, String portId) {
checkNotNull(id);
checkNotNull(portId);
String inner = String.format("{ \"port_id\":\"%s\" }", portId);
String json = String.format("{ \"%s\": %s }", "floatingip", inner);
return put(NeutronFloatingIP.class, uri("/floatingips/%s",id)).json(json)
.execute(ExecutionOptions.create(PropagateOnStatus.on(404)));
}
/**
* {@inheritDoc}
*/
@Override
public NetFloatingIP disassociateFromPort(String id) {
checkNotNull(id);
String json = String.format("{ \"%s\": %s }", "floatingip", "{ \"port_id\":null }");
return put(NeutronFloatingIP.class, uri("/floatingips/%s",id)).json(json)
.execute(ExecutionOptions.create(PropagateOnStatus.on(404)));
}
}