use of com.cloud.agent.api.DeleteBcfStaticNatCommand in project cloudstack by apache.
the class BigSwitchBcfElement method applyStaticNats.
@Override
public boolean applyStaticNats(Network network, List<? extends StaticNat> rules) throws ResourceUnavailableException {
bcfUtilsInit();
_bcfUtils.listACLbyNetwork(network);
Vpc vpc = null;
if (network.getVpcId() != null) {
vpc = _vpcDao.acquireInLockTable(network.getVpcId());
}
String tenantId;
if (vpc != null) {
tenantId = vpc.getUuid();
_vpcDao.releaseFromLockTable(vpc.getId());
} else {
// use account in CS as tenant in BSN
// use network uuid as tenantId for non-VPC networks
tenantId = network.getUuid();
}
for (StaticNat rule : rules) {
String srcIp = _ipAddressDao.findById(rule.getSourceIpAddressId()).getAddress().addr();
String dstIp = rule.getDestIpAddress();
String mac = rule.getSourceMacAddress();
if (!rule.isForRevoke()) {
s_logger.debug("BCF enables static NAT for public IP: " + srcIp + " private IP " + dstIp + " mac " + mac);
CreateBcfStaticNatCommand cmd = new CreateBcfStaticNatCommand(tenantId, network.getUuid(), dstIp, srcIp, mac);
_bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network);
} else {
s_logger.debug("BCF removes static NAT for public IP: " + srcIp + " private IP " + dstIp + " mac " + mac);
DeleteBcfStaticNatCommand cmd = new DeleteBcfStaticNatCommand(tenantId, srcIp);
_bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network);
}
}
return true;
}
use of com.cloud.agent.api.DeleteBcfStaticNatCommand in project cloudstack by apache.
the class BigSwitchBcfResourceTest method testDeleteStaticNatRetryOnce.
@Test
public void testDeleteStaticNatRetryOnce() throws ConfigurationException, BigSwitchBcfApiException {
_resource.configure("BigSwitchBcfResource", _parameters);
when(_bigswitchBcfApi.deleteFloatingIp((String) any(), (String) any())).thenThrow(new BigSwitchBcfApiException()).thenReturn(UUID.randomUUID().toString());
DeleteBcfStaticNatCommand cmd = new DeleteBcfStaticNatCommand("tenantid", "10.4.4.100");
BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
assertTrue(ans.getResult());
}
use of com.cloud.agent.api.DeleteBcfStaticNatCommand in project cloudstack by apache.
the class BigSwitchBcfResourceTest method testDeleteStaticNatApiException.
@Test
public void testDeleteStaticNatApiException() throws ConfigurationException, BigSwitchBcfApiException {
_resource.configure("BigSwitchBcfResource", _parameters);
doThrow(new BigSwitchBcfApiException()).when(_bigswitchBcfApi).deleteFloatingIp((String) any(), (String) any());
DeleteBcfStaticNatCommand cmd = new DeleteBcfStaticNatCommand("tenantid", "10.4.4.100");
BcfAnswer ans = (BcfAnswer) _resource.executeRequest(cmd);
assertFalse(ans.getResult());
verify(_bigswitchBcfApi, times(3)).deleteFloatingIp((String) any(), (String) any());
}
Aggregations