Skip to content
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
@@ -0,0 +1,58 @@
package org.openstack4j.api.network;

import org.openstack4j.api.AbstractTest;
import org.openstack4j.model.common.ActionResponse;
import org.openstack4j.model.network.ext.NetQosPolicyBandwidthLimitRule;
import org.openstack4j.openstack.networking.domain.ext.NeutronNetQosPolicyBandwidthLimitRule;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.List;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

/**
* Test cases for (Neutron) qos policy bandwidth limit rule extension based Services
*
* @author bboyHan
*/
@Test(suiteName = "Network/qosPolicyBandwidthLimitRule")
public class NetQosBandwidthLimitRuleTests extends AbstractTest {

private static final String QOS_POLICY_BANDWIDTH_LIMIT_RULE_JSON = "/network/qos_bandwidth_limit_rule.json";
private static final String QOS_POLICY_BANDWIDTH_LIMIT_RULES_JSON = "/network/qos_bandwidth_limit_rules.json";

public void list() throws IOException {
respondWith(QOS_POLICY_BANDWIDTH_LIMIT_RULES_JSON);
List<? extends NetQosPolicyBandwidthLimitRule> qosPolicyBandwidthLimitRules = osv3().networking().netQosPolicyBandWidthLimitRule().list("policyId");
assertEquals(1, qosPolicyBandwidthLimitRules.size());
assertEquals(10000, (int)qosPolicyBandwidthLimitRules.get(0).getMaxKbps());
}

public void get() throws IOException {
respondWith(QOS_POLICY_BANDWIDTH_LIMIT_RULE_JSON);
NetQosPolicyBandwidthLimitRule netQosPolicyBandwidthLimitRule = osv3().networking().netQosPolicyBandWidthLimitRule().get("networkId", "ruleId");
assertEquals("5f126d84-551a-4dcf-bb01-0e9c0df0c793", netQosPolicyBandwidthLimitRule.getId());
assertEquals("egress", netQosPolicyBandwidthLimitRule.getDirection());
}

public void delete() {
respondWith(204);
ActionResponse response = osv3().networking().netQosPolicyBandWidthLimitRule().delete("policyId", "ruleId");
assertTrue(response.isSuccess());
}

public void create() throws IOException {
respondWith(QOS_POLICY_BANDWIDTH_LIMIT_RULE_JSON);
NetQosPolicyBandwidthLimitRule netQosPolicyBandwidthLimitRule = osv3().networking().netQosPolicyBandWidthLimitRule()
.create("policyId", NeutronNetQosPolicyBandwidthLimitRule.builder().maxKbps(10000).build());
assertEquals("5f126d84-551a-4dcf-bb01-0e9c0df0c793", netQosPolicyBandwidthLimitRule.getId());
assertEquals("egress", netQosPolicyBandwidthLimitRule.getDirection());
}

@Override
protected Service service() {
return Service.NETWORK;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"bandwidth_limit_rule": {
"id": "5f126d84-551a-4dcf-bb01-0e9c0df0c793",
"max_kbps": 10000,
"max_burst_kbps": 0,
"direction": "egress"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"bandwidth_limit_rules": [
{
"id": "5f126d84-551a-4dcf-bb01-0e9c0df0c793",
"max_kbps": 10000,
"max_burst_kbps": 0,
"direction": "egress"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,10 @@ public interface NetworkingService extends RestService {
* @return the Networking (Neutron) Qos Policy Extension API
*/
NetQosPolicyService netQosPolicy();

/**
* @return the Networking (Neutron) Qos Policy Bandwidth Limit Rule Extension API
*/
NetQosPolicyBLRuleService netQosPolicyBandWidthLimitRule();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please unify the BandWidth/Bandwidth spelling. Latter is better imo.


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.openstack4j.api.networking.ext;

import org.openstack4j.common.RestService;
import org.openstack4j.model.common.ActionResponse;
import org.openstack4j.model.network.ext.NetQosPolicyBandwidthLimitRule;

import java.util.List;

/**
* Networking (Neutron) Qos Policy Bandwidth Limit Rule Extension API
*
* @author bboyHan
*/
public interface NetQosPolicyBLRuleService extends RestService {

/**
* Lists qos policy bandwidth-limit-rules for tenants
*
* @param policyId policy id
* @return the list of qos policy bandwidth limit rules
*/
List<? extends NetQosPolicyBandwidthLimitRule> list(String policyId);

/**
* Fetches the network qos policy bandwidth-limit-rule for the specified tenant
*
* @param policyId policy id
* @return NetQosPolicyBandwidthLimitRule
*/
NetQosPolicyBandwidthLimitRule get(String policyId, String ruleId);

/**
* Updates the network qos policy bandwidth limit rule for the current tenant
*
* @param policyId policy id
* @param bandwidthLimitRule the net qos policy bandwidth limit rule to update
* @return NetQosPolicyBandwidthLimitRule
*/
NetQosPolicyBandwidthLimitRule update(String policyId, NetQosPolicyBandwidthLimitRule bandwidthLimitRule);

/**
* Create the current network qos policy bandwidth limit rule for the current tenant back to defaults
*
* @param policyId policy id
* @return NetQosPolicyBandwidthLimitRule the response object
*/
NetQosPolicyBandwidthLimitRule create(String policyId, NetQosPolicyBandwidthLimitRule bandwidthLimitRule);

/**
* Delete the current network qos policy bandwidth limit rule for the current tenant back to defaults
*
* @param policyId policy id
* @param ruleId the net qos policy bandwidth limit rule uuid
* @return the action response
*/
ActionResponse delete(String policyId, String ruleId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.openstack4j.model.network.ext;

import org.openstack4j.common.Buildable;
import org.openstack4j.model.common.IdEntity;
import org.openstack4j.model.network.ext.builder.NetQosPolicyBandwidthLimitRuleBuilder;
import org.openstack4j.openstack.networking.domain.ext.NeutronNetQosPolicyRuleTag;

/**
* Network qos policy band-width-limit that are bound to a Tenant
*
* @author bboyHan
*/
public interface NetQosPolicyBandwidthLimitRule extends IdEntity, Buildable<NetQosPolicyBandwidthLimitRuleBuilder> {

/**
* The maximum KBPS (kilobits per second) value.
* If you specify this value, must be greater than 0 otherwise max_kbps will have no value.
*
* @return maxKbps
*/
Integer getMaxKbps();

/**
* The maximum burst size (in kilobits).
*
* @return maxBurstKbps
*/
Integer getMaxBurstKbps();

/**
* The direction of the traffic to which the QoS rule is applied, as seen from the point of view of the port.
* Valid values are egress and ingress. Default value is egress.
*
* @return direction
*/
String getDirection();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be cleaner to have an enum for the 2 valid values.


/**
* The list of tags on the resource.
*
* @return tags
*/
NeutronNetQosPolicyRuleTag getTags();

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

import org.openstack4j.common.Buildable.Builder;
import org.openstack4j.model.network.ext.NetQosPolicyBandwidthLimitRule;

/**
* A Builder which creates a NetQosPolicyBandwidthLimitRule entity
*
* @author bboyHan
*/
public interface NetQosPolicyBandwidthLimitRuleBuilder extends Builder<NetQosPolicyBandwidthLimitRuleBuilder, NetQosPolicyBandwidthLimitRule> {

/**
* See {@link NetQosPolicyBandwidthLimitRule#getMaxKbps()} for details
*
* @param maxKbps maxKbps
* @return NetQosPolicyBandwidthLimitRuleBuilder
*/
NetQosPolicyBandwidthLimitRuleBuilder maxKbps(Integer maxKbps);

/**
* See {@link NetQosPolicyBandwidthLimitRule#getMaxBurstKbps()} for details
*
* @param maxBurstKbps maxBurstKbps
* @return NetQosPolicyBandwidthLimitRuleBuilder
*/
NetQosPolicyBandwidthLimitRuleBuilder maxBurstKbps(Integer maxBurstKbps);

/**
* See {@link NetQosPolicyBandwidthLimitRule#getDirection()} for details
*
* @param direction direction
* @return NetQosPolicyBandwidthLimitRuleBuilder
*/
NetQosPolicyBandwidthLimitRuleBuilder direction(String direction);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package org.openstack4j.openstack.networking.domain.ext;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import org.openstack4j.model.network.ext.NetQosPolicyBandwidthLimitRule;
import org.openstack4j.model.network.ext.builder.NetQosPolicyBandwidthLimitRuleBuilder;
import org.openstack4j.openstack.common.ListResult;

import java.util.List;

import static com.google.common.base.MoreObjects.toStringHelper;

/**
* Network qos policy band-width-limit that are bound to a Tenant
*
* @author bboyHan
*/
@JsonRootName("bandwidth_limit_rule")
public class NeutronNetQosPolicyBandwidthLimitRule implements NetQosPolicyBandwidthLimitRule {

private static final long serialVersionUID = 1L;

@JsonProperty
private String id;
@JsonProperty("max_kbps")
private Integer maxKbps;
@JsonProperty("max_burst_kbps")
private Integer maxBurstKbps;
@JsonProperty
private String direction;
@JsonProperty
private NeutronNetQosPolicyRuleTag tags;

public static NetQosPolicyBandwidthLimitRuleBuilder builder() {
return new NetQosPolicyBandwidthLimitRuleConcreteBuilder();
}

@Override
public NetQosPolicyBandwidthLimitRuleBuilder toBuilder() {
return new NetQosPolicyBandwidthLimitRuleConcreteBuilder(this);
}

public String getId() {
return id;
}

@Override
public void setId(String id) {
this.id = id;
}

public Integer getMaxKbps() {
return maxKbps;
}

public Integer getMaxBurstKbps() {
return maxBurstKbps;
}

public String getDirection() {
return direction;
}

public NeutronNetQosPolicyRuleTag getTags() {
return tags;
}

@Override
public String toString() {
return toStringHelper(this)
.add("id", id).add("maxKbps", maxKbps).add("maxBurstKbps", maxBurstKbps)
.add("direction", direction).add("tags", tags)
.toString();
}

public static class NetQosPolicyBandwidthLimitRuleConcreteBuilder implements NetQosPolicyBandwidthLimitRuleBuilder {

private NeutronNetQosPolicyBandwidthLimitRule model;

public NetQosPolicyBandwidthLimitRuleConcreteBuilder() {
model = new NeutronNetQosPolicyBandwidthLimitRule();
}

public NetQosPolicyBandwidthLimitRuleConcreteBuilder(NeutronNetQosPolicyBandwidthLimitRule model) {
this.model = model;
}

@Override
public NetQosPolicyBandwidthLimitRule build() {
return model;
}

@Override
public NetQosPolicyBandwidthLimitRuleBuilder from(NetQosPolicyBandwidthLimitRule in) {
model = (NeutronNetQosPolicyBandwidthLimitRule) in;
return this;
}

@Override
public NetQosPolicyBandwidthLimitRuleBuilder maxKbps(Integer maxKbps) {
model.maxKbps = maxKbps;
return this;
}

@Override
public NetQosPolicyBandwidthLimitRuleBuilder maxBurstKbps(Integer maxBurstKbps) {
model.maxBurstKbps = maxBurstKbps;
return this;
}

@Override
public NetQosPolicyBandwidthLimitRuleBuilder direction(String direction) {
model.direction = direction;
return this;
}

}

public static class NeutronNetQosPolicyBLRules extends ListResult<NeutronNetQosPolicyBandwidthLimitRule> {

private static final long serialVersionUID = 1L;

@JsonProperty("bandwidth_limit_rules")
private List<NeutronNetQosPolicyBandwidthLimitRule> bandwidthLimitRules;

@Override
protected List<NeutronNetQosPolicyBandwidthLimitRule> value() {
return bandwidthLimitRules;
}
}

}
Loading