Beispiel #1
0
   def DoIt(self, host, vm, variable, value):
      """
      This operation can set arbitrary key/value pairs for a VM
      running VMware Tools.

      This data is stored in the config.extraConfig VMODL property.

      Examples:

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getguestinfo marc
      getguestinfo(marc) = 101

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' setguestinfo marc 102
      setguestinfo(marc, 102) = success

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getguestinfo marc
      getguestinfo(marc) = 102

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getguestinfo abc
      None

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' setguestinfo abc def
      setguestinfo(abc, def) = success

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getguestinfo abc
      getguestinfo(abc) = def
      """

      vm = Operation.GetVm(host, vm)

      extraConfig = vm.GetExtraConfig()
      extraConfig['guestinfo.%s' % variable] = value

      return extraConfig.Save()
Beispiel #2
0
    def DoIt(self, host, vm, variable, value):
        """
      @todo Currently, this is only handling config items that map to
      extraConfig so this is not complete. It needs to handle config
      items that map to specialized VMODL properties.

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig annotation
      getconfig(annotation) = 'jhu VC 2.5 VM'

      [Bugs]

      ### ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' setconfig annotation xyz
      None

      ### ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig annotation
      getconfig(annotation) = 'jhu VC 2.5 VM'

      @todo Cannot do setconfig on annotation
      """

        vm = Operation.GetVm(host, vm)

        extraConfig = vm.GetExtraConfig()
        if variable in extraConfig:
            extraConfig[variable] = value
            return extraConfig.Save()
Beispiel #3
0
    def DoIt(self, host, vm, name, description, quiesce, memory):
        """
      Example:

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 hassnapshot
      hassnapshot() = 0

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 createsnapshot test_snapshot 'a test snapshot' 1 1
      createsnapshot(test_snapshot, a test snapshot, 1, 1) = success

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 hassnapshot
      hassnapshot() = 1
      """
        """
      print('### CreateSnapshot.DoIt: ' +
            'vm = %s; ' % vm +
            'name = "%s"; ' % name +
            'description = "%s"; ' % description +
            'quiesce = %s; ' % bool(int(quiesce)) +
            'memory = %s; ' % bool(int(memory)))
      """

        vm = Operation.GetVm(host, vm)

        memory = self.GetParamValue(memory, 'memory')
        quiesce = self.GetParamValue(quiesce, 'quiesce')
        return vm.CreateSnapshot(name, description, memory, quiesce)
Beispiel #4
0
    def DoIt(self, host, vm):
        """
      Example:

      $ ./vmware-cmd2 -H sdk167 deletevm mabramow-test3
      ???
      """

        vm = Operation.GetVm(host, vm)

        return vm.Destroy()
Beispiel #5
0
   def DoIt(self, host, vm):
      """
      Example:

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getstate
      getstate() = off
      """

      vm = Operation.GetVm(host, vm)

      return vm.powerState
Beispiel #6
0
    def DoIt(self, host, vm):
        """
      Example:

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfigfile
      getconfigfile() = /vmfs/volumes/44ee4eb7-28601011-5305-000e0c6dbc76/VirtualCenter 2.5 VM/VirtualCenter 2.5 VM.vmx
      """

        vm = Operation.GetVm(host, vm)

        return vm.localPath
Beispiel #7
0
    def DoIt(self, host, *args):
        if len(args) >= 2:
            vm = Operation.GetVm(host, args[0])
            entity = vm.managedObject
            variable = args[-1]
            instance = variable.split('.')[-2]
        else:
            entity = host.hostSystem
            variable = args[-1]
            instance = ''

        return self.GetResourceHelper(host, entity, instance, variable)
Beispiel #8
0
   def DoIt(self, host, vm):
      """
      Example:

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' gettoolslastactive
      gettoolslastactive() = 1
      """

      vm = Operation.GetVm(host, vm)

      status = vm.GetGuestHeartbeatStatus()

      return self.FakeLastActiveCountFromHeartbeatColor(status)
