Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add baseListOptions #1323

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ notifications:
install: /bin/true

# When run on JDK7, modules that require JDK8 needs to be skipped
script: mvn clean verify -B $SKIP_JDK8_MODULES
#script: mvn clean verify -B $SKIP_JDK8_MODULES

after_success:
- "[[ $DEPLOY == 1 && $TRAVIS_BRANCH == \"master\" ]] && { mvn deploy --settings distribution/settings.xml -DskipTests=true -B; };"
Expand All @@ -36,3 +36,4 @@ after_success:
# infrastructure. This should prevent the buffer overflow from
# https://github.com/travis-ci/travis-ci/issues/5227
sudo: false
dist: trusty
4 changes: 3 additions & 1 deletion core-test/src/main/resources/network/network.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
],
"shared": false,
"port_security_enabled": true,
"id": "4e8e5957-649f-477b-9e5b-f1f75b21c03c"
"id": "4e8e5957-649f-477b-9e5b-f1f75b21c03c",
"updated_at": "2020-10-19T10:30:34Z",
"created_at": "2020-10-19T10:30:34Z"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.openstack4j.model.common.ActionResponse;
import org.openstack4j.model.network.Network;
import org.openstack4j.model.network.NetworkUpdate;
import org.openstack4j.model.network.options.NetworkListOptions;

/**
* OpenStack (Neutron) Network based Operations
Expand All @@ -24,8 +25,15 @@ public interface NetworkService extends RestService {
* @return List of Network
*/
List<? extends Network> list(Map<String, String> filteringParams);


/**
* Lists the networks to which the current authorized tenant has access
*
* @author bboyHan (bboyhan@yeah.net)
* @param options setting filter parameters
* @return List of Network
*/
List<? extends Network> list(NetworkListOptions options);
/**
* Lists the networks to which the current authorized tenant has access
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.openstack4j.common.RestService;
import org.openstack4j.model.common.ActionResponse;
import org.openstack4j.model.network.Subnet;
import org.openstack4j.model.network.options.SubnetListOptions;

/**
* OpenStack (Neutron) Subnet based Operations
Expand All @@ -20,6 +21,15 @@ public interface SubnetService extends RestService {
*/
List<? extends Subnet> list();

/**
* List the Subnet(s) which are authorized by the current Tenant
*
* @author bboyHan (bboyHan@yeah.net)
* @param options filter parameters
* @return the list of subnets or empty
*/
List<? extends Subnet> list(SubnetListOptions options);

