Skip to content

Commit 4a40920

Browse files
committed
fix build for rhel6 and fix router default gw
1 parent 468ea1a commit 4a40920

3 files changed

Lines changed: 42 additions & 30 deletions

File tree

agent/src/com/cloud/agent/resource/computing/LibvirtCapXMLParser.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class LibvirtCapXMLParser extends LibvirtXMLParser {
3636
private boolean _osType = false;
3737
private boolean _domainTypeKVM = false;
3838
private boolean _emulatorFlag = false;
39-
private String _emulator ;
39+
private final StringBuffer _emulator = new StringBuffer() ;
4040
private final StringBuffer _capXML = new StringBuffer();
4141
private static final Logger s_logger = Logger.getLogger(LibvirtCapXMLParser.class);
4242
private final ArrayList<String> guestOsTypes = new ArrayList<String>();
@@ -53,6 +53,7 @@ public void endElement(String uri, String localName, String qName)
5353
_domainTypeKVM = false;
5454
} else if (qName.equalsIgnoreCase("emulator")) {
5555
_emulatorFlag = false;
56+
5657
} else if (_host) {
5758
_capXML.append("<").append("/").append(qName).append(">");
5859
}
@@ -65,7 +66,7 @@ public void characters(char[] ch, int start, int length) throws SAXException {
6566
} else if (_osType) {
6667
guestOsTypes.add(new String(ch, start, length));
6768
} else if (_emulatorFlag) {
68-
_emulator = new String(ch, start, length);
69+
_emulator.append(ch, start, length);
6970
}
7071
}
7172

