Beispiel #1
0
def _mergeNewUsers(oldFile, newFile):
    for userData in newFile:
        if not oldFile.hasName(userData.name):
            args = [
                "/usr/sbin/useradd",
                "-o",  # XXX ignore duplicate uids, see bug 278064
                "-c",
                userData.gecos,
                "-d",
                userData.dir,
                "-g",
                userData.gid,
                "-s",
                userData.shell,
                "-u",
                userData.uid,
                userData.name
            ]

            try:
                execWithLog(args[0], args, root=HOST_ROOT, raiseException=True)
            except Exception, e:
                raise InstallationError(
                    "Could not add user, '%s', from old installation." %
                    userData.name, e)
Beispiel #2
0
    def run(self, chroot="/"):
        path = "tmp/ks-script"

        openPath = os.path.join(chroot, path)
        if self.inChroot:
            execPath = os.path.join('/', path)
        else:
            execPath = openPath

        f = open(openPath, "w")
        f.write(self.script)
        f.close()
        os.chmod(openPath, 0700)

        cmd = [self.interp, execPath]

        if self.inChroot:
            execRoot = chroot
        else:
            execRoot = '/'

        try:
            rc = util.execWithLog(cmd[0],
                                  cmd,
                                  level=LOGLEVEL_HUMAN,
                                  root=execRoot,
                                  timeoutInSecs=self.timeoutInSecs,
                                  raiseException=(not self.ignoreFailure))
        except Exception, e:
            raise InstallationError("User-supplied script failed.", e)
Beispiel #3
0
    def formatDevice(self, devicePath=None, progress=None):
        args = ["/usr/sbin/mkswap", "-v1", devicePath]

        try:
            util.execWithLog(args[0], args, raiseException=True)
        except Exception, e:
            raise InstallationError("Could not format a linux swap partition.",
                                    e)
Beispiel #4
0
    def formatDevice(self, entry=None, progress=None, chroot='/'):
        raise RuntimeError, "Fat filesystem creation unimplemented."

        devicePath = "/tmp/foobar"
        args = ["/sbin/mkdosfs", devicePath]

        try:
            util.execWithLog(args[0], args, raiseException=True)
        except Exception, e:
            raise InstallationError("Could not format a DOS partition", e)
Beispiel #5
0
    def formatDevice(self, devicePath="", progress=None, chroot='/'):
        args = ["/usr/sbin/mkfs.ext2"]
        if self.label:
            args += ["-L", self.label]

        args += [devicePath]
        args.extend(self.extraFormatArgs)

        try:
            util.execWithLog(args[0], args, raiseException=True)
        except Exception, e:
            raise InstallationError("Could not format a linux partition.", e)
Beispiel #6
0
 def cbFileError(self, callbackArgs):
     if callbackArgs:
         package = callbackArgs[0]
         msg = "Unpack or CPIO error installing package %s" % \
               package.localLocation
     else:
         msg = "Unpack or CPIO error"
     #TODO: expand on the message of this error saying that there is a
     #      problem with the local storage that the user is installing onto
     #      or the CD that they burned is likely scratched / bad
     log.error(msg)
     raise InstallationError(msg)
Beispiel #7
0
    def mount(self):
        path = os.path.join("/vmfs/volumes", self.vmfsVolume, self.imagePath,
                            self.imageName)
        path = os.path.normpath(path)
        args = ["/usr/sbin/vsd", "-cu", "-f", path]

        try:
            devicePath = util.execWithCapture(args[0],
                                              args,
                                              raiseException=True)
        except Exception, e:
            raise InstallationError("Could not mount COS vmdk file.", e)
Beispiel #8
0
    def write(self):
        args = ["/usr/sbin/esxcfg-auth", "--kickstart", "--nostart"]
        # Set the required password complexity (see bug 359840)
        # XXX Need to keep in sync with visor parameters held here:
        #   bora/install/vmvisor/environ/etc/pam.d/common-password
        args += ["--usepamqc", "8", "8", "8", "7", "6", "0"]
        args += self.getArgList()

        try:
            execWithLog(args[0], args, root=HOST_ROOT, raiseException=True)
        except Exception, e:
            raise InstallationError("Could not set authentication method.", e)
