New model for RemoteAccessVpn and moving into the new structure

This commit is contained in:
Sander Botman 2014-08-12 12:34:27 +02:00 committed by wilderrodrigues
parent caef7ee9a9
commit b4acd77abf
4 changed files with 122 additions and 27 deletions

View File

@ -23,10 +23,6 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.cloud.agent.api.BumpUpPriorityCommand;
import com.cloud.agent.api.SetupGuestNetworkCommand;
import com.cloud.agent.api.routing.CreateIpAliasCommand;
@ -69,6 +65,7 @@ import com.cloud.agent.resource.virtualnetwork.model.IpAliases;
import com.cloud.agent.resource.virtualnetwork.model.IpAssociation;
import com.cloud.agent.resource.virtualnetwork.model.NetworkACL;
import com.cloud.agent.resource.virtualnetwork.model.ProtocolAclRule;
import com.cloud.agent.resource.virtualnetwork.model.RemoteAccessVpn;
import com.cloud.agent.resource.virtualnetwork.model.Site2SiteVpn;
import com.cloud.agent.resource.virtualnetwork.model.StaticNatRule;
import com.cloud.agent.resource.virtualnetwork.model.StaticNatRules;
@ -87,6 +84,9 @@ import com.cloud.network.rules.FirewallRule;
import com.cloud.network.vpc.StaticRouteProfile;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class ConfigHelper {
private final static Gson gson;
@ -124,7 +124,7 @@ public class ConfigHelper {
} else if (cmd instanceof BumpUpPriorityCommand) {
cfg = generateConfig((BumpUpPriorityCommand)cmd);
} else if (cmd instanceof RemoteAccessVpnCfgCommand) {
cfg = generateConfig((RemoteAccessVpnCfgCommand)cmd);
cfg = generateConfig((RemoteAccessVpnCfgCommand)cmd); //WIP (SB)
} else if (cmd instanceof VpnUsersCfgCommand) {
cfg = generateConfig((VpnUsersCfgCommand)cmd); // Migrated (SB)
} else if (cmd instanceof Site2SiteVpnCfgCommand) {
@ -157,29 +157,21 @@ public class ConfigHelper {
return generateConfigItems(vpnUserList);
}
private static List<ConfigItem> generateConfig(RemoteAccessVpnCfgCommand cmd) {
LinkedList<ConfigItem> cfg = new LinkedList<>();
String args = "";
if (cmd.isCreate()) {
args += "-r ";
args += cmd.getIpRange();
args += " -p ";
args += cmd.getPresharedKey();
args += " -s ";
args += cmd.getVpnServerIp();
args += " -l ";
args += cmd.getLocalIp();
args += " -c ";
} else {
args += "-d ";
args += " -s ";
args += cmd.getVpnServerIp();
}
args += " -C " + cmd.getLocalCidr();
args += " -i " + cmd.getPublicInterface();
cfg.add(new ScriptConfigItem(VRScripts.VPN_L2TP, args));
return cfg;
/*
private static List<ConfigItem> generateConfig(DhcpEntryCommand cmd) {
VmDhcpConfig vmDhcpConfig = new VmDhcpConfig(cmd.getVmName(), cmd.getVmMac(), cmd.getVmIpAddress(), cmd.getVmIp6Address(), cmd.getDuid(), cmd.getDefaultDns(),
cmd.getDefaultRouter(), cmd.getStaticRoutes(), cmd.isDefault());
return generateConfigItems(vmDhcpConfig);
}
*/
private static List<ConfigItem> generateConfig(RemoteAccessVpnCfgCommand cmd) {
RemoteAccessVpn remoteAccessVpn = new RemoteAccessVpn(cmd.isCreate(), cmd.getIpRange(), cmd.getPresharedKey(), cmd.getVpnServerIp(), cmd.getLocalIp(), cmd.getLocalCidr(),
cmd.getPublicInterface());
return generateConfigItems(remoteAccessVpn);
}
private static List<ConfigItem> generateConfig(SetFirewallRulesCommand cmd) {
LinkedList<ConfigItem> cfg = new LinkedList<>();
@ -556,6 +548,9 @@ public class ConfigHelper {
case ConfigBase.SITE2SITEVPN:
destinationFile = VRScripts.SITE_2_SITE_VPN_CONFIG;
break;
case ConfigBase.REMOTEACCESSVPN:
destinationFile = VRScripts.REMOTE_ACCESS_VPN_CONFIG;
break;
default:
throw new CloudRuntimeException("Unable to process the configuration for " + configuration.getType());
}

View File

@ -32,6 +32,7 @@ public class VRScripts {
protected static final String STATICNAT_RULES_CONFIG = "staticnat_rules.json";
protected static final String SITE_2_SITE_VPN_CONFIG = "site_2_site_vpn.json";
protected static final String STATIC_ROUTES_CONFIG = "static_routes.json";
protected static final String REMOTE_ACCESS_VPN_CONFIG = "remote_access_vpn.json";
protected final static String CONFIG_CACHE_LOCATION = "/var/cache/cloud/";
protected final static int DEFAULT_EXECUTEINVR_TIMEOUT = 120; //Seconds

View File

@ -33,6 +33,7 @@ public abstract class ConfigBase {
public static final String IP_ALIAS_CONFIG = "ipaliases";
public static final String SITE2SITEVPN = "site2sitevpn";
public static final String STATIC_ROUTES = "staticroutes";
public static final String REMOTEACCESSVPN = "remoteaccessvpn";
private String type = UNKNOWN;

View File

@ -0,0 +1,98 @@
//
// 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.resource.virtualnetwork.model;
public class RemoteAccessVpn extends ConfigBase {
public boolean create;
public String ipRange, presharedKey, vpnServerIp, localIp, localCidr, publicInterface;
public RemoteAccessVpn() {
super(ConfigBase.REMOTEACCESSVPN);
}
public RemoteAccessVpn(boolean create, String ipRange, String presharedKey, String vpnServerIp, String localIp, String localCidr, String publicInterface) {
super(ConfigBase.REMOTEACCESSVPN);
this.create = create;
this.ipRange = ipRange;
this.presharedKey = presharedKey;
this.vpnServerIp = vpnServerIp;
this.localIp = localIp;
this.localCidr = localCidr;
this.publicInterface = publicInterface;
}
public boolean isCreate() {
return create;
}
public void setCreate(boolean create) {
this.create = create;
}
public String getIpRange() {
return ipRange;
}
public void setIpRange(String ipRange) {
this.ipRange = ipRange;
}
public String getPresharedKey() {
return presharedKey;
}
public void setPresharedKey(String presharedKey) {
this.presharedKey = presharedKey;
}
public String getVpnServerIp() {
return vpnServerIp;
}
public void setVpnServerIp(String vpnServerIp) {
this.vpnServerIp = vpnServerIp;
}
public String getLocalIp() {
return localIp;
}
public void setLocalIp(String localIp) {
this.localIp = localIp;
}
public String getLocalCidr() {
return localCidr;
}
public void setLocalCidr(String localCidr) {
this.localCidr = localCidr;
}
public String getPublicInterface() {
return publicInterface;
}
public void setPublicInterface(String publicInterface) {
this.publicInterface = publicInterface;
}
}