Created
August 7, 2015 15:14
-
-
Save pathcl/2ed990cdeec3e38ddc42 to your computer and use it in GitHub Desktop.
Get some cluster through pymomi
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 ssl | |
| import tools.cli as cli | |
| # Monkey patch for SSL :-) | |
| ssl._create_default_https_context = ssl._create_unverified_context | |
| def main(): | |
| args = cli.get_args() | |
| service_instance = connect.SmartConnect(host=args.host, | |
| user=args.user, | |
| pwd=args.password, | |
| port=args.port) | |
| content = service_instance.RetrieveContent() | |
| obj_view = content.viewManager.CreateContainerView(content.rootFolder, [vim.ClusterComputeResource], True) | |
| clusters = obj_view.view | |
| list_clusters = [cluster.name for cluster in clusters] | |
| print("") | |
| print("Connected to {0} as {1}".format(args.host, args.user)) | |
| print("Clusters available here are {0}".format(list_clusters)) | |
| print("") | |
| # Select cluster r710 | |
| r710 = clusters[1] | |
| # Get status | |
| onVms = [[(host.summary.config.instanceUuid) for host in eh.vm if | |
| host.runtime.powerState == 'poweredOn'] for eh in r710.host] | |
| offVms = [[(host.summary.config.instanceUuid) for host in eh.vm if | |
| host.runtime.powerState == 'poweredOff'] for eh in r710.host] | |
| valOn = '\n'.join([str(i) for i in onVms]) | |
| valOff = '\n'.join([str(i) for i in offVms]) | |
| print("Current poweredOn vm") | |
| print("\n") | |
| print(valOn, end='\n') | |
| print("\n") | |
| print("Current poweredOff vm") | |
| print("\n") | |
| print(valOff) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment