Skip to content

Commit 39b773e

Browse files
author
Erik Johnson
committed
Merge pull request #2 from greese/2013.04
2013.04
2 parents 2f73370 + 73d55c2 commit 39b773e

File tree

3 files changed

+113
-27
lines changed

3 files changed

+113
-27
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>org.dasein</groupId>
44
<artifactId>dasein-cloud-openstack</artifactId>
5-
<version>2013.04.2-SNAPSHOT</version>
5+
<version>2013.04.4-SNAPSHOT</version>
66
<name>Dasein Cloud Nova</name>
77
<description>Dasein Cloud implementation for the Nova APIs</description>
88

src/main/java/org/dasein/cloud/openstack/nova/os/compute/NovaServer.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,20 +1304,26 @@ else if( addr.getVersion().equals(IPVersion.IPV6) ) {
13041304
}
13051305
vm.setPlatform(p);
13061306
}
1307-
Iterable<String> fwIds = listFirewalls(vm.getProviderVirtualMachineId(), server);
1308-
int count = 0;
1309-
1310-
//noinspection UnusedDeclaration
1311-
for( String id : fwIds ) {
1312-
count++;
1307+
if (getProvider().getProviderName().equalsIgnoreCase("RACKSPACE")){
1308+
//Rackspace does not support the concept for firewalls in servers
1309+
vm.setProviderFirewallIds(null);
13131310
}
1314-
String[] ids = new String[count];
1315-
int i = 0;
1311+
else{
1312+
Iterable<String> fwIds = listFirewalls(vm.getProviderVirtualMachineId(), server);
1313+
int count = 0;
1314+
1315+
//noinspection UnusedDeclaration
1316+
for( String id : fwIds ) {
1317+
count++;
1318+
}
1319+
String[] ids = new String[count];
1320+
int i = 0;
13161321

1317-
for( String id : fwIds ) {
1318-
ids[i++] = id;
1322+
for( String id : fwIds ) {
1323+
ids[i++] = id;
1324+
}
1325+
vm.setProviderFirewallIds(ids);
13191326
}
1320-
vm.setProviderFirewallIds(ids);
13211327
return vm;
13221328
}
13231329

src/main/java/org/dasein/cloud/openstack/nova/os/network/Quantum.java

Lines changed: 95 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,20 @@
4040
import org.dasein.cloud.network.VLANState;
4141
import org.dasein.cloud.openstack.nova.os.NovaMethod;
4242
import org.dasein.cloud.openstack.nova.os.NovaOpenStack;
43+
import org.dasein.cloud.openstack.nova.os.OpenStackProvider;
4344
import org.dasein.cloud.util.APITrace;
45+
import org.dasein.cloud.util.Cache;
46+
import org.dasein.cloud.util.CacheLevel;
4447
import org.json.JSONArray;
4548
import org.json.JSONException;
4649
import org.json.JSONObject;
4750

4851
import javax.annotation.Nonnull;
4952
import javax.annotation.Nullable;
5053
import java.util.ArrayList;
54+
import java.util.Collections;
5155
import java.util.HashMap;
56+
import java.util.Iterator;
5257
import java.util.Locale;
5358
import java.util.Map;
5459

@@ -66,13 +71,80 @@ public Quantum(@Nonnull NovaOpenStack provider) {
6671
super(provider);
6772
}
6873

74+
private enum QuantumType {
75+
NONE, RACKSPACE, NOVA, QUANTUM;
76+
77+
public String getNetworkResource() {
78+
switch( this ) {
79+
case QUANTUM: return "/networks";
80+
case RACKSPACE: return "/os-networksv2";
81+
case NOVA: return "/os-networks";
82+
}
83+
return "/networks";
84+
}
85+
86+
public String getSubnetResource() {
87+
switch( this ) {
88+
case QUANTUM: return "/subnets";
89+
}
90+
return "/subnets";
91+
}
92+
}
93+
94+
private QuantumType getNetworkType() throws CloudException, InternalException {
95+
Cache<QuantumType> cache = Cache.getInstance(getProvider(), "quantumness", QuantumType.class, CacheLevel.CLOUD);
96+
97+
Iterable<QuantumType> it = cache.get(getContext());
98+
99+
if( it != null ) {
100+
Iterator<QuantumType> b = it.iterator();
101+
102+
if( b.hasNext() ) {
103+
return b.next();
104+
}
105+
}
106+
try {
107+
if( ((NovaOpenStack)getProvider()).getCloudProvider().equals(OpenStackProvider.RACKSPACE) ) {
108+
cache.put(getContext(), Collections.singletonList(QuantumType.RACKSPACE));
109+
return QuantumType.RACKSPACE;
110+
}
111+
NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
112+
try {
113+
JSONObject ob = method.getServers("/networks", null, false);
114+
115+
if( ob != null && ob.has("networks") ) {
116+
cache.put(getContext(), Collections.singletonList(QuantumType.QUANTUM));
117+
return QuantumType.QUANTUM;
118+
}
119+
}
120+
catch( Throwable ignore ) {
121+
// ignore
122+
}
123+
try {
124+
JSONObject ob = method.getServers("/os-networks", null, false);
125+
126+
if( ob != null && ob.has("networks") ) {
127+
cache.put(getContext(), Collections.singletonList(QuantumType.NOVA));
128+
return QuantumType.NOVA;
129+
}
130+
}
131+
catch( Throwable ignore ) {
132+
// ignore
133+
}
134+
return QuantumType.NONE;
135+
}
136+
finally {
137+
APITrace.end();
138+
}
139+
}
140+
69141
private @Nonnull String getTenantId() throws CloudException, InternalException {
70142
return ((NovaOpenStack)getProvider()).getAuthenticationContext().getTenantId();
71143
}
72144

73145
@Override
74146
public boolean allowsNewSubnetCreation() throws CloudException, InternalException {
75-
return !((NovaOpenStack)getProvider()).isRackspace();
147+
return getNetworkType().equals(QuantumType.QUANTUM);
76148
}
77149

78150
@Override
@@ -115,7 +187,7 @@ public boolean allowsMultipleTrafficTypesOverVlan() throws CloudException, Inter
115187

116188
wrapper.put("port", json);
117189

118-
JSONObject result = method.postServers("/networks/" + subnet.getProviderVlanId() + "/ports", null, new JSONObject(wrapper), false);
190+
JSONObject result = method.postServers(getNetworkResource() + "/" + subnet.getProviderVlanId() + "/ports", null, new JSONObject(wrapper), false);
119191

120192
if( result != null && result.has("port") ) {
121193
try {
@@ -177,7 +249,7 @@ else if( versions[0].equals(IPVersion.IPV6) ) {
177249

178250
wrapper.put("subnet", json);
179251

180-
JSONObject result = method.postServers("/subnets", null, new JSONObject(wrapper), false);
252+
JSONObject result = method.postServers(getSubnetResource(), null, new JSONObject(wrapper), false);
181253

182254
if( result != null && result.has("subnet") ) {
183255
try {
@@ -264,13 +336,12 @@ public int getMaxVlanCount() throws CloudException, InternalException {
264336
return -2;
265337
}
266338

267-
private @Nonnull String getNetworkResource() {
268-
if( ((NovaOpenStack)getProvider()).isRackspace() ) {
269-
return "/os-networksv2";
270-
}
271-
else {
272-
return "/networks";
273-
}
339+
private @Nonnull String getNetworkResource() throws CloudException, InternalException {
340+
return getNetworkType().getNetworkResource();
341+
}
342+
343+
private @Nonnull String getSubnetResource() throws CloudException, InternalException {
344+
return getNetworkType().getSubnetResource();
274345
}
275346

276347
@Override
@@ -292,8 +363,11 @@ public int getMaxVlanCount() throws CloudException, InternalException {
292363
public Subnet getSubnet(@Nonnull String subnetId) throws CloudException, InternalException {
293364
APITrace.begin(getProvider(), "VLAN.getSubnet");
294365
try {
366+
if( !getNetworkType().equals(QuantumType.QUANTUM) ) {
367+
return null;
368+
}
295369
NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
296-
JSONObject ob = method.getServers("/subnets", subnetId, false);
370+
JSONObject ob = method.getServers(getSubnetResource(), subnetId, false);
297371

298372
try {
299373
if( ob != null && ob.has("subnet") ) {
@@ -317,8 +391,8 @@ public Subnet getSubnet(@Nonnull String subnetId) throws CloudException, Interna
317391
}
318392

319393
@Override
320-
public @Nonnull Requirement getSubnetSupport() {
321-
return (((NovaOpenStack)getProvider()).isRackspace() ? Requirement.NONE : Requirement.REQUIRED);
394+
public @Nonnull Requirement getSubnetSupport() throws CloudException, InternalException {
395+
return (getNetworkType().equals(QuantumType.QUANTUM) ? Requirement.REQUIRED : Requirement.NONE);
322396
}
323397

324398
@Override
@@ -400,8 +474,11 @@ public boolean isVlanDataCenterConstrained() throws CloudException, InternalExce
400474
public @Nonnull Iterable<Subnet> listSubnets(@Nonnull String inVlanId) throws CloudException, InternalException {
401475
APITrace.begin(getProvider(), "VLAN.listSubnets");
402476
try {
477+
if( !getNetworkType().equals(QuantumType.QUANTUM) ) {
478+
return Collections.emptyList();
479+
}
403480
NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
404-
JSONObject ob = method.getServers("/subnets", null, false);
481+
JSONObject ob = method.getServers(getSubnetResource(), null, false);
405482
ArrayList<Subnet> subnets = new ArrayList<Subnet>();
406483

407484
try {
@@ -516,9 +593,12 @@ public boolean isVlanDataCenterConstrained() throws CloudException, InternalExce
516593
public void removeSubnet(String subnetId) throws CloudException, InternalException {
517594
APITrace.begin(getProvider(), "VLAN.removeSubnet");
518595
try {
596+
if( !getNetworkType().equals(QuantumType.QUANTUM) ) {
597+
throw new OperationNotSupportedException("Cannot remove subnets in an OpenStack network of type: " + getNetworkType());
598+
}
519599
NovaMethod method = new NovaMethod((NovaOpenStack)getProvider());
520600

521-
method.deleteServers("/subnets", subnetId);
601+
method.deleteServers(getSubnetResource(), subnetId);
522602
}
523603
finally {
524604
APITrace.end();

0 commit comments

Comments
 (0)