How to initialize Datastore?

89 views
Skip to first unread message

Stefan Midjich

unread,
Apr 26, 2013, 4:01:49 AM4/26/13
to psp...@googlegroups.com
I'm only just learning and the 0.5.1 docs are not properly using the Datastore class, for the 0.5.2 code.

So I'm wondering, where is mo_ref supposed to come from when initializing the Datastore class? It says that mo_ref is ManagedObject reference, but I can't initialize __init__.ManagedObject without having an mo_ref as second argument.

Could someone please explain this?

My goal is to list datastores, get sizes and used space of datastores.

Matthew Welch

unread,
Apr 26, 2013, 10:49:48 AM4/26/13
to psp...@googlegroups.com
Hey Stefan,

I've included a basic sample of how you might want to go about getting a lite of datastores, their sizes and used space. 

Its been a while, but if I recall, you can grab all the datastores from a cluster ( or ComputeResource MOR ). 

So, with that in mind..

from psphere import client
from psphere.managedobjects import ComputeResource

vlink = client.Client('host', 'username', 'password')

cluster = ComputeResource.get(vlink, name="<name>")

for store in cluster.datastore:
    print "Name: %s" % store.name
    print "Free Space: %s" % store.summary.freeSpace
    print "Capacity: %s" % store.summary.capacity

Obviously that can be made into a more complete script, but should help you get going. I've played around with a repo I made that sits on top of psphere called omoto ( https://github.com/intr1nsic/omoto/ ) that basically tries to ( in a very janky way though ) wrap some helper methods around the managedobjects in psphere; I called them aobjects ( advanced objects ). 

An example that may help you here is the aobjects/datastore.py

class Datastore(managedobjects.Datastore):
def __init__(self, mo_ref, client):
managedobjects.Datastore.__init__(self, mo_ref, client)

@classmethod
def all(cls, client):
"""
Grab all the Datastores in all the Datacenters that
vcenter manages
"""
datastores = []

datacenters = client.find_entity_views('Datacenter')

if not datacenters:
return

for dc in datacenters:
for ds in dc.datastore:
datastores.append(ds)

return datastores

@property
def provisioned_space(self):
"""
Return the provisioned space
"""
self.provisioned = (self.capacity_space - self.free_space) + \
self.uncommitted_space
return self.provisioned

@property
def capacity_space(self):
"""
Return the capacity of the Datastore
"""
return self.summary.capacity

@property
def free_space(self):
"""
Return the free space of the Datastore
"""
return self.summary.freeSpace

@property
def used_space(self):
"""
Return the used space of the Datastore
"""
self.used = self.capacity_space - self.free_space
return self.used

@property
def uncommitted_space(self):
"""
Return the uncommitted space
"""
try:
self.uncommitted = self.summary.uncommitted
except:
self.uncommitted = 0
return self.uncommitted



--
You received this message because you are subscribed to the Google Groups "psphere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psphere+u...@googlegroups.com.
To post to this group, send an email to psp...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msg/psphere/-/gzu8gPZ3DAAJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages