コード例 #1
0
def ejectCdrom():
    if not os.path.exists(CDROM_DEVICE_PATH):
        # The drive is empty.
        return

    cmd = ["/usr/bin/eject"]
    util.execWithCapture(cmd[0], cmd, timeoutInSecs=10)
コード例 #2
0
ファイル: pciidlib.py プロジェクト: vmware/weasel
    def scanSystem(self, pciClass=''):
        '''Scan the pci id's on the system

           >>> x = PciDeviceSet()
           >>> x.scanSystem()
        '''
        import util

        pciTable = util.execWithCapture(LSPCI_PATH, [LSPCI_PATH, '-n'])

        #  NOTE:  this does not currently populate the sub-device id info

        for entry in pciTable.split('\n'):
            pciEntry = entry.split(' ')

            if len(pciEntry) >= 3:
                devPciClass = pciEntry[PCI_CLASS].strip(':')

                if pciClass and pciClass != devPciClass:
                    # only search for the pci class we're looking for
                    continue

                pciText = formatPciId(pciEntry[PCI_ID])
                vendorId, deviceId = pciText.split()

                self.devices[pciText] = \
                    PciDevice(vendorId, deviceId, pciClass=devPciClass)
コード例 #3
0
    def scanSystem(self, pciClass=''):
        '''Scan the pci id's on the system

           >>> x = PciDeviceSet()
           >>> x.scanSystem()
        '''
        import util

        pciTable = util.execWithCapture(LSPCI_PATH, [LSPCI_PATH, '-n'])

        #  NOTE:  this does not currently populate the sub-device id info

        for entry in pciTable.split('\n'):
            pciEntry = entry.split(' ')

            if len(pciEntry) >= 3:
                devPciClass = pciEntry[PCI_CLASS].strip(':')

                if pciClass and pciClass != devPciClass:
                    # only search for the pci class we're looking for
                    continue

                pciText = formatPciId(pciEntry[PCI_ID])
                vendorId, deviceId = pciText.split()

                self.devices[pciText] = \
                    PciDevice(vendorId, deviceId, pciClass=devPciClass)
コード例 #4
0
ファイル: devices.py プロジェクト: vmware/weasel
    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)
コード例 #5
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)
コード例 #6
0
ファイル: script.py プロジェクト: vmware/weasel
def tidyAction():
    # Kill the udevd process since it has files open in the installed system.
    args = ["/mnt/sysimage/sbin/pidof", "-x", "udevd"]
    if os.path.exists(args[0]):
        out = util.execWithCapture(args[0], args)
        try:
            pid = int(out)
            os.kill(pid, signal.SIGTERM)
            time.sleep(1)
        except ValueError:
            # not running
            pass
        except OSError:
            # kill failed, oh well...
            pass
コード例 #7
0
ファイル: script.py プロジェクト: vmware-archive/weasel
def tidyAction():
    # Kill the udevd process since it has files open in the installed system.
    args = ["/mnt/sysimage/sbin/pidof", "-x", "udevd"]
    if os.path.exists(args[0]):
        out = util.execWithCapture(args[0], args)
        try:
            pid = int(out)
            os.kill(pid, signal.SIGTERM)
            time.sleep(1)
        except ValueError:
            # not running
            pass
        except OSError:
            # kill failed, oh well...
            pass
