Skip to content

Commit 5c73e46

Browse files
committed
bug 7296: add kvm.public.network.device and kvm.private.network.device from UI
status 7296: resolved fixed
1 parent 98eb58b commit 5c73e46

6 files changed

Lines changed: 99 additions & 15 deletions

File tree

agent/bindir/cloud-setup-agent.in

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ backupdir = "@SHAREDSTATEDIR@/@AGENTPATH@/etcbackup"
4040

4141
try:
4242
# parse cmd line
43-
opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod=", "cluster=", "no-kvm", "guid="])
43+
opts, args = getopt.getopt(sys.argv[1:], "a", ["host=", "zone=", "pod=", "cluster=", "no-kvm", "guid=", "pubNic=", "prvNic="])
4444
host=None
4545
zone=None
4646
pod=None
4747
cluster=None
4848
guid=None
49+
pubNic=None
50+
prvNic=None
4951
autoMode=False
5052
do_check_kvm = True
5153
for opt, arg in opts:
@@ -64,6 +66,10 @@ try:
6466
elif opt == "--guid":
6567
if arg != "":
6668
guid = arg
69+
elif opt == "--pubNic":
70+
pubNic = arg
71+
elif opt == "--prvNic":
72+
prvNic = arg
6773
elif opt == "--no-kvm":
6874
do_check_kvm = False
6975
elif opt == "-a":
@@ -89,7 +95,7 @@ try:
8995
# system configuration tasks that our Cloud Agent setup performs
9096

9197
try:
92-
tasks = cloud_utils.config_tasks(brname)
98+
tasks = cloud_utils.config_tasks(brname, pubNic, prvNic)
9399
for t in tasks:
94100
t.setAutoMode(autoMode)
95101
if all( [ t.done() for t in tasks ] ):
@@ -116,7 +122,7 @@ try:
116122
stderr(str(e))
117123
bail(cloud_utils.E_SETUPFAILED,"Cloud Agent setup failed")
118124

119-
setup_agent_config(configfile, host, zone, pod, cluster, guid)
125+
setup_agent_config(configfile, host, zone, pod, cluster, guid, pubNic, prvNic)
120126
stderr("Enabling and starting the Cloud Agent")
121127
stop_service(servicename)
122128
enable_service(servicename)

python/lib/cloud_utils.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,11 @@ def isAutoMode(self):
357357

358358
class SetupNetworking(ConfigTask):
359359
name = "network setup"
360-
def __init__(self,brname):
360+
def __init__(self,brname, pubNic, prvNic):
361361
ConfigTask.__init__(self)
362362
self.brname = brname
363+
self.pubNic = pubNic
364+
self.prvNic = prvNic
363365
self.runtime_state_changed = False
364366
self.was_nm_service_running = None
365367
self.was_net_service_running = None
@@ -373,10 +375,22 @@ def __init__(self,brname):
373375

374376
def done(self):
375377
try:
378+
alreadysetup = False
376379
if distro in (Fedora,CentOS):
377-
alreadysetup = augtool._print("/files/etc/sysconfig/network-scripts/ifcfg-%s"%self.brname).stdout.strip()
380+
if self.pubNic != None:
381+
alreadysetup = alreadysetup or augtool._print("/files/etc/sysconfig/network-scripts/ifcfg-%s"%self.pubNic).stdout.strip()
382+
if self.prvNic != None:
383+
alreadysetup = alreadysetup or augtool._print("/files/etc/sysconfig/network-scripts/ifcfg-%s"%self.prvNic).stdout.strip()
384+
if not alreadysetup:
385+
alreadysetup = augtool._print("/files/etc/sysconfig/network-scripts/ifcfg-%s"%self.brname).stdout.strip()
386+
378387
else:
379-
alreadysetup = augtool.match("/files/etc/network/interfaces/iface",self.brname).stdout.strip()
388+
if self.pubNic != None:
389+
alreadysetup = alreadysetup or augtool._print("/files/etc/network/interfaces/iface",self.pubNic).stdout.strip()
390+
if self.prvNic != None:
391+
alreadysetup = alreadysetup or augtool._print("/files/etc/network/interfaces/iface",self.prvNic).stdout.strip()
392+
if not alreadysetup:
393+
alreadysetup = augtool.match("/files/etc/network/interfaces/iface",self.brname).stdout.strip()
380394
return alreadysetup
381395
except OSError,e:
382396
if e.errno is 2: raise TaskFailed("augtool has not been properly installed on this system")
@@ -833,18 +847,18 @@ def execute(self):
833847

