Created
August 19, 2015 17:15
-
-
Save pathcl/7aa1c2629bbcf1444224 to your computer and use it in GitHub Desktop.
export vm procceses to csv through vmware-tools
This file contains hidden or 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
| from pyVim import connect | |
| from pyVmomi import vim | |
| import pandas as pd | |
| import ssl | |
| import tools.cli as cli | |
| import atexit | |
| import json | |
| # Monkey patch SSL | |
| ssl._create_default_https_context = ssl._create_unverified_context | |
| # Setup args function and get arguments | |
| def setup_args(): | |
| parser = cli.build_arg_parser() | |
| parser.add_argument('-uuid', '--uuid', | |
| help='file of uuid', | |
| required=True) | |
| parser.add_argument('-vmpass', '--vmpass', | |
| help='vm passwd', | |
| required=True) | |
| parser.add_argument('-vmuser', '--vmuser', | |
| help='file of uuid', | |
| required=True) | |
| my_args = parser.parse_args() | |
| return cli.prompt_for_password(my_args) | |
| ARGS = setup_args() | |
| try: | |
| SI = connect.SmartConnect(host=ARGS.host, | |
| user=ARGS.user, | |
| pwd=ARGS.password, | |
| port=ARGS.port) | |
| content = SI.RetrieveContent() | |
| atexit.register(connect.Disconnect, SI) | |
| creds = vim.vm.guest.NamePasswordAuthentication(username=ARGS.vmuser, | |
| password=ARGS.vmpass) | |
| except IOError: | |
| pass | |
| # Main function which tries to find VM through UUID | |
| def main(vm): | |
| vm = content.searchIndex.FindByUuid(None, ARGS.uuid, True, True) | |
| procs = content.guestOperationsManager.processManager.ListProcesses(vm, | |
| creds) | |
| vmprocs = [(proc.owner, proc.pid, proc.cmdLine) for proc in procs] | |
| print("Process for {0}".format(vm.name)) | |
| print("") | |
| csv = pd.DataFrame(vmprocs) | |
| csv.to_csv(vm.name + '.csv', index=False, header=False) | |
| print(csv) | |
| if __name__ == '__main__': | |
| main(ARGS.uuid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment