Skip to content

Commit

Permalink
complete interface of Network
Browse files Browse the repository at this point in the history
  • Loading branch information
int32bit committed Dec 30, 2014
1 parent bcddcdd commit 72d0702
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/bupt/openstack/neutron/api/NetworkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

public interface NetworkManager {
List<Network> list() throws OperationException;
List<Network> listExternal() throws OperationException;
Network create(Network network) throws OperationException;
void delete(String id) throws OperationException;
Network get(String id) throws OperationException;
Network update(Network network) throws OperationException;
}
3 changes: 3 additions & 0 deletions src/bupt/openstack/neutron/api/SubnetManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
public interface SubnetManager {
List<Subnet> list() throws OperationException;
Subnet get(String id) throws OperationException;
Subnet create(Subnet subnet) throws OperationException;
Subnet update(Subnet subnet) throws OperationException;
void delete(String id) throws OperationException;
}
19 changes: 19 additions & 0 deletions src/bupt/openstack/neutron/api/v2/Networks.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package bupt.openstack.neutron.api.v2;
import java.util.List;
import java.util.Objects;

import bupt.openstack.authentication.Authenticated;
import bupt.openstack.common.OperationException;
Expand All @@ -26,4 +27,22 @@ public void delete(String id) throws OperationException {
public Network get(String id) throws OperationException {
return super._get(PREFIX + "/networks/" + id + ".json");
}
@Override
public List<Network> listExternal() throws OperationException {
String url = PREFIX + "/networks.json?router%3Aexternal=True";
return _list(url);
}
@Override
public Network update(Network network) throws OperationException {
Objects.requireNonNull(network);
Objects.requireNonNull(network.getId());
String id = network.getId();
Network t = new Network();
t.setName(network.getName());
t.setExternal(network.isExternal());
t.setShared(network.isShared());
t.setUp(network.isUp());
return super._update(PREFIX + "/networks/" + id + ".json", t.toJSONObject(false));
}

}
22 changes: 21 additions & 1 deletion src/bupt/openstack/neutron/api/v2/Subnets.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bupt.openstack.neutron.api.v2;

import java.util.List;
import java.util.Objects;

import bupt.openstack.authentication.Authenticated;
import bupt.openstack.common.OperationException;
Expand All @@ -21,5 +22,24 @@ public List<Subnet> list() throws OperationException {
public Subnet get(String id) throws OperationException {
return super._get(PREFIX + "/subnets/" + id + ".json");
}

@Override
public Subnet create(Subnet subnet) throws OperationException {
return super._create(PREFIX + "/subnets.json", subnet);
}
@Override
public Subnet update(Subnet subnet) throws OperationException {
Objects.requireNonNull(subnet);
Objects.requireNonNull(subnet.getId());
String id = subnet.getId();
// To ignore read-only attribute
subnet.setCIDR(null);
subnet.setId(null);
subnet.setNetworkId(null);
subnet.setTenantId(null);
return super._update(PREFIX + "/subnets/" + id + ".json", subnet);
}
@Override
public void delete(String id) throws OperationException {
super._delete(PREFIX + "/subnets/" + id + ".json");
}
}
4 changes: 3 additions & 1 deletion src/bupt/openstack/neutron/model/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,7 @@ public void setShared(boolean isShared) {
public void setSegmentationId(String segmentationId) {
this.segmentationId = segmentationId;
}

public void setStatus(String status) {
this.status = status;
}
}
1 change: 1 addition & 0 deletions src/bupt/openstack/neutron/model/Subnet.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public Subnet(Object o) {
public Subnet() {
super();
this.enableDHCP = true;
this.ipVersion = "4";
}

public boolean isEnableDHCP() {
Expand Down
12 changes: 8 additions & 4 deletions src/bupt/openstack/test/SessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
import bupt.openstack.common.OpenstackSession;
import bupt.openstack.common.OperationException;
import bupt.openstack.neutron.Neutron;
import bupt.openstack.neutron.model.Subnet;
import bupt.openstack.neutron.model.Network;

public class SessionTest {
public static void main(String[] args) throws OperationException {
OpenstackSession session = OpenstackSession.getSession("hadoop", "admin", "ADMIN_PASS");
Neutron neutron = session.getNeutronClient();
System.out.println(neutron.subnets.get("77abe006-c62d-46a5-825a-36b92eda0c65").toString(4));
for (Subnet subnet : neutron.subnets.list()) {
//System.out.println(subnet.toString(4));
Network network = neutron.networks.get("8e3b4f41-7285-4ab0-93b3-09ab5776c8c9");
network.setShared(false);
network.setUp(true);
network.setName("NEWNAME111");
neutron.networks.update(network);
for (Network net : neutron.networks.list()) {
System.out.println(net.toString(4));
}
}
}

0 comments on commit 72d0702

Please sign in to comment.