return response;
}
@Override
public IpForwardingRuleResponse createIpForwardingRuleResponse(StaticNatRule fwRule) {
IpForwardingRuleResponse response = new IpForwardingRuleResponse();
response.setId(fwRule.getUuid());
response.setProtocol(fwRule.getProtocol());
IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId());
response.setPublicIpAddressId(ip.getId());
response.setPublicIpAddress(ip.getAddress().addr());
if (ip != null && fwRule.getDestIpAddress() != null) {
UserVm vm = ApiDBUtils.findUserVmById(ip.getAssociatedWithVmId());
if (vm != null) {// vm might be destroyed
response.setVirtualMachineId(vm.getUuid());
response.setVirtualMachineName(vm.getHostName());
if (vm.getDisplayName() != null) {
response.setVirtualMachineDisplayName(vm.getDisplayName());
} else {
response.setVirtualMachineDisplayName(vm.getHostName());
}
}
}
FirewallRule.State state = fwRule.getState();
String stateToSet = state.toString();
if (state.equals(FirewallRule.State.Revoke)) {
stateToSet = "Deleting";
}
response.setStartPort(fwRule.getSourcePortStart());
response.setEndPort(fwRule.getSourcePortEnd());
response.setProtocol(fwRule.getProtocol());
response.setState(stateToSet);
response.setObjectName("ipforwardingrule");
return response;
}