File tree Expand file tree Collapse file tree 7 files changed +57
-6
lines changed
Expand file tree Collapse file tree 7 files changed +57
-6
lines changed Original file line number Diff line number Diff line change 77
88public interface NetworkManager {
99 List <Network > list () throws OperationException ;
10+ List <Network > listExternal () throws OperationException ;
1011 Network create (Network network ) throws OperationException ;
1112 void delete (String id ) throws OperationException ;
1213 Network get (String id ) throws OperationException ;
14+ Network update (Network network ) throws OperationException ;
1315}
Original file line number Diff line number Diff line change 88public interface SubnetManager {
99 List <Subnet > list () throws OperationException ;
1010 Subnet get (String id ) throws OperationException ;
11+ Subnet create (Subnet subnet ) throws OperationException ;
12+ Subnet update (Subnet subnet ) throws OperationException ;
13+ void delete (String id ) throws OperationException ;
1114}
Original file line number Diff line number Diff line change 11package bupt .openstack .neutron .api .v2 ;
22import java .util .List ;
3+ import java .util .Objects ;
34
45import bupt .openstack .authentication .Authenticated ;
56import bupt .openstack .common .OperationException ;
@@ -26,4 +27,22 @@ public void delete(String id) throws OperationException {
2627 public Network get (String id ) throws OperationException {
2728 return super ._get (PREFIX + "/networks/" + id + ".json" );
2829 }
30+ @ Override
31+ public List <Network > listExternal () throws OperationException {
32+ String url = PREFIX + "/networks.json?router%3Aexternal=True" ;
33+ return _list (url );
34+ }
35+ @ Override
36+ public Network update (Network network ) throws OperationException {
37+ Objects .requireNonNull (network );
38+ Objects .requireNonNull (network .getId ());
39+ String id = network .getId ();
40+ Network t = new Network ();
41+ t .setName (network .getName ());
42+ t .setExternal (network .isExternal ());
43+ t .setShared (network .isShared ());
44+ t .setUp (network .isUp ());
45+ return super ._update (PREFIX + "/networks/" + id + ".json" , t .toJSONObject (false ));
46+ }
47+
2948}
Original file line number Diff line number Diff line change 11package bupt .openstack .neutron .api .v2 ;
22
33import java .util .List ;
4+ import java .util .Objects ;
45
56import bupt .openstack .authentication .Authenticated ;
67import bupt .openstack .common .OperationException ;
@@ -21,5 +22,24 @@ public List<Subnet> list() throws OperationException {
2122 public Subnet get (String id ) throws OperationException {
2223 return super ._get (PREFIX + "/subnets/" + id + ".json" );
2324 }
24-
25+ @ Override
26+ public Subnet create (Subnet subnet ) throws OperationException {
27+ return super ._create (PREFIX + "/subnets.json" , subnet );
28+ }
29+ @ Override
30+ public Subnet update (Subnet subnet ) throws OperationException {
31+ Objects .requireNonNull (subnet );
32+ Objects .requireNonNull (subnet .getId ());
33+ String id = subnet .getId ();
34+ // To ignore read-only attribute
35+ subnet .setCIDR (null );
36+ subnet .setId (null );
37+ subnet .setNetworkId (null );
38+ subnet .setTenantId (null );
39+ return super ._update (PREFIX + "/subnets/" + id + ".json" , subnet );
40+ }
41+ @ Override
42+ public void delete (String id ) throws OperationException {
43+ super ._delete (PREFIX + "/subnets/" + id + ".json" );
44+ }
2545}
Original file line number Diff line number Diff line change @@ -98,5 +98,7 @@ public void setShared(boolean isShared) {
9898 public void setSegmentationId (String segmentationId ) {
9999 this .segmentationId = segmentationId ;
100100 }
101-
101+ public void setStatus (String status ) {
102+ this .status = status ;
103+ }
102104}
Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ public Subnet(Object o) {
5454 public Subnet () {
5555 super ();
5656 this .enableDHCP = true ;
57+ this .ipVersion = "4" ;
5758 }
5859
5960 public boolean isEnableDHCP () {
Original file line number Diff line number Diff line change 33import bupt .openstack .common .OpenstackSession ;
44import bupt .openstack .common .OperationException ;
55import bupt .openstack .neutron .Neutron ;
6- import bupt .openstack .neutron .model .Subnet ;
6+ import bupt .openstack .neutron .model .Network ;
77
88public class SessionTest {
99 public static void main (String [] args ) throws OperationException {
1010 OpenstackSession session = OpenstackSession .getSession ("hadoop" , "admin" , "ADMIN_PASS" );
1111 Neutron neutron = session .getNeutronClient ();
12- System .out .println (neutron .subnets .get ("77abe006-c62d-46a5-825a-36b92eda0c65" ).toString (4 ));
13- for (Subnet subnet : neutron .subnets .list ()) {
14- //System.out.println(subnet.toString(4));
12+ Network network = neutron .networks .get ("8e3b4f41-7285-4ab0-93b3-09ab5776c8c9" );
13+ network .setShared (false );
14+ network .setUp (true );
15+ network .setName ("NEWNAME111" );
16+ neutron .networks .update (network );
17+ for (Network net : neutron .networks .list ()) {
18+ System .out .println (net .toString (4 ));
1519 }
1620 }
1721}
You can’t perform that action at this time.
0 commit comments