From 2c2956ed3306561055f07f1af386511bb852705e Mon Sep 17 00:00:00 2001 From: int32bit <krystism@gmail.com> Date: Fri, 25 Nov 2016 21:23:47 +0800 Subject: [PATCH] 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 --- oslo_vmware/objects/datastore.py | 10 ++++++++-- oslo_vmware/tests/objects/test_datastore.py | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/oslo_vmware/objects/datastore.py b/oslo_vmware/objects/datastore.py index 9816215e..cd89d4f2 100644 --- a/oslo_vmware/objects/datastore.py +++ b/oslo_vmware/objects/datastore.py @@ -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 diff --git a/oslo_vmware/tests/objects/test_datastore.py b/oslo_vmware/tests/objects/test_datastore.py index d50389d5..28bfacfc 100644 --- a/oslo_vmware/tests/objects/test_datastore.py +++ b/oslo_vmware/tests/objects/test_datastore.py @@ -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,