From dcbbf2bf77e35673ee84fc189379e488cf9f18c7 Mon Sep 17 00:00:00 2001 From: Thiago Paiva Date: Thu, 11 Feb 2016 10:55:18 -0300 Subject: [PATCH] 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 --- oneview_client/models.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/oneview_client/models.py b/oneview_client/models.py index efe5e55..ee006bf 100644 --- a/oneview_client/models.py +++ b/oneview_client/models.py @@ -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():