Esempio n. 1
0
def getStatus(rh):
    """
    Get the power (logon/off) status of a virtual machine.

    Input:
       Request Handle with the following properties:
          function    - 'POWERVM'
          subfunction - 'STATUS'
          userid      - userid of the virtual machine

    Output:
       Request Handle updated with the results.
       results['overallRC'] - 0: ok, non-zero: error
       if ok:
          results['rc'] - 0: for both on and off cases
          results['rs'] - 0: powered on
          results['rs'] - 1: powered off
    """

    rh.printSysLog("Enter powerVM.getStatus, userid: " + rh.userid)

    results = isLoggedOn(rh, rh.userid)
    if results['overallRC'] != 0:
        # Unexpected error
        pass
    elif results['rs'] == 0:
        rh.printLn("N", rh.userid + ": on")
    else:
        rh.printLn("N", rh.userid + ": off")

    rh.updateResults(results)

    rh.printSysLog("Exit powerVM.getStatus, rc: " +
                   str(rh.results['overallRC']))
    return rh.results['overallRC']
Esempio n. 2
0
def dedicate(rh):
    """
    Dedicate device.

    Input:
       Request Handle with the following properties:
          function    - 'CHANGEVM'
          subfunction - 'DEDICATEDM'
          userid      - userid of the virtual machine
          parms['vaddr']      - Virtual address
          parms['raddr']      - Real address
          parms['mode']       - Read only mode or not.

    Output:
       Request Handle updated with the results.
       Return code - 0: ok, non-zero: error
    """
    rh.printSysLog("Enter changeVM.dedicate")

    parms = [
        "-T", rh.userid,
        "-v", rh.parms['vaddr'],
        "-r", rh.parms['raddr'],
        "-R", rh.parms['mode']]

    hideList = []
    results = invokeSMCLI(rh,
                          "Image_Device_Dedicate_DM",
                          parms,
                          hideInLog=hideList)

    if results['overallRC'] != 0:
        # SMAPI API failed.
        rh.printLn("ES", results['response'])
        rh.updateResults(results)    # Use results from invokeSMCLI

    if results['overallRC'] == 0:
        results = isLoggedOn(rh, rh.userid)
        if (results['overallRC'] == 0 and results['rs'] == 0):
            # Dedicate device to active configuration.
            parms = [
                "-T", rh.userid,
                "-v", rh.parms['vaddr'],
                "-r", rh.parms['raddr'],
                "-R", rh.parms['mode']]

            results = invokeSMCLI(rh, "Image_Device_Dedicate", parms)
            if results['overallRC'] == 0:
                rh.printLn("N", "Dedicated device " + rh.parms['vaddr'] +
                    " to the active configuration.")
            else:
                # SMAPI API failed.
                rh.printLn("ES", results['response'])
                rh.updateResults(results)    # Use results from invokeSMCLI

    rh.printSysLog("Exit changeVM.dedicate, rc: " +
                   str(rh.results['overallRC']))
    return rh.results['overallRC']
Esempio n. 3
0
def removeDisk(rh):
    """
    Remove a disk from a virtual machine.

    Input:
       Request Handle with the following properties:
          function         - 'CHANGEVM'
          subfunction      - 'REMOVEDISK'
          userid           - userid of the virtual machine
          parms['vaddr']   - Virtual address

    Output:
       Request Handle updated with the results.
       Return code - 0: ok, non-zero: error
    """

    rh.printSysLog("Enter changeVM.removeDisk")

    results = {'overallRC': 0, 'rc': 0, 'rs': 0}

    # Is image logged on
    loggedOn = False
    results = isLoggedOn(rh, rh.userid)
    if results['overallRC'] == 0:
        if results['rs'] == 0:
            loggedOn = True

            results = disableEnableDisk(
                rh,
                rh.userid,
                rh.parms['vaddr'],
                '-d')
            if results['overallRC'] != 0:
                rh.printLn("ES", results['response'])
                rh.updateResults(results)

    if results['overallRC'] == 0 and loggedOn:
        strCmd = "/sbin/vmcp detach " + rh.parms['vaddr']
        results = execCmdThruIUCV(rh, rh.userid, strCmd)
        if results['overallRC'] != 0:
            if re.search('(^HCP\w\w\w040E)', results['response']):
                # Device does not exist, ignore the error
                results = {'overallRC': 0, 'rc': 0, 'rs': 0, 'response': ''}
            else:
                rh.printLn("ES", results['response'])
                rh.updateResults(results)

    if results['overallRC'] == 0:
        # Remove the disk from the user entry.
        parms = [
            "-T", rh.userid,
            "-v", rh.parms['vaddr'],
            "-e", "0"]

        results = invokeSMCLI(rh, "Image_Disk_Delete_DM", parms)
        if results['overallRC'] != 0:
            if (results['overallRC'] == 8 and results['rc'] == 208 and
                    results['rs'] == 36):
                # Disk does not exist, ignore the error
                results = {'overallRC': 0, 'rc': 0, 'rs': 0, 'response': ''}
            else:
                # SMAPI API failed.
                rh.printLn("ES", results['response'])
                rh.updateResults(results)    # Use results from invokeSMCLI

    else:
        # Unexpected error.  Message already sent.
        rh.updateResults(results)

    rh.printSysLog("Exit changeVM.removeDisk, rc: " +
        str(rh.results['overallRC']))
    return rh.results['overallRC']
