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

Adds QoS Policy Support #1260

Open
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ public interface NetworkingService extends RestService {
* @return the Availability Zone Service API
*/
AvailabilityZoneService availabilityzone();

/**
*
* @return QoS Policy Service API
*/
QoSPolicyService qosPolicies();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.openstack4j.api.networking;

import org.openstack4j.common.RestService;
import org.openstack4j.model.common.ActionResponse;
import org.openstack4j.model.network.QoSPolicy;
import org.openstack4j.model.network.options.QoSPolicyListOptions;

import java.util.List;

public interface QoSPolicyService extends RestService {

/**
* Lists all QoS policies authorized by the current Tenant
*
* @return the list of QoS policies
*/
List<? extends QoSPolicy> list();

/**
* Lists all QoS policies authorized by the current Tenant
*
* @param options filtering options
* @return the list of QoS policies
*/
List<? extends QoSPolicy> list(QoSPolicyListOptions options);

/**
* Gets the QoS policy by ID
*
* @param policyId the QoS QoSPolicy identifier
* @return the QoSPolicy or null if not found
*/
QoSPolicy get(String policyId);

/**
* Delete a QoSPolicy by ID
*
* @param policyId the policy identifier to delete
* @return the action response
*/
ActionResponse delete(String policyId);

/**
* Creates a new QoSPolicy
* @param policy the QoSPolicy to create
* @return the newly create QoSPolicy
*/
QoSPolicy create(QoSPolicy policy);

/**
* Updates an existing QoSPolicy. The QoSPolicy identifier must be set on the policy object to be successful
* @param policy the QoSPolicy to update
* @return the updated QoSPolicy
*/
QoSPolicy update(QoSPolicy policy);
}
2 changes: 2 additions & 0 deletions core/src/main/java/org/openstack4j/model/network/Port.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ public interface Port extends Resource, Buildable<PortBuilder> {
String getvNicType();

Map<String, Object> getProfile();

String getQosPolicyId();
}
42 changes: 42 additions & 0 deletions core/src/main/java/org/openstack4j/model/network/QoSPolicy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.openstack4j.model.network;

import org.openstack4j.common.Buildable;
import org.openstack4j.model.common.Resource;
import org.openstack4j.model.network.builder.BandwidthLimitRuleBuilder;
import org.openstack4j.model.network.builder.DscpMarkingRuleBuilder;
import org.openstack4j.model.network.builder.MinimumBandwidthRuleBuilder;
import org.openstack4j.model.network.builder.QoSPolicyBuilder;

import java.util.List;
import java.util.Set;

public interface QoSPolicy extends Resource, Buildable<QoSPolicyBuilder> {
String getDescription();
String getProjectId();
int getRevisionNumber();
boolean isShared();
List<? extends Rule> getRules();
boolean isDefault();
String getCreatedAt();
String getUpdatedAt();

interface Rule extends Resource {
String getType();
Set<String> getTags();
}

interface BandwidthLimitRule extends Rule, Buildable<BandwidthLimitRuleBuilder> {
Integer getMaxKbps();
Integer getMaxBurstKbps();
String getDirection();
}

interface DscpMarkingRule extends Rule, Buildable<DscpMarkingRuleBuilder> {
Integer getDscpMark();
}

interface MinimumBandwidthRule extends Rule, Buildable<MinimumBandwidthRuleBuilder> {
Integer getMinKbps();
String getDirection();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.openstack4j.model.network.builder;

import org.openstack4j.common.Buildable.Builder;
import org.openstack4j.model.network.QoSPolicy;

public interface BandwidthLimitRuleBuilder extends Builder<BandwidthLimitRuleBuilder, QoSPolicy.BandwidthLimitRule> {
BandwidthLimitRuleBuilder maxKbps(Integer maxKbps);
BandwidthLimitRuleBuilder maxBurstKbps(Integer maxBurstKbps);
BandwidthLimitRuleBuilder direction(String direction);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.openstack4j.model.network.builder;

import org.openstack4j.common.Buildable.Builder;
import org.openstack4j.model.network.QoSPolicy.DscpMarkingRule;

import java.util.Set;

public interface DscpMarkingRuleBuilder extends Builder<DscpMarkingRuleBuilder, DscpMarkingRule> {
DscpMarkingRuleBuilder dscpMark(Integer dscpMark);
DscpMarkingRuleBuilder id(String id);
DscpMarkingRuleBuilder tags(Set<String> tags);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.openstack4j.model.network.builder;

import org.openstack4j.common.Buildable.Builder;
import org.openstack4j.model.network.QoSPolicy.MinimumBandwidthRule;

import java.util.Set;

public interface MinimumBandwidthRuleBuilder extends Builder<MinimumBandwidthRuleBuilder, MinimumBandwidthRule> {
MinimumBandwidthRuleBuilder minKbps(Integer minKbps);
MinimumBandwidthRuleBuilder id(String id);
MinimumBandwidthRuleBuilder direction(String direction);
MinimumBandwidthRuleBuilder tags(Set<String> tags);
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,13 @@ public interface NetworkBuilders {
* @return HealthMonitorV2UpdateBuilder
*/
public HealthMonitorV2UpdateBuilder healthMonitorV2Update();

QoSPolicyBuilder qosPolicy();

BandwidthLimitRuleBuilder bandwidthLimitRule();

DscpMarkingRuleBuilder dscpMarkingRule();

MinimumBandwidthRuleBuilder minimumBandwidthRule();

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,6 @@ public interface PortBuilder extends Builder<PortBuilder, Port> {

PortBuilder profile(Map<String, Object> profile);

PortBuilder qosPolicyId(String qosPolicyId);

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

import org.openstack4j.common.Buildable.Builder;
import org.openstack4j.model.network.QoSPolicy;
import org.openstack4j.model.network.QoSPolicy.Rule;

import java.util.List;

public interface QoSPolicyBuilder extends Builder<QoSPolicyBuilder, QoSPolicy> {
QoSPolicyBuilder description(String description);
QoSPolicyBuilder tenantId(String tenantId);
QoSPolicyBuilder projectId(String projectId);
QoSPolicyBuilder revisionNumber(int revisionNumber);
QoSPolicyBuilder shared(boolean shared);
QoSPolicyBuilder rules(List<? extends Rule> rules);
QoSPolicyBuilder id(String id);
QoSPolicyBuilder isDefault(boolean isDefault);
QoSPolicyBuilder name(String name);
QoSPolicyBuilder createdAt(String createdAt);
QoSPolicyBuilder updatedAt(String updatedAt);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
package org.openstack4j.model.network.options;

import com.google.common.collect.Maps;

import java.util.Map;
import java.util.Set;

public class QoSPolicyListOptions {

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

private QoSPolicyListOptions() { }

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

/**
* The human-readable description of the resource
*
* @param description QoS policy description
* @return options
*/
public QoSPolicyListOptions description(String description) {
return add("description", description);
}

/**
* ID of the project that owns the resource
*
* @param tenantId ID of the project
* @return options
*/
public QoSPolicyListOptions tenantId(String tenantId) {
return add("tenant_id", tenantId);
}

/**
* ID of the project that owns the resource
*
* @param projectId ID of the project
* @return options
*/
public QoSPolicyListOptions projectId(String projectId) {
return add("project_id", projectId);
}

/**
* Revision number of the resource
*
* @param revisionNumber revision number
* @return options
*/
public QoSPolicyListOptions revisionNumber(Integer revisionNumber) {
return add("revision_number", revisionNumber);
}

/**
* Whether a policy is shared across all projects.
*
* @param shared whether this policy is shared across all projects.
* @return options
*/
public QoSPolicyListOptions shared(Boolean shared) {
return add("shared", shared);
}

/**
* ID of the resource
*
* @param id QoS policy ID
* @return options
*/
public QoSPolicyListOptions id(String id) {
return add("id", id);
}

/**
* Whether a policy is the default policy
*
* @param isDefault a policy is the default policy
* @return options
*/
public QoSPolicyListOptions isDefault(Boolean isDefault) {
return add("is_default", isDefault);
}

/**
* Name of a policy
*
* @param name policy name
* @return options
*/
public QoSPolicyListOptions name(String name) {
return add("name", name);
}

/**
* Set of tags that all must be associated to a policy
*
* @param tags set of tags
* @return options
*/
public QoSPolicyListOptions tags(Set<String> tags) {
return add("tags", String.join(",", tags));
}

/**
* Set of tags that only some must be associated to a policy
*
* @param tags set that only some must be associated to a policy
* @return options
*/
public QoSPolicyListOptions tagsAny(Set<String> tags) {
return add("tags-any", String.join(",", tags));
}

/**
* Set of tags that must not all be associated to a policy.
*
* @param tags set that must not all be associated to a policy
* @return options
*/
public QoSPolicyListOptions notTags(Set<String> tags) {
return add("not-tags", String.join(",", tags));
}

/**
* Set of tags where no subset should be associated to a policy
*
* @param tags no subset should be associated to a policy
* @return options
*/
public QoSPolicyListOptions notTagsAny(Set<String> tags) {
return add("not-tags-any", String.join(",", tags));
}

/**
* Sort direction:
* - asc (ascending)
* - desc (descending)
*
* @param direction sort direction
* @return options
*/
public QoSPolicyListOptions sortDir(String direction) {
return add("sort_dir", direction);
}

/**
* Name of field by which to to sort
*
* @param key sort key
* @return options
*/
public QoSPolicyListOptions sortKey(String key) {
return add("sort_key", key);
}

/**
* Set of field names to include in the list of QoS policies
*
* @param fields set of field names to include in the list of QoS policies
* @return options
*/
public QoSPolicyListOptions fields(Set<String> fields) {
return add("fields", fields);
}

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

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