Last active
August 29, 2015 14:27
-
-
Save pathcl/02e793a01282335787ee to your computer and use it in GitHub Desktop.
get procs on vm through pyvmomi
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
| # Attempts to get procs on a given VM (uuid) | |
| # Through pyvmomi and vmware-tools | |
| # | |
| from pyVim import connect | |
| from pyVmomi import vim | |
| import ssl | |
| import tools.cli as cli | |
| import atexit | |
| # Monkey patch SSL | |
| ssl._create_default_https_context = ssl._create_unverified_context | |
| 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 | |
| def main(vm): | |
| vm = content.searchIndex.FindByUuid(None, ARGS.uuid, True, True) | |
| print(content.guestOperationsManager.processManager.ListProcesses(vm, | |
| creds)) | |
| if __name__ == '__main__': | |
| main(ARGS.uuid) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment