@@ -0,0 +1,2585 @@
+#!/usr/bin/python%0A# William Lam%0A# www.virtuallyghetto.com%0A%0A%22%22%22%0AvSphere Python SDK program for listing Datastores in Datastore Cluster%0A%22%22%22%0A%0Afrom optparse import OptionParser, make_option%0Afrom pyVim.connect import SmartConnect, Disconnect%0A%0Afrom datetime import timedelta%0Afrom pyVmomi import vmodl%0Afrom pyVmomi import vim%0A%0Aimport argparse%0Aimport atexit%0Aimport datetime%0Aimport sys%0A%0A%0Adef GetArgs():%0A    %22%22%22%0A   Supports the command-line arguments listed below.%0A   %22%22%22%0A    parser = argparse.ArgumentParser(description='Process args for retrieving all the Virtual Machines')%0A    parser.add_argument('-s', '--host', required=True, action='store', help='Remote host to connect to')%0A    parser.add_argument('-o', '--port', type=int, default=443, action='store', help='Port to connect on')%0A    parser.add_argument('-u', '--user', required=True, action='store', help='User name to use when connecting to host')%0A    parser.add_argument('-p', '--password', required=True, action='store', help='Password to use when connecting to host')%0A    parser.add_argument('-d', '--dscluster', required=True, action='store', help='Name of vSphere Datastore Cluster')%0A    args = parser.parse_args()%0A    return args%0A%0Adef main():%0A    %22%22%22%0A   Simple command-line program for listing Datastores in Datastore Cluster%0A   %22%22%22%0A%0A    args = GetArgs()%0A    try:%0A        si = None%0A        try:%0A            si = SmartConnect(host=args.host,%0A                              user=args.user,%0A                              pwd=args.password,%0A                              port=int(args.port))%0A        except IOError, e:%0A            pass%0A        if not si:%0A            print %22Could not connect to the specified host using specified username and password%22%0A            return -1%0A%0A        atexit.register(Disconnect, si)%0A%0A        content = si.RetrieveContent()%0A        # Search for all Datastore Clusters aka StoragePod%0A        objView = content.viewManager.CreateContainerView(content.rootFolder,%5Bvim.StoragePod%5D,True)%0A        datastoreClusters = objView.view%0A        objView.Destroy()%0A        %0A        for datastoreCluster in datastoreClusters:%0A            if datastoreCluster.name == args.dscluster:%0A                datastores = datastoreCluster.childEntity%0A                print %22Datastores: %22%0A                for datastore in datastores:%0A                    print datastore.name%0A%0A    except vmodl.MethodFault, e:%0A        print %22Caught vmodl fault : %22 + e.msg%0A        return -1%0A    except Exception, e:%0A        print %22Caught exception : %22 + str(e)%0A        return -1%0A%0A    return 0%0A%0A# Start program%0Aif __name__ == %22__main__%22:%0A    main()%0A

List all Datastores given a Datastore Clusters