From 371bf1bdffe957490700e36bf4b982c7a8dbd43a Mon Sep 17 00:00:00 2001
From: gecong1973 <ge.cong@zte.com.cn>
Date: Mon, 5 Sep 2016 16:40:44 +0800
Subject: [PATCH] Add __ne__ built-in function

In Python 3 __ne__ by default delegates to __eq__ and inverts the
result, but in Python 2 they urge you to define __ne__ when you
define __eq__ for it to work properly [1].There are no implied
relationships among the comparison operators. The truth of x==y
does not imply that x!=y is false. Accordingly, when defining __eq__(),
one should also define __ne__() so that the operators will behave
as expected.
[1]https://docs.python.org/2/reference/datamodel.html#object.__ne__

Change-Id: Ib9db2166313f49f3b40df7ce0aba8b01c6a2869a
---
 almanach/core/model.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/almanach/core/model.py b/almanach/core/model.py
index 99df8b5..cd750fd 100644
--- a/almanach/core/model.py
+++ b/almanach/core/model.py
@@ -36,6 +36,9 @@ class Entity(object):
                 other.name == self.name and
                 other.entity_type == self.entity_type)
 
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
 
 class Instance(Entity):
     TYPE = "instance"
@@ -56,6 +59,9 @@ class Instance(Entity):
                 other.os == self.os and
                 other.metadata == self.metadata)
 
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
 
 class OS(object):
     def __init__(self, os_type, distro, version):
@@ -68,6 +74,9 @@ class OS(object):
                 other.distro == self.distro and
                 other.version == self.version)
 
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
 
 class Volume(Entity):
     TYPE = "volume"
@@ -85,6 +94,9 @@ class Volume(Entity):
                 other.size == self.size and
                 other.attached_to == self.attached_to)
 
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
 
 class VolumeType(object):
     def __init__(self, volume_type_id, volume_type_name):
@@ -94,6 +106,9 @@ class VolumeType(object):
     def __eq__(self, other):
         return other.__dict__ == self.__dict__
 
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
     def as_dict(self):
         return todict(self)