def __create_device(self):
<EOL>device_dict = getattr(self, '<STR_LIT>', self.netengine.to_dict())<EOL>device = Device()<EOL>device.node_id = self.node_id<EOL>device.name = device_dict['<STR_LIT:name>']<EOL>device.type = device_dict['<STR_LIT:type>']<EOL>device.status = DEVICE_STATUS.get('<STR_LIT>')<EOL>device.os = device_dict['<STR_LIT>']<EOL>device.os_version = device_dict['<STR_LIT>']<EOL>device.first_seen = now()<EOL>device.last_seen = now()<EOL>device.full_clean()<EOL>device.save()<EOL>for routing_protocol in device_dict['<STR_LIT>']:<EOL><INDENT>try:<EOL><INDENT>rp = RoutingProtocol.objects.filter(<EOL>name__iexact=routing_protocol['<STR_LIT:name>'],<EOL>version__iexact=routing_protocol['<STR_LIT:version>']<EOL>)[<NUM_LIT:0>]<EOL><DEDENT>except IndexError:<EOL><INDENT>rp = RoutingProtocol(<EOL>name=routing_protocol['<STR_LIT:name>'],<EOL>version=routing_protocol['<STR_LIT:version>']<EOL>)<EOL>rp.full_clean()<EOL>rp.save()<EOL><DEDENT>device.routing_protocols.add(rp)<EOL><DEDENT>for interface in device_dict['<STR_LIT>']:<EOL><INDENT>interface_object = False<EOL>vap_object = False<EOL>if interface['<STR_LIT:type>'] == '<STR_LIT>':<EOL><INDENT>interface_object = Ethernet(**{<EOL>'<STR_LIT>': device,<EOL>'<STR_LIT:name>': interface['<STR_LIT:name>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>']<EOL>})<EOL><DEDENT>elif interface['<STR_LIT:type>'] == '<STR_LIT>':<EOL><INDENT>interface_object = Wireless(**{<EOL>'<STR_LIT>': device,<EOL>'<STR_LIT:name>': interface['<STR_LIT:name>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>'],<EOL>'<STR_LIT>': interface['<STR_LIT>']<EOL>})<EOL>for vap in interface['<STR_LIT>']:<EOL><INDENT>vap_object = Vap(<EOL>essid=vap['<STR_LIT>'],<EOL>bssid=vap['<STR_LIT>'],<EOL>encryption=vap['<STR_LIT>']<EOL>)<EOL><DEDENT><DEDENT>if interface_object:<EOL><INDENT>interface_object.full_clean()<EOL>interface_object.save()<EOL>if vap_object:<EOL><INDENT>vap_object.interface = interface_object<EOL>vap_object.full_clean()<EOL>vap_object.save()<EOL><DEDENT>for ip in interface['<STR_LIT>']:<EOL><INDENT>ip_object = Ip(**{<EOL>'<STR_LIT>': interface_object,<EOL>'<STR_LIT:address>': ip['<STR_LIT:address>'],<EOL>})<EOL>ip_object.full_clean()<EOL>ip_object.save()<EOL><DEDENT><DEDENT><DEDENT>if HARDWARE_INSTALLED:<EOL><INDENT>try:<EOL><INDENT>device_model = DeviceModel.objects.filter(name__iexact=device_dict['<STR_LIT>'])[<NUM_LIT:0>]<EOL><DEDENT>except IndexError as e:<EOL><INDENT>try:<EOL><INDENT>manufacturer = Manufacturer.objects.filter(name__iexact=device_dict['<STR_LIT>'])[<NUM_LIT:0>]<EOL><DEDENT>except IndexError as e:<EOL><INDENT>manufacturer = Manufacturer(name=device_dict['<STR_LIT>'])<EOL>manufacturer.full_clean()<EOL>manufacturer.save()<EOL><DEDENT>device_model = DeviceModel(<EOL>manufacturer=manufacturer,<EOL>name=device_dict['<STR_LIT>']<EOL>)<EOL>device_model.ram = device_dict['<STR_LIT>']<EOL><DEDENT>device_model.full_clean()<EOL>device_model.save()<EOL>rel = DeviceToModelRel(device=device, model=device_model)<EOL>rel.full_clean()<EOL>rel.save()<EOL><DEDENT>return device<EOL>
creates device, internal use only