bug 7296: add kvm.public.network.device and kvm.private.network.device from UI

status 7296: resolved fixed
This commit is contained in:
edison 2010-12-04 20:00:04 -08:00
parent 98eb58bf84
commit 5c73e46113
6 changed files with 99 additions and 15 deletions

View File

@ -40,12 +40,14 @@ backupdir = "@SHAREDSTATEDIR@/@AGENTPATH@/etcbackup"
try:
# parse cmd line
opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod=", "cluster=", "no-kvm", "guid="])
opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod=", "cluster=", "no-kvm", "guid=", "pubNic=", "prvNic="])
host=None
zone=None
pod=None
cluster=None
guid=None
pubNic=None
prvNic=None
autoMode=False
do_check_kvm = True
for opt, arg in opts:
@ -64,6 +66,10 @@ try:
elif opt == "--guid":
if arg != "":
guid = arg
elif opt == "--pubNic":
pubNic = arg
elif opt == "--prvNic":
prvNic = arg
elif opt == "--no-kvm":
do_check_kvm = False
elif opt == "-a":
@ -89,7 +95,7 @@ try:
# system configuration tasks that our Cloud Agent setup performs
try:
tasks = cloud_utils.config_tasks(brname)
tasks = cloud_utils.config_tasks(brname, pubNic, prvNic)
for t in tasks:
t.setAutoMode(autoMode)
if all( [ t.done() for t in tasks ] ):
@ -116,7 +122,7 @@ try:
stderr(str(e))
bail(cloud_utils.E_SETUPFAILED,"Cloud Agent setup failed")
setup_agent_config(configfile, host, zone, pod, cluster, guid)
setup_agent_config(configfile, host, zone, pod, cluster, guid, pubNic, prvNic)
stderr("Enabling and starting the Cloud Agent")
stop_service(servicename)
enable_service(servicename)

View File

@ -357,9 +357,11 @@ class ConfigTask:
class SetupNetworking(ConfigTask):
name = "network setup"
def __init__(self,brname):
def __init__(self,brname, pubNic, prvNic):
ConfigTask.__init__(self)
self.brname = brname
self.pubNic = pubNic
self.prvNic = prvNic
self.runtime_state_changed = False
self.was_nm_service_running = None
self.was_net_service_running = None
@ -373,10 +375,22 @@ class SetupNetworking(ConfigTask):
def done(self):
try:
alreadysetup = False
if distro in (Fedora,CentOS):
alreadysetup = augtool._print("/files/etc/sysconfig/network-scripts/ifcfg-%s"%self.brname).stdout.strip()
if self.pubNic != None:
alreadysetup = alreadysetup or augtool._print("/files/etc/sysconfig/network-scripts/ifcfg-%s"%self.pubNic).stdout.strip()
if self.prvNic != None:
alreadysetup = alreadysetup or augtool._print("/files/etc/sysconfig/network-scripts/ifcfg-%s"%self.prvNic).stdout.strip()
if not alreadysetup:
alreadysetup = augtool._print("/files/etc/sysconfig/network-scripts/ifcfg-%s"%self.brname).stdout.strip()
else:
alreadysetup = augtool.match("/files/etc/network/interfaces/iface",self.brname).stdout.strip()
if self.pubNic != None:
alreadysetup = alreadysetup or augtool._print("/files/etc/network/interfaces/iface",self.pubNic).stdout.strip()
if self.prvNic != None:
alreadysetup = alreadysetup or augtool._print("/files/etc/network/interfaces/iface",self.prvNic).stdout.strip()
if not alreadysetup:
alreadysetup = augtool.match("/files/etc/network/interfaces/iface",self.brname).stdout.strip()
return alreadysetup
except OSError,e:
if e.errno is 2: raise TaskFailed("augtool has not been properly installed on this system")
@ -833,10 +847,10 @@ class SetupFirewall2(ConfigTask):
# Tasks according to distribution -- at some point we will split them in separate modules
def config_tasks(brname):
def config_tasks(brname, pubNic, prvNic):
if distro is CentOS:
config_tasks = (
SetupNetworking(brname),
SetupNetworking(brname, pubNic, prvNic),
SetupLibvirt(),
SetupRequiredServices(),
SetupFirewall(),
@ -844,7 +858,7 @@ def config_tasks(brname):
)
elif distro in (Ubuntu,Fedora):
config_tasks = (
SetupNetworking(brname),
SetupNetworking(brname, pubNic, prvNic),
SetupCgConfig(),
SetupCgRules(),
SetupCgroupControllers(),
@ -912,7 +926,18 @@ def prompt_for_hostpods(zonespods):
# this configures the agent
def setup_agent_config(configfile, host, zone, pod, cluster, guid):
def device_exist(devName):
try:
alreadysetup = False
if distro in (Fedora,CentOS):
alreadysetup = augtool._print("/files/etc/sysconfig/network-scripts/ifcfg-%s"%devName).stdout.strip()
else:
alreadysetup = augtool.match("/files/etc/network/interfaces/iface",devName).stdout.strip()
return alreadysetup
except OSError,e:
return False
def setup_agent_config(configfile, host, zone, pod, cluster, guid, pubNic, prvNic):
stderr("Examining Agent configuration")
fn = configfile
text = file(fn).read(-1)
@ -937,6 +962,16 @@ def setup_agent_config(configfile, host, zone, pod, cluster, guid):
confopts["host"] = host
if pubNic != None and device_exist(pubNic):
confopts["public.network.device"] = pubNic
if prvNic == None or not device_exist(prvNic):
confopts["private.network.device"] = pubNic
if prvNic != None and device_exits(prvNic):
confopts["private.network.device"] = prvNic
if pubNic == None or not device_exits(pubNic):
confopts["public.network.device"] = prvNic
stderr("Querying %s for zones and pods",host)
try:

View File

@ -151,7 +151,9 @@ pod=
cluster=
guid=
dflag=
while getopts 'h:z:p:u:c:d' OPTION
pubNic=
prvNic=
while getopts 'h:z:p:u:c:P:N:d' OPTION
do
case $OPTION in
h)
@ -172,11 +174,35 @@ do
d)
dflag=1
;;
P)
pubNic="$OPTARG"
;;
N)
prvNic="$OPTARG"
;;
*) ;;
esac
done
#install_cloud_agent $dflag
#install_cloud_consoleP $dflag
cloud_agent_setup $host $zone $pod $cluster $guid
paramters=
if [ -n "$pubNic" ]
then
paramters=" --pubNic=$pubNic"
fi
if [ -n "$prvNic" ]
then
paramters=" --prvNic=$prvNic $paramters"
fi
selenabled=`cat /selinux/enforce`
if [ "$selenabled" == "1" ]
then
sed -i 's/\(SELINUX\)\(.*\)/\1=permissive/' /etc/selinux/config
setenforce 0
fi
cloud-setup-agent --host=$host --zone=$zone --pod=$pod --cluster=$cluster --guid=$guid $paramters -a > /dev/null
#cloud_consoleP_setup $host $zone $pod

