Add instance port support.
[ganeti-local] / lib / bdev.py
index 38c327a..5069bb2 100644 (file)
@@ -400,8 +400,8 @@ class LogicalVolume(BlockDev):
     """
     result = utils.RunCmd(["lvdisplay", self.dev_path])
     if result.failed:
-      logger.Error("Can't find LV %s: %s" %
-                   (self.dev_path, result.fail_reason))
+      logger.Error("Can't find LV %s: %s, %s" %
+                   (self.dev_path, result.fail_reason, result.output))
       return False
     match = re.compile("^ *Block device *([0-9]+):([0-9]+).*$")
     for line in result.stdout.splitlines():
@@ -1341,7 +1341,8 @@ class DRBDev(BaseDRBD):
 
     """
     result = utils.RunCmd(["drbdsetup", cls._DevPath(minor), "disconnect"])
-    logger.Error("Can't shutdown network: %s" % result.output)
+    if result.failed:
+      logger.Error("Can't shutdown network: %s" % result.output)
     return not result.failed
 
   def Assemble(self):
@@ -1701,7 +1702,7 @@ class DRBD8(BaseDRBD):
     rbrace = pyp.Literal("}").suppress()
     semi = pyp.Literal(";").suppress()
     # this also converts the value to an int
-    number = pyp.Word(pyp.nums).setParseAction(lambda s, l, t:(l, [int(t[0])]))
+    number = pyp.Word(pyp.nums).setParseAction(lambda s, l, t: int(t[0]))
 
     comment = pyp.Literal ("#") + pyp.Optional(pyp.restOfLine)
     defa = pyp.Literal("_is_default").suppress()
@@ -1857,6 +1858,11 @@ class DRBD8(BaseDRBD):
 
     """
     lhost, lport, rhost, rport = net_info
+    if None in net_info:
+      # we don't want network connection and actually want to make
+      # sure its shutdown
+      return cls._ShutdownNet(minor)
+
     args = ["drbdsetup", cls._DevPath(minor), "net",
             "%s:%s" % (lhost, lport), "%s:%s" % (rhost, rport), protocol,
             "-A", "discard-zero-changes",
@@ -2093,6 +2099,24 @@ class DRBD8(BaseDRBD):
       # even though we were passed some children at init time
       if match_r and "local_dev" not in info:
         break
+      if match_l and not match_r and "local_addr" in info:
+        # strange case - the device network part points to somewhere
+        # else, even though its local storage is ours; as we own the
+        # drbd space, we try to disconnect from the remote peer and
+        # reconnect to our correct one
+        if not self._ShutdownNet(minor):
+          raise errors.BlockDeviceError("Device has correct local storage,"
+                                        " wrong remote peer and is unable to"
+                                        " disconnect in order to attach to"
+                                        " the correct peer")
+        # note: _AssembleNet also handles the case when we don't want
+        # local storage (i.e. one or more of the _[lr](host|port) is
+        # None)
+        if (self._AssembleNet(minor, (self._lhost, self._lport,
+                                      self._rhost, self._rport), "C") and
+            self._MatchesNet(self._GetDevInfo(minor))):
+          break
+
     else:
       minor = None
 
@@ -2170,7 +2194,8 @@ class DRBD8(BaseDRBD):
 
     """
     result = utils.RunCmd(["drbdsetup", cls._DevPath(minor), "disconnect"])
-    logger.Error("Can't shutdown network: %s" % result.output)
+    if result.failed:
+      logger.Error("Can't shutdown network: %s" % result.output)
     return not result.failed
 
   @classmethod
@@ -2198,27 +2223,6 @@ class DRBD8(BaseDRBD):
     self.dev_path = None
     return True
 
-  def Rename(self, new_uid):
-    """Re-connect this device to another peer.
-
-    """
-    if self.minor is None:
-      raise errors.BlockDeviceError("Device not attached during rename")
-    if self._rhost is not None:
-      # this means we did have a host when we attached, so we are connected
-      if not self._ShutdownNet(self.minor):
-        raise errors.BlockDeviceError("Can't disconnect from remote peer")
-      old_id = self.unique_id
-    else:
-      old_id = None
-    self.unique_id = new_uid
-    if not self._AssembleNet(self.minor, self.unique_id, "C"):
-      logger.Error("Can't attach to new peer!")
-      if old_id is not None:
-        self._AssembleNet(self.minor, old_id, "C")
-      self.unique_id = old_id
-      raise errors.BlockDeviceError("Can't attach to new peer")
-
   def Remove(self):
     """Stub remove for DRBD devices.