bug 5800: add cluster for KVM

TODO: need to make sure the host cpu is from the same vender in a cluster
This commit is contained in:
edison 2010-09-10 15:57:01 -07:00
parent 55ebf465f6
commit d933f19d35
8 changed files with 28 additions and 34 deletions

View File

@ -40,10 +40,11 @@ backupdir = "@SHAREDSTATEDIR@/@AGENTPATH@/etcbackup"
try: try:
# parse cmd line # parse cmd line
opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod=", "no-kvm", "guid="]) opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod=", "cluster=", "no-kvm", "guid="])
host=None host=None
zone=None zone=None
pod=None pod=None
cluster=None
guid=None guid=None
autoMode=False autoMode=False
do_check_kvm = True do_check_kvm = True
@ -57,6 +58,9 @@ try:
elif opt == "--pod": elif opt == "--pod":
if arg != "": if arg != "":
pod = arg pod = arg
elif opt == "--cluster":
if arg != "":
cluster = arg
elif opt == "--guid": elif opt == "--guid":
if arg != "": if arg != "":
guid = arg guid = arg
@ -112,7 +116,7 @@ try:
stderr(str(e)) stderr(str(e))
bail(cloud_utils.E_SETUPFAILED,"Cloud Agent setup failed") bail(cloud_utils.E_SETUPFAILED,"Cloud Agent setup failed")
setup_agent_config(configfile, host, zone, pod, guid) setup_agent_config(configfile, host, zone, pod, cluster, guid)
stderr("Enabling and starting the Cloud Agent") stderr("Enabling and starting the Cloud Agent")
stop_service(servicename) stop_service(servicename)
enable_service(servicename) enable_service(servicename)

View File

@ -222,6 +222,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
private String _host; private String _host;
private String _dcId; private String _dcId;
private String _pod; private String _pod;
private String _clusterId;
private long _hvVersion; private long _hvVersion;
private final String _SSHKEYSPATH = "/root/.ssh"; private final String _SSHKEYSPATH = "/root/.ssh";
private final String _SSHPRVKEYPATH = _SSHKEYSPATH + File.separator + "id_rsa.cloud"; private final String _SSHPRVKEYPATH = _SSHKEYSPATH + File.separator + "id_rsa.cloud";
@ -561,8 +562,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
if (_pod == null) { if (_pod == null) {
_pod = "default"; _pod = "default";
} }
_clusterId = (String) params.get("cluster");
_createvnetPath = Script.findScript(networkScriptsDir, "createvnet.sh"); _createvnetPath = Script.findScript(networkScriptsDir, "createvnet.sh");
if(_createvnetPath == null) { if(_createvnetPath == null) {
throw new ConfigurationException("Unable to find createvnet.sh"); throw new ConfigurationException("Unable to find createvnet.sh");
@ -2559,6 +2561,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
fillNetworkInformation(cmd); fillNetworkInformation(cmd);
cmd.getHostDetails().putAll(getVersionStrings()); cmd.getHostDetails().putAll(getVersionStrings());
cmd.setPool(_pool); cmd.setPool(_pool);
cmd.setCluster(_clusterId);
return new StartupCommand[]{cmd}; return new StartupCommand[]{cmd};
} }

View File

@ -110,8 +110,9 @@
<dao name="GuestOSDao" class="com.cloud.storage.dao.GuestOSDaoImpl"/> <dao name="GuestOSDao" class="com.cloud.storage.dao.GuestOSDaoImpl"/>
<dao name="GuestOSCategoryDao" class="com.cloud.storage.dao.GuestOSCategoryDaoImpl"/> <dao name="GuestOSCategoryDao" class="com.cloud.storage.dao.GuestOSCategoryDaoImpl"/>
<dao name="ClusterDao" class="com.cloud.dc.dao.ClusterDaoImpl"/> <dao name="ClusterDao" class="com.cloud.dc.dao.ClusterDaoImpl"/>
<dao name="NetworkProfileDao" class="com.cloud.network.dao.NetworkProfileDaoImpl"/> <dao name="NetworkConfigurationDao" class="com.cloud.network.dao.NetworkConfigurationDaoImpl"/>
<dao name="NetworkOfferingDao" class="com.cloud.offerings.dao.NetworkOfferingDaoImpl"/> <dao name="NetworkOfferingDao" class="com.cloud.offerings.dao.NetworkOfferingDaoImpl"/>
<dao name="NicDao" class="com.cloud.vm.dao.NicDaoImpl"/>
<adapters key="com.cloud.agent.manager.allocator.HostAllocator"> <adapters key="com.cloud.agent.manager.allocator.HostAllocator">
<adapter name="FirstFitRouting" class="com.cloud.agent.manager.allocator.impl.FirstFitRoutingAllocator"/> <adapter name="FirstFitRouting" class="com.cloud.agent.manager.allocator.impl.FirstFitRoutingAllocator"/>