Beispiel #9
0
def removeVmdkFile(vmdkPath):
    if os.path.exists(vmdkPath):
        # remove the vmdk file with vmkfstools first and then attempt
        # to remove the directory
        args = ["/usr/sbin/vmkfstools", "-U", vmdkPath]

        try:
            util.execWithLog(args[0], args, raiseException=True)
        except Exception, e:
            raise InstallationError("Could not delete old COS vmdk.", e)

        log.debug("Removing %s" % vmdkPath)
        shutil.rmtree(os.path.dirname(vmdkPath))
Beispiel #10
0
    def formatDevice(self, devicePath=None, progress=None):
        assert self.volumeName

        args = [
            "/usr/sbin/vmkfstools", "-C", self.name, "-b",
            "%dm" % self.blockSizeMB, "-S", self.volumeName, devicePath
        ]
        args.extend(self.extraFormatArgs)

        try:
            util.execWithLog(args[0], args, raiseException=True)
        except Exception, e:
            raise InstallationError("Could not format a vmfs volume.", e)
Beispiel #11
0
    def formatDevice(self, devicePath="", progress=None, chroot='/'):
        extFileSystem.formatDevice(self, devicePath, progress, chroot)

        # XXX - crufty hack for ext3
        os.system('touch /etc/mtab')

        # XXX - add back -Odir_index when htree is safe
        args = ["/usr/sbin/tune2fs", "-c0", "-i0", "-j", devicePath]

        try:
            util.execWithLog(args[0], args, raiseException=True)
        except Exception, e:
            raise InstallationError(
                "Could not enable journalling on a linux partition.", e)
Beispiel #12
0
    def mount(self,
              device,
              mountPoint,
              readOnly=False,
              bindMount=False,
              loopMount=False):

        #if not self.isMountable():
        #    print "Couldn't mount %s" % (device)
        #    return

        status = util.mount(device, mountPoint, readOnly, bindMount, loopMount)
        if status:
            raise InstallationError("Could not mount '%s' onto '%s'." %
                                    (device, mountPoint))
Beispiel #13
0
def _normalizeUsers(oldFile):
    '''Performs extra migrations steps for users.  Ensures that non-pseudo-users
    have a home directory under /home and their shell is sane.'''
    for userData in oldFile:
        log.debug("migrating user -- %s" % userData.name)

        if userData.shell == "/sbin/nologin":
            # XXX remove me?
            log.debug("  not normalizing pseudo-user")
            continue

        newHomeDir = os.path.join(HOST_ROOT, userData.dir.lstrip('/'))
        oldHomeDir = os.path.join(ESX3_INSTALLATION, userData.dir.lstrip('/'))

        if os.path.exists(newHomeDir):
            log.debug("  user dir already exists in new install, skipping...")
            continue
        if not os.path.exists(os.path.join(HOST_ROOT, oldHomeDir.lstrip('/'))):
            log.debug("  user dir does not exist in old install, skipping...")
            continue

        expectedDir = "/home/%s" % userData.name
        if userData.dir != expectedDir:
            log.warn("changing home directory path for %s to %s" %
                     (userData.name, expectedDir))
            userData.dir = expectedDir
            newHomeDir = os.path.join(HOST_ROOT, expectedDir.lstrip('/'))
            args = ["/usr/sbin/usermod", "-d", expectedDir, userData.name]

            execWithLog(args[0], args, root=HOST_ROOT, raiseException=True)

        shellPath = os.path.join(HOST_ROOT, userData.shell.lstrip('/'))
        if not os.path.exists(shellPath):
            oldShell = userData.shell
            userData.shell = "/bin/bash"
            log.warn("unknown user shell, %s, switching to %s" %
                     (oldShell, userData.shell))
            args = ["/usr/sbin/usermod", "-s", userData.shell, userData.name]

            try:
                execWithLog(args[0], args, root=HOST_ROOT, raiseException=True)
            except Exception, e:
                raise InstallationError("Could not change user shell.", e)

        _copyTreeForUser(os.path.join(HOST_ROOT, "etc/skel"),
                         HOST_ROOT + userData.dir, int(userData.uid),
                         int(userData.gid))
        os.symlink(oldHomeDir, os.path.join(newHomeDir, "esx3-home"))
Beispiel #14
0
    def create(self):
        assert self.vmfsVolume

        path = os.path.join("/vmfs/volumes", self.vmfsVolume, self.imagePath)

        fullPath = os.path.normpath(os.path.join(path, self.imageName))

        # remove any existing vmdk file first
        removeVmdkFile(fullPath)

        if not os.path.exists(path):
            os.makedirs(path)

        args = ["/usr/sbin/vmkfstools", "-c", "%dM" % (self.size, ), fullPath]

        try:
            util.execWithLog(args[0], args, raiseException=True)
        except Exception, e:
            raise InstallationError("Could not create new COS vmdk.", e)
