def exists(self): prev_obj = None id_exists = False name_exists = False o_id = self.new_object.get("id") o_id = o_id or self.new_object.get("member_id") name = self.new_object.get("name") if o_id: prev_obj = self.get_object_by_id(o_id) id_exists = prev_obj is not None and isinstance(prev_obj, dict) if not id_exists and name: prev_obj = self.get_object_by_name(name) name_exists = prev_obj is not None and isinstance(prev_obj, dict) if name_exists: _id = prev_obj.get("id") _id = _id or prev_obj.get("memberId") if id_exists and name_exists and o_id != _id: raise InconsistentParameters( "The 'id' and 'name' params don't refer to the same object" ) if _id: self.new_object.update(dict(id=_id)) self.new_object.update(dict(member_id=_id)) if _id: prev_obj = self.get_object_by_id(_id) it_exists = prev_obj is not None and isinstance(prev_obj, dict) return (it_exists, prev_obj)
def exists(self): id_exists = False name_exists = False prev_obj = None o_id = self.new_object.get("id") name = self.new_object.get("name") or \ self.new_object.get('ipAddress') if isinstance(name, list) and len(name) > 0: name = name[0] if o_id: prev_obj = self.get_object_by_id(o_id) id_exists = prev_obj is not None and isinstance(prev_obj, dict) if not id_exists and name: prev_obj = self.get_object_by_name(name) name_exists = prev_obj is not None and isinstance(prev_obj, dict) if name_exists: _id = prev_obj.get("id") if id_exists and name_exists and o_id != _id: raise InconsistentParameters( "The 'id' and 'name' params don't refer to the same object" ) if _id: self.new_object.update(dict(id=_id)) if _id: prev_obj = self.get_object_by_id(_id) it_exists = prev_obj is not None and isinstance(prev_obj, dict) return (it_exists, prev_obj)
def exists(self): id_exists = False name_exists = False prev_obj = None o_id = self.new_object.get("id") name = self.new_object.get("name") o_id = o_id or self.new_object.get("_id") device_info = self.new_object.get('deviceInfo') if device_info and isinstance(device_info, dict) and device_info.get('name'): name = name or device_info.get('name') if o_id: prev_obj = self.get_object_by_id(o_id) id_exists = prev_obj is not None and isinstance(prev_obj, dict) if not id_exists and name: prev_obj = self.get_object_by_name(name) name_exists = prev_obj is not None and isinstance(prev_obj, dict) if name_exists: _id = prev_obj.get("id") if id_exists and name_exists and o_id != _id: raise InconsistentParameters( "The 'id' and 'name' params don't refer to the same object" ) if _id: self.new_object.update(dict(id=_id)) if _id: prev_obj = self.get_object_by_id(_id) it_exists = prev_obj is not None and isinstance(prev_obj, dict) return (it_exists, prev_obj)
def exists(self): id_exists = False name_exists = False prev_obj = None requested_obj = self.new_object.get('payload') if requested_obj and len(requested_obj) > 0: requested_obj = requested_obj[0] o_id = self.new_object.get("id") or requested_obj.get("id") name = self.new_object.get("name") or requested_obj.get("name") if o_id: prev_obj = self.get_object_by_id(o_id) id_exists = prev_obj is not None and isinstance(prev_obj, dict) if not id_exists and name: prev_obj = self.get_object_by_name(name) name_exists = prev_obj is not None and isinstance(prev_obj, dict) if name_exists: _id = prev_obj.get("id") if id_exists and name_exists and o_id != _id: raise InconsistentParameters( "The 'id' and 'name' params don't refer to the same object" ) if _id: self.new_object.update(dict(id=_id)) it_exists = prev_obj is not None and isinstance(prev_obj, dict) return (it_exists, prev_obj)
def exists(self): id_exists = False name_exists = False prev_obj = None o_id = self.new_object.get("id") name = self.new_object.get("name") settings = self.new_object.get('settings') if settings and isinstance(settings, dict) and settings.get('ippool'): settings = settings.get('ippool') if settings and isinstance(settings, dict) and settings.get('ipPoolName'): name = name or settings.get('ipPoolName') elif settings and isinstance(settings, list) and len(settings) > 0: if settings[0].get('ipPoolName'): name = settings[0].get('ipPoolName') if o_id: prev_obj = self.get_object_by_id(o_id) id_exists = prev_obj is not None and isinstance(prev_obj, dict) if not id_exists and name: prev_obj = self.get_object_by_name(name) name_exists = prev_obj is not None and isinstance(prev_obj, dict) if name_exists: _id = prev_obj.get("id") if id_exists and name_exists and o_id != _id: raise InconsistentParameters( "The 'id' and 'name' params don't refer to the same object" ) if _id: self.new_object.update(dict(id=_id)) it_exists = prev_obj is not None and isinstance(prev_obj, dict) return (it_exists, prev_obj)