from custom_commands import desktop, micrepo, micboot, partition, installerfw
from mic.utils.safeurl import SafeURL
-
AUTH_URL_PTN = r"(?P<scheme>.*)://(?P<username>.*)(:?P<password>.*)?@(?P<url>.*)"
def wrapper(*kargs, **kwargs):
try:
func(*kargs, **kwargs)
- except (OSError, IOError, errors.KsError), err:
+ except (OSError, IOError, errors.KsError) as err:
cfgcls = kargs[0].__class__.__name__
if msger.ask("Failed to apply %s, skip and continue?" % cfgcls):
msger.warning("%s" % err)
try:
ks.readKickstart(path)
- except (kserrors.KickstartParseError, kserrors.KickstartError), err:
+ except (kserrors.KickstartParseError, kserrors.KickstartError) as err:
if msger.ask("Errors occured on kickstart file, skip and continue?"):
msger.warning("%s" % err)
pass
subprocess.call([lncmd, "-s",
self.path(tz_midst),
self.path(tz_dest)])
- except (IOError, OSError), (errno, msg):
+ except (IOError, OSError) as msg:
raise errors.KsError("Timezone setting error: %s" % msg)
class AuthConfig(KickstartConfig):
p1 = subprocess.Popen(["/bin/echo", "%s:%s" %(user, password)],
stdout = subprocess.PIPE,
preexec_fn = self.chroot)
- p2 = subprocess.Popen(["/usr/sbin/chpasswd", "-m"],
+ p2 = subprocess.Popen(["/usr/sbin/chpasswd", "-c","SHA512"],
stdin = p1.stdout,
stdout = subprocess.PIPE,
preexec_fn = self.chroot)
@apply_wrapper
def apply(self, user):
for userconfig in user.userList:
+ #There exist root user already.
+ if userconfig.name == "root":
+ msger.debug("root user, just set root user groups attribution")
+ if userconfig.groups:
+ self.call(["/usr/sbin/usermod", "-a", "-G", "%s" % string.join(userconfig.groups, ","), "root"])
+ continue
self.addUser(userconfig)
class ServicesConfig(KickstartConfig):
@apply_wrapper
def apply(self, ksxconfig):
if ksxconfig.startX and os.path.exists(self.path("/etc/inittab")):
- f = open(self.path("/etc/inittab"), "rw+")
+ f = open(self.path("/etc/inittab"), "r+")
buf = f.read()
buf = buf.replace("id:3:initdefault", "id:5:initdefault")
f.seek(0)
p = self.path("/etc/sysconfig/network-scripts/ifcfg-" + network.device)
f = file(p, "w+")
- os.chmod(p, 0644)
+ os.chmod(p, 0o644)
f.write("DEVICE=%s\n" % network.device)
f.write("BOOTPROTO=%s\n" % network.bootProto)
p = self.path("/etc/sysconfig/network-scripts/keys-" + network.device)
f = file(p, "w+")
- os.chmod(p, 0600)
+ os.chmod(p, 0o600)
f.write("KEY=%s\n" % network.wepkey)
f.close()
def write_sysconfig(self, useipv6, hostname, gateway):
path = self.path("/etc/sysconfig/network")
f = file(path, "w+")
- os.chmod(path, 0644)
+ os.chmod(path, 0o644)
f.write("NETWORKING=yes\n")
path = self.path("/etc/hosts")
f = file(path, "w+")
- os.chmod(path, 0644)
+ os.chmod(path, 0o644)
f.write("127.0.0.1\t\t%s\n" % localline)
f.write("::1\t\tlocalhost6.localdomain6 localhost6\n")
f.close()
path = self.path("/etc/resolv.conf")
f = file(path, "w+")
- os.chmod(path, 0644)
+ os.chmod(path, 0o644)
for ns in (nameservers):
if ns:
nameservers = network.nameserver.split(",")
self.write_sysconfig(useipv6, hostname, gateway)
- self.write_hosts(hostname)
+
+ #to avoid import error because of import each other
+ from mic.conf import configmgr
+ path=self.path("/etc/hosts")
+ if configmgr.create['skip_set_hosts'] == False and os.path.exists(path) == False:
+ self.write_hosts(hostname)
self.write_resolv(nodns, nameservers)
def use_installerfw(ks, feature):
if p.mountpoint == "/" and p.size:
__size = p.size
if __size > 0:
- return int(__size) * 1024L * 1024L
+ return int(__size) * 1024 * 1024
else:
return default