def _xml_to_obj(cls, serialized_str): """ @summary: Returns an instance of a Hypervisor based on the xml serialized_str passed in. @param serialized_str: XML serialized string @type serialized_str: String @return: List of Hypervisors @rtype: List """ element = ET.fromstring(serialized_str) hypervisors = [] for hypervisor in element.findall('hypervisor'): hypervisor_dict = hypervisor.attrib id = hypervisor_dict['id'] hypervisor_hostname = hypervisor_dict['hypervisor_hostname'] if "servers" in [elem.tag for elem in hypervisor.iter()]: servers = [] for server in hypervisor.iter('server'): servers.append(Server._dict_to_obj(server.attrib)) return Hypervisor(id, hypervisor_hostname, servers) else: servers = None hypervisor.attrib.update({"servers": servers}) hypervisors.append(Hypervisor(id, hypervisor_hostname, servers)) return hypervisors
def _xml_to_obj(cls, serialized_str): """ @summary: Returns an instance of a Hypervisor based on the xml serialized_str passed in. @param serialized_str: XML serialized string @type serialized_str: String @return: List of Hypervisors @rtype: List """ element = ET.fromstring(serialized_str) hypervisors = [] for hypervisor in element.findall('hypervisor'): if "servers" in [elem.tag for elem in hypervisor.iter()]: for server in hypervisor.iter('server'): servers = [Server._dict_to_obj(server.attrib)] else: servers = None hypervisor.attrib.update({"servers": servers}) hypervisor_dict = hypervisor.attrib id = hypervisor_dict['id'] hypervisor_hostname = hypervisor_dict['hypervisor_hostname'] hypervisors.append(Hypervisor(id, hypervisor_hostname, servers)) return hypervisors
def _json_to_obj(cls, serialized_str): """ @summary: Returns an instance of a Hypervisor based on the json serialized_str passed in. @param serialized_str: JSON serialized string @type serialized_str: String @return: List of Hypervisors @rtype: List """ json_dict = json.loads(serialized_str) hypervisors = [] for hypervisor_dict in json_dict['hypervisors']: id = hypervisor_dict['id'] hypervisor_hostname = hypervisor_dict['hypervisor_hostname'] if 'servers' in hypervisor_dict.keys(): servers = [] for server_dict in hypervisor_dict['servers']: servers.append(Server._dict_to_obj(server_dict)) return Hypervisor(id, hypervisor_hostname, servers) else: servers = None hypervisor_dict.update({"servers": servers}) hypervisors.append(Hypervisor(id, hypervisor_hostname, servers)) return hypervisors