----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/ -----------------------------------------------------------
Review request for OpenLMI Developers.
Repository: openlmi-tools
Description -------
Honza S.:
In a lmishell script I want to manually loop over all properties and get their values. I can use _LmiInstance.properties() to get list of properties, but there is no way, how to get property values. Either _LmiInstance.properties() should return a dictionary or there should be _LmiInstance.get_property(name) method.
Sample code:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, i.get_property(p)
-----
There is a way, how to get properties:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, getattr(i, p) ^^
Or how to get Names property value: i.Names
Dunno, if it is a correct (python) way. Maybe it should be switched to a "dictionary style". I used this attitude just because of methods access.
Diffs -----
cli-tools/lmi/lmi_client_shell.py 54bd8b263002c5df9f3d7dad414e75cae9bc3c41
Diff: http://reviewboard-openlmi.rhcloud.com/r/461/diff/
Testing -------
Thanks,
Peter Hatina
----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/#review552 -----------------------------------------------------------
In my opinion, it would be preferable to implement get_property_value() method for standard objects. The "pythonic" way of handling this is just as it currently is: object.property contains the value. Returning the dictionary would be a bad idea, as for complex objects this may result in a huge waste of memory for the common case. If you want a handy dictionary like that, I'd recommend making it a separate function from object.properties() like object.properties_dict() with a note in the pydoc that it may result in significant memory overhead.
To sum up: I suggest adding: .get_property_val(property_name) that can internally use getattr() to retrieve the value, hiding it from the public interface
Optionally, if it is useful in some situations, we can add .properties_dict() which will return a full dictionary of all properties, at the expense of memory.
If you implement both of these, please do *not* implement get_property_val() using properties_dict(), as this would be inefficient.
- Stephen Gallagher
On June 18, 2013, 11:36 a.m., Peter Hatina wrote:
This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/
(Updated June 18, 2013, 11:36 a.m.)
Review request for OpenLMI Developers.
Repository: openlmi-tools
Description
Honza S.:
In a lmishell script I want to manually loop over all properties and get their values. I can use _LmiInstance.properties() to get list of properties, but there is no way, how to get property values. Either _LmiInstance.properties() should return a dictionary or there should be _LmiInstance.get_property(name) method.
Sample code:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, i.get_property(p)
There is a way, how to get properties:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, getattr(i, p) ^^
Or how to get Names property value: i.Names
Dunno, if it is a correct (python) way. Maybe it should be switched to a "dictionary style". I used this attitude just because of methods access.
Diffs
cli-tools/lmi/lmi_client_shell.py 54bd8b263002c5df9f3d7dad414e75cae9bc3c41
Diff: http://reviewboard-openlmi.rhcloud.com/r/461/diff/
Testing
Thanks,
Peter Hatina
On June 18, 2013, noon, Stephen Gallagher wrote:
In my opinion, it would be preferable to implement get_property_value() method for standard objects. The "pythonic" way of handling this is just as it currently is: object.property contains the value. Returning the dictionary would be a bad idea, as for complex objects this may result in a huge waste of memory for the common case. If you want a handy dictionary like that, I'd recommend making it a separate function from object.properties() like object.properties_dict() with a note in the pydoc that it may result in significant memory overhead.
To sum up: I suggest adding: .get_property_val(property_name) that can internally use getattr() to retrieve the value, hiding it from the public interface
Optionally, if it is useful in some situations, we can add .properties_dict() which will return a full dictionary of all properties, at the expense of memory.
If you implement both of these, please do *not* implement get_property_val() using properties_dict(), as this would be inefficient.
This sounds reasonable.
- Peter
----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/#review552 -----------------------------------------------------------
On June 18, 2013, 1:10 p.m., Peter Hatina wrote:
This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/
(Updated June 18, 2013, 1:10 p.m.)
Review request for OpenLMI Developers.
Repository: openlmi-tools
Description
Honza S.:
In a lmishell script I want to manually loop over all properties and get their values. I can use _LmiInstance.properties() to get list of properties, but there is no way, how to get property values. Either _LmiInstance.properties() should return a dictionary or there should be _LmiInstance.get_property(name) method.
Sample code:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, i.get_property(p)
There is a way, how to get properties:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, getattr(i, p) ^^
Or how to get Names property value: i.Names
Dunno, if it is a correct (python) way. Maybe it should be switched to a "dictionary style". I used this attitude just because of methods access.
Diffs
cli-tools/lmi/lmi_client_shell.py 54bd8b263002c5df9f3d7dad414e75cae9bc3c41
Diff: http://reviewboard-openlmi.rhcloud.com/r/461/diff/
Testing
Thanks,
Peter Hatina
----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/#review553 -----------------------------------------------------------
cli-tools/lmi/lmi_client_shell.py http://reviewboard-openlmi.rhcloud.com/r/461/#comment324
Wouldn't be better to return _cim_instance.properties directly? It's already a dict (mapping of property name to CIMProperty. Iteration of key/value can be done easily:
for k, v in i.properties().items(): print k, v.value
With this solution one can also access type of the property. And the list of properties will remain be modifiable instead of making a copy.
- Radek Novacek
On June 18, 2013, 1:36 p.m., Peter Hatina wrote:
This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/
(Updated June 18, 2013, 1:36 p.m.)
Review request for OpenLMI Developers.
Repository: openlmi-tools
Description
Honza S.:
In a lmishell script I want to manually loop over all properties and get their values. I can use _LmiInstance.properties() to get list of properties, but there is no way, how to get property values. Either _LmiInstance.properties() should return a dictionary or there should be _LmiInstance.get_property(name) method.
Sample code:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, i.get_property(p)
There is a way, how to get properties:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, getattr(i, p) ^^
Or how to get Names property value: i.Names
Dunno, if it is a correct (python) way. Maybe it should be switched to a "dictionary style". I used this attitude just because of methods access.
Diffs
cli-tools/lmi/lmi_client_shell.py 54bd8b263002c5df9f3d7dad414e75cae9bc3c41
Diff: http://reviewboard-openlmi.rhcloud.com/r/461/diff/
Testing
Thanks,
Peter Hatina
On June 18, 2013, 12:01 p.m., Radek Novacek wrote:
cli-tools/lmi/lmi_client_shell.py, line 890 http://reviewboard-openlmi.rhcloud.com/r/461/diff/1/?file=2724#file2724line890
Wouldn't be better to return _cim_instance.properties directly? It's already a dict (mapping of property name to CIMProperty. Iteration of key/value can be done easily: for k, v in i.properties().items(): print k, v.value With this solution one can also access type of the property. And the list of properties will remain be modifiable instead of making a copy.
I would rather stick to this "filtered" dictionary. In my opinion, CIM NocasDict contains members, that are not useful for the script/users. That's the only reason I didn't return directly self._cim_instance.properties.
- Peter
----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/#review553 -----------------------------------------------------------
On June 18, 2013, 1:10 p.m., Peter Hatina wrote:
This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/
(Updated June 18, 2013, 1:10 p.m.)
Review request for OpenLMI Developers.
Repository: openlmi-tools
Description
Honza S.:
In a lmishell script I want to manually loop over all properties and get their values. I can use _LmiInstance.properties() to get list of properties, but there is no way, how to get property values. Either _LmiInstance.properties() should return a dictionary or there should be _LmiInstance.get_property(name) method.
Sample code:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, i.get_property(p)
There is a way, how to get properties:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, getattr(i, p) ^^
Or how to get Names property value: i.Names
Dunno, if it is a correct (python) way. Maybe it should be switched to a "dictionary style". I used this attitude just because of methods access.
Diffs
cli-tools/lmi/lmi_client_shell.py 54bd8b263002c5df9f3d7dad414e75cae9bc3c41
Diff: http://reviewboard-openlmi.rhcloud.com/r/461/diff/
Testing
Thanks,
Peter Hatina
----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/ -----------------------------------------------------------
(Updated June 18, 2013, 1:10 p.m.)
Review request for OpenLMI Developers.
Changes -------
Updated wrt Stephen's thoughts.
Repository: openlmi-tools
Description -------
Honza S.:
In a lmishell script I want to manually loop over all properties and get their values. I can use _LmiInstance.properties() to get list of properties, but there is no way, how to get property values. Either _LmiInstance.properties() should return a dictionary or there should be _LmiInstance.get_property(name) method.
Sample code:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, i.get_property(p)
-----
There is a way, how to get properties:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, getattr(i, p) ^^
Or how to get Names property value: i.Names
Dunno, if it is a correct (python) way. Maybe it should be switched to a "dictionary style". I used this attitude just because of methods access.
Diffs (updated) -----
cli-tools/lmi/lmi_client_shell.py 54bd8b263002c5df9f3d7dad414e75cae9bc3c41
Diff: http://reviewboard-openlmi.rhcloud.com/r/461/diff/
Testing -------
Thanks,
Peter Hatina
----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/#review557 -----------------------------------------------------------
Ship it!
Ship It!
- Radek Novacek
On June 18, 2013, 3:10 p.m., Peter Hatina wrote:
This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/
(Updated June 18, 2013, 3:10 p.m.)
Review request for OpenLMI Developers.
Repository: openlmi-tools
Description
Honza S.:
In a lmishell script I want to manually loop over all properties and get their values. I can use _LmiInstance.properties() to get list of properties, but there is no way, how to get property values. Either _LmiInstance.properties() should return a dictionary or there should be _LmiInstance.get_property(name) method.
Sample code:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, i.get_property(p)
There is a way, how to get properties:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, getattr(i, p) ^^
Or how to get Names property value: i.Names
Dunno, if it is a correct (python) way. Maybe it should be switched to a "dictionary style". I used this attitude just because of methods access.
Diffs
cli-tools/lmi/lmi_client_shell.py 54bd8b263002c5df9f3d7dad414e75cae9bc3c41
Diff: http://reviewboard-openlmi.rhcloud.com/r/461/diff/
Testing
Thanks,
Peter Hatina
----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/#review558 -----------------------------------------------------------
Ship it!
Ship It!
- Stephen Gallagher
On June 18, 2013, 1:10 p.m., Peter Hatina wrote:
This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/
(Updated June 18, 2013, 1:10 p.m.)
Review request for OpenLMI Developers.
Repository: openlmi-tools
Description
Honza S.:
In a lmishell script I want to manually loop over all properties and get their values. I can use _LmiInstance.properties() to get list of properties, but there is no way, how to get property values. Either _LmiInstance.properties() should return a dictionary or there should be _LmiInstance.get_property(name) method.
Sample code:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, i.get_property(p)
There is a way, how to get properties:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, getattr(i, p) ^^
Or how to get Names property value: i.Names
Dunno, if it is a correct (python) way. Maybe it should be switched to a "dictionary style". I used this attitude just because of methods access.
Diffs
cli-tools/lmi/lmi_client_shell.py 54bd8b263002c5df9f3d7dad414e75cae9bc3c41
Diff: http://reviewboard-openlmi.rhcloud.com/r/461/diff/
Testing
Thanks,
Peter Hatina
----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: http://reviewboard-openlmi.rhcloud.com/r/461/ -----------------------------------------------------------
(Updated June 19, 2013, 6:18 a.m.)
Status ------
This change has been marked as submitted.
Review request for OpenLMI Developers.
Repository: openlmi-tools
Description -------
Honza S.:
In a lmishell script I want to manually loop over all properties and get their values. I can use _LmiInstance.properties() to get list of properties, but there is no way, how to get property values. Either _LmiInstance.properties() should return a dictionary or there should be _LmiInstance.get_property(name) method.
Sample code:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, i.get_property(p)
-----
There is a way, how to get properties:
i = c.root.cimv2.LMI_StorageExtent.first_instance() for p in i.properties: print p, getattr(i, p) ^^
Or how to get Names property value: i.Names
Dunno, if it is a correct (python) way. Maybe it should be switched to a "dictionary style". I used this attitude just because of methods access.
Diffs -----
cli-tools/lmi/lmi_client_shell.py 54bd8b263002c5df9f3d7dad414e75cae9bc3c41
Diff: http://reviewboard-openlmi.rhcloud.com/r/461/diff/
Testing -------
Thanks,
Peter Hatina
openlmi-reviews@lists.fedorahosted.org