834848
# Tasks according to distribution -- at some point we will split them in separate modules
835849

836-
def config_tasks(brname):
850+
def config_tasks(brname, pubNic, prvNic):
837851
if distro is CentOS:
838852
config_tasks = (
839-
SetupNetworking(brname),
853+
SetupNetworking(brname, pubNic, prvNic),
840854
SetupLibvirt(),
841855
SetupRequiredServices(),
842856
SetupFirewall(),
843857
SetupFirewall2(brname),
844858
)
845859
elif distro in (Ubuntu,Fedora):
846860
config_tasks = (
847-
SetupNetworking(brname),
861+
SetupNetworking(brname, pubNic, prvNic),
848862
SetupCgConfig(),
849863
SetupCgRules(),
850864
SetupCgroupControllers(),
@@ -912,7 +926,18 @@ def prompt_for_hostpods(zonespods):
912926

913927
# this configures the agent
914928

915-
def setup_agent_config(configfile, host, zone, pod, cluster, guid):
929+
def device_exist(devName):
930+
try:
931+
alreadysetup = False
932+
if distro in (Fedora,CentOS):
933+
alreadysetup = augtool._print("/files/etc/sysconfig/network-scripts/ifcfg-%s"%devName).stdout.strip()
934+
else:
935+
alreadysetup = augtool.match("/files/etc/network/interfaces/iface",devName).stdout.strip()
936+
return alreadysetup
937+
except OSError,e:
938+
return False
939+
940+
def setup_agent_config(configfile, host, zone, pod, cluster, guid, pubNic, prvNic):
916941
stderr("Examining Agent configuration")
917942
fn = configfile
918943
text = file(fn).read(-1)
@@ -937,6 +962,16 @@ def setup_agent_config(configfile, host, zone, pod, cluster, guid):
937962

938963
confopts["host"] = host
939964

965+
if pubNic != None and device_exist(pubNic):
966+
confopts["public.network.device"] = pubNic
967+
if prvNic == None or not device_exist(prvNic):
968+
confopts["private.network.device"] = pubNic
969+
970+
if prvNic != None and device_exits(prvNic):
971+
confopts["private.network.device"] = prvNic
972+
if pubNic == None or not device_exits(pubNic):
973+
confopts["public.network.device"] = prvNic
974+
940975
stderr("Querying %s for zones and pods",host)
941976

942977
try:

scripts/vm/hypervisor/kvm/setup_agent.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ pod=
151151
cluster=
152152
guid=
153153
dflag=
154-
while getopts 'h:z:p:u:c:d' OPTION
154+
pubNic=
155+
prvNic=
156+
while getopts 'h:z:p:u:c:P:N:d' OPTION
155157
do
156158
case $OPTION in
157159
h)
@@ -172,11 +174,35 @@ do
172174
d)
173175
dflag=1
174176
;;
177+
P)
178+
pubNic="$OPTARG"
179+
;;
180+
N)
181+
prvNic="$OPTARG"
182+
;;
175183
*) ;;
176184
esac
177185
done
178186

179187
#install_cloud_agent $dflag
180188
#install_cloud_consoleP $dflag
181-
cloud_agent_setup $host $zone $pod $cluster $guid
189+
paramters=
190+
if [ -n "$pubNic" ]
191+
then
192+
paramters=" --pubNic=$pubNic"
193+
fi
194+
195+
if [ -n "$prvNic" ]
196+
then
197+
paramters=" --prvNic=$prvNic $paramters"
198+
fi
199+
200+
selenabled=`cat /selinux/enforce`
201+
if [ "$selenabled" == "1" ]
202+
then
203+
sed -i 's/\(SELINUX\)\(.*\)/\1=permissive/' /etc/selinux/config
204+
setenforce 0
205+
fi
206+
207+
cloud-setup-agent --host=$host --zone=$zone --pod=$pod --cluster=$cluster --guid=$guid $paramters -a > /dev/null
182208
#cloud_consoleP_setup $host $zone $pod

