I think I got AdvancedNetworkOptionsConverter figured out.

Also made sure not to try to remove FirewallRules unless there's a
public IP in the first place.
This commit is contained in:
Andrew Bayer 2012-05-23 10:15:34 -07:00 committed by Andrei Savu
parent e6eaa2e192
commit 1261a4c9b0
2 changed files with 12 additions and 9 deletions

View File

@ -52,7 +52,7 @@ public class AdvancedNetworkOptionsConverter implements OptionsConverter {
checkArgument(!networks.isEmpty(), "please setup a network for zone: " + zoneId);
Network defaultNetworkInZone = Iterables.getFirst(filter(networks.values(), and(defaultNetworkInZone(zoneId), supportsStaticNAT())), null);
if(defaultNetworkInZone == null) {
defaultNetworkInZone = Iterables.getFirst(filter(networks.values(), and(isIsolatedNetwork(), not(supportsStaticNAT()))), null);
defaultNetworkInZone = Iterables.getFirst(filter(networks.values(), isIsolatedNetwork()), null);
}
if (defaultNetworkInZone == null) {
throw new IllegalArgumentException("please choose a specific network in zone " + zoneId + ": " + networks);

View File

@ -329,14 +329,17 @@ public class CloudStackComputeServiceAdapter implements
// immutable doesn't permit duplicates
Set<String> ipAddresses = Sets.newLinkedHashSet();
Set<FirewallRule> firewallRules = client.getFirewallClient()
.listFirewallRules(ListFirewallRulesOptions.Builder.ipAddressId(client.getVirtualMachineClient().getVirtualMachine(virtualMachineId).getPublicIPId()));
for (FirewallRule rule : firewallRules) {
if (!FirewallRule.State.fromValue("DELETEING").equals(rule.getState())) {
ipAddresses.add(rule.getIpAddressId());
client.getFirewallClient().deleteFirewallRule(rule.getId());
logger.debug(">> deleting FirewallRule(%s)", rule.getId());
String publicIpId = client.getVirtualMachineClient().getVirtualMachine(virtualMachineId).getPublicIPId();
if (publicIpId != null) {
Set<FirewallRule> firewallRules = client.getFirewallClient()
.listFirewallRules(ListFirewallRulesOptions.Builder.ipAddressId(client.getVirtualMachineClient().getVirtualMachine(virtualMachineId).getPublicIPId()));
for (FirewallRule rule : firewallRules) {
if (!FirewallRule.State.fromValue("DELETEING").equals(rule.getState())) {
ipAddresses.add(rule.getIpAddressId());
client.getFirewallClient().deleteFirewallRule(rule.getId());
logger.debug(">> deleting FirewallRule(%s)", rule.getId());
}
}
}
return ipAddresses;