Esempio n. 4
0
def add9336(rh):
    """
    Adds a 9336 (FBA) disk to virtual machine's directory entry.

    Input:
       Request Handle with the following properties:
          function    - 'CHANGEVM'
          subfunction - 'ADD9336'
          userid      - userid of the virtual machine
          parms['diskPool']   - Disk pool
          parms['diskSize']   - size of the disk in blocks or bytes.
          parms['fileSystem'] - Linux filesystem to install on the disk.
          parms['mode']       - Disk access mode
          parms['multiPW']    - Multi-write password
          parms['readPW']     - Read password
          parms['vaddr']      - Virtual address
          parms['writePW']    - Write password

    Output:
       Request Handle updated with the results.
       Return code - 0: ok, non-zero: error
    """

    rh.printSysLog("Enter changeVM.add9336")
    results, blocks = generalUtils.cvtToBlocks(rh, rh.parms['diskSize'])
    if results['overallRC'] != 0:
        # message already sent.  Only need to update the final results.
        rh.updateResults(results)

    if results['overallRC'] == 0:
        parms = [
            "-T", rh.userid,
            "-v", rh.parms['vaddr'],
            "-t", "9336",
            "-a", "AUTOG",
            "-r", rh.parms['diskPool'],
            "-u", "1",
            "-z", blocks,
            "-f", "1"]
        hideList = []

        if 'mode' in rh.parms:
            parms.extend(["-m", rh.parms['mode']])
        else:
            parms.extend(["-m", 'W'])
        if 'readPW' in rh.parms:
            parms.extend(["-R", rh.parms['readPW']])
            hideList.append(len(parms) - 1)
        if 'writePW' in rh.parms:
            parms.extend(["-W", rh.parms['writePW']])
            hideList.append(len(parms) - 1)
        if 'multiPW' in rh.parms:
            parms.extend(["-M", rh.parms['multiPW']])
            hideList.append(len(parms) - 1)

        results = invokeSMCLI(rh,
                              "Image_Disk_Create_DM",
                              parms,
                              hideInLog=hideList)

        if results['overallRC'] != 0:
            # SMAPI API failed.
            rh.printLn("ES", results['response'])
            rh.updateResults(results)    # Use results from invokeSMCLI

    if (results['overallRC'] == 0 and 'fileSystem' in rh.parms):
        # Install the file system
        results = installFS(
            rh,
            rh.parms['vaddr'],
            rh.parms['mode'],
            rh.parms['fileSystem'],
            "9336")

    if results['overallRC'] == 0:
        results = isLoggedOn(rh, rh.userid)
        if (results['overallRC'] == 0 and results['rs'] == 0):
            # Add the disk to the active configuration.
            parms = [
                "-T", rh.userid,
                "-v", rh.parms['vaddr'],
                "-m", rh.parms['mode']]

            results = invokeSMCLI(rh, "Image_Disk_Create", parms)
            if results['overallRC'] == 0:
                rh.printLn("N", "Added dasd " + rh.parms['vaddr'] +
                    " to the active configuration.")
            else:
                # SMAPI API failed.
                rh.printLn("ES", results['response'])
                rh.updateResults(results)    # Use results from invokeSMCLI

    rh.printSysLog("Exit changeVM.add9336, rc: " +
                   str(rh.results['overallRC']))
    return rh.results['overallRC']
