mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
cloudutils: fix adding rocky9 host failure due to missing /etc/sysconfig/libvirtd (#7779)
This commit is contained in:
parent
d958882282
commit
d89d40595c
@ -15,6 +15,7 @@
|
|||||||
# specific language governing permissions and limitations
|
# specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
import re
|
import re
|
||||||
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
from .utilities import bash
|
from .utilities import bash
|
||||||
@ -59,39 +60,42 @@ class configFileOps:
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
fp = open(self.fileName, "r")
|
|
||||||
newLines = []
|
newLines = []
|
||||||
for line in fp.readlines():
|
if os.path.exists(self.fileName) and os.path.isfile(self.fileName):
|
||||||
matched = False
|
fp = open(self.fileName, "r")
|
||||||
for entry in self.entries:
|
for line in fp.readlines():
|
||||||
if entry.op == "add":
|
matched = False
|
||||||
if entry.separator == "=":
|
for entry in self.entries:
|
||||||
matchString = "^\ *" + entry.name + ".*"
|
if entry.op == "add":
|
||||||
elif entry.separator == " ":
|
if entry.separator == "=":
|
||||||
matchString = "^\ *" + entry.name + "\ *" + entry.value
|
matchString = "^\ *" + entry.name + ".*"
|
||||||
else:
|
elif entry.separator == " ":
|
||||||
if entry.separator == "=":
|
matchString = "^\ *" + entry.name + "\ *" + entry.value
|
||||||
matchString = "^\ *" + entry.name + "\ *=\ *" + entry.value
|
|
||||||
else:
|
else:
|
||||||
matchString = "^\ *" + entry.name + "\ *" + entry.value
|
if entry.separator == "=":
|
||||||
|
matchString = "^\ *" + entry.name + "\ *=\ *" + entry.value
|
||||||
|
else:
|
||||||
|
matchString = "^\ *" + entry.name + "\ *" + entry.value
|
||||||
|
|
||||||
match = re.match(matchString, line)
|
match = re.match(matchString, line)
|
||||||
if match is not None:
|
if match is not None:
|
||||||
if entry.op == "add" and entry.separator == "=":
|
if entry.op == "add" and entry.separator == "=":
|
||||||
newline = "\n" + entry.name + "=" + entry.value + "\n"
|
newline = "\n" + entry.name + "=" + entry.value + "\n"
|
||||||
entry.setState("set")
|
entry.setState("set")
|
||||||
newLines.append(newline)
|
newLines.append(newline)
|
||||||
self.backups.append([line, newline])
|
self.backups.append([line, newline])
|
||||||
matched = True
|
matched = True
|
||||||
break
|
break
|
||||||
elif entry.op == "rm":
|
elif entry.op == "rm":
|
||||||
entry.setState("set")
|
entry.setState("set")
|
||||||
self.backups.append([line, None])
|
self.backups.append([line, None])
|
||||||
matched = True
|
matched = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if not matched:
|
if not matched:
|
||||||
newLines.append(line)
|
newLines.append(line)
|
||||||
|
|
||||||
|
fp.close()
|
||||||
|
|
||||||
for entry in self.entries:
|
for entry in self.entries:
|
||||||
if entry.getState() != "set":
|
if entry.getState() != "set":
|
||||||
@ -101,8 +105,6 @@ class configFileOps:
|
|||||||
self.backups.append([None, newline])
|
self.backups.append([None, newline])
|
||||||
entry.setState("set")
|
entry.setState("set")
|
||||||
|
|
||||||
fp.close()
|
|
||||||
|
|
||||||
open(self.fileName, "w").writelines(newLines)
|
open(self.fileName, "w").writelines(newLines)
|
||||||
|
|
||||||
def replace_line(self, startswith,stanza,always_add=False):
|
def replace_line(self, startswith,stanza,always_add=False):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user