diff --git a/core/src/main/java/org/openstack4j/api/networking/NetworkingService.java b/core/src/main/java/org/openstack4j/api/networking/NetworkingService.java index 296d07ec0..9f3b78ed2 100644 --- a/core/src/main/java/org/openstack4j/api/networking/NetworkingService.java +++ b/core/src/main/java/org/openstack4j/api/networking/NetworkingService.java @@ -83,4 +83,10 @@ public interface NetworkingService extends RestService { * @return the Availability Zone Service API */ AvailabilityZoneService availabilityzone(); + + /** + * + * @return QoS Policy Service API + */ + QoSPolicyService qosPolicies(); } diff --git a/core/src/main/java/org/openstack4j/api/networking/QoSPolicyService.java b/core/src/main/java/org/openstack4j/api/networking/QoSPolicyService.java new file mode 100644 index 000000000..882510474 --- /dev/null +++ b/core/src/main/java/org/openstack4j/api/networking/QoSPolicyService.java @@ -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 list(); + + /** + * Lists all QoS policies authorized by the current Tenant + * + * @param options filtering options + * @return the list of QoS policies + */ + List 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); +} diff --git a/core/src/main/java/org/openstack4j/model/network/Port.java b/core/src/main/java/org/openstack4j/model/network/Port.java index d68aa65e3..6c3bff8b2 100644 --- a/core/src/main/java/org/openstack4j/model/network/Port.java +++ b/core/src/main/java/org/openstack4j/model/network/Port.java @@ -71,4 +71,6 @@ public interface Port extends Resource, Buildable { String getvNicType(); Map getProfile(); + + String getQosPolicyId(); } diff --git a/core/src/main/java/org/openstack4j/model/network/QoSPolicy.java b/core/src/main/java/org/openstack4j/model/network/QoSPolicy.java new file mode 100644 index 000000000..b9f6e50a2 --- /dev/null +++ b/core/src/main/java/org/openstack4j/model/network/QoSPolicy.java @@ -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 { + String getDescription(); + String getProjectId(); + int getRevisionNumber(); + boolean isShared(); + List getRules(); + boolean isDefault(); + String getCreatedAt(); + String getUpdatedAt(); + + interface Rule extends Resource { + String getType(); + Set getTags(); + } + + interface BandwidthLimitRule extends Rule, Buildable { + Integer getMaxKbps(); + Integer getMaxBurstKbps(); + String getDirection(); + } + + interface DscpMarkingRule extends Rule, Buildable { + Integer getDscpMark(); + } + + interface MinimumBandwidthRule extends Rule, Buildable { + Integer getMinKbps(); + String getDirection(); + } +} diff --git a/core/src/main/java/org/openstack4j/model/network/builder/BandwidthLimitRuleBuilder.java b/core/src/main/java/org/openstack4j/model/network/builder/BandwidthLimitRuleBuilder.java new file mode 100644 index 000000000..251bb5a5f --- /dev/null +++ b/core/src/main/java/org/openstack4j/model/network/builder/BandwidthLimitRuleBuilder.java @@ -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 maxKbps(Integer maxKbps); + BandwidthLimitRuleBuilder maxBurstKbps(Integer maxBurstKbps); + BandwidthLimitRuleBuilder direction(String direction); +} diff --git a/core/src/main/java/org/openstack4j/model/network/builder/DscpMarkingRuleBuilder.java b/core/src/main/java/org/openstack4j/model/network/builder/DscpMarkingRuleBuilder.java new file mode 100644 index 000000000..a1bbbb97e --- /dev/null +++ b/core/src/main/java/org/openstack4j/model/network/builder/DscpMarkingRuleBuilder.java @@ -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 dscpMark(Integer dscpMark); + DscpMarkingRuleBuilder id(String id); + DscpMarkingRuleBuilder tags(Set tags); +} diff --git a/core/src/main/java/org/openstack4j/model/network/builder/MinimumBandwidthRuleBuilder.java b/core/src/main/java/org/openstack4j/model/network/builder/MinimumBandwidthRuleBuilder.java new file mode 100644 index 000000000..d6586f5e3 --- /dev/null +++ b/core/src/main/java/org/openstack4j/model/network/builder/MinimumBandwidthRuleBuilder.java @@ -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 minKbps(Integer minKbps); + MinimumBandwidthRuleBuilder id(String id); + MinimumBandwidthRuleBuilder direction(String direction); + MinimumBandwidthRuleBuilder tags(Set tags); +} diff --git a/core/src/main/java/org/openstack4j/model/network/builder/NetworkBuilders.java b/core/src/main/java/org/openstack4j/model/network/builder/NetworkBuilders.java index 4ef73dc5b..3a2519e6a 100644 --- a/core/src/main/java/org/openstack4j/model/network/builder/NetworkBuilders.java +++ b/core/src/main/java/org/openstack4j/model/network/builder/NetworkBuilders.java @@ -252,4 +252,13 @@ public interface NetworkBuilders { * @return HealthMonitorV2UpdateBuilder */ public HealthMonitorV2UpdateBuilder healthMonitorV2Update(); + + QoSPolicyBuilder qosPolicy(); + + BandwidthLimitRuleBuilder bandwidthLimitRule(); + + DscpMarkingRuleBuilder dscpMarkingRule(); + + MinimumBandwidthRuleBuilder minimumBandwidthRule(); + } diff --git a/core/src/main/java/org/openstack4j/model/network/builder/PortBuilder.java b/core/src/main/java/org/openstack4j/model/network/builder/PortBuilder.java index e6bef4708..dddf186c0 100644 --- a/core/src/main/java/org/openstack4j/model/network/builder/PortBuilder.java +++ b/core/src/main/java/org/openstack4j/model/network/builder/PortBuilder.java @@ -116,5 +116,6 @@ public interface PortBuilder extends Builder { PortBuilder profile(Map profile); + PortBuilder qosPolicyId(String qosPolicyId); } diff --git a/core/src/main/java/org/openstack4j/model/network/builder/QoSPolicyBuilder.java b/core/src/main/java/org/openstack4j/model/network/builder/QoSPolicyBuilder.java new file mode 100644 index 000000000..5babe0ac9 --- /dev/null +++ b/core/src/main/java/org/openstack4j/model/network/builder/QoSPolicyBuilder.java @@ -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 description(String description); + QoSPolicyBuilder tenantId(String tenantId); + QoSPolicyBuilder projectId(String projectId); + QoSPolicyBuilder revisionNumber(int revisionNumber); + QoSPolicyBuilder shared(boolean shared); + QoSPolicyBuilder rules(List rules); + QoSPolicyBuilder id(String id); + QoSPolicyBuilder isDefault(boolean isDefault); + QoSPolicyBuilder name(String name); + QoSPolicyBuilder createdAt(String createdAt); + QoSPolicyBuilder updatedAt(String updatedAt); +} diff --git a/core/src/main/java/org/openstack4j/model/network/options/QoSPolicyListOptions.java b/core/src/main/java/org/openstack4j/model/network/options/QoSPolicyListOptions.java new file mode 100644 index 000000000..64b78ae8d --- /dev/null +++ b/core/src/main/java/org/openstack4j/model/network/options/QoSPolicyListOptions.java @@ -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 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 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 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 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 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 fields) { + return add("fields", fields); + } + + private QoSPolicyListOptions add(String param, Object value) { + if (value != null) + this.queryParams.put(param, value); + return this; + } + + public Map getOptions() { + return queryParams; + } +} diff --git a/core/src/main/java/org/openstack4j/openstack/networking/builder/NeutronBuilders.java b/core/src/main/java/org/openstack4j/openstack/networking/builder/NeutronBuilders.java index 734e5f4d9..cb239c7ef 100644 --- a/core/src/main/java/org/openstack4j/openstack/networking/builder/NeutronBuilders.java +++ b/core/src/main/java/org/openstack4j/openstack/networking/builder/NeutronBuilders.java @@ -190,4 +190,24 @@ public ListenerV2Builder listenerV2(){ public ListenerV2UpdateBuilder listenerV2Update(){ return NeutronListenerV2Update.builder(); } + + @Override + public QoSPolicyBuilder qosPolicy() { + return NeutronQoSPolicy.builder(); + } + + @Override + public BandwidthLimitRuleBuilder bandwidthLimitRule() { + return NeutronBandwidthLimitRule.builder(); + } + + @Override + public DscpMarkingRuleBuilder dscpMarkingRule() { + return NeutronDscpMarkingRule.builder(); + } + + @Override + public MinimumBandwidthRuleBuilder minimumBandwidthRule() { + return NeutronMinimumBandwidthRule.builder(); + } } diff --git a/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronBandwidthLimitRule.java b/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronBandwidthLimitRule.java new file mode 100644 index 000000000..a71a0eafe --- /dev/null +++ b/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronBandwidthLimitRule.java @@ -0,0 +1,130 @@ +package org.openstack4j.openstack.networking.domain; + +import org.openstack4j.model.common.builder.ResourceBuilder; +import org.openstack4j.model.network.QoSPolicy.BandwidthLimitRule; +import org.openstack4j.model.network.builder.BandwidthLimitRuleBuilder; + +import java.util.List; +import java.util.Set; + +public class NeutronBandwidthLimitRule implements BandwidthLimitRule { + + private String id; + private String tenantId; + private String type; + private String name; + private Integer maxKbps; + private Integer maxBurstKbps; + private String direction; + private List tags; + + @Override + public String getId() { + return id; + } + + @Override + public void setId(String id) { + this.id = id; + } + + @Override + public String getTenantId() { + return tenantId; + } + + @Override + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + @Override + public String getType() { + return type; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public Integer getMaxKbps() { + return maxKbps; + } + + @Override + public Integer getMaxBurstKbps() { + return 0; + } + + @Override + public String getDirection() { + return null; + } + + @Override + public Set getTags() { + return null; + } + + @Override + public BandwidthLimitRuleBuilder toBuilder() { + return new BandwidthLimitRuleConcreteBuilder(this); + } + + public static BandwidthLimitRuleBuilder builder() { + return new BandwidthLimitRuleConcreteBuilder(); + } + + public static class BandwidthLimitRuleConcreteBuilder extends ResourceBuilder implements BandwidthLimitRuleBuilder { + private NeutronBandwidthLimitRule m; + + BandwidthLimitRuleConcreteBuilder() { + this(new NeutronBandwidthLimitRule()); + } + + BandwidthLimitRuleConcreteBuilder(NeutronBandwidthLimitRule rule) { + this.m = rule; + } + + @Override + protected BandwidthLimitRule reference() { + return m; + } + + @Override + public BandwidthLimitRuleBuilder maxKbps(Integer maxKbps) { + m.maxKbps = maxKbps; + return this; + } + + @Override + public BandwidthLimitRuleBuilder maxBurstKbps(Integer maxBurstKbps) { + m.maxBurstKbps = maxBurstKbps; + return this; + } + + @Override + public BandwidthLimitRuleBuilder direction(String direction) { + m.direction = direction; + return this; + } + + @Override + public BandwidthLimitRule build() { + return m; + } + + @Override + public BandwidthLimitRuleBuilder from(BandwidthLimitRule in) { + m = (NeutronBandwidthLimitRule) in; + return this; + } + } +} diff --git a/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronDscpMarkingRule.java b/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronDscpMarkingRule.java new file mode 100644 index 000000000..3cfdce0ca --- /dev/null +++ b/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronDscpMarkingRule.java @@ -0,0 +1,116 @@ +package org.openstack4j.openstack.networking.domain; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.openstack4j.model.common.builder.ResourceBuilder; +import org.openstack4j.model.network.QoSPolicy.DscpMarkingRule; +import org.openstack4j.model.network.builder.DscpMarkingRuleBuilder; + +import java.util.Set; + +public class NeutronDscpMarkingRule implements DscpMarkingRule { + + private String id; + private String type; + + @JsonProperty("tenant_id") + private String tenantId; + + private String name; + private Integer dscpMark; + private Set tags; + + @Override + public String getId() { + return id; + } + + @Override + public void setId(String id) { + this.id = id; + } + + @Override + public String getType() { + return type; + } + + @Override + public String getTenantId() { + return tenantId; + } + + @Override + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public Set getTags() { + return tags; + } + + @Override + public Integer getDscpMark() { + return dscpMark; + } + + @Override + public DscpMarkingRuleBuilder toBuilder() { + return new DscpMarkingRuleConcreteBuilder(this); + } + + public static DscpMarkingRuleBuilder builder() { + return new DscpMarkingRuleConcreteBuilder(); + } + + public static class DscpMarkingRuleConcreteBuilder extends ResourceBuilder implements DscpMarkingRuleBuilder { + + private NeutronDscpMarkingRule m; + + DscpMarkingRuleConcreteBuilder() { + this(new NeutronDscpMarkingRule()); + } + + DscpMarkingRuleConcreteBuilder(NeutronDscpMarkingRule rule) { + this.m = rule; + } + + @Override + protected DscpMarkingRule reference() { + return m; + } + + @Override + public DscpMarkingRuleBuilder dscpMark(Integer dscpMark) { + m.dscpMark = dscpMark; + return this; + } + + @Override + public DscpMarkingRuleBuilder tags(Set tags) { + m.tags = tags; + return this; + } + + @Override + public DscpMarkingRule build() { + return m; + } + + @Override + public DscpMarkingRuleBuilder from(DscpMarkingRule in) { + m = (NeutronDscpMarkingRule) in; + return this; + } + } +} diff --git a/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronMinimumBandwidthRule.java b/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronMinimumBandwidthRule.java new file mode 100644 index 000000000..12e09afd4 --- /dev/null +++ b/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronMinimumBandwidthRule.java @@ -0,0 +1,131 @@ +package org.openstack4j.openstack.networking.domain; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.openstack4j.model.common.builder.ResourceBuilder; +import org.openstack4j.model.network.QoSPolicy.MinimumBandwidthRule; +import org.openstack4j.model.network.builder.MinimumBandwidthRuleBuilder; + +import java.util.Set; + +public class NeutronMinimumBandwidthRule implements MinimumBandwidthRule { + + private String id; + + @JsonProperty("tenant_id") + private String tenantId; + + private String name; + + @JsonProperty("min_kbps") + private Integer minKbps; + + private String direction; + private Set tags; + private String type; + + @Override + public String getId() { + return id; + } + + @Override + public void setId(String id) { + this.id = id; + } + + @Override + public String getType() { + return type; + } + + @Override + public String getTenantId() { + return tenantId; + } + + @Override + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public Set getTags() { + return tags; + } + + @Override + public Integer getMinKbps() { + return minKbps; + } + + @Override + public String getDirection() { + return direction; + } + + @Override + public MinimumBandwidthRuleBuilder toBuilder() { + return new MinimumBandwidthRuleConcreteBuilder(this); + } + + public static MinimumBandwidthRuleBuilder builder() { + return new MinimumBandwidthRuleConcreteBuilder(); + } + + public static class MinimumBandwidthRuleConcreteBuilder extends ResourceBuilder implements MinimumBandwidthRuleBuilder { + + private NeutronMinimumBandwidthRule m; + + MinimumBandwidthRuleConcreteBuilder() { + this(new NeutronMinimumBandwidthRule()); + } + + MinimumBandwidthRuleConcreteBuilder(NeutronMinimumBandwidthRule rule) { + this.m = rule; + } + + @Override + protected MinimumBandwidthRule reference() { + return m; + } + + @Override + public MinimumBandwidthRuleBuilder minKbps(Integer minKbps) { + m.minKbps = minKbps; + return this; + } + + @Override + public MinimumBandwidthRuleBuilder direction(String direction) { + m.direction = direction; + return this; + } + + @Override + public MinimumBandwidthRuleBuilder tags(Set tags) { + m.tags = tags; + return this; + } + + @Override + public MinimumBandwidthRule build() { + return m; + } + + @Override + public MinimumBandwidthRuleBuilder from(MinimumBandwidthRule in) { + m = (NeutronMinimumBandwidthRule) in; + return this; + } + } +} diff --git a/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronPort.java b/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronPort.java index b3ace7d62..4a150e9d8 100644 --- a/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronPort.java +++ b/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronPort.java @@ -87,6 +87,9 @@ public class NeutronPort implements Port { @JsonProperty("binding:profile") private Map profile; + @JsonProperty("qos_policy_id") + private String qosPolicyId; + public static PortBuilder builder() { return new PortConcreteBuilder(); } @@ -232,6 +235,14 @@ public Map getProfile() { return profile; } + /** + * {@inheritDoc} + */ + @Override + public String getQosPolicyId() { + return qosPolicyId; + } + /** * {@inheritDoc} */ @@ -276,6 +287,10 @@ public void setProfile(Map profile) { this.profile = profile; } + public void setQosPolicyId(String qosPolicyId) { + this.qosPolicyId = qosPolicyId; + } + /** * {@inheritDoc} */ @@ -297,6 +312,7 @@ public String toString() { .add("allowed_address_pairs", allowedAddressPairs).add("port_security_enabled ", portSecurityEnabled) .add("binding:host_id", hostId).add("binding:vif_type", vifType).add("binding:vif_details", vifDetails) .add("binding:vnic_type", vNicType).add("binding:profile", profile) + .add("qos_policy_id", qosPolicyId) .toString(); } @@ -308,7 +324,7 @@ public int hashCode() { return java.util.Objects.hash(id, name, adminStateUp, deviceId, deviceOwner, fixedIps, macAddress, networkId, tenantId, securityGroups, allowedAddressPairs, portSecurityEnabled, hostId, - vifType, vifDetails, vNicType, profile); + vifType, vifDetails, vNicType, profile, qosPolicyId); } /** @@ -338,7 +354,8 @@ public boolean equals(Object obj) { java.util.Objects.equals(vifType, that.vifType) && java.util.Objects.equals(vifDetails, that.vifDetails) && java.util.Objects.equals(vNicType, that.vNicType) && - java.util.Objects.equals(profile, that.profile)) { + java.util.Objects.equals(profile, that.profile) && + java.util.Objects.equals(qosPolicyId, that.qosPolicyId)) { return true; } } @@ -529,6 +546,11 @@ public PortBuilder profile(Map profile) { return this; } + @Override + public PortBuilder qosPolicyId(String qosPolicyId) { + m.qosPolicyId = qosPolicyId; + return this; + } } } diff --git a/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronPortCreate.java b/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronPortCreate.java index f34ad257c..e4de3f251 100644 --- a/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronPortCreate.java +++ b/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronPortCreate.java @@ -69,6 +69,8 @@ public class NeutronPortCreate implements ModelEntity { @JsonProperty("binding:profile") private Map profile; + @JsonProperty("qos_policy_id") + private String qosPolicyId; public NeutronPortCreate() { } @@ -97,6 +99,7 @@ public static NeutronPortCreate fromPort(Port port) { c.vifDetails = port.getVifDetails(); c.vNicType = port.getvNicType(); c.profile = port.getProfile(); + c.qosPolicyId = port.getQosPolicyId(); return c; diff --git a/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronQoSPolicy.java b/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronQoSPolicy.java new file mode 100644 index 000000000..5c8acadc0 --- /dev/null +++ b/core/src/main/java/org/openstack4j/openstack/networking/domain/NeutronQoSPolicy.java @@ -0,0 +1,221 @@ +package org.openstack4j.openstack.networking.domain; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import org.openstack4j.model.common.builder.ResourceBuilder; +import org.openstack4j.model.network.QoSPolicy; +import org.openstack4j.model.network.builder.QoSPolicyBuilder; +import org.openstack4j.openstack.common.ListResult; + +import java.util.List; + +public class NeutronQoSPolicy implements QoSPolicy { + + private static final long serialVersionUID = 1L; + + private String id; + private String name; + private String description; + + @JsonProperty("tenant_id") + private String tenantId; + + @JsonProperty("project_id") + private String projectId; + + @JsonProperty("revision_number") + private int revisionNumber; + + private boolean shared; + + @JsonProperty("is_default") + private boolean isDefault; + + @JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.PROPERTY, + property = "type" + ) + @JsonSubTypes({ + @JsonSubTypes.Type(value = NeutronBandwidthLimitRule.class, name = "bandwidth_limit"), + @JsonSubTypes.Type(value = NeutronDscpMarkingRule.class, name = "dscp_marking"), + @JsonSubTypes.Type(value = NeutronMinimumBandwidthRule.class, name = "minimum_bandwidth"), + }) + @JsonProperty("rules") + private List rules; + + @JsonProperty("created_at") + private String createdAt; + + @JsonProperty("updated_at") + private String updatedAt; + + @Override + public String getDescription() { + return description; + } + + @Override + public String getProjectId() { + return projectId; + } + + @Override + public int getRevisionNumber() { + return revisionNumber; + } + + @Override + public boolean isShared() { + return shared; + } + + @Override + public List getRules() { + return rules; + } + + @Override + public boolean isDefault() { + return isDefault; + } + + @Override + public String getCreatedAt() { + return createdAt; + } + + @Override + public String getUpdatedAt() { + return updatedAt; + } + + @Override + public QoSPolicyBuilder toBuilder() { + return new QoSPolicyConcreteBuilder(this); + } + + @Override + public String getTenantId() { + return tenantId; + } + + @Override + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public String getId() { + return id; + } + + @Override + public void setId(String id) { + this.id = id; + } + + public static QoSPolicyBuilder builder() { + return new QoSPolicyConcreteBuilder(); + } + + public static class Policies extends ListResult { + + private static final long serialVersionUID = 1L; + + @JsonProperty("policies") + private List policies; + + @Override + protected List value() { + return policies; + } + } + + public static class QoSPolicyConcreteBuilder extends ResourceBuilder implements QoSPolicyBuilder { + private NeutronQoSPolicy m; + + QoSPolicyConcreteBuilder() { + this(new NeutronQoSPolicy()); + } + + QoSPolicyConcreteBuilder(NeutronQoSPolicy policy) { + this.m = policy; + } + + @Override + protected QoSPolicy reference() { + return m; + } + + @Override + public QoSPolicyBuilder description(String description) { + m.description = description; + return this; + } + + @Override + public QoSPolicyBuilder projectId(String projectId) { + m.projectId = projectId; + return this; + } + + @Override + public QoSPolicyBuilder revisionNumber(int revisionNumber) { + m.revisionNumber = revisionNumber; + return this; + } + + @Override + public QoSPolicyBuilder shared(boolean shared) { + m.shared = shared; + return this; + } + + @Override + public QoSPolicyBuilder rules(List rules) { + m.rules = rules; + return this; + } + + @Override + public QoSPolicyBuilder isDefault(boolean isDefault) { + m.isDefault = isDefault; + return this; + } + + @Override + public QoSPolicyBuilder createdAt(String createdAt) { + m.createdAt = createdAt; + return this; + } + + @Override + public QoSPolicyBuilder updatedAt(String updatedAt) { + m.updatedAt = updatedAt; + return this; + } + + @Override + public QoSPolicy build() { + return m; + } + + @Override + public QoSPolicyBuilder from(QoSPolicy in) { + m = (NeutronQoSPolicy) in; + return this; + } + } +} diff --git a/core/src/main/java/org/openstack4j/openstack/networking/internal/NetworkingServiceImpl.java b/core/src/main/java/org/openstack4j/openstack/networking/internal/NetworkingServiceImpl.java index 2ddf8768e..14ef1a704 100644 --- a/core/src/main/java/org/openstack4j/openstack/networking/internal/NetworkingServiceImpl.java +++ b/core/src/main/java/org/openstack4j/openstack/networking/internal/NetworkingServiceImpl.java @@ -6,6 +6,7 @@ import org.openstack4j.api.networking.NetworkService; import org.openstack4j.api.networking.NetworkingService; import org.openstack4j.api.networking.PortService; +import org.openstack4j.api.networking.QoSPolicyService; import org.openstack4j.api.networking.RouterService; import org.openstack4j.api.networking.SecurityGroupRuleService; import org.openstack4j.api.networking.SecurityGroupService; @@ -125,6 +126,10 @@ public AgentService agent() { @Override public AvailabilityZoneService availabilityzone() { return Apis.get(AvailabilityZoneService.class); - } + } + @Override + public QoSPolicyService qosPolicies() { + return Apis.get(QoSPolicyService.class); + } } diff --git a/core/src/main/java/org/openstack4j/openstack/networking/internal/QoSPolicyServiceImpl.java b/core/src/main/java/org/openstack4j/openstack/networking/internal/QoSPolicyServiceImpl.java new file mode 100644 index 000000000..fb971b64b --- /dev/null +++ b/core/src/main/java/org/openstack4j/openstack/networking/internal/QoSPolicyServiceImpl.java @@ -0,0 +1,76 @@ +package org.openstack4j.openstack.networking.internal; + +import org.openstack4j.api.networking.QoSPolicyService; +import org.openstack4j.model.common.ActionResponse; +import org.openstack4j.model.network.QoSPolicy; +import org.openstack4j.model.network.options.QoSPolicyListOptions; +import org.openstack4j.openstack.networking.domain.NeutronQoSPolicy; + +import java.util.List; + +import static com.google.common.base.Preconditions.checkNotNull; + +public class QoSPolicyServiceImpl extends BaseNetworkingServices implements QoSPolicyService { + + /** + * {@inheritDoc} + */ + @Override + public List list() { + return get(NeutronQoSPolicy.Policies.class, uri("/qos/policies")).execute().getList(); + } + + @Override + public List list(QoSPolicyListOptions options) { + if (options == null) + return list(); + + return get(NeutronQoSPolicy.Policies.class, uri("/qos/policies")).params(options.getOptions()).execute().getList(); + } + + /** + * {@inheritDoc} + */ + @Override + public QoSPolicy get(String policyId) { + checkNotNull(policyId); + return get(NeutronQoSPolicy.class, uri("/qos/policies/%s", policyId)).execute(); + } + + /** + * {@inheritDoc} + */ + @Override + public ActionResponse delete(String policyId) { + checkNotNull(policyId); + return deleteWithResponse(uri("/qos/policies/%s", policyId)).execute(); + } + + /** + * {@inheritDoc} + */ + @Override + public QoSPolicy create(QoSPolicy policy) { + checkNotNull(policy); + return post(NeutronQoSPolicy.class, uri("/qos/policies")).entity(policy).execute(); + } + + /** + * {@inheritDoc} + */ + @Override + public QoSPolicy update(QoSPolicy policy) { + checkNotNull(policy); + checkNotNull(policy.getId()); + QoSPolicy p = policy.toBuilder() + .tenantId(null) + .build(); + return put(NeutronQoSPolicy.class, uri("/qos/policies/%s", getAndClearIdentifier(p))).entity(p).execute(); + } + + private String getAndClearIdentifier(QoSPolicy policy) { + String portId = policy.getId(); + policy.setId(null); + return portId; + } +} diff --git a/core/src/main/java/org/openstack4j/openstack/provider/DefaultAPIProvider.java b/core/src/main/java/org/openstack4j/openstack/provider/DefaultAPIProvider.java index 18102e6d6..14b1d4045 100644 --- a/core/src/main/java/org/openstack4j/openstack/provider/DefaultAPIProvider.java +++ b/core/src/main/java/org/openstack4j/openstack/provider/DefaultAPIProvider.java @@ -87,6 +87,7 @@ import org.openstack4j.api.networking.NetworkService; import org.openstack4j.api.networking.NetworkingService; import org.openstack4j.api.networking.PortService; +import org.openstack4j.api.networking.QoSPolicyService; import org.openstack4j.api.networking.RouterService; import org.openstack4j.api.networking.SecurityGroupRuleService; import org.openstack4j.api.networking.SecurityGroupService; @@ -254,6 +255,7 @@ import org.openstack4j.openstack.networking.internal.NetworkServiceImpl; import org.openstack4j.openstack.networking.internal.NetworkingServiceImpl; import org.openstack4j.openstack.networking.internal.PortServiceImpl; +import org.openstack4j.openstack.networking.internal.QoSPolicyServiceImpl; import org.openstack4j.openstack.networking.internal.RouterServiceImpl; import org.openstack4j.openstack.networking.internal.SecurityGroupRuleServiceImpl; import org.openstack4j.openstack.networking.internal.SecurityGroupServiceImpl; @@ -389,6 +391,7 @@ public void initialize() { bind(SubnetService.class, SubnetServiceImpl.class); bind(AvailabilityZoneService.class, AvailabilityZoneServiceImpl.class); bind(PortService.class, PortServiceImpl.class); + bind(QoSPolicyService.class, QoSPolicyServiceImpl.class); bind(RouterService.class, RouterServiceImpl.class); bind(OctaviaService.class, OctaviaServiceImpl.class); bind(org.openstack4j.api.octavia.LoadBalancerV2Service.class, org.openstack4j.openstack.octavia.internal.LoadBalancerV2ServiceImpl.class);