Add 'uncommitted' field to the 'Datastore' class

The 'uncommitted' field is in official API, but currently not in our
Datastore class, we need it to compute the amount of provisioned space:

provisionedSpace = Capacity - freeSpace - uncommitted

So a `uncommitted` keyword argument has to be added to the Datastore
class.

Change-Id: I156e2b4fb9a8355848947ec9dbb6abf014588fdf
Closes-Bug: #1643569
This commit is contained in:
int32bit 2016-11-25 21:23:47 +08:00
parent 4c88bb4cf5
commit 2c2956ed33
2 changed files with 10 additions and 3 deletions

View File

@ -37,7 +37,9 @@ def get_datastore_by_ref(session, ds_ref):
lst_properties = ["summary.type",
"summary.name",
"summary.capacity",
"summary.freeSpace"]
"summary.freeSpace",
"summary.uncommitted"]
props = session.invoke_api(
vim_util,
"get_object_properties_dict",
@ -48,19 +50,22 @@ def get_datastore_by_ref(session, ds_ref):
return Datastore(ds_ref, props["summary.name"],
capacity=props.get("summary.capacity"),
freespace=props.get("summary.freeSpace"),
uncommitted=props.get("summary.uncommitted"),
type=props.get("summary.type"))
class Datastore(object):
def __init__(self, ref, name, capacity=None, freespace=None,
type=None, datacenter=None):
uncommitted=None, type=None, datacenter=None):
"""Datastore object holds ref and name together for convenience.
:param ref: a vSphere reference to a datastore
:param name: vSphere unique name for this datastore
:param capacity: (optional) capacity in bytes of this datastore
:param freespace: (optional) free space in bytes of datastore
:param uncommitted: (optional) Total additional storage space
in bytes of datastore
:param type: (optional) datastore type
:param datacenter: (optional) oslo_vmware Datacenter object
"""
@ -78,6 +83,7 @@ class Datastore(object):
self.name = name
self.capacity = capacity
self.freespace = freespace
self.uncommitted = uncommitted
self.type = type
self.datacenter = datacenter

View File

@ -43,11 +43,12 @@ class DatastoreTestCase(base.TestCase):
def test_ds(self):
ds = datastore.Datastore(
"fake_ref", "ds_name", 2 * units.Gi, 1 * units.Gi)
"fake_ref", "ds_name", 2 * units.Gi, 1 * units.Gi, 1 * units.Gi)
self.assertEqual('ds_name', ds.name)
self.assertEqual('fake_ref', ds.ref)
self.assertEqual(2 * units.Gi, ds.capacity)
self.assertEqual(1 * units.Gi, ds.freespace)
self.assertEqual(1 * units.Gi, ds.uncommitted)
def test_ds_invalid_space(self):
self.assertRaises(ValueError, datastore.Datastore,