New style save password command

This commit is contained in:
Hugo Trippaers 2014-08-07 11:17:26 +02:00 committed by wilderrodrigues
parent bda4c0d2c9
commit 3ab83fdba7
5 changed files with 70 additions and 19 deletions

View File

@ -69,6 +69,7 @@ import com.cloud.agent.resource.virtualnetwork.model.TcpAclRule;
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.network.HAProxyConfigurator;
import com.cloud.network.LoadBalancerConfigurator;
import com.cloud.network.rules.FirewallRule;
@ -95,7 +96,7 @@ public class ConfigHelper {
} else if (cmd instanceof LoadBalancerConfigCommand) {
cfg = generateConfig((LoadBalancerConfigCommand)cmd);
} else if (cmd instanceof SavePasswordCommand) {
cfg = generateConfig((SavePasswordCommand)cmd);
cfg = generateConfig((SavePasswordCommand)cmd); // Migrated
} else if (cmd instanceof DhcpEntryCommand) {
cfg = generateConfig((DhcpEntryCommand)cmd); // Migrated
} else if (cmd instanceof CreateIpAliasCommand) {
@ -327,16 +328,9 @@ public class ConfigHelper {
}
private static List<ConfigItem> generateConfig(SavePasswordCommand cmd) {
LinkedList<ConfigItem> cfg = new LinkedList<>();
VmPassword vmPassword = new VmPassword(cmd.getVmIpAddress(), cmd.getPassword());
final String password = cmd.getPassword();
final String vmIpAddress = cmd.getVmIpAddress();
String args = "-v " + vmIpAddress;
args += " -p " + password;
cfg.add(new ScriptConfigItem(VRScripts.PASSWORD, args));
return cfg;
return generateConfigItems(vmPassword);
}
private static List<ConfigItem> generateConfig(DhcpEntryCommand cmd) {
@ -618,21 +612,24 @@ public class ConfigHelper {
String destinationFile;
switch (configuration.getType()) {
case ConfigBase.DHCP_ENTRY:
destinationFile = VRScripts.DHCP_ENTRY_CONFIG;
case ConfigBase.GUEST_NETWORK:
destinationFile = VRScripts.GUEST_NETWORK_CONFIG;
break;
case ConfigBase.IP_ASSOCIATION:
destinationFile = VRScripts.IP_ASSOCIATION_CONFIG;
break;
case ConfigBase.GUEST_NETWORK:
destinationFile = VRScripts.GUEST_NETWORK_CONFIG;
break;
case ConfigBase.NETWORK_ACL:
destinationFile = VRScripts.NETWORK_ACL_CONFIG;
break;
case ConfigBase.VM_DHCP:
destinationFile = VRScripts.VM_DHCP_CONFIG;
break;
case ConfigBase.VM_METADATA:
destinationFile = VRScripts.VM_METADATA_CONFIG;
break;
case ConfigBase.VM_PASSWORD:
destinationFile = VRScripts.VM_PASSWORD_CONFIG;
break;
default:
throw new CloudRuntimeException("Unable to process the configuration for " + configuration.getType());
}

View File

@ -25,7 +25,8 @@ public class VRScripts {
protected final static String GUEST_NETWORK_CONFIG = "guest_network.json";
protected final static String NETWORK_ACL_CONFIG = "network_acl.json";
protected final static String VM_METADATA_CONFIG = "vm_metadata.json";
protected final static String DHCP_ENTRY_CONFIG = "vm_dhcp_entry.json";
protected final static String VM_DHCP_CONFIG = "vm_dhcp_entry.json";
protected final static String VM_PASSWORD_CONFIG = "vm_password.json";
protected final static String CONFIG_CACHE_LOCATION = "/var/cache/cloud/";
protected final static int DEFAULT_EXECUTEINVR_TIMEOUT = 120; //Seconds

View File

@ -21,11 +21,12 @@ package com.cloud.agent.resource.virtualnetwork.model;
public abstract class ConfigBase {
public final static String UNKNOWN = "unknown";
public final static String DHCP_ENTRY = "dhcpentry";
public final static String VM_DHCP = "dhcpentry";
public final static String IP_ASSOCIATION = "ips";
public final static String GUEST_NETWORK = "guestnetwork";
public static final String NETWORK_ACL = "networkacl";
public static final String VM_METADATA = "vmdata";
public static final String VM_PASSWORD = "vmpassword";
private String type = UNKNOWN;

View File

@ -31,12 +31,12 @@ public class VmDhcpConfig extends ConfigBase {
private boolean defaultEntry;
public VmDhcpConfig() {
setType(DHCP_ENTRY);
setType(VM_DHCP);
}
public VmDhcpConfig(String hostName, String macAddress, String ipv4Adress, String ipv6Address, String ipv6Duid, String dnsAdresses, String defaultGateway,
String staticRoutes, boolean defaultEntry) {
setType(DHCP_ENTRY);
setType(VM_DHCP);
this.hostName = hostName;
this.macAddress = macAddress;
this.ipv4Adress = ipv4Adress;

View File

@ -0,0 +1,52 @@
//
// 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 VmPassword extends ConfigBase {
private String ipAddress;
private String password;
public VmPassword() {
setType(ConfigBase.VM_PASSWORD);
}
public VmPassword(String ipAddress, String password) {
setType(ConfigBase.VM_PASSWORD);
this.ipAddress = ipAddress;
this.password = password;
}
public String getIpAddress() {
return ipAddress;
}
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}