コード例 #8
0
def hostActionLoadDrivers(context):
    global DRIVERS_LOADED

    if DRIVERS_LOADED:
        return

    uiHook = context.cb

    # when in rome...
    f = open('/tmp/initscripts.sh', 'w')
    f.write(FIND_INIT_SCRIPTS)
    f.close()

    initScripts = util.execWithCapture('/bin/bash',
                                       ['/bin/bash', '/tmp/initscripts.sh'])
    initScripts = initScripts.split()

    units = len(initScripts)
    uiHook.pushStatusGroup(units)

    criticalFailure = False

    scriptsFailed = []
    log.info("Starting driver load ...")
    for script in initScripts:
        script = os.path.basename(script)

        if _findBaseInitLevel(script) < INIT_START_LEVEL:
            continue

        log.info("Loading %s" % script)
        uiHook.pushStatus("Loading %s" % script)
        rc, stdout, stderr = \
            execCommand("cd / && INSTALLER=1 %s %s" % (INIT_WRAPPER, script))

        if rc == 1:
            warningMessage = "The script %s returned status 1" % script
            log.warning(warningMessage)
        elif rc == 2:
            errorMessage = "A non-critical error has happened in the " + \
                    "script %s.  The installation can continue " % script + \
                    "but you may experience reduced functionality."
            log.error(errorMessage)
            scriptsFailed.append(script)
        elif rc == 3:
            errorMessage = "The script %s failed to execute " % (script) + \
                           "and the installation can not continue."
            criticalFailure = True
            break
        elif rc:
            errorMessage = "An unexpected error occurred in the " + \
                           "script %s." % script
            criticalFailure = True
            break

        uiHook.popStatus()

    if criticalFailure:
        log.error(errorMessage)
        uiHook.popStatus()
        uiHook.popStatusGroup()
        raise CriticalScriptLoadError(errorMessage)

    # XXX should be done by the init scripts...  the device nodes will get
    # created implicitly by devices.DiskSet() but not everything that needs
    # a device node goes through there.
    import partition
    partition.createDeviceNodes()

    DRIVERS_LOADED = True

    uiHook.popStatusGroup()

    if scriptsFailed:
        messageText = SCRIPT_ERROR_MSG % ", ".join(scriptsFailed)
        raise ScriptLoadError(messageText)
コード例 #9
0
ファイル: customdrivers.py プロジェクト: vmware/weasel
def hostActionLoadDrivers(context):
    global DRIVERS_LOADED

    if DRIVERS_LOADED:
        return

    uiHook = context.cb

    # when in rome...
    f = open("/tmp/initscripts.sh", "w")
    f.write(FIND_INIT_SCRIPTS)
    f.close()

    initScripts = util.execWithCapture("/bin/bash", ["/bin/bash", "/tmp/initscripts.sh"])
    initScripts = initScripts.split()

    units = len(initScripts)
    uiHook.pushStatusGroup(units)

    criticalFailure = False

    scriptsFailed = []
    log.info("Starting driver load ...")
    for script in initScripts:
        script = os.path.basename(script)

        if _findBaseInitLevel(script) < INIT_START_LEVEL:
            continue

        log.info("Loading %s" % script)
        uiHook.pushStatus("Loading %s" % script)
        rc, stdout, stderr = execCommand("cd / && INSTALLER=1 %s %s" % (INIT_WRAPPER, script))

        if rc == 1:
            warningMessage = "The script %s returned status 1" % script
            log.warning(warningMessage)
        elif rc == 2:
            errorMessage = (
                "A non-critical error has happened in the "
                + "script %s.  The installation can continue " % script
                + "but you may experience reduced functionality."
            )
            log.error(errorMessage)
            scriptsFailed.append(script)
        elif rc == 3:
            errorMessage = "The script %s failed to execute " % (script) + "and the installation can not continue."
            criticalFailure = True
            break
        elif rc:
            errorMessage = "An unexpected error occurred in the " + "script %s." % script
            criticalFailure = True
            break

        uiHook.popStatus()

    if criticalFailure:
        log.error(errorMessage)
        uiHook.popStatus()
        uiHook.popStatusGroup()
        raise CriticalScriptLoadError(errorMessage)

    # XXX should be done by the init scripts...  the device nodes will get
    # created implicitly by devices.DiskSet() but not everything that needs
    # a device node goes through there.
    import partition

    partition.createDeviceNodes()

    DRIVERS_LOADED = True

    uiHook.popStatusGroup()

    if scriptsFailed:
        messageText = SCRIPT_ERROR_MSG % ", ".join(scriptsFailed)
        raise ScriptLoadError(messageText)