mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
1) Disabled updatePortForwardingRule api command.
2) Added vm information (id, name, display_text) to all port forwarding rule responses.
This commit is contained in:
parent
7270b2f285
commit
1f7d74dbec
@ -59,7 +59,7 @@ public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements Por
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
public Long getVirtualMachineId() {
|
||||
public long getVirtualMachineId() {
|
||||
return virtualMachineId;
|
||||
}
|
||||
|
||||
|
||||
@ -80,12 +80,12 @@ public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements
|
||||
public String getPublicPort() {
|
||||
return publicPort;
|
||||
}
|
||||
|
||||
public Long getVirtualMachineId() {
|
||||
|
||||
@Override
|
||||
public long getVirtualMachineId() {
|
||||
return virtualMachineId;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@ -46,6 +46,9 @@ public class FirewallRuleResponse extends BaseResponse {
|
||||
@SerializedName("ipaddress") @Param(description="the public ip address for the port forwarding rule")
|
||||
private String publicIpAddress;
|
||||
|
||||
@SerializedName("state") @Param(description="the state of the rule")
|
||||
private String state;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@ -109,4 +112,12 @@ public class FirewallRuleResponse extends BaseResponse {
|
||||
public void setPublicIpAddress(String publicIpAddress) {
|
||||
this.publicIpAddress = publicIpAddress;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,4 +37,9 @@ public interface PortForwardingRule extends FirewallRule {
|
||||
* @return end of destination port range
|
||||
*/
|
||||
int getDestinationPortEnd();
|
||||
|
||||
/**
|
||||
* @return destination ip address.
|
||||
*/
|
||||
long getVirtualMachineId();
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ listPublicIpAddresses=com.cloud.api.commands.ListPublicIpAddressesCmd;15
|
||||
listPortForwardingRules=com.cloud.api.commands.ListPortForwardingRulesCmd;15
|
||||
createPortForwardingRule=com.cloud.api.commands.CreatePortForwardingRuleCmd;15
|
||||
deletePortForwardingRule=com.cloud.api.commands.DeletePortForwardingRuleCmd;15
|
||||
updatePortForwardingRule=com.cloud.api.commands.UpdatePortForwardingRuleCmd;15
|
||||
#### updatePortForwardingRule=com.cloud.api.commands.UpdatePortForwardingRuleCmd;15
|
||||
|
||||
#### NAT commands
|
||||
createIpForwardingRule=com.cloud.api.commands.CreateIpForwardingRuleCmd;15
|
||||
|
||||
@ -100,6 +100,7 @@ import com.cloud.network.Network;
|
||||
import com.cloud.network.RemoteAccessVpn;
|
||||
import com.cloud.network.VpnUser;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.LoadBalancer;
|
||||
import com.cloud.network.rules.PortForwardingRule;
|
||||
import com.cloud.network.security.IngressRule;
|
||||
@ -138,8 +139,8 @@ import com.cloud.user.UserAccount;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.user.UserStatisticsVO;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.InstanceGroup;
|
||||
import com.cloud.vm.InstanceGroupVO;
|
||||
@ -1065,13 +1066,20 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
response.setPublicPort(Integer.toString(fwRule.getSourcePortStart()));
|
||||
response.setPublicIpAddress(fwRule.getSourceIpAddress().toString());
|
||||
if (fwRule.getSourceIpAddress() != null && fwRule.getDestinationIpAddress() != null) {
|
||||
UserVm vm = ApiDBUtils.findUserVmByPublicIpAndGuestIp(fwRule.getSourceIpAddress().toString(), fwRule.getDestinationIpAddress().toString());
|
||||
//UserVm vm = ApiDBUtils.findUserVmByPublicIpAndGuestIp(fwRule.getSourceIpAddress().toString(), fwRule.getDestinationIpAddress().toString());
|
||||
UserVm vm = ApiDBUtils.findUserVmById(fwRule.getVirtualMachineId());
|
||||
if(vm != null){
|
||||
response.setVirtualMachineId(vm.getId());
|
||||
response.setVirtualMachineName(vm.getHostName());
|
||||
response.setVirtualMachineDisplayName(vm.getDisplayName());
|
||||
}
|
||||
}
|
||||
FirewallRule.State state = fwRule.getState();
|
||||
String stateToSet = state.toString();
|
||||
if (state.equals(FirewallRule.State.Revoke)) {
|
||||
stateToSet = "Deleting";
|
||||
}
|
||||
response.setState(stateToSet);
|
||||
response.setObjectName("portforwardingrule");
|
||||
return response;
|
||||
}
|
||||
|
||||
@ -42,20 +42,24 @@ public class PortForwardingRuleVO extends FirewallRuleVO implements PortForwardi
|
||||
private int destinationPortStart;
|
||||
|
||||
@Column(name="dest_port_end")
|
||||
private int destinationPortEnd;
|
||||
private int destinationPortEnd;
|
||||
|
||||
@Column(name="instance_id")
|
||||
private long instanceId;
|
||||
|
||||
public PortForwardingRuleVO() {
|
||||
}
|
||||
|
||||
public PortForwardingRuleVO(String xId, Ip srcIp, int srcPortStart, int srcPortEnd, Ip dstIp, int dstPortStart, int dstPortEnd, String protocol, long networkId, long accountId, long domainId) {
|
||||
public PortForwardingRuleVO(String xId, Ip srcIp, int srcPortStart, int srcPortEnd, Ip dstIp, int dstPortStart, int dstPortEnd, String protocol, long networkId, long accountId, long domainId, long instanceId) {
|
||||
super(xId, srcIp, srcPortStart, srcPortEnd, protocol, networkId, accountId, domainId, Purpose.PortForwarding);
|
||||
this.destinationIpAddress = dstIp;
|
||||
this.instanceId = instanceId;
|
||||
this.destinationPortStart = dstPortStart;
|
||||
this.destinationPortEnd = dstPortEnd;
|
||||
}
|
||||
|
||||
public PortForwardingRuleVO(String xId, Ip srcIp, int srcPort, Ip dstIp, int dstPort, String protocol, long networkId, long accountId, long domainId) {
|
||||
this(xId, srcIp, srcPort, srcPort, dstIp, dstPort, dstPort, protocol, networkId, accountId, domainId);
|
||||
public PortForwardingRuleVO(String xId, Ip srcIp, int srcPort, Ip dstIp, int dstPort, String protocol, long networkId, long accountId, long domainId, long instanceId) {
|
||||
this(xId, srcIp, srcPort, srcPort, dstIp, dstPort, dstPort, protocol, networkId, accountId, domainId, instanceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -71,6 +75,11 @@ public class PortForwardingRuleVO extends FirewallRuleVO implements PortForwardi
|
||||
@Override
|
||||
public int getDestinationPortEnd() {
|
||||
return destinationPortEnd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVirtualMachineId() {
|
||||
return instanceId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -147,6 +147,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
IPAddressVO ipAddress = _ipAddressDao.findById(ipAddr);
|
||||
|
||||
Ip dstIp = rule.getDestinationIpAddress();
|
||||
Long instanceId = null;
|
||||
long networkId;
|
||||
UserVmVO vm = null;
|
||||
Network network = null;
|
||||
@ -156,7 +157,6 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
if (vm == null) {
|
||||
throw new InvalidParameterValueException("Unable to create ip forwarding rule on address " + ipAddress + ", invalid virtual machine id specified (" + vmId + ").");
|
||||
}
|
||||
|
||||
dstIp = null;
|
||||
List<? extends Nic> nics = _networkMgr.getNics(vm);
|
||||
for (Nic nic : nics) {
|
||||
@ -203,7 +203,7 @@ public class RulesManagerImpl implements RulesManager, RulesService, Manager {
|
||||
rule.getProtocol(),
|
||||
networkId,
|
||||
accountId,
|
||||
domainId);
|
||||
domainId, vmId);
|
||||
newRule = _forwardingDao.persist(newRule);
|
||||
|
||||
if (isNat) {
|
||||
|
||||
@ -489,6 +489,7 @@ CREATE TABLE `cloud`.`load_balancer_vm_map` (
|
||||
|
||||
CREATE TABLE `cloud`.`port_forwarding_rules` (
|
||||
`id` bigint unsigned NOT NULL COMMENT 'id',
|
||||
`instance_id` bigint unsigned NOT NULL COMMENT 'vm instance id',
|
||||
`dest_ip_address` bigint unsigned NOT NULL COMMENT 'id_address',
|
||||
`dest_port_start` int(10) NOT NULL COMMENT 'starting port of the port range to map to',
|
||||
`dest_port_end` int(10) NOT NULL COMMENT 'end port of the the port range to map to',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user