server/src/com/cloud/configuration/Config.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ public enum Config {
184184
VmwarePublicNetworkVSwitch("Advanced", ManagementServer.class, String.class, "vmware.public.vswitch", null, "Specify the vSwitch on host for public network", null),
185185
VmwareGuestNetworkVSwitch("Advanced", ManagementServer.class, String.class, "vmware.guest.vswitch", null, "Specify the vSwitch on host for guest network", null),
186186

187+
// KVM
188+
KvmPublicNetwork("Advanced", ManagementServer.class, String.class, "kvm.public.network.device", null, "Specify the public bridge on host for public network", null),
189+
KvmPrivateNetwork("Advanced", ManagementServer.class, String.class, "kvm.private.network.device", null, "Specify the private bridge on host for private network", null),
190+
187191
// Premium
188192

189193
UsageExecutionTimezone("Premium", ManagementServer.class, String.class, "usage.execution.timezone", null, "The timezone to use for usage job execution time", null),

server/src/com/cloud/hypervisor/kvm/discoverer/KvmServerDiscoverer.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.cloud.agent.api.Answer;
2121
import com.cloud.agent.api.Command;
2222
import com.cloud.agent.api.StartupCommand;
23+
import com.cloud.configuration.Config;
2324
import com.cloud.configuration.dao.ConfigurationDao;
2425
import com.cloud.dc.ClusterVO;
2526
import com.cloud.dc.dao.ClusterDao;
@@ -48,6 +49,8 @@ public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
4849
private ConfigurationDao _configDao;
4950
private String _hostIp;
5051
private int _waitTime = 5; /*wait for 5 minutes*/
52+
private String _kvmPrivateNic;
53+
private String _kvmPublicNic;
5154
@Inject HostDao _hostDao = null;
5255
@Inject ClusterDao _clusterDao;
5356

@@ -218,8 +221,18 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId,
218221
s_logger.debug("copying " + _setupAgentPath + " to host");
219222
SCPClient scp = new SCPClient(sshConnection);
220223
scp.put(_setupAgentPath, "/usr/bin", "0755");
224+
225+
String parameters = " -h " + _hostIp + " -z " + dcId + " -p " + podId + " -c " + clusterId + " -u " + guid;
226+
227+
if (_kvmPublicNic != null) {
228+
parameters += " -P " + _kvmPublicNic;
229+
}
230+
231+
if (_kvmPrivateNic != null) {
232+
parameters += " -N " + _kvmPrivateNic;
233+
}
221234

222-
sshExecuteCmd(sshConnection, "/usr/bin/setup_agent.sh " + " -h " + _hostIp + " -z " + dcId + " -p " + podId + " -c " + clusterId + " -u " + guid + " 1>&2", 3);
235+
sshExecuteCmd(sshConnection, "/usr/bin/setup_agent.sh " + parameters + " 1>&2", 3);
223236

224237
KvmDummyResourceBase kvmResource = new KvmDummyResourceBase();
225238
Map<String, Object> params = new HashMap<String, Object>();
@@ -276,6 +289,8 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
276289
ComponentLocator locator = ComponentLocator.getCurrentLocator();
277290
_configDao = locator.getDao(ConfigurationDao.class);
278291
_setupAgentPath = Script.findScript(getPatchPath(), "setup_agent.sh");
292+
_kvmPrivateNic = _configDao.getValue(Config.KvmPrivateNetwork.key());
293+
_kvmPublicNic = _configDao.getValue(Config.KvmPublicNetwork.key());
279294

280295
if (_setupAgentPath == null) {
281296
throw new ConfigurationException("Can't find setup_agent.sh");

wscript_configure

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ systemjars = {
3333
'Fedora':
3434
(
3535
"tomcat6-servlet-2.5-api.jar",
36-
"tomcat6-jsp-2.1-api-6.0.26.jar",
37-
"tomcat6-el-2.1-api-6.0.26.jar",
3836
#"tomcat6/catalina.jar", # all supported distros put the file there
3937
),
4038
'CentOS':

0 commit comments

Comments
 (0)