@@ -90,6 +91,7 @@ public void startElement(String uri, String localName, String qName,
9091
}
9192
} else if (qName.equalsIgnoreCase("emulator") && _domainTypeKVM) {
9293
_emulatorFlag = true;
94+
_emulator.delete(0, _emulator.length());
9395
} else if (_host) {
9496
_capXML.append("<").append(qName);
9597
for (int i=0; i < attributes.getLength(); i++) {
@@ -120,7 +122,7 @@ public ArrayList<String> getGuestOsType() {
120122
}
121123

122124
public String getEmulator() {
123-
return _emulator;
125+
return _emulator.toString();
124126
}
125127

126128
public static void main(String [] args) {

patches/systemvm/debian/config/etc/init.d/cloud-early-config

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,13 @@ setup_common() {
180180
ip route add $MGMTNET via $LOCAL_GW dev eth1
181181
fi
182182

183-
ip route delete default
184-
ip route add default via $GW dev eth2
183+
ip route delete default
184+
if [ -n $3 ]
185+
then
186+
ip route add default via $GW dev $3
187+
else
188+
ip route add default via $GW dev eth1
189+
fi
185190
}
186191

187192
setup_dnsmasq() {

python/lib/cloud_utils.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
Fedora = 1
3535
CentOS = 2
3636
Ubuntu = 3
37+
RHEL6 = 4
3738

3839
IPV4 = 4
3940
IPV6 = 6
@@ -42,10 +43,14 @@
4243

4344
if os.path.exists("/etc/fedora-release"): distro = Fedora
4445
elif os.path.exists("/etc/centos-release"): distro = CentOS
45-
elif os.path.exists("/etc/redhat-release") and not os.path.exists("/etc/fedora-release"): distro = CentOS
46+
elif os.path.exists("/etc/redhat-release"):
47+
version = file("/etc/redhat-release").readline()
48+
if version.find("Red Hat Enterprise Linux Server release 6") != -1:
49+
distro = RHEL6
50+
elif version.find("Centos release") != -1:
51+
distro = CentOS
4652
elif os.path.exists("/etc/legal") and "Ubuntu" in file("/etc/legal").read(-1): distro = Ubuntu
4753
else: distro = Unknown
48-
4954
logFileName=None
5055
# ================== LIBRARY UTILITY CODE=============
5156
def setLogFile(logFile):
@@ -264,7 +269,7 @@ def check_hostname():
264269

265270
#check function
266271
def check_kvm():
267-
if distro in (Fedora,CentOS):
272+
if distro in (Fedora,CentOS,RHEL6):
268273
if os.path.exists("/dev/kvm"): return True
269274
raise CheckFailed("KVM is not correctly installed on this system, or support for it is not enabled in the BIOS")
270275
else:
@@ -284,7 +289,7 @@ def check_cgroups():
284289

285290
#check function
286291
def check_selinux():
287-
if distro not in [Fedora,CentOS]: return # no selinux outside of those
292+
if distro not in [Fedora,CentOS,RHEL6]: return # no selinux outside of those
288293
enforcing = False
289294
try:
290295
output = getenforce().stdout.strip()
@@ -365,7 +370,7 @@ def __init__(self,brname, pubNic, prvNic):
365370
self.runtime_state_changed = False
366371
self.was_nm_service_running = None
367372
self.was_net_service_running = None
368-
if distro in (Fedora, CentOS):
373+
if distro in (Fedora, CentOS, RHEL6):
369374
self.nmservice = 'NetworkManager'
370375
self.netservice = 'network'
371376
else:
@@ -376,7 +381,7 @@ def __init__(self,brname, pubNic, prvNic):
376381
def done(self):
377382
try:
378383
alreadysetup = False
379-
if distro in (Fedora,CentOS):
384+
if distro in (Fedora,CentOS, RHEL6):
380385
if self.pubNic != None:
381386
alreadysetup = alreadysetup or augtool._print("/files/etc/sysconfig/network-scripts/ifcfg-%s"%self.pubNic).stdout.strip()
382387
if self.prvNic != None:
@@ -463,30 +468,30 @@ def execute(self):
463468

464469
self.old_net_device = dev
465470

466-
if distro in (Fedora, CentOS):
471+
if distro in (Fedora, CentOS, RHEL6):
467472
inconfigfile = "/".join(augtool.match("/files/etc/sysconfig/network-scripts/*/DEVICE",dev).stdout.strip().split("/")[:-1])
468473
if not inconfigfile: raise TaskFailed("Device %s has not been set up in /etc/sysconfig/network-scripts"%dev)
469474
pathtoconfigfile = inconfigfile[6:]
470475

471-
if distro in (Fedora, CentOS):
476+
if distro in (Fedora, CentOS, RHEL6):
472477
automatic = augtool.match("%s/ONBOOT"%inconfigfile,"yes").stdout.strip()
473478
else:
474479
automatic = augtool.match("/files/etc/network/interfaces/auto/*/",dev).stdout.strip()
475480
if not automatic:
476481
if distro is Fedora: raise TaskFailed("Device %s has not been set up in %s as automatic on boot"%dev,pathtoconfigfile)
477482
else: raise TaskFailed("Device %s has not been set up in /etc/network/interfaces as automatic on boot"%dev)
478483

479-
if distro not in (Fedora , CentOS):
484+
if distro not in (Fedora , CentOS, RHEL6):
480485
inconfigfile = augtool.match("/files/etc/network/interfaces/iface",dev).stdout.strip()
481486
if not inconfigfile: raise TaskFailed("Device %s has not been set up in /etc/network/interfaces"%dev)
482487

483-
if distro in (Fedora, CentOS):
488+
if distro in (Fedora, CentOS, RHEL6):
484489
isstatic = augtool.match(inconfigfile + "/BOOTPROTO","none").stdout.strip()
485490
if not isstatic: isstatic = augtool.match(inconfigfile + "/BOOTPROTO","static").stdout.strip()
486491
else:
487492
isstatic = augtool.match(inconfigfile + "/method","static").stdout.strip()
488493
if not isstatic:
489-
if distro in (Fedora, CentOS): raise TaskFailed("Device %s has not been set up as a static device in %s"%(dev,pathtoconfigfile))
494+
if distro in (Fedora, CentOS, RHEL6): raise TaskFailed("Device %s has not been set up as a static device in %s"%(dev,pathtoconfigfile))
490495
else: raise TaskFailed("Device %s has not been set up as a static device in /etc/network/interfaces"%dev)
491496

492497
if is_service_running(self.nmservice):
@@ -503,7 +508,7 @@ def execute(self):
503508

504509
yield "Creating Cloud bridging device and making device %s member of this bridge"%dev
505510

506-
if distro in (Fedora, CentOS):
511+
if distro in (Fedora, CentOS, RHEL6):
507512
ifcfgtext = file(pathtoconfigfile).read()
508513
newf = "/etc/sysconfig/network-scripts/ifcfg-%s"%self.brname
509514
#def restore():
@@ -687,7 +692,7 @@ class SetupLibvirt(ConfigTask):
687692
cfgline = "export CGROUP_DAEMON='cpu:/virt'"
688693
def done(self):
689694
try:
690-
if distro in (Fedora,CentOS): libvirtfile = "/etc/sysconfig/libvirtd"
695+
if distro in (Fedora,CentOS, RHEL6): libvirtfile = "/etc/sysconfig/libvirtd"
691696
elif distro is Ubuntu: libvirtfile = "/etc/default/libvirt-bin"
692697
else: raise AssertionError, "We should not reach this"
693698
return self.cfgline in file(libvirtfile,"r").read(-1)
@@ -696,14 +701,14 @@ def done(self):
696701
raise
697702

698703
def execute(self):
699-
if distro in (Fedora,CentOS): libvirtfile = "/etc/sysconfig/libvirtd"
704+
if distro in (Fedora,CentOS, RHEL6): libvirtfile = "/etc/sysconfig/libvirtd"
700705
elif distro is Ubuntu: libvirtfile = "/etc/default/libvirt-bin"
701706
else: raise AssertionError, "We should not reach this"
702707
libvirtbin = file(libvirtfile,"r").read(-1)
703708
libvirtbin = libvirtbin + "\n" + self.cfgline + "\n"
704709
file(libvirtfile,"w").write(libvirtbin)
705710

706-
if distro in (CentOS, Fedora): svc = "libvirtd"
711+
if distro in (CentOS, Fedora, RHEL6): svc = "libvirtd"
707712
else: svc = "libvirt-bin"
708713
stop_service(svc)
709714
enable_service(svc)
@@ -731,7 +736,7 @@ def execute(self):
731736
startswith = stanza.split("=")[0] + '='
732737
replace_or_add_line("/etc/libvirt/libvirtd.conf",startswith,stanza)
733738

734-
if distro is Fedora:
739+
if distro in (Fedora, RHEL6):
735740
replace_or_add_line("/etc/sysconfig/libvirtd","LIBVIRTD_ARGS=","LIBVIRTD_ARGS=-l")
736741

737742
elif distro is Ubuntu:
@@ -743,7 +748,7 @@ def execute(self):
743748
else:
744749
raise AssertionError("Unsupported distribution")
745750

746-
if distro in (CentOS, Fedora): svc = "libvirtd"
751+
if distro in (CentOS, Fedora, RHEL6): svc = "libvirtd"
747752
else: svc = "libvirt-bin"
748753
stop_service(svc)
749754
enable_service(svc)
@@ -753,14 +758,14 @@ class SetupRequiredServices(ConfigTask):
753758
name = "required services setup"
754759

755760
def done(self):
756-
if distro is Fedora: nfsrelated = "rpcbind nfslock"
761+
if distro in (Fedora, RHEL6): nfsrelated = "rpcbind nfslock"
757762
elif distro is CentOS: nfsrelated = "portmap nfslock"
758763
else: return True
759764
return all( [ is_service_running(svc) for svc in nfsrelated.split() ] )
760765

761766
def execute(self):
762767

763-
if distro is Fedora: nfsrelated = "rpcbind nfslock"
768+
if distro in (Fedora, RHEL6): nfsrelated = "rpcbind nfslock"
764769
elif distro is CentOS: nfsrelated = "portmap nfslock"
765770
else: raise AssertionError("Unsupported distribution")
766771

@@ -772,7 +777,7 @@ class SetupFirewall(ConfigTask):
772777

773778
def done(self):
774779

775-
if distro in (Fedora, CentOS):
780+
if distro in (Fedora, CentOS,RHEL6):
776781
if not os.path.exists("/etc/sysconfig/iptables"): return True
777782
if ":on" not in chkconfig("--list","iptables").stdout: return True
778783
else:
@@ -784,7 +789,7 @@ def done(self):
784789

785790
def execute(self):
786791
ports = "22 1798 16509".split()
787-
if distro in (Fedora , CentOS):
792+
if distro in (Fedora , CentOS, RHEL6):
788793
for p in ports: iptables("-I","INPUT","1","-p","tcp","--dport",p,'-j','ACCEPT')
789794
o = service.iptables.save() ; print o.stdout + o.stderr
790795
else:
@@ -800,7 +805,7 @@ def __init__(self,brname):
800805

801806
def done(self):
802807

803-
if distro in (Fedora, CentOS):
808+
if distro in (Fedora, CentOS, RHEL6):
804809
if not os.path.exists("/etc/sysconfig/iptables"): return True
805810
if ":on" not in chkconfig("--list","iptables").stdout: return True
806811
rule = "FORWARD -i %s -o %s -j ACCEPT"%(self.brname,self.brname)
@@ -817,7 +822,7 @@ def execute(self):
817822

818823
yield "Permitting traffic in the bridge interface, migration port and for VNC ports"
819824

820-
if distro in (Fedora , CentOS):
825+
if distro in (Fedora , CentOS, RHEL6):
821826

822827
for rule in (
823828
"-I FORWARD -i %s -o %s -j ACCEPT"%(self.brname,self.brname),
@@ -856,7 +861,7 @@ def config_tasks(brname, pubNic, prvNic):
856861
SetupFirewall(),
857862
SetupFirewall2(brname),
858863
)
859-
elif distro in (Ubuntu,Fedora):
864+
elif distro in (Ubuntu,Fedora, RHEL6):
860865
config_tasks = (
861866
SetupNetworking(brname, pubNic, prvNic),
862867
SetupCgConfig(),
@@ -929,7 +934,7 @@ def prompt_for_hostpods(zonespods):
929934
def device_exist(devName):
930935
try:
931936
alreadysetup = False
932-
if distro in (Fedora,CentOS):
937+
if distro in (Fedora,CentOS, RHEL6):
933938
alreadysetup = augtool._print("/files/etc/sysconfig/network-scripts/ifcfg-%s"%devName).stdout.strip()
934939
else:
935940
alreadysetup = augtool.match("/files/etc/network/interfaces/iface",devName).stdout.strip()

0 commit comments

Comments
 (0)