View File

@ -20,6 +20,7 @@ import com.cloud.vm.State;
public class KvmDummyResourceBase extends ServerResourceBase implements ServerResource { public class KvmDummyResourceBase extends ServerResourceBase implements ServerResource {
private String _zoneId; private String _zoneId;
private String _podId; private String _podId;
private String _clusterId;
private String _guid; private String _guid;
private String _agentIp; private String _agentIp;
@Override @Override
@ -33,6 +34,7 @@ public class KvmDummyResourceBase extends ServerResourceBase implements ServerRe
StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.Type.KVM, new HashMap<String, String>(), new HashMap<String, State>()); StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.Type.KVM, new HashMap<String, String>(), new HashMap<String, State>());
cmd.setDataCenter(_zoneId); cmd.setDataCenter(_zoneId);
cmd.setPod(_podId); cmd.setPod(_podId);
cmd.setCluster(_clusterId);
cmd.setGuid(_guid); cmd.setGuid(_guid);
cmd.setName(_agentIp); cmd.setName(_agentIp);
cmd.setPrivateIpAddress(_agentIp); cmd.setPrivateIpAddress(_agentIp);
@ -63,6 +65,7 @@ public class KvmDummyResourceBase extends ServerResourceBase implements ServerRe
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException { public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
_zoneId = (String)params.get("zone"); _zoneId = (String)params.get("zone");
_podId = (String)params.get("pod"); _podId = (String)params.get("pod");
_clusterId = (String)params.get("cluster");
_guid = (String)params.get("guid"); _guid = (String)params.get("guid");
_agentIp = (String)params.get("agentIp"); _agentIp = (String)params.get("agentIp");
return true; return true;

View File

@ -911,7 +911,7 @@ def prompt_for_hostpods(zonespods):
# this configures the agent # this configures the agent
def setup_agent_config(configfile, host, zone, pod, guid): def setup_agent_config(configfile, host, zone, pod, cluster, guid):
stderr("Examining Agent configuration") stderr("Examining Agent configuration")
fn = configfile fn = configfile
text = file(fn).read(-1) text = file(fn).read(-1)
@ -949,6 +949,7 @@ def setup_agent_config(configfile, host, zone, pod, guid):
else: else:
confopts["zone"] = zone confopts["zone"] = zone
confopts["pod"] = pod confopts["pod"] = pod
confopts["cluster"] = cluster
except (urllib2.URLError,urllib2.HTTPError),e: except (urllib2.URLError,urllib2.HTTPError),e:
stderr("Query failed: %s. Defaulting to zone %s pod %s",str(e),confopts["zone"],confopts["pod"]) stderr("Query failed: %s. Defaulting to zone %s pod %s",str(e),confopts["zone"],confopts["pod"])

View File

@ -126,7 +126,8 @@ cloud_agent_setup() {
local host=$1 local host=$1
local zone=$2 local zone=$2
local pod=$3 local pod=$3
local guid=$4 local cluster=$4
local guid=$5
# disable selinux # disable selinux
selenabled=`cat /selinux/enforce` selenabled=`cat /selinux/enforce`
if [ "$selenabled" == "1" ] if [ "$selenabled" == "1" ]
@ -134,7 +135,7 @@ cloud_agent_setup() {
sed -i 's/\(SELINUX\)\(.*\)/\1=permissive/' /etc/selinux/config sed -i 's/\(SELINUX\)\(.*\)/\1=permissive/' /etc/selinux/config
setenforce 0 setenforce 0
fi fi
cloud-setup-agent --host=$host --zone=$zone --pod=$pod --guid=$guid -a > /dev/null cloud-setup-agent --host=$host --zone=$zone --pod=$pod --cluster=$cluster --guid=$guid -a > /dev/null
} }
cloud_consoleP_setup() { cloud_consoleP_setup() {
@ -147,9 +148,10 @@ cloud_consoleP_setup() {
host= host=
zone= zone=
pod= pod=
cluster=
guid= guid=
dflag= dflag=
while getopts 'h:z:p:u:d' OPTION while getopts 'h:z:p:u:c:d' OPTION
do do
case $OPTION in case $OPTION in
h) h)
@ -161,6 +163,9 @@ do
p) p)
pod="$OPTARG" pod="$OPTARG"
;; ;;
c)
cluster="$OPTARG"
;;
u) u)
guid="$OPTARG" guid="$OPTARG"
;; ;;
@ -173,5 +178,5 @@ done
#install_cloud_agent $dflag #install_cloud_agent $dflag
#install_cloud_consoleP $dflag #install_cloud_consoleP $dflag
cloud_agent_setup $host $zone $pod $guid cloud_agent_setup $host $zone $pod $cluster $guid
#cloud_consoleP_setup $host $zone $pod #cloud_consoleP_setup $host $zone $pod