Beispiel #9
0
    def DoIt(self, host, vm):
        """
      Example:

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getheartbeat
      332
      """

        vm = Operation.GetVm(host, vm)

        status = vm.GetGuestHeartbeatStatus()

        return self.FakeHeartbeatTimeFromStatus(vm, status)
Beispiel #10
0
    def DoIt(self, host, vm):
        """
      Example:

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getuptime
      getuptime() = 17066128
      """

        vm = Operation.GetVm(host, vm)

        perfManager = host.perfManager

        return GetResource().GetCounterById(perfManager,
                                            entity=vm.managedObject,
                                            instance='',
                                            counterId=COUNTER_ID_UPTIME)
Beispiel #11
0
   def DoIt(self, host, vm, variable=None):
      """
      Gets information about the vm's guest operating system, such as
      the guest's IP address, or gets the value of a key/value pair
      that was set by the user (e.g.: using the"setguestinfo" operation).

      Examples:

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getguestinfo ip
      getguestinfo(ip) = 10.17.40.249

      (More examples in the docs for "setguestinfo").
      """

      vm = Operation.GetVm(host, vm)

      return GetConfig().DoIt(host, vm, 'guestinfo.%s' % variable)
Beispiel #12
0
    def DoIt(self, host, vm):
        """
      Example:

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 hassnapshot
      hassnapshot() = 1

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 removesnapshots
      removesnapshots() = success

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 hassnapshot
      hassnapshot() = 0
      """

        vm = Operation.GetVm(host, vm)

        return vm.RemoveAllSnapshots()
Beispiel #13
0
    def DoIt(self, host, vm, powerOpMode='soft'):
        vm = Operation.GetVm(host, vm)

        if powerOpMode == 'soft':
            return self.SoftPowerOp(vm)
        elif powerOpMode == 'trysoft':
            try:
                return self.SoftPowerOp(vm)
            except:
                if self.HardPowerOp != self.SoftPowerOp:
                    return self.HardPowerOp(vm)
                else:
                    raise
        elif powerOpMode == 'hard':
            return self.HardPowerOp(vm)
        else:
            raise RuntimeError('Invalid power operation mode: %s' %
                               powerOpMode)
Beispiel #14
0
    def DoIt(self, host, vm):
        """
      Example:

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 hassnapshot
      hassnapshot() = 0

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 createsnapshot test_snapshot 'a test snapshot' 1 1
      createsnapshot(test_snapshot, a test snapshot, 1, 1) = success

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 hassnapshot
      hassnapshot() = 1
      """

        vm = Operation.GetVm(host, vm)

        if vm.snapshot: return 1
        else: return 0
Beispiel #15
0
   def DoIt(self, host, vm):
      """
      Examples:

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getid
      getid() = 4560

      $ ./vmware-cmd2 -q -H pivot02 mabramow-test1 getid
      4560

      $ ./vmware-cmd2
      ...
        VM Operations:
      ...
          ./vmware-cmd2 <cfg> getid
      ...
      """

      vm = Operation.GetVm(host, vm)

      return vm.moId
Beispiel #16
0
    def _DoIt(self,
              host,
              vm,
              attrs='label',
              displayType='list',
              useVt100Chars=True):
        """
      Display virtual devices as a tree or a flat list.

      @param attrs: Attributes to display for each node
      @type  attrs: str (comma-separated values)
      """

        vm = Operation.GetVm(host, vm)
        attrsList = attrs.split(',')

        if displayType == 'tree':
            return self.DisplayDevicesAsTree(vm, attrsList, useVt100Chars)
        elif displayType == 'list':
            return self.DisplayDevicesAsTable(vm)
        else:
            raise ValueError('Illegal displayType: "%s"' % displayType)
Beispiel #17
0
    def DoIt(self, host, vm, deviceName):
        """
      Disconnect a virtual device.

      Example scenario:

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig floppy0.connectable.connected
      getconfig(floppy0.connectable.connected) = 1

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' disconnectdevice floppy0
      disconnectdevice(floppy0) = success

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig floppy0.connectable.connected
      getconfig(floppy0.connectable.connected) = 0
      """

        vm = Operation.GetVm(host, vm)

        device = vm.GetDevice(deviceName)
        device.SetConnected(False)

        return device.Save()