Esempio n. 5
0
def getStatus(rh):
    """
    Get the basic status of a virtual machine.

    Input:
       Request Handle with the following properties:
          function    - 'CMDVM'
          subfunction - 'CMD'
          userid      - userid of the virtual machine

    Output:
       Request Handle updated with the results.
       Return code - 0: ok, non-zero: error
    """

    rh.printSysLog("Enter getVM.getStatus, userid: " + rh.userid)

    results = isLoggedOn(rh, rh.userid)
    if results['rc'] != 0:
        # Uhoh, can't determine if guest is logged on or not
        rh.updateResults(results)
        rh.printSysLog("Exit getVM.getStatus, rc: " +
                       str(rh.results['overallRC']))
        return rh.results['overallRC']

    if results['rs'] == 1:
        # Guest is logged off, everything is 0
        powerStr = "Power state: off"
        memStr = "Total Memory: 0M"
        usedMemStr = "Used Memory: 0M"
        procStr = "Processors: 0"
        timeStr = "CPU Used Time: 0 sec"

    else:
        powerStr = "Power state: on"

    if 'power' in rh.parms:
        # Test here to see if we only need power state
        # Then we can return early
        rh.printLn("N", powerStr)
        rh.updateResults(results)
        rh.printSysLog("Exit getVM.getStatus, rc: " +
                       str(rh.results['overallRC']))
        return rh.results['overallRC']

    if results['rs'] != 1:
        # Guest is logged on, go get more info
        results = getPerfInfo(rh, rh.userid)

        if results['overallRC'] != 0:
            # Something went wrong in subroutine, exit
            rh.updateResults(results)
            rh.printSysLog("Exit getVM.getStatus, rc: " +
                           str(rh.results['overallRC']))
            return rh.results['overallRC']
        else:
            # Everything went well, response should be good
            memStr = results['response'].split("\n")[0]
            usedMemStr = results['response'].split("\n")[1]
            procStr = results['response'].split("\n")[2]
            timeStr = results['response'].split("\n")[3]

    # Build our output string according
    # to what information was asked for
    if 'memory' in rh.parms:
        outStr = memStr + "\n" + usedMemStr
    elif 'cpu' in rh.parms:
        outStr = procStr + "\n" + timeStr
    else:
        # Default to all
        outStr = powerStr + "\n" + memStr + "\n" + usedMemStr
        outStr += "\n" + procStr + "\n" + timeStr
    rh.printLn("N", outStr)
    rh.printSysLog("Exit getVM.getStatus, rc: " + str(rh.results['overallRC']))
    return rh.results['overallRC']
Esempio n. 6
0
def deleteMachine(rh):
    """
    Delete a virtual machine from the user directory.

    Input:
       Request Handle with the following properties:
          function    - 'DELETEVM'
          subfunction - 'DIRECTORY'
          userid      - userid of the virtual machine to be deleted.

    Output:
       Request Handle updated with the results.
       Return code - 0: ok, non-zero: error
    """

    rh.printSysLog("Enter deleteVM.deleteMachine")

    results = {'overallRC': 0, 'rc': 0, 'rs': 0}

    # Is image logged on ?
    state = 'on'    # Assume 'on'.
    results = isLoggedOn(rh, rh.userid)
    if results['overallRC'] != 0:
        # Cannot determine the log on/off state.
        # Message already included.  Act as if it is 'on'.
        pass
    elif results['rs'] == 0:
        # State is powered on.
        pass
    else:
        state = 'off'
        # Reset values for rest of subfunction
        results['overallRC'] = 0
        results['rc'] = 0
        results['rs'] = 0

    if state == 'on':
        parms = ["-T", rh.userid, "-f IMMED"]
        results = invokeSMCLI(rh, "Image_Deactivate", parms)
        if results['overallRC'] == 0:
            pass
        elif (results['overallRC'] == 8 and results['rc'] == 200 and
            (results['rs'] == 12 or results['rs'] == 16)):
            # Tolerable error.  Machine is already in or going into the state
            # that we want it to enter.
            rh.updateResults({}, reset=1)
        else:
            # SMAPI API failed.
            rh.printLn("ES", results['response'])
            rh.updateResults(results)  # Use results returned by invokeSMCLI

    # Clean up the reader before delete
    if results['overallRC'] == 0:
        result = purgeReader(rh)
        if result['overallRC'] != 0:
            # Tolerable the purge failure error
            rh.updateResults({}, reset=1)

    if results['overallRC'] == 0:
        parms = ["-T", rh.userid, "-e", "0"]
        results = invokeSMCLI(rh, "Image_Delete_DM", parms)
        if results['overallRC'] != 0:
            # SMAPI API failed.
            rh.printLn("ES", results['response'])
            rh.updateResults(results)  # Use results returned by invokeSMCLI

    rh.printSysLog("Exit deleteVM.deleteMachine, rc: " +
        str(rh.results['overallRC']))
    return rh.results['overallRC']