/**
* Gets a Subnet by ID
*
Expand Down
24 changes: 24 additions & 0 deletions core/src/main/java/org/openstack4j/model/TimeEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.openstack4j.model;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
* created_at/updated_at time field
*
* @author bboyHan
*/
public class TimeEntity {

@JsonProperty("created_at")
protected String createdTime;
@JsonProperty("updated_at")
protected String updatedTime;

public String getUpdatedTime() {
return updatedTime;
}

public String getCreatedTime() {
return createdTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* The type of Network
*
*
* @author Jeremy Unruh
*/
public enum NetworkType {
Expand All @@ -16,7 +16,7 @@ public enum NetworkType {
VXLAN,
GRE
;

@JsonCreator
public static NetworkType forValue(String value) {
if (value != null)
Expand All @@ -28,10 +28,10 @@ public static NetworkType forValue(String value) {
}
return null;
}

@JsonValue
public String toJson() {
public String getNetworkType() {
return name().toLowerCase();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.openstack4j.model.network.options;

import com.google.common.collect.Maps;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* @author bboyHan
*/
public class BaseListOptions<T> {

protected Map<String, List<Object>> queryParams = Maps.newHashMap();

protected void putParams(String key, Object value) {
checkNotNull(key);

if (value != null) {
List<Object> list;
if (queryParams.containsKey(key)) {
list = queryParams.get(key);
} else {
list = new ArrayList<>();
}
list.add(value);
queryParams.put(key, list);
}
}

public Map<String, List<Object>> getOptions() {
return queryParams;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.openstack4j.model.network.options;

import org.openstack4j.model.network.NetworkType;

/**
* @author bboyHan
*/
public class NetworkListOptions extends BaseListOptions<NetworkListOptions> {

private NetworkListOptions() {
}

public NetworkListOptions name(String name) {
return add("name", name);
}

public NetworkListOptions projectId(String projectId) {
return add("project_id", projectId);
}

public NetworkListOptions tenantId(String tenantId) {
return add("tenant_id", tenantId);
}

public NetworkListOptions networkType(NetworkType networkType) {
return add("provider:network_type", networkType.getNetworkType());
}

public NetworkListOptions description(String description) {
return add("description", description);
}

public NetworkListOptions shared(boolean shared) {
return add("shared", shared);
}

/**
* port status - ACTIVE, DOWN, BUILD and ERROR
*
* @param status - ACTIVE, DOWN, BUILD and ERROR
* @return options
*/
public NetworkListOptions status(String status) {
return add("status", status);
}

public static NetworkListOptions create() {
return new NetworkListOptions();
}

public NetworkListOptions add(String key, Object value) {
putParams(key, value);
return this;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author Jeremy Unruh
*
*/
public class PortListOptions {
public class PortListOptions extends BaseListOptions<PortListOptions> {

private Map<String,String> queryParams = Maps.newHashMap();

Expand Down Expand Up @@ -102,14 +102,31 @@ public PortListOptions tenantId(String tenantId) {
public PortListOptions macAddress(String macAddress) {
return add("mac_address", macAddress);
}

private PortListOptions add(String param, String value) {
if (value != null)
this.queryParams.put(param, value);
return this;

/**
* port status - ACTIVE, DOWN, BUILD and ERROR
*
* @param status - ACTIVE, DOWN, BUILD and ERROR
* @return options
*/
public PortListOptions status(String status) {
return add("status", status);
}

public Map<String, String> getOptions() {
return queryParams;

public PortListOptions fixedIpWithSub(String subnetId) {
return add("fixed_ips", "subnet_id=" + subnetId);
}

public PortListOptions fixedIpWithIp(String ipAddr) {
return add("fixed_ips", "ip_address=" + ipAddr);
}

public PortListOptions fixedIpWithIpPre(String ipAddr) {
return add("fixed_ips", "ip_address_substr=" + ipAddr);
}

public PortListOptions add(String key, String value) {
putParams(key, value);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.openstack4j.model.network.options;

/**
* @author bboyHan
*/
public class SubnetListOptions extends BaseListOptions<SubnetListOptions> {

private SubnetListOptions() {
}

public SubnetListOptions name(String name) {
return add("name", name);
}

public SubnetListOptions projectId(String projectId) {
return add("project_id", projectId);
}

/**
* port status - ACTIVE, DOWN, BUILD and ERROR
*
* @param status - ACTIVE, DOWN, BUILD and ERROR
* @return options
*/
public SubnetListOptions status(String status) {
return add("status", status);
}

public SubnetListOptions ipVersion(int ipVersion) {
return add("ip_version", ipVersion);
}

public SubnetListOptions enableDHCP(boolean enableDHCP) {
return add("enable_dhcp", enableDHCP);
}

public SubnetListOptions gatewayIp(boolean gatewayIp) {
return add("gateway_ip", gatewayIp);
}

public SubnetListOptions cidr(boolean cidr) {
return add("cidr", cidr);
}

public SubnetListOptions segmentId(boolean segmentId) {
return add("segment_id", segmentId);
}

public SubnetListOptions shared(boolean shared) {
return add("shared", shared);
}

public static SubnetListOptions create() {
return new SubnetListOptions();
}

public SubnetListOptions add(String key, Object value) {
putParams(key, value);
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import org.openstack4j.api.Apis;
import org.openstack4j.model.TimeEntity;
import org.openstack4j.model.network.Network;
import org.openstack4j.model.network.NetworkType;
import org.openstack4j.model.network.State;
Expand All @@ -24,7 +25,7 @@
* @author Jeremy Unruh
*/
@JsonRootName("network")
public class NeutronNetwork implements Network {
public class NeutronNetwork extends TimeEntity implements Network {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -118,7 +119,7 @@ public List<String> getSubnets() {
public List<? extends Subnet> getNeutronSubnets() {
if ( neutronSubnets == null && (subnets != null && subnets.size() > 0))
{
neutronSubnets = new ArrayList<NeutronSubnet>();
neutronSubnets = new ArrayList<>();
for ( String subnetId : subnets) {
NeutronSubnet sub = (NeutronSubnet)Apis.getNetworkingServices().subnet().get(subnetId);
neutronSubnets.add(sub);
Expand Down
Loading