View File

@ -184,6 +184,10 @@ public enum Config {
VmwarePublicNetworkVSwitch("Advanced", ManagementServer.class, String.class, "vmware.public.vswitch", null, "Specify the vSwitch on host for public network", null),
VmwareGuestNetworkVSwitch("Advanced", ManagementServer.class, String.class, "vmware.guest.vswitch", null, "Specify the vSwitch on host for guest network", null),
// KVM
KvmPublicNetwork("Advanced", ManagementServer.class, String.class, "kvm.public.network.device", null, "Specify the public bridge on host for public network", null),
KvmPrivateNetwork("Advanced", ManagementServer.class, String.class, "kvm.private.network.device", null, "Specify the private bridge on host for private network", null),
// Premium
UsageExecutionTimezone("Premium", ManagementServer.class, String.class, "usage.execution.timezone", null, "The timezone to use for usage job execution time", null),

View File

@ -20,6 +20,7 @@ import com.cloud.agent.api.AgentControlCommand;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.StartupCommand;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.dao.ClusterDao;
@ -48,6 +49,8 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
private ConfigurationDao _configDao;
private String _hostIp;
private int _waitTime = 5; /*wait for 5 minutes*/
private String _kvmPrivateNic;
private String _kvmPublicNic;
@Inject HostDao _hostDao = null;
@Inject ClusterDao _clusterDao;
@ -218,8 +221,18 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
s_logger.debug("copying " + _setupAgentPath + " to host");
SCPClient scp = new SCPClient(sshConnection);
scp.put(_setupAgentPath, "/usr/bin", "0755");
String parameters = " -h " + _hostIp + " -z " + dcId + " -p " + podId + " -c " + clusterId + " -u " + guid;
if (_kvmPublicNic != null) {
parameters += " -P " + _kvmPublicNic;
}
if (_kvmPrivateNic != null) {
parameters += " -N " + _kvmPrivateNic;
}
sshExecuteCmd(sshConnection, "/usr/bin/setup_agent.sh " + " -h " + _hostIp + " -z " + dcId + " -p " + podId + " -c " + clusterId + " -u " + guid + " 1>&2", 3);
sshExecuteCmd(sshConnection, "/usr/bin/setup_agent.sh " + parameters + " 1>&2", 3);
KvmDummyResourceBase kvmResource = new KvmDummyResourceBase();
Map<String, Object> params = new HashMap<String, Object>();
@ -276,6 +289,8 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
ComponentLocator locator = ComponentLocator.getCurrentLocator();
_configDao = locator.getDao(ConfigurationDao.class);
_setupAgentPath = Script.findScript(getPatchPath(), "setup_agent.sh");
_kvmPrivateNic = _configDao.getValue(Config.KvmPrivateNetwork.key());
_kvmPublicNic = _configDao.getValue(Config.KvmPublicNetwork.key());
if (_setupAgentPath == null) {
throw new ConfigurationException("Can't find setup_agent.sh");

View File

@ -33,8 +33,6 @@ systemjars = {
'Fedora':
(
"tomcat6-servlet-2.5-api.jar",
"tomcat6-jsp-2.1-api-6.0.26.jar",
"tomcat6-el-2.1-api-6.0.26.jar",
#"tomcat6/catalina.jar", # all supported distros put the file there
),
'CentOS':