Beispiel #18
0
    def DoIt(self, host, vm):
        vm = Operation.GetVm(host, vm)

        question = vm.runtime.question
        if not question:
            sys.stderr.write("No questions pending.\n")
            return None

        print('\nQuestion (id = %s) :%s' % (question.id, question.text))

        choices = {}
        for choice in question.choice.choiceInfo:
            choices[choice.key] = choice.label
            print('\t%s) %s' % (choice.key, choice.label))

        choice = raw_input('Select choice. Press enter for default <%s> : ' %
                           question.choice.defaultIndex)
        if choice:
            print('selected %s : %s' % (choice, choices[choice]))
        else:
            choice = str(question.choice.defaultIndex)

        ret = vm.Answer(question.id, choice)
Beispiel #19
0
    def DoIt(self, host, vm, useVt100LineDrawingChars=False):
        """
      Examples:

      $ ./vmware-cmd -H pivot02 mabramow-test1 showsnapshottree
      mabramow-test1
      `- foo
         |- Marc
         |  |- Nicole
         |  `- Test 1
         `- Test 2
            `- Test 3
      """

        vm = Operation.GetVm(host, vm)

        rootNode = Tree.Node(name=vm.name,
                             childSnapshotList=vm.snapshot.rootSnapshotList)

        print Tree.FormatAsTree(
            data=rootNode,
            labelAttr='name',
            childrenAttr='childSnapshotList',
            useVt100LineDrawingChars=useVt100LineDrawingChars)
