Tolerate the absence of server at maas for storage configuration

Change-Id: Iae987dcbf8e0d8f5e89607ed56b633b49e390b9b
diff --git a/_modules/maasng.py b/_modules/maasng.py
index 90e04f1..0ec08f6 100644
--- a/_modules/maasng.py
+++ b/_modules/maasng.py
@@ -121,11 +121,16 @@
     .. code-block:: bash
 
         salt-call maasng.get_machine server_hostname
+
+    Error codes:
+        0 : Machine not found
     """
     try:
         return list_machines()[hostname]
     except KeyError:
-        return {"error": "Machine not found on MaaS server"}
+        return {"error":
+                       { 0: "Machine not found" }
+               }
 
 
 def list_machines(status_filter=None):
diff --git a/_states/maasng.py b/_states/maasng.py
index 22c68fc..7bfdcd8 100644
--- a/_states/maasng.py
+++ b/_states/maasng.py
@@ -56,10 +56,13 @@
 
     machine = __salt__['maasng.get_machine'](hostname)
     if "error" in machine:
-        ret['comment'] = "State execution failed for machine {0}".format(
-            hostname)
-        ret['result'] = False
-        ret['changes'] = machine
+        if 0 in machine["error"]:
+            ret['comment'] = "No such machine {0}".format(hostname)
+            ret['changes'] = machine
+        else:
+            ret['comment'] = "State execution failed for machine {0}".format(hostname)
+            ret['result'] = False
+            ret['changes'] = machine
         return ret
 
     if machine["status_name"] != "Ready":
@@ -108,10 +111,14 @@
 
     machine = __salt__['maasng.get_machine'](hostname)
     if "error" in machine:
-        ret['comment'] = "State execution failed for machine {0}".format(
-            hostname)
-        ret['result'] = False
-        ret['changes'] = machine
+        if 0 in machine["error"]:
+            ret['comment'] = "No such machine {0}".format(hostname)
+            ret['changes'] = machine
+        else:
+            ret['comment'] = "State execution failed for machine {0}".format(
+                hostname)
+            ret['result'] = False
+            ret['changes'] = machine
         return ret
 
     if machine["status_name"] != "Ready":
@@ -166,10 +173,14 @@
 
     machine = __salt__['maasng.get_machine'](hostname)
     if "error" in machine:
-        ret['comment'] = "State execution failed for machine {0}".format(
-            hostname)
-        ret['result'] = False
-        ret['changes'] = machine
+        if 0 in machine["error"]:
+            ret['comment'] = "No such machine {0}".format(hostname)
+            ret['changes'] = machine
+        else:
+            ret['comment'] = "State execution failed for machine {0}".format(
+                hostname)
+            ret['result'] = False
+            ret['changes'] = machine
         return ret
 
     if machine["status_name"] != "Ready":
@@ -242,10 +253,14 @@
 
     machine = __salt__['maasng.get_machine'](hostname)
     if "error" in machine:
-        ret['comment'] = "State execution" \
-                         "failed for machine {0}".format(hostname)
-        ret['result'] = False
-        ret['changes'] = machine
+        if 0 in machine["error"]:
+            ret['comment'] = "No such machine {0}".format(hostname)
+            ret['changes'] = machine
+        else:
+            ret['comment'] = "State execution" \
+                             "failed for machine {0}".format(hostname)
+            ret['result'] = False
+            ret['changes'] = machine
         return ret
 
     if machine["status_name"] != "Ready":
@@ -289,10 +304,14 @@
 
     machine = __salt__['maasng.get_machine'](hostname)
     if "error" in machine:
-        ret['comment'] = "State execution failed for machine {0}".format(
-            hostname)
-        ret['result'] = False
-        ret['changes'] = machine
+        if 0 in machine["error"]:
+            ret['comment'] = "No such machine {0}".format(hostname)
+            ret['changes'] = machine
+        else:
+            ret['comment'] = "State execution failed for machine {0}".format(
+                hostname)
+            ret['result'] = False
+            ret['changes'] = machine
         return ret
 
     if machine["status_name"] != "Ready":
@@ -327,10 +346,14 @@
 
     machine = __salt__['maasng.get_machine'](hostname)
     if "error" in machine:
-        ret['comment'] = "State execution" \
-                         "failed for machine {0}".format(hostname)
-        ret['result'] = False
-        ret['changes'] = machine
+        if 0 in machine["error"]:
+            ret['comment'] = "No such machine {0}".format(hostname)
+            ret['changes'] = machine
+        else:
+            ret['comment'] = "State execution" \
+                             "failed for machine {0}".format(hostname)
+            ret['result'] = False
+            ret['changes'] = machine
         return ret
 
     if machine["status_name"] != "Ready":