mirror of https://github.com/apache/cloudstack.git
New style manage VPN user command <Still need some testing with the VR image>
This commit is contained in:
parent
2aed586bfc
commit
f423f3ea4e
|
|
@ -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;
|
||||
|
|
@ -72,11 +68,16 @@ import com.cloud.agent.resource.virtualnetwork.model.UdpAclRule;
|
|||
import com.cloud.agent.resource.virtualnetwork.model.VmData;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.VmDhcpConfig;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.VmPassword;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.VpnUser;
|
||||
import com.cloud.agent.resource.virtualnetwork.model.VpnUserList;
|
||||
import com.cloud.network.HAProxyConfigurator;
|
||||
import com.cloud.network.LoadBalancerConfigurator;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
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;
|
||||
|
|
@ -116,7 +117,7 @@ public class ConfigHelper {
|
|||
} else if (cmd instanceof RemoteAccessVpnCfgCommand) {
|
||||
cfg = generateConfig((RemoteAccessVpnCfgCommand)cmd);
|
||||
} else if (cmd instanceof VpnUsersCfgCommand) {
|
||||
cfg = generateConfig((VpnUsersCfgCommand)cmd);
|
||||
cfg = generateConfig((VpnUsersCfgCommand)cmd); // Migrated
|
||||
} else if (cmd instanceof Site2SiteVpnCfgCommand) {
|
||||
cfg = generateConfig((Site2SiteVpnCfgCommand)cmd);
|
||||
} else if (cmd instanceof SetMonitorServiceCommand) {
|
||||
|
|
@ -135,20 +136,16 @@ public class ConfigHelper {
|
|||
return cfg;
|
||||
}
|
||||
|
||||
|
||||
private static List<ConfigItem> generateConfig(VpnUsersCfgCommand cmd) {
|
||||
LinkedList<ConfigItem> cfg = new LinkedList<>();
|
||||
|
||||
List<VpnUser> vpnUsers = new LinkedList<VpnUser>();
|
||||
for (VpnUsersCfgCommand.UsernamePassword userpwd : cmd.getUserpwds()) {
|
||||
String args = "";
|
||||
if (!userpwd.isAdd()) {
|
||||
args += "-U ";
|
||||
args += userpwd.getUsername();
|
||||
} else {
|
||||
args += "-u ";
|
||||
args += userpwd.getUsernamePassword();
|
||||
}
|
||||
cfg.add(new ScriptConfigItem(VRScripts.VPN_L2TP, args));
|
||||
vpnUsers.add(new VpnUser(userpwd.getUsername(), userpwd.getPassword(), userpwd.isAdd()));
|
||||
}
|
||||
return cfg;
|
||||
|
||||
VpnUserList vpnUserList = new VpnUserList(vpnUsers);
|
||||
return generateConfigItems(vpnUserList);
|
||||
}
|
||||
|
||||
private static List<ConfigItem> generateConfig(RemoteAccessVpnCfgCommand cmd) {
|
||||
|
|
@ -615,6 +612,9 @@ public class ConfigHelper {
|
|||
case ConfigBase.VM_PASSWORD:
|
||||
destinationFile = VRScripts.VM_PASSWORD_CONFIG;
|
||||
break;
|
||||
case ConfigBase.VPN_USER_LIST:
|
||||
destinationFile = VRScripts.VPN_USER_LIST_CONFIG;
|
||||
break;
|
||||
default:
|
||||
throw new CloudRuntimeException("Unable to process the configuration for " + configuration.getType());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ public class VRScripts {
|
|||
protected final static String VM_DHCP_CONFIG = "vm_dhcp_entry.json";
|
||||
protected final static String VM_PASSWORD_CONFIG = "vm_password.json";
|
||||
protected static final String FORWARDING_RULES_CONFIG = "forwarding_rules.json";
|
||||
protected static final String VPN_USER_LIST_CONFIG = "vpn_user_list.json";
|
||||
|
||||
protected final static String CONFIG_CACHE_LOCATION = "/var/cache/cloud/";
|
||||
protected final static int DEFAULT_EXECUTEINVR_TIMEOUT = 120; //Seconds
|
||||
|
|
@ -66,4 +67,5 @@ public class VRScripts {
|
|||
protected static final String VPN_L2TP = "vpn_l2tp.sh";
|
||||
|
||||
protected static final String VR_CFG = "vr_cfg.sh";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ public abstract class ConfigBase {
|
|||
public static final String VM_METADATA = "vmdata";
|
||||
public static final String VM_PASSWORD = "vmpassword";
|
||||
public static final String FORWARDING_RULES = "forwardrules";
|
||||
public static final String VPN_USER_LIST = "vpnuserlist";
|
||||
|
||||
private String type = UNKNOWN;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
//
|
||||
// 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 VpnUser {
|
||||
private String user;
|
||||
private String password;
|
||||
private boolean add;
|
||||
|
||||
public VpnUser() {
|
||||
// Empty constructor for serialization
|
||||
}
|
||||
|
||||
public VpnUser(String user, String password, boolean add) {
|
||||
super();
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
this.add = add;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public boolean isAdd() {
|
||||
return add;
|
||||
}
|
||||
|
||||
public void setAdd(boolean add) {
|
||||
this.add = add;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
//
|
||||
// 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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VpnUserList extends ConfigBase {
|
||||
private List<VpnUser> vpnUsers;
|
||||
|
||||
public VpnUserList() {
|
||||
super(ConfigBase.VPN_USER_LIST);
|
||||
}
|
||||
|
||||
public VpnUserList(List<VpnUser> vpnUsers) {
|
||||
super(ConfigBase.VPN_USER_LIST);
|
||||
this.vpnUsers = vpnUsers;
|
||||
}
|
||||
|
||||
public List<VpnUser> getVpnUsers() {
|
||||
return vpnUsers;
|
||||
}
|
||||
|
||||
public void setVpnUsers(List<VpnUser> vpnUsers) {
|
||||
this.vpnUsers = vpnUsers;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue