-
Notifications
You must be signed in to change notification settings - Fork 765
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add VmomiSupport.VmomiJSONEncoder for encoding pyVmomi objects as JSON.
- Loading branch information
Showing
18 changed files
with
18,791 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
build | ||
dist | ||
.idea | ||
.tox | ||
*.iml | ||
*.patch | ||
*.diff | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env python | ||
# VMware vSphere Python SDK | ||
# Copyright (c) 2008-2018 VMware, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
Python program for dumping JSON of any object given the type and MOID | ||
""" | ||
|
||
from __future__ import print_function | ||
|
||
from pyVim.connect import SmartConnect, Disconnect | ||
from pyVmomi import vim, VmomiSupport | ||
|
||
import argparse | ||
import atexit | ||
import getpass | ||
import json | ||
import ssl | ||
|
||
def GetArgs(): | ||
""" | ||
Supports the command-line arguments listed below. | ||
""" | ||
parser = argparse.ArgumentParser( | ||
description='Process args for extracting JSON from a Managed Object') | ||
parser.add_argument('-s', '--host', required=True, action='store', | ||
help='Remote host to connect to') | ||
parser.add_argument('-o', '--port', type=int, default=443, action='store', | ||
help='Port to connect on') | ||
parser.add_argument('-u', '--user', required=True, action='store', | ||
help='User name to use when connecting to host') | ||
parser.add_argument('-p', '--password', required=False, action='store', | ||
help='Password to use when connecting to host') | ||
parser.add_argument('-t', '--type', required=True, action='store', | ||
help='The vim type lookup, ex: "VirtualMachine"') | ||
parser.add_argument('-i', '--id', required=True, action='store', | ||
help='The MOID to lookup, ex: "vm-42"') | ||
args = parser.parse_args() | ||
return args | ||
|
||
def main(): | ||
""" | ||
Simple command-line program for dumping the contents of any managed object. | ||
""" | ||
|
||
args = GetArgs() | ||
if args.password: | ||
password = args.password | ||
else: | ||
password = getpass.getpass(prompt='Enter password for host %s and ' | ||
'user %s: ' % (args.host,args.user)) | ||
|
||
context = None | ||
if hasattr(ssl, '_create_unverified_context'): | ||
context = ssl._create_unverified_context() | ||
si = SmartConnect(host=args.host, | ||
user=args.user, | ||
pwd=password, | ||
port=int(args.port), | ||
sslContext=context) | ||
if not si: | ||
print("Could not connect to the specified host using specified " | ||
"username and password") | ||
return -1 | ||
|
||
atexit.register(Disconnect, si) | ||
|
||
obj = VmomiSupport.templateOf(args.type)(args.id, si._stub) | ||
print(json.dumps(obj, cls=VmomiSupport.VmomiJSONEncoder, | ||
sort_keys=True, indent=4)) | ||
|
||
# Start program | ||
if __name__ == "__main__": | ||
main() |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"_vimid": "datastore-15", "_vimref": "vim.Datastore:datastore-15", "_vimtype": "vim.Datastore", "alarmActionsEnabled": true, "availableField": [], "browser": "vim.host.DatastoreBrowser:datastoreBrowser-datastore-15", "capability": {"directoryHierarchySupported": true, "dynamicProperty": [], "dynamicType": null, "nativeSnapshotSupported": false, "perFileThinProvisioningSupported": true, "rawDiskMappingsSupported": true, "seSparseSupported": true, "storageIORMSupported": true, "topLevelDirectoryCreateSupported": true, "upitSupported": null, "vmdkExpandSupported": true, "vmfsSparseSupported": false, "vsanSparseSupported": false}, "configIssue": [], "configStatus": "gray", "customValue": [], "declaredAlarmState": [{"acknowledged": false, "acknowledgedByUser": null, "acknowledgedTime": null, "alarm": "vim.alarm.Alarm:alarm-110", "dynamicProperty": [], "dynamicType": null, "entity": "vim.Datastore:datastore-15", "eventKey": null, "key": "alarm-110.datastore-15", "overallStatus": "gray", "time": "2018-09-19T18:00:22.353264Z"}, {"acknowledged": false, "acknowledgedByUser": null, "acknowledgedTime": null, "alarm": "vim.alarm.Alarm:alarm-24", "dynamicProperty": [], "dynamicType": null, "entity": "vim.Datastore:datastore-15", "eventKey": null, "key": "alarm-24.datastore-15", "overallStatus": "gray", "time": "2018-09-19T18:00:22.353397Z"}, {"acknowledged": false, "acknowledgedByUser": null, "acknowledgedTime": null, "alarm": "vim.alarm.Alarm:alarm-28", "dynamicProperty": [], "dynamicType": null, "entity": "vim.Datastore:datastore-15", "eventKey": null, "key": "alarm-28.datastore-15", "overallStatus": "gray", "time": "2018-09-19T18:00:22.353475Z"}, {"acknowledged": false, "acknowledgedByUser": null, "acknowledgedTime": null, "alarm": "vim.alarm.Alarm:alarm-29", "dynamicProperty": [], "dynamicType": null, "entity": "vim.Datastore:datastore-15", "eventKey": null, "key": "alarm-29.datastore-15", "overallStatus": "gray", "time": "2018-09-19T18:00:22.353541Z"}, {"acknowledged": false, "acknowledgedByUser": null, "acknowledgedTime": null, "alarm": "vim.alarm.Alarm:alarm-53", "dynamicProperty": [], "dynamicType": null, "entity": "vim.Datastore:datastore-15", "eventKey": null, "key": "alarm-53.datastore-15", "overallStatus": "gray", "time": "2018-09-19T18:00:22.353598Z"}, {"acknowledged": false, "acknowledgedByUser": null, "acknowledgedTime": null, "alarm": "vim.alarm.Alarm:alarm-7", "dynamicProperty": [], "dynamicType": null, "entity": "vim.Datastore:datastore-15", "eventKey": null, "key": "alarm-7.datastore-15", "overallStatus": "green", "time": "2018-09-19T18:00:22.353783Z"}, {"acknowledged": false, "acknowledgedByUser": null, "acknowledgedTime": null, "alarm": "vim.alarm.Alarm:alarm-79", "dynamicProperty": [], "dynamicType": null, "entity": "vim.Datastore:datastore-15", "eventKey": null, "key": "alarm-79.datastore-15", "overallStatus": "gray", "time": "2018-09-19T18:00:22.353844Z"}, {"acknowledged": false, "acknowledgedByUser": null, "acknowledgedTime": null, "alarm": "vim.alarm.Alarm:alarm-80", "dynamicProperty": [], "dynamicType": null, "entity": "vim.Datastore:datastore-15", "eventKey": null, "key": "alarm-80.datastore-15", "overallStatus": "gray", "time": "2018-09-19T18:00:22.356378Z"}, {"acknowledged": false, "acknowledgedByUser": null, "acknowledgedTime": null, "alarm": "vim.alarm.Alarm:alarm-84", "dynamicProperty": [], "dynamicType": null, "entity": "vim.Datastore:datastore-15", "eventKey": null, "key": "alarm-84.datastore-15", "overallStatus": "gray", "time": "2018-09-19T18:00:22.356497Z"}], "disabledMethod": ["DatastoreExitMaintenanceMode_Task"], "effectiveRole": [-1], "host": [{"dynamicProperty": [], "dynamicType": null, "key": "vim.HostSystem:host-14", "mountInfo": {"accessMode": "readWrite", "accessible": true, "dynamicProperty": [], "dynamicType": null, "inaccessibleReason": null, "mounted": true, "path": "/vmfs/volumes/5b7ee5c9-4e8f1921-93b3-90b11c51ac73"}}], "info": {"aliasOf": null, "containerId": null, "dynamicProperty": [], "dynamicType": null, "freeSpace": 177978998784, "lun": [], "maxFileSize": 70368744177664, "maxMemoryFileSize": 70368744177664, "maxPhysicalRDMFileSize": 70368744177664, "maxVirtualDiskCapacity": 68169720922112, "maxVirtualRDMFileSize": 68169720922112, "name": "datastore1", "timestamp": "2018-10-25T00:07:06.456385Z", "url": "ds:///vmfs/volumes/5b7ee5c9-4e8f1921-93b3-90b11c51ac73/", "vmfs": {"blockSize": 1024, "blockSizeMb": 1, "capacity": 590826438656, "dynamicProperty": [], "dynamicType": null, "extent": [{"diskName": "naa.6b8ca3a0e65228002312a2e3098048bf", "dynamicProperty": [], "dynamicType": null, "partition": 3}], "forceMountedInfo": null, "local": true, "majorVersion": 6, "maxBlocks": 63963136, "name": "datastore1", "scsiDiskType": null, "ssd": false, "type": "VMFS", "unmapBandwidthSpec": null, "unmapGranularity": 1024, "unmapPriority": "low", "uuid": "5b7ee5c9-4e8f1921-93b3-90b11c51ac73", "version": "6.82", "vmfsUpgradable": false}}, "iormConfiguration": {"congestionThreshold": 30, "congestionThresholdMode": "automatic", "dynamicProperty": [], "dynamicType": null, "enabled": false, "percentOfPeakThroughput": 90, "reservableIopsThreshold": null, "reservationEnabled": true, "statsAggregationDisabled": false, "statsCollectionEnabled": false}, "name": "datastore1", "overallStatus": "green", "parent": "vim.Folder:group-s5", "permission": [], "recentTask": [], "summary": {"accessible": true, "capacity": 590826438656, "datastore": "vim.Datastore:datastore-15", "dynamicProperty": [], "dynamicType": null, "freeSpace": 177978998784, "maintenanceMode": "normal", "multipleHostAccess": false, "name": "datastore1", "type": "VMFS", "uncommitted": 335226992919, "url": "ds:///vmfs/volumes/5b7ee5c9-4e8f1921-93b3-90b11c51ac73/"}, "tag": [], "triggeredAlarmState": [], "value": [], "vm": ["vim.VirtualMachine:vm-127", "vim.VirtualMachine:vm-69", "vim.VirtualMachine:vm-17", "vim.VirtualMachine:vm-42", "vim.VirtualMachine:vm-18", "vim.VirtualMachine:vm-36", "vim.VirtualMachine:vm-19", "vim.VirtualMachine:vm-21", "vim.VirtualMachine:vm-20", "vim.VirtualMachine:vm-22", "vim.VirtualMachine:vm-32"]} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"_vimid": "network-16", "_vimref": "vim.Network:network-16", "_vimtype": "vim.Network", "alarmActionsEnabled": true, "availableField": [], "configIssue": [], "configStatus": "green", "customValue": [], "declaredAlarmState": [], "disabledMethod": [], "effectiveRole": [-1], "host": ["vim.HostSystem:host-14", "vim.HostSystem:host-25"], "name": "VM Network", "overallStatus": "green", "parent": "vim.Folder:group-n6", "permission": [], "recentTask": [], "summary": {"accessible": true, "dynamicProperty": [], "dynamicType": null, "ipPoolId": null, "ipPoolName": "", "name": "VM Network", "network": "vim.Network:network-16"}, "tag": [], "triggeredAlarmState": [], "value": [], "vm": ["vim.VirtualMachine:vm-17", "vim.VirtualMachine:vm-18", "vim.VirtualMachine:vm-19", "vim.VirtualMachine:vm-20", "vim.VirtualMachine:vm-21", "vim.VirtualMachine:vm-22", "vim.VirtualMachine:vm-27", "vim.VirtualMachine:vm-28", "vim.VirtualMachine:vm-29", "vim.VirtualMachine:vm-32", "vim.VirtualMachine:vm-36", "vim.VirtualMachine:vm-42", "vim.VirtualMachine:vm-69", "vim.VirtualMachine:vm-86", "vim.VirtualMachine:vm-111", "vim.VirtualMachine:vm-127"]} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.