Skip to content

Commit 39a918a

Browse files
committed
bf
1 parent d6d8311 commit 39a918a

File tree

6 files changed

+293
-13
lines changed

6 files changed

+293
-13
lines changed

src/main/java/org/openstack/api/compute/TenantResource.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ public VolumesResource volumes() {
5858
return path("/os-volumes", VolumesResource.class);
5959
}
6060

61-
public SimpleTenantUsageResource usage() {
62-
return path("/os-simple-tenant-usage", SimpleTenantUsageResource.class);
61+
public SimpleTenantUsageResource usage(String id) {
62+
return new SimpleTenantUsageResource(target.path("/os-simple-tenant-usage/{id}").pathParam("id", id), properties);
6363
}
6464

65-
public QuotasResource quotas() {
66-
return path("/os-quota-sets", QuotasResource.class);
65+
public QuotasResource quotas(String id) {
66+
return new QuotasResource(target.path("/os-quota-sets/{id}").pathParam("id", id), properties);
67+
//return path(""+id, QuotasResource.class);
6768
}
6869

6970
public NetworksResource networks() {

src/main/java/org/openstack/api/compute/ext/QuotasResource.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import java.util.Properties;
44

5+
import javax.ws.rs.client.Entity;
56
import javax.ws.rs.client.Target;
67
import javax.ws.rs.core.MediaType;
78

89
import org.openstack.api.common.Resource;
10+
import org.openstack.model.compute.nova.quota.NovaQuotaSet;
911

1012
/**
1113
* Quotas management support
@@ -19,12 +21,12 @@ public QuotasResource(Target target, Properties properties) {
1921
super(target, properties);
2022
}
2123

22-
public String get() {
23-
return target.request(MediaType.APPLICATION_JSON).get(String.class);
24+
public NovaQuotaSet get() {
25+
return target.request(MediaType.APPLICATION_JSON).get(NovaQuotaSet.class);
2426
}
2527

26-
public String update() {
27-
return null;
28+
public NovaQuotaSet update(NovaQuotaSet quotaSet) {
29+
return target.request(MediaType.APPLICATION_JSON).put(Entity.json(quotaSet),NovaQuotaSet.class);
2830
}
2931

3032
}

src/main/java/org/openstack/api/compute/ext/SimpleTenantUsageResource.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import javax.ws.rs.core.MediaType;
77

88
import org.openstack.api.common.Resource;
9+
import org.openstack.model.compute.nova.usage.NovaSimpleTenantUsage;
910

1011
/**
1112
* Simple tenant usage extension
@@ -19,8 +20,15 @@ public SimpleTenantUsageResource(Target target, Properties properties) {
1920
super(target, properties);
2021
}
2122

22-
public String get() {
23-
return target.request(MediaType.APPLICATION_JSON).get(String.class);
23+
public NovaSimpleTenantUsage get(String start, String end) {
24+
Target localTarget = target.queryParam("detailed",1);
25+
if(start != null) {
26+
localTarget = localTarget.queryParam("detailed",1);
27+
}
28+
if(end != null) {
29+
localTarget = localTarget.queryParam("detailed",1);
30+
}
31+
return localTarget.request(MediaType.APPLICATION_JSON).get(NovaSimpleTenantUsage.class);
2432
}
2533

2634
}

src/main/java/org/openstack/client/OpenStackClient.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,14 @@ public static OpenStackClient authenticate() {
8888
}
8989
}
9090

91-
public void reauthenticateOnTenant(String tenantName) {
92-
properties.setProperty("auth.tenant.name", tenantName);
93-
authenticate(properties);
91+
public OpenStackClient reauthenticateOnTenantById(String tenantId) {
92+
properties.setProperty("auth.tenantId", tenantId);
93+
return authenticate(properties);
94+
}
95+
96+
public OpenStackClient reauthenticateOnTenantByName(String tenantName) {
97+
properties.setProperty("auth.tenantName", tenantName);
98+
return authenticate(properties);
9499
}
95100

96101
public void exchangeTokenForTenant(String tenantId) {
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package org.openstack.model.compute.nova.quota;
2+
3+
import java.io.Serializable;
4+
5+
import org.codehaus.jackson.annotate.JsonProperty;
6+
import org.codehaus.jackson.map.annotate.JsonRootName;
7+
8+
@JsonRootName("quota_set")
9+
public class NovaQuotaSet implements Serializable {
10+
11+
private String id;
12+
13+
@JsonProperty("metadata_items")
14+
private Integer metadataItems;
15+
16+
@JsonProperty("injected_file_content_bytes")
17+
private Integer injectedFileContentBytes;
18+
19+
@JsonProperty("injected_files")
20+
private Integer injectedFiles;
21+
22+
private Integer gigabytes;
23+
24+
private Integer ram;
25+
26+
@JsonProperty("floating_ips")
27+
private Integer floatingIps;
28+
29+
private Integer instances;
30+
31+
private Integer volumes;
32+
33+
private Integer cores;
34+
35+
public String getId() {
36+
return id;
37+
}
38+
39+
public void setId(String id) {
40+
this.id = id;
41+
}
42+
43+
public Integer getMetadataItems() {
44+
return metadataItems;
45+
}
46+
47+
public void setMetadataItems(Integer metadataItems) {
48+
this.metadataItems = metadataItems;
49+
}
50+
51+
public Integer getInjectedFileContentBytes() {
52+
return injectedFileContentBytes;
53+
}
54+
55+
public void setInjectedFileContentBytes(Integer injectedFileContentBytes) {
56+
this.injectedFileContentBytes = injectedFileContentBytes;
57+
}
58+
59+
public Integer getInjectedFiles() {
60+
return injectedFiles;
61+
}
62+
63+
public void setInjectedFiles(Integer injectedFiles) {
64+
this.injectedFiles = injectedFiles;
65+
}
66+
67+
public Integer getGigabytes() {
68+
return gigabytes;
69+
}
70+
71+
public void setGigabytes(Integer gigabytes) {
72+
this.gigabytes = gigabytes;
73+
}
74+
75+
public Integer getRam() {
76+
return ram;
77+
}
78+
79+
public void setRam(Integer ram) {
80+
this.ram = ram;
81+
}
82+
83+
public Integer getFloatingIps() {
84+
return floatingIps;
85+
}
86+
87+
public void setFloatingIps(Integer floatingIps) {
88+
this.floatingIps = floatingIps;
89+
}
90+
91+
public Integer getInstances() {
92+
return instances;
93+
}
94+
95+
public void setInstances(Integer instances) {
96+
this.instances = instances;
97+
}
98+
99+
public Integer getVolumes() {
100+
return volumes;
101+
}
102+
103+
public void setVolumes(Integer volumes) {
104+
this.volumes = volumes;
105+
}
106+
107+
public Integer getCores() {
108+
return cores;
109+
}
110+
111+
public void setCores(Integer cores) {
112+
this.cores = cores;
113+
}
114+
115+
}
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package org.openstack.model.compute.nova.usage;
2+
3+
import java.io.Serializable;
4+
import java.math.BigDecimal;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
import org.codehaus.jackson.annotate.JsonProperty;
9+
import org.codehaus.jackson.map.annotate.JsonRootName;
10+
11+
@JsonRootName("tenant_usage")
12+
public class NovaSimpleTenantUsage implements Serializable {
13+
14+
public static class NovaServerUsage implements Serializable {
15+
16+
private BigDecimal hours;
17+
18+
private BigDecimal uptime;
19+
20+
@JsonProperty("local_gb")
21+
private BigDecimal localGb;
22+
23+
@JsonProperty("started_at")
24+
private String startedAt;
25+
26+
@JsonProperty("ended_at")
27+
private String endedAt;
28+
29+
@JsonProperty("name")
30+
private String name;
31+
32+
@JsonProperty("tenant_id")
33+
private String tenantId;
34+
35+
@JsonProperty("vcpus")
36+
private String vcpus;
37+
38+
@JsonProperty("memory_mb")
39+
private String memoryMb;
40+
41+
@JsonProperty("state")
42+
private String state;
43+
44+
@JsonProperty("flavor")
45+
private String flavor;
46+
47+
public BigDecimal getHours() {
48+
return hours;
49+
}
50+
51+
public BigDecimal getUptime() {
52+
return uptime;
53+
}
54+
55+
public BigDecimal getLocalGb() {
56+
return localGb;
57+
}
58+
59+
public String getStartedAt() {
60+
return startedAt;
61+
}
62+
63+
public String getEndedAt() {
64+
return endedAt;
65+
}
66+
67+
public String getName() {
68+
return name;
69+
}
70+
71+
public String getTenantId() {
72+
return tenantId;
73+
}
74+
75+
public String getVcpus() {
76+
return vcpus;
77+
}
78+
79+
public String getMemoryMb() {
80+
return memoryMb;
81+
}
82+
83+
public String getState() {
84+
return state;
85+
}
86+
87+
public String getFlavor() {
88+
return flavor;
89+
}
90+
91+
}
92+
93+
@JsonProperty("tenant_id")
94+
private String tenantId;
95+
96+
@JsonProperty("total_vcpus_usage")
97+
private BigDecimal totalVcpus;
98+
99+
@JsonProperty("total_memory_mb_usage")
100+
private BigDecimal totalMemoryMb;
101+
102+
@JsonProperty("total_local_gb_usage")
103+
private BigDecimal totalLocalGbUsage;
104+
105+
@JsonProperty("total_hours")
106+
private BigDecimal totalHours;
107+
108+
@JsonProperty("start")
109+
private String start;
110+
111+
@JsonProperty("stop")
112+
private String stop;
113+
114+
@JsonProperty("server_usages")
115+
private List<NovaServerUsage> serversUsages = new ArrayList<NovaSimpleTenantUsage.NovaServerUsage>();
116+
117+
public String getTenantId() {
118+
return tenantId;
119+
}
120+
121+
public BigDecimal getTotalVcpus() {
122+
return totalVcpus;
123+
}
124+
125+
public BigDecimal getTotalMemoryMb() {
126+
return totalMemoryMb;
127+
}
128+
129+
public BigDecimal getTotalLocalGbUsage() {
130+
return totalLocalGbUsage;
131+
}
132+
133+
public BigDecimal getTotalHours() {
134+
return totalHours;
135+
}
136+
137+
public String getStart() {
138+
return start;
139+
}
140+
141+
public String getStop() {
142+
return stop;
143+
}
144+
145+
public List<NovaServerUsage> getServersUsages() {
146+
return serversUsages;
147+
}
148+
149+
}

0 commit comments

Comments
 (0)