Reverts removal of from_json on ServerProfile cls

The method was doing something different from the one on OneViewObject: It was
adding keys on the ServerProfile object that weren't on the attribute_map.
Without it, Bad Requests are being sent to OneView since they doesn't had the
required parameters.

Reverting it back and fixing the problem of the instatiation on the old method.

Change-Id: I4e52209153a0184df274cade6db553b891bf0da6
This commit is contained in:
Thiago Paiva 2016-02-11 10:55:18 -03:00
parent efd42351fa
commit dcbbf2bf77

View File

@ -95,6 +95,25 @@ class ServerProfile(OneViewObject):
'sanStorage': 'san_storage',
}
@classmethod
def from_json(cls, json_body):
"""Returns an instance of ServerProfile with values parsed from json
This method differs from the one in OneViewObject since it adds keys in
the ServerProfile object for values that aren't on attribute_map. This
is needed because to send the Server Profile back to OneView, we need
to preserve state and required fields that aren't exploited by
python-oneviewclient
"""
instance = cls()
for attr_key in json_body.keys():
attribute_value = json_body.get(attr_key)
attribute_map_value = cls.attribute_map.get(attr_key)
if attribute_map_value is not None:
attr_key = attribute_map_value
setattr(instance, attr_key, attribute_value)
return instance
def to_oneview_dict(self):
server_profile_dict = {}
for attr_key in self.__dict__.keys():