def FormatRecord(self, record): return self.fieldSep.join([ self.FormatField(key=column, value=rec_getattr(record, column), width=columnOptions['maxWidth']) for column, columnOptions in self.columnsInfo ]).rstrip()
def Format(self, data): rootNode = Tree.Node(nodeLabel='[' + '/'.join(self.groupByAttrs) + ']', children=[], nodesDict={}) for item in data: node = rootNode for groupByAttr in self.groupByAttrs: groupByValue = str(rec_getattr(item, groupByAttr)) nodesDict = node.nodesDict oldNode = node node = nodesDict.get(groupByValue, None) if not node: node = Tree.Node(nodeLabel=groupByValue, children=[], nodesDict={}) oldNode.nodesDict[groupByValue] = node oldNode.children.append(node) node.children.append(item) print Tree.FormatAsTree(data=rootNode, labelAttr='nodeLabel', labelFunc=self.labelFunc, childrenAttr='children', useVt100LineDrawingChars=True) return ''
def _CalcMaxWidthsForColumns(data, columnsInfo): for record in data: for column, columnOptions in columnsInfo: value = str(rec_getattr(record, column)) columnOptions['maxWidth'] = max(columnOptions['maxWidth'], len(value)) return columnsInfo
def __getattr__(self, name): """ Delegate unknown attributes/methods to the managed object. """ value = rec_getattr(self.managedObject, name) if value: return value else: return getattr(self.managedObject, name)
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))
def FormatRecord(record): return ', '.join( [str(rec_getattr(record, attr)) for attr in attrs]).rstrip()
def labelFunc(self, record): if self.attrs: return ', '.join( [str(rec_getattr(record, attr)) for attr in self.attrs]) else: return rec_getattr(record, self.columnsInfo[0][0])
def testMethod(self): result = GetConfig().DoIt(self.host, self.vm.name, argsStr) #print(result) self.assertEqual(result, rec_getattr(self.vm, key))
def __getattr__(self, name): return rec_getattr(self.managedObject, name)