Beispiel #15
0
def hostAction(_context):
    choices = userchoices.getESXFirewall()

    if choices:
        if choices['incoming'] == userchoices.ESXFIREWALL_ALLOW:
            incomingFlag = "--allowIncoming"
        else:
            incomingFlag = "--blockIncoming"
        if choices['outgoing'] == userchoices.ESXFIREWALL_ALLOW:
            outgoingFlag = "--allowOutgoing"
        else:
            outgoingFlag = "--blockOutgoing"

        try:
            util.execCommand("/usr/sbin/esxcfg-firewall %s %s" %
                             (incomingFlag, outgoingFlag),
                             root=HOST_ROOT,
                             raiseException=True)
        except Exception, e:
            raise InstallationError("Could not change global firewall rules.",
                                    e)
Beispiel #16
0
        else:
            args += [
                "--closePort",
                "%(number)s,%(protocol)s,%(direction)s" % rule
            ]

        # esxcfg-firewall fails if --closePort is used on an already closed port
        try:
            util.execWithLog(args[0],
                             args,
                             root=HOST_ROOT,
                             raiseException=True)
        except util.ExecError, e:
            if rule['state'] == userchoices.PORT_STATE_OPEN:
                raise InstallationError(
                    "Could not %(state)s port %(number)s in the firewall." %
                    rule, e)
        except Exception, e:
            raise InstallationError(
                "Could not %(state)s port %(number)s in the firewall." % rule,
                e)

    serviceRules = userchoices.getServiceRules()

    # If we've set the time from an NTP server, we also need to open port 123
    isNTP = bool(userchoices.getTimedate().get('ntpServer'))
    if isNTP:
        # TODO: a user-specified NTP service rule should trump this implicit
        # setting however this shouldn't come up in Kandinsky because
        # scripted install doesn't let you set the ntp server, and the
        # GUI / Text installs don't let you set up firewall rules
Beispiel #17
0
 def umount(self, mountPoint):
     status = util.umount(mountPoint)
     if status:
         raise InstallationError("Could not unmount '%s'." % mountPoint)
Beispiel #18
0
class VirtualDiskDev(DiskDev):
    '''A class for vmdk container'''
    def __init__(self,
                 name,
                 size=5500,
                 imagePath='',
                 imageName='',
                 physicalDeviceName=None,
                 vmfsVolume=None):

        # XXX isinstance(str) is not py3k compliant.
        assert physicalDeviceName is None or isinstance(
            physicalDeviceName, str)

        DiskDev.__init__(self,
                         name,
                         size=size,
                         deviceExists=False,
                         probePartitions=False,
                         sectorSize=1,
                         sizeUnit='MB')

        self.imagePath = imagePath
        if imageName:
            self.imageName = imageName
        else:
            self.imageName = DEFAULT_COS_IMAGE
        self.physicalDeviceName = physicalDeviceName
        self.vmfsVolume = vmfsVolume

        self.stable = True

        if not self.imagePath:
            # The default vmdk path includes the system UUID so it will be
            # unique on shared storage.
            self.imagePath = \
                fsset.vmfs3FileSystem.systemUniqueName('esxconsole')

            log.info("creating virtualdisk %s/%s" %
                     (self.imagePath, self.imageName))
        else:
            # XXX - do we want to raise something here if ValueError is
            #       raised?
            pass

    def create(self):
        assert self.vmfsVolume

        path = os.path.join("/vmfs/volumes", self.vmfsVolume, self.imagePath)

        fullPath = os.path.normpath(os.path.join(path, self.imageName))

        # remove any existing vmdk file first
        removeVmdkFile(fullPath)

        if not os.path.exists(path):
            os.makedirs(path)

        args = ["/usr/sbin/vmkfstools", "-c", "%dM" % (self.size, ), fullPath]

        try:
            util.execWithLog(args[0], args, raiseException=True)
        except Exception, e:
            raise InstallationError("Could not create new COS vmdk.", e)
        '''
        Add a disk database entry that will allow upper layers to know this
        is a cos disk.
        '''
        try:
            fh = open(fullPath, "a")
            fh.write('ddb.consoleOsDisk = "True"\n')
            fh.close()
        except Exception, e:
            raise InstallationError("Could not bless COS vmdk.", e)