Beispiel #20
0
    def DoIt(self, host, vm, variable):
        """
      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig floppy0.present
      getconfig(floppy0.present) = 1

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig floppy0.fileType
      getconfig(floppy0.fileType) = file

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig floppy0.fileName
      getconfig(floppy0.fileName) = [] /vmimages/floppies/vmscsi-1.2.0.2.flp

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig floppy0.clientDevice
      getconfig(floppy0.clientDevice) = 0

      $ ./vmware-cmd2 -H pivot02 mabramow-esx-1-cos getconfig floppy0.startConnected
      getconfig(floppy0.startConnected) = 0

      $ ./vmware-cmd2 -H pivot02 mabramow-esx-1-cos getconfig floppy0.ex.connected
      getconfig(floppy0.ex.connected) = 0

      $ ./vmware-cmd2 -H pivot02 mabramow-esx-1-cos getconfig floppy0.connectable.connected
      getconfig(floppy0.connectable.connected) = 0

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig floppy0.deviceInfo.label
      getconfig(floppy0.deviceInfo.label) = Floppy Drive 1

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig floppy0.key
      getconfig(floppy0.key) = 8000

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig floppy0
      (vim.vm.device.VirtualFloppy) {
         dynamicType = <unset>,
         dynamicProperty = (vmodl.DynamicProperty) [],
         key = 8000,
         ...
      }

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig ide0:0.present
      getconfig(ide0:0.present) = 1

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig ide0:0.clientDevice
      getconfig(ide0:0.clientDevice) = 1

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig ide0:0.deviceType
      getconfig(ide0:0.deviceType) = cdrom-raw

      $ ./vmware-cmd2 -H pivot02 mabramow-esx-1-cos getconfig ide0:0.deviceType
      getconfig(ide0:0.deviceType) = cdrom-image

      $ ./vmware-cmd2 -H pivot02 mabramow-esx-1-cos getconfig ide0:0.fileName
      getconfig(ide0:0.fileName) = [storage1] iso/mabramow/beta/esx-kl.iso

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig ide0:0.startConnected
      getconfig(ide0:0.startConnected) = 1

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig ide0:0.ex.connected
      getconfig(ide0:0.ex.connected) = 1

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig ide0:0.connectable.connected
      getconfig(ide0:0.connectable.connected) = 1

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig ide0:0.deviceInfo.label
      getconfig(ide0:0.deviceInfo.label) = CD/DVD Drive 1

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig ide0:0.key
      getconfig(ide0:0.key) = 3000

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig ide0:0
      (vim.vm.device.VirtualCdrom) {
         dynamicType = <unset>,
         dynamicProperty = (vmodl.DynamicProperty) [],
         key = 3000,
         ...
      }

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig scsi0:0.present
      getconfig(scsi0:0.present) = 1

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig scsi0:0.clientDevice
      getconfig(scsi0:0.clientDevice) = 0

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig scsi0:0.deviceType
      getconfig(scsi0:0.deviceType) = disk

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig scsi0:0.fileName
      getconfig(scsi0:0.fileName) = [storage1] VirtualCenter 2.5 VM/VirtualCenter 2.5 VM.vmdk

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig scsi0:0.mode
      getconfig(scsi0:0.mode) = persistent

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig scsi0:0.key
      getconfig(scsi0:0.key) = 2000

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig extraConfig
      getconfig(extraConfig) = (vim.option.OptionValue) [
         (vim.option.OptionValue) {
               dynamicType = <unset>,
               dynamicProperty = (vmodl.DynamicProperty) [],
               key = 'checkpoint.vmState.readOnly',
               value = 'FALSE'
         }, ...
      ]

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig guestinfo.ip
      getconfig(guestinfo.ip) = 10.17.40.249

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig memSize
      getconfig(memSize) = 4

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig config.version
      getconfig(config.version) = vmx-04

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig displayName
      getconfig(displayName) = mabramow-test1

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig uuid.location
      getconfig(uuid.location) = 564d7e1c-c8f7-b7cf-29a1-dd05bc561c03

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig uuid.bios
      getconfig(uuid.bios) = 564d7e1c-c8f7-b7cf-29a1-dd05bc561c03

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig annotation
      getconfig(annotation) = 'jhu VC 2.5 VM'

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig workingDir
      getconfig(workingDir) = [storage1] VirtualCenter 2.5 VM

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig redoLogDir
      getconfig(redoLogDir) = [storage1] VirtualCenter 2.5 VM

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig suspend.directory
      getconfig(suspend.directory) = [storage1] VirtualCenter 2.5 VM

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig disable_acceleration
      getconfig(disable_acceleration) = 0

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig debug
      getconfig(debug) = 0

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig logging
      getconfig(logging) = 1

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig net.toe
      getconfig(net.toe) = 0

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig toolScripts.afterPowerOn
      getconfig(toolScripts.afterPowerOn) = 1

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig toolScripts.afterResume
      getconfig(toolScripts.afterResume) = 1

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig toolScripts.beforePowerOff
      getconfig(toolScripts.beforePowerOff) = 1

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig toolScripts.beforeSuspend
      getconfig(toolScripts.beforeSuspend) = 1

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig powerType.powerOff
      getconfig(powerType.powerOff) = preset

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig powerType.suspend
      getconfig(powerType.suspend) = preset

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig powerType.reset
      getconfig(powerType.reset) = preset

      $ ./vmware-cmd2 -H pioneer-131 'VirtualCenter 2.5 VM' getconfig numvcpus
      getconfig(numvcpus) = 2

      $ ./vmware-cmd2 -H pivot02 mabramow-test1 getconfig config
      ... lots of output ...
      """

        vm = Operation.GetVm(host, vm)

        variableComponents = variable.split('.', 1)
        device = vm.GetDevice(variableComponents[0])
        if device:
            if len(variableComponents) > 1:
                return rec_getattr(device, variableComponents[1])
            else:
                return device

        value = vm.GetExtraConfig().get(variable, None)
        if value: return value

        return rec_getattr(vm, self.GetVmodlProperty(variable))
Beispiel #21
0
    def DoIt(self, host, vm):
        vm = Operation.GetVm(host, vm)

        return vm.RevertToCurrentSnapshot()
Beispiel #22
0
 def DoIt(self, host, vm):
    return Operation.GetVm(host, vm).powerState