Skip to content

Commit bcddcdd

Browse files
committed
add neutron
1 parent 0448538 commit bcddcdd

18 files changed

Lines changed: 499 additions & 22 deletions

src/bupt/openstack/cinder/Cinder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
import bupt.openstack.cinder.api.v1.Types;
1212
import bupt.openstack.cinder.api.v1.Volumes;
1313
import bupt.openstack.cinder.model.Snapshots;
14+
import bupt.openstack.common.Client;
1415

15-
public class Cinder {
16+
public class Cinder extends Client {
1617
public final VolumeManager volumes;
1718
public final VolumeTypeManager types;
1819
public final ServiceManager services;
1920
public final SnapshotManager snapshots;
2021
public final LimitManager limits;
2122
public Cinder(Authenticated credentical) {
23+
super(credentical);
2224
volumes = new Volumes(credentical);
2325
types = new Types(credentical);
2426
services = new Services(credentical);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package bupt.openstack.common;
2+
3+
import bupt.openstack.authentication.Authenticated;
4+
5+
public abstract class Client {
6+
protected Authenticated credentical;
7+
public Client(Authenticated credentical) {
8+
this.credentical = credentical;
9+
}
10+
public void setRegion(String region) {
11+
credentical.setWorkRegion(region);
12+
}
13+
public Authenticated getCredentical () {
14+
return credentical;
15+
}
16+
}

src/bupt/openstack/common/OpenstackSession.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import bupt.openstack.glance.Glance;
1111
import bupt.openstack.keystone.Keystone;
1212
import bupt.openstack.keystone.model.Secret;
13+
import bupt.openstack.neutron.Neutron;
1314
import bupt.openstack.nova.Nova;
1415

1516
public class OpenstackSession {
@@ -22,6 +23,7 @@ public class OpenstackSession {
2223
private final Glance glance;
2324
private final Keystone keystone;
2425
private final Cinder cinder;
26+
private final Neutron neutron;
2527
@SuppressWarnings("unused")
2628
private final Configure configure;
2729
/**
@@ -35,6 +37,7 @@ public OpenstackSession(Authenticated credentical) {
3537
this.glance = new Glance(credentical);
3638
this.keystone = new Keystone(credentical);
3739
this.cinder = new Cinder(credentical);
40+
this.neutron = new Neutron(credentical);
3841
this.availableTenants = DataBaseAccessor.getTenants(credentical.getUser().getName());
3942
}
4043
/**
@@ -53,6 +56,9 @@ public Keystone getKeystoneClient() {
5356
public Cinder getCinderClient() {
5457
return cinder;
5558
}
59+
public Neutron getNeutronClient() {
60+
return neutron;
61+
}
5662
/**
5763
* 切换region
5864
* @param region 需要切换代region,region必须存在,否则失败

src/bupt/openstack/common/model/AbstractEntity.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ public JSONObject toIntervalJSONObject() {
103103
public String toIntervalString(int indent) {
104104
return toIntervalJSONObject().toString(4);
105105
}*/
106-
@Override
107-
public JSONObject toJSONObject() {
108-
JSONObject meta = JSONConverter.EntityToJSON(this);
106+
public JSONObject toJSONObject(boolean colonSeparate) {
107+
JSONObject meta = JSONConverter.EntityToJSON(this,colonSeparate);
109108
if (getClass().isMemberClass()) {
110109
return meta;
111110
}
@@ -117,7 +116,10 @@ public JSONObject toJSONObject() {
117116
entity.put(name, meta);
118117
return entity;
119118
}
120-
119+
@Override
120+
public JSONObject toJSONObject() {
121+
return toJSONObject(true);
122+
}
121123
@Override
122124
public String toString() {
123125
return toJSONObject().toString();

src/bupt/openstack/common/tools/JSONConverter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ public class JSONConverter {
2020
/**
2121
* 把一个AbstractEntity(它的之类)实例转化成JSONObject表示形式
2222
* @param entity 需要转化的对象
23+
* @param colon 属性名包含冒号时,是否分隔,true为分隔,false不分隔
2324
* @return 该对象的JSONObject表示
2425
*/
25-
public static JSONObject EntityToJSON(AbstractEntity entity) {
26+
public static JSONObject EntityToJSON(AbstractEntity entity, boolean colon) {
2627
JSONObject json = new JSONObject();
2728
/* 获取该对象的所有属性 */
2829
Set<Field> fields = Reflector.getFields(entity);
@@ -34,7 +35,7 @@ public static JSONObject EntityToJSON(AbstractEntity entity) {
3435
if (name == null)
3536
continue;
3637
/* 处理属性名为 DDD:ddd的情况 */
37-
if (name.indexOf(':') > 0) {
38+
if (name.indexOf(':') > 0 && colon) {
3839
name = name.split(":")[1];
3940
}
4041
Object value = null;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package bupt.openstack.glance;
22

33
import bupt.openstack.authentication.Authenticated;
4+
import bupt.openstack.common.Client;
45
import bupt.openstack.glance.api.ImageManager;
56
import bupt.openstack.glance.api.v2.Images;
67

7-
public class Glance {
8+
public class Glance extends Client {
89
public final ImageManager images;
910
public Glance(Authenticated credentical) {
11+
super(credentical);
1012
this.images = new Images(credentical);
1113
}
1214
}

src/bupt/openstack/keystone/Keystone.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package bupt.openstack.keystone;
22

33
import bupt.openstack.authentication.Authenticated;
4+
import bupt.openstack.common.Client;
45
import bupt.openstack.common.OperationException;
56
import bupt.openstack.keystone.api.EndpointManager;
67
import bupt.openstack.keystone.api.RoleManager;
@@ -16,14 +17,15 @@
1617
import bupt.openstack.keystone.api.v2.Users;
1718
import bupt.openstack.keystone.model.Secret;
1819

19-
public class Keystone {
20+
public class Keystone extends Client {
2021
public final UserManager users;
2122
public final RoleManager roles;
2223
public final TokenManager tokens;
2324
public final ServiceManager services;
2425
public final TenantManager tenants;
2526
public final EndpointManager endpoints;
2627
public Keystone(Authenticated credentical) {
28+
super(credentical);
2729
this.users = new Users(credentical);
2830
this.roles = new Roles(credentical);
2931
this.tokens = new Tokens(credentical);

src/bupt/openstack/keystone/model/CatalogType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package bupt.openstack.keystone.model;
22

33
public enum CatalogType {
4-
compute,image,identity, cloudformation, volume, volumev2, orchestration;
4+
compute,image,identity, cloudformation, volume, volumev2, orchestration,network;
55
public static CatalogType of(String type) {
66
return CatalogType.valueOf(type);
77
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package bupt.openstack.neutron;
2+
3+
import bupt.openstack.authentication.Authenticated;
4+
import bupt.openstack.common.Client;
5+
import bupt.openstack.neutron.api.NetworkManager;
6+
import bupt.openstack.neutron.api.SubnetManager;
7+
import bupt.openstack.neutron.api.v2.Networks;
8+
import bupt.openstack.neutron.api.v2.Subnets;
9+
10+
public class Neutron extends Client {
11+
public final NetworkManager networks;
12+
public final SubnetManager subnets;
13+
public Neutron(Authenticated credentical) {
14+
super(credentical);
15+
this.networks = new Networks(credentical);
16+
this.subnets = new Subnets(credentical);
17+
}
18+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package bupt.openstack.neutron.api;
2+
3+
import java.util.List;
4+
5+
import bupt.openstack.common.OperationException;
6+
import bupt.openstack.neutron.model.Network;
7+
8+
public interface NetworkManager {
9+
List<Network> list() throws OperationException;
10+
Network create(Network network) throws OperationException;
11+
void delete(String id) throws OperationException;
12+
Network get(String id) throws OperationException;
13+
}

0 commit comments

Comments
 (0)