Cleaning up VNMC config as part of network shutdown

This commit is contained in:
Koushik Das 2013-03-27 16:48:28 +05:30
parent 5a427d48e2
commit fc0ed9adb6
3 changed files with 83 additions and 7 deletions

View File

@ -0,0 +1,43 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.agent.api;
/**
* Command for cleaning up logical edge firewall in VNMC
*/
public class CleanupLogicalEdgeFirewallCommand extends Command {
private long _vlanId;
public CleanupLogicalEdgeFirewallCommand(long vlanId) {
super();
this._vlanId = vlanId;
}
@Override
public boolean executeInSequence() {
return false;
}
public long getVlanId() {
return _vlanId;
}
public void setVlanId(long vlanId) {
this._vlanId = vlanId;
}
}

View File

@ -34,6 +34,7 @@ import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.AssociateAsaWithLogicalEdgeFirewallCommand;
import com.cloud.agent.api.CleanupLogicalEdgeFirewallCommand;
import com.cloud.agent.api.ConfigureNexusVsmForAsaCommand;
import com.cloud.agent.api.CreateLogicalEdgeFirewallCommand;
import com.cloud.agent.api.StartupCommand;
@ -401,16 +402,27 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
return true;
}
private boolean cleanupLogicalEdgeFirewall(long vlanId, long hostId) {
CleanupLogicalEdgeFirewallCommand cmd = new CleanupLogicalEdgeFirewallCommand(vlanId);
Answer answer = _agentMgr.easySend(hostId, cmd);
return answer.getResult();
}
@Override
public boolean shutdown(Network network, ReservationContext context,
boolean cleanup) throws ConcurrentOperationException,
ResourceUnavailableException {
unassignAsa1000vFromNetwork(network);
// disassociateAsaFromLogicalEdgeFirewall()
// delete ACL and NAT policies
// delete logical edge firewall
// delete tenant/VDC
String vlan = network.getBroadcastUri().getHost();
long vlanId = Long.parseLong(vlan);
List<CiscoVnmcControllerVO> devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (!devices.isEmpty()) {
CiscoVnmcControllerVO ciscoVnmcDevice = devices.get(0);
HostVO ciscoVnmcHost = _hostDao.findById(ciscoVnmcDevice.getHostId());
cleanupLogicalEdgeFirewall(vlanId, ciscoVnmcHost.getId());
}
return true;
}
@ -526,7 +538,6 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
}
}
@Override
public CiscoVnmcResourceResponse createCiscoVnmcResourceResponse(
CiscoVnmcController ciscoVnmcResourceVO) {
@ -541,7 +552,6 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
return response;
}
@Override
public boolean deleteCiscoVnmcResource(DeleteCiscoVnmcResourceCmd cmd) {
Long vnmcResourceId = cmd.getCiscoVnmcResourceId();
@ -573,7 +583,6 @@ public class CiscoVnmcElement extends AdapterBase implements SourceNatServicePro
return true;
}
@Override
public List<CiscoVnmcControllerVO> listCiscoVnmcResources(
ListCiscoVnmcResourcesCmd cmd) {

View File

@ -28,6 +28,7 @@ import org.apache.log4j.Logger;
import com.cloud.agent.IAgentControl;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.AssociateAsaWithLogicalEdgeFirewallCommand;
import com.cloud.agent.api.CleanupLogicalEdgeFirewallCommand;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.ConfigureNexusVsmForAsaCommand;
import com.cloud.agent.api.CreateLogicalEdgeFirewallCommand;
@ -100,6 +101,8 @@ public class CiscoVnmcResource implements ServerResource {
return execute((ExternalNetworkResourceUsageCommand) cmd);
} else if (cmd instanceof CreateLogicalEdgeFirewallCommand) {
return execute((CreateLogicalEdgeFirewallCommand)cmd);
} else if (cmd instanceof CleanupLogicalEdgeFirewallCommand) {
return execute((CleanupLogicalEdgeFirewallCommand)cmd);
} else if (cmd instanceof ConfigureNexusVsmForAsaCommand) {
return execute((ConfigureNexusVsmForAsaCommand)cmd);
} else if (cmd instanceof AssociateAsaWithLogicalEdgeFirewallCommand) {
@ -711,6 +714,27 @@ public class CiscoVnmcResource implements ServerResource {
return new Answer(cmd, true, "Success");
}
/*
* Cleanup
*/
private synchronized Answer execute(CleanupLogicalEdgeFirewallCommand cmd) {
refreshVnmcConnection();
return execute(cmd, _numRetries);
}
private Answer execute(CleanupLogicalEdgeFirewallCommand cmd, int numRetries) {
String tenant = "vlan-" + cmd.getVlanId();
try {
_connection.deleteTenant(tenant);
} catch (Throwable e) {
String msg = "CleanupLogicalEdgeFirewallCommand failed due to " + e.getMessage();
s_logger.error(msg, e);
return new Answer(cmd, false, msg);
}
return new Answer(cmd, true, "Success");
}
@Override
public void setName(String name) {
// TODO Auto-generated method stub