View File

@ -211,13 +211,14 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
SCPClient scp = new SCPClient(sshConnection); SCPClient scp = new SCPClient(sshConnection);
scp.put(_setupAgentPath, "/usr/bin", "0755"); scp.put(_setupAgentPath, "/usr/bin", "0755");
sshExecuteCmd(sshConnection, "/usr/bin/setup_agent.sh " + " -h " + _hostIp + " -z " + dcId + " -p " + podId + " -u " + guid + " 1>&2", 3); sshExecuteCmd(sshConnection, "/usr/bin/setup_agent.sh " + " -h " + _hostIp + " -z " + dcId + " -p " + podId + " -c " + clusterId + " -u " + guid + " 1>&2", 3);
KvmDummyResourceBase kvmResource = new KvmDummyResourceBase(); KvmDummyResourceBase kvmResource = new KvmDummyResourceBase();
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
params.put("zone", Long.toString(dcId)); params.put("zone", Long.toString(dcId));
params.put("pod", Long.toString(podId)); params.put("pod", Long.toString(podId));
params.put("cluster", Long.toString(clusterId));
params.put("guid", guid + "-LibvirtComputingResource"); /*tail added by agent.java*/ params.put("guid", guid + "-LibvirtComputingResource"); /*tail added by agent.java*/
params.put("agentIp", agentIp); params.put("agentIp", agentIp);
kvmResource.configure("kvm agent", params); kvmResource.configure("kvm agent", params);

View File

@ -33,10 +33,6 @@ function showHostsTab() {
var dialogAddRouting = $("#dialog_add_routing"); var dialogAddRouting = $("#dialog_add_routing");
//xenserver supports cluster. kvm doesn't support cluster.
if (getHypervisorType() == "kvm")
dialogAddRouting.find("#cluster_options_container, #new_cluster_radio_container, #existing_cluster_radio_container, #no_cluster_radio_container").hide();
$.ajax({ $.ajax({
data: createURL("command=listZones&available=true&response=json"+maxPageSize), data: createURL("command=listZones&available=true&response=json"+maxPageSize),
dataType: "json", dataType: "json",
@ -594,11 +590,6 @@ function showHostsTab() {
isValid &= validateString("Host name", dialogBox.find("#host_hostname"), dialogBox.find("#host_hostname_errormsg")); isValid &= validateString("Host name", dialogBox.find("#host_hostname"), dialogBox.find("#host_hostname_errormsg"));
isValid &= validateString("User name", dialogBox.find("#host_username"), dialogBox.find("#host_username_errormsg")); isValid &= validateString("User name", dialogBox.find("#host_username"), dialogBox.find("#host_username_errormsg"));
isValid &= validateString("Password", dialogBox.find("#host_password"), dialogBox.find("#host_password_errormsg")); isValid &= validateString("Password", dialogBox.find("#host_password"), dialogBox.find("#host_password_errormsg"));
//xenserver supports cluster. kvm doesn't support cluster.
if (getHypervisorType() != "kvm") {
if(clusterRadio == "new_cluster_radio")
isValid &= validateString("Cluster name", dialogBox.find("#new_cluster_name"), dialogBox.find("#new_cluster_name_errormsg"));
}
if (!isValid) return; if (!isValid) return;
var array1 = []; var array1 = [];
@ -615,21 +606,6 @@ function showHostsTab() {
var password = trim(dialogBox.find("#host_password").val()); var password = trim(dialogBox.find("#host_password").val());
array1.push("&password="+encodeURIComponent(password)); array1.push("&password="+encodeURIComponent(password));
//xenserver supports cluster. kvm doesn't support cluster.
if (getHypervisorType() != "kvm") {
if(clusterRadio == "new_cluster_radio") {
var newClusterName = trim(dialogBox.find("#new_cluster_name").val());
array1.push("&clustername="+encodeURIComponent(newClusterName));
}
else if(clusterRadio == "existing_cluster_radio") {
var clusterId = dialogBox.find("#cluster_select").val();
// We will default to no cluster if someone selects Join Cluster with no cluster available.
if (clusterId != '-1') {
array1.push("&clusterid="+clusterId);
}
}
}
var hostname = trim(dialogBox.find("#host_hostname").val()); var hostname = trim(dialogBox.find("#host_hostname").val());
var url; var url;
if(hostname.indexOf("http://")==-1) if(hostname.indexOf("http://")==-1)