commit c79198a032e7663078cac8e8128a12d434170823
Author: Andrea Spadaccini <spadaccio@google.com>
Date:   Wed Nov 2 17:51:58 2011 +0000

    Pass MasterNetworkParameters instances in RPCs
    
    Pass instances of objects.MasterNetworkParameters when calling RPCs for
    activation and deactivation of master IP.
    
    Signed-off-by: Andrea Spadaccini <spadaccio@google.com>
    Reviewed-by: Guido Trotter <ultrotter@google.com>

diff --git a/lib/backend.py b/lib/backend.py
index 29f0723..bc96104 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -301,30 +301,28 @@ def _BuildMasterIpEnv():
 
 @RunLocalHooks(constants.FAKE_OP_MASTER_TURNUP, "master-ip-turnup",
                _BuildMasterIpEnv)
-def ActivateMasterIp(master_ip, master_netmask, master_netdev, family):
+def ActivateMasterIp(master_params):
   """Activate the IP address of the master daemon.
 
-  @param master_ip: the master IP
-  @param master_netmask: the master IP netmask
-  @param master_netdev: the master network device
-  @param family: the IP family
+  @type master_params: L{objects.MasterNetworkParameters}
+  @param master_params: network parameters of the master
 
   """
   err_msg = None
-  if netutils.TcpPing(master_ip, constants.DEFAULT_NODED_PORT):
-    if netutils.IPAddress.Own(master_ip):
+  if netutils.TcpPing(master_params.ip, constants.DEFAULT_NODED_PORT):
+    if netutils.IPAddress.Own(master_params.ip):
       # we already have the ip:
       logging.debug("Master IP already configured, doing nothing")
     else:
       err_msg = "Someone else has the master ip, not activating"
       logging.error(err_msg)
   else:
-    ipcls = netutils.IPAddress.GetClassFromIpFamily(family)
+    ipcls = netutils.IPAddress.GetClassFromIpFamily(master_params.ip_family)
 
     result = utils.RunCmd([constants.IP_COMMAND_PATH, "address", "add",
-                           "%s/%s" % (master_ip, master_netmask),
-                           "dev", master_netdev, "label",
-                           "%s:0" % master_netdev])
+                           "%s/%s" % (master_params.ip, master_params.netmask),
+                           "dev", master_params.netdev, "label",
+                           "%s:0" % master_params.netdev])
     if result.failed:
       err_msg = "Can't activate master IP: %s" % result.output
       logging.error(err_msg)
@@ -332,11 +330,12 @@ def ActivateMasterIp(master_ip, master_netmask, master_netdev, family):
     else:
       # we ignore the exit code of the following cmds
       if ipcls == netutils.IP4Address:
-        utils.RunCmd(["arping", "-q", "-U", "-c 3", "-I", master_netdev, "-s",
-                      master_ip, master_ip])
+        utils.RunCmd(["arping", "-q", "-U", "-c 3", "-I", master_params.netdev,
+                      "-s", master_params.ip, master_params.ip])
       elif ipcls == netutils.IP6Address:
         try:
-          utils.RunCmd(["ndisc6", "-q", "-r 3", master_ip, master_netdev])
+          utils.RunCmd(["ndisc6", "-q", "-r 3", master_params.ip,
+                        master_params.netdev])
         except errors.OpExecError:
           # TODO: Better error reporting
           logging.warning("Can't execute ndisc6, please install if missing")
@@ -375,22 +374,19 @@ def StartMasterDaemons(no_voting):
 
 @RunLocalHooks(constants.FAKE_OP_MASTER_TURNDOWN, "master-ip-turndown",
                _BuildMasterIpEnv)
-def DeactivateMasterIp(master_ip, master_netmask, master_netdev, family):
+def DeactivateMasterIp(master_params):
   """Deactivate the master IP on this node.
 
-  @param master_ip: the master IP
-  @param master_netmask: the master IP netmask
-  @param master_netdev: the master network device
-  @param family: the IP family
+  @type master_params: L{objects.MasterNetworkParameters}
+  @param master_params: network parameters of the master
 
   """
-  # pylint: disable=W0613
   # TODO: log and report back to the caller the error failures; we
   # need to decide in which case we fail the RPC for this
 
   result = utils.RunCmd([constants.IP_COMMAND_PATH, "address", "del",
-                         "%s/%s" % (master_ip, master_netmask),
-                         "dev", master_netdev])
+                         "%s/%s" % (master_params.ip, master_params.netmask),
+                         "dev", master_params.netdev])
   if result.failed:
     logging.error("Can't remove the master IP, error: %s", result.output)
     # but otherwise ignore the failure
diff --git a/lib/bootstrap.py b/lib/bootstrap.py
index 461df73..17df67e 100644
--- a/lib/bootstrap.py
+++ b/lib/bootstrap.py
@@ -568,11 +568,10 @@ def FinalizeClusterDestroy(master):
   runner = rpc.BootstrapRunner()
 
   master_params = cfg.GetMasterNetworkParameters()
-  result = runner.call_node_deactivate_master_ip(master,
-                                                 master_params.ip,
-                                                 master_params.netmask,
-                                                 master_params.netdev,
-                                                 master_params.ip_family)
+  master_params.name = master
+  result = runner.call_node_deactivate_master_ip(master_params.name,
+                                                 master_params)
+
   msg = result.fail_msg
   if msg:
     logging.warning("Could not disable the master IP: %s", msg)
@@ -712,11 +711,10 @@ def MasterFailover(no_voting=False):
 
   runner = rpc.BootstrapRunner()
   master_params = cfg.GetMasterNetworkParameters()
-  result = runner.call_node_deactivate_master_ip(old_master,
-                                                 master_params.ip,
-                                                 master_params.netmask,
-                                                 master_params.netdev,
-                                                 master_params.ip_family)
+  master_params.name = old_master
+  result = runner.call_node_deactivate_master_ip(master_params.name,
+                                                 master_params)
+
   msg = result.fail_msg
   if msg:
     logging.warning("Could not disable the master IP: %s", msg)
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 6f894a7..5a30684 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -1361,10 +1361,7 @@ class LUClusterDestroy(LogicalUnit):
     _RunPostHook(self, master_params.name)
 
     result = self.rpc.call_node_deactivate_master_ip(master_params.name,
-                                                     master_params.ip,
-                                                     master_params.netmask,
-                                                     master_params.netdev,
-                                                     master_params.ip_family)
+                                                     master_params)
     result.Raise("Could not disable the master role")
 
     return master_params.name
@@ -3332,10 +3329,7 @@ class LUClusterRename(LogicalUnit):
     # shutdown the master IP
     master_params = self.cfg.GetMasterNetworkParameters()
     result = self.rpc.call_node_deactivate_master_ip(master_params.name,
-                                                     master_params.ip,
-                                                     master_params.netmask,
-                                                     master_params.netdev,
-                                                     master_params.ip_family)
+                                                     master_params)
     result.Raise("Could not disable the master role")
 
     try:
@@ -3353,11 +3347,9 @@ class LUClusterRename(LogicalUnit):
         pass
       _UploadHelper(self, node_list, constants.SSH_KNOWN_HOSTS_FILE)
     finally:
+      master_params.ip = new_ip
       result = self.rpc.call_node_activate_master_ip(master_params.name,
-                                                     new_ip,
-                                                     master_params.netmask,
-                                                     master_params.netdev,
-                                                     master_params.ip_family)
+                                                     master_params)
       msg = result.fail_msg
       if msg:
         self.LogWarning("Could not re-enable the master role on"
@@ -3715,10 +3707,7 @@ class LUClusterSetParams(LogicalUnit):
       feedback_fn("Shutting down master ip on the current netdev (%s)" %
                   self.cluster.master_netdev)
       result = self.rpc.call_node_deactivate_master_ip(master_params.name,
-                                                       master_params.ip,
-                                                       master_params.netmask,
-                                                       master_params.netdev,
-                                                       master_params.ip_family)
+                                                       master_params)
       result.Raise("Could not disable the master ip")
       feedback_fn("Changing master_netdev from %s to %s" %
                   (master_params.netdev, self.op.master_netdev))
@@ -3746,10 +3735,7 @@ class LUClusterSetParams(LogicalUnit):
       feedback_fn("Starting the master ip on the new master netdev (%s)" %
                   self.op.master_netdev)
       result = self.rpc.call_node_activate_master_ip(master_params.name,
-                                                     master_params.ip,
-                                                     master_params.netmask,
-                                                     master_params.netdev,
-                                                     master_params.ip_family)
+                                                     master_params)
       if result.fail_msg:
         self.LogWarning("Could not re-enable the master ip on"
                         " the master, please restart manually: %s",
@@ -3913,10 +3899,7 @@ class LUClusterActivateMasterIp(NoHooksLU):
     """
     master_params = self.cfg.GetMasterNetworkParameters()
     self.rpc.call_node_activate_master_ip(master_params.name,
-                                          master_params.ip,
-                                          master_params.netmask,
-                                          master_params.netdev,
-                                          master_params.ip_family)
+                                          master_params)
 
 
 class LUClusterDeactivateMasterIp(NoHooksLU):
@@ -3928,11 +3911,7 @@ class LUClusterDeactivateMasterIp(NoHooksLU):
 
     """
     master_params = self.cfg.GetMasterNetworkParameters()
-    self.rpc.call_node_deactivate_master_ip(master_params.name,
-                                            master_params.ip,
-                                            master_params.netmask,
-                                            master_params.netdev,
-                                            master_params.ip_family)
+    self.rpc.call_node_deactivate_master_ip(master_params.name, master_params)
 
 
 def _WaitForSync(lu, instance, disks=None, oneshot=False):
diff --git a/lib/config.py b/lib/config.py
index 91f0ea0..ee9747c 100644
--- a/lib/config.py
+++ b/lib/config.py
@@ -939,11 +939,11 @@ class ConfigWriter:
 
     """
     cluster = self._config_data.cluster
-    result = objects.MasterNetworkParameters(cluster.master_node,
-      cluster.master_ip,
-      cluster.master_netdev,
-      cluster.master_netmask,
-      cluster.primary_ip_family)
+    result = objects.MasterNetworkParameters(name=cluster.master_node,
+      ip=cluster.master_ip,
+      netmask=cluster.master_netmask,
+      netdev=cluster.master_netdev,
+      ip_family=cluster.primary_ip_family)
 
     return result
 
diff --git a/lib/rpc_defs.py b/lib/rpc_defs.py
index 6550b57..d6b5183 100644
--- a/lib/rpc_defs.py
+++ b/lib/rpc_defs.py
@@ -399,19 +399,13 @@ CALLS = {
       ("no_voting", None, None),
       ], None, "Starts master daemons on a node"),
     ("node_activate_master_ip", SINGLE, TMO_FAST, [
-      ("master_ip", None, "The master IP"),
-      ("master_netmask", None, "The master IP netmask"),
-      ("master_netdev", None, "The master network device"),
-      ("ip_family", None, "The cluster IP family"),
+      ("master_params", ED_OBJECT_DICT, "Network parameters of the master"),
       ], None,
       "Activates master IP on a node"),
     ("node_stop_master", SINGLE, TMO_FAST, [], None,
      "Deactivates master IP and stops master daemons on a node"),
     ("node_deactivate_master_ip", SINGLE, TMO_FAST, [
-      ("master_ip", None, "The master IP"),
-      ("master_netmask", None, "The master IP netmask"),
-      ("master_netdev", None, "The master network device"),
-      ("ip_family", None, "The cluster IP family"),
+      ("master_params", ED_OBJECT_DICT, "Network parameters of the master"),
       ], None,
      "Deactivates master IP on a node"),
     ("node_change_master_netmask", SINGLE, TMO_FAST, [
diff --git a/lib/server/masterd.py b/lib/server/masterd.py
index 39821a8..5956332 100644
--- a/lib/server/masterd.py
+++ b/lib/server/masterd.py
@@ -537,10 +537,7 @@ def ActivateMasterIP():
   master_params = cfg.GetMasterNetworkParameters()
   runner = rpc.BootstrapRunner()
   result = runner.call_node_activate_master_ip(master_params.name,
-                                               master_params.ip,
-                                               master_params.netmask,
-                                               master_params.netdev,
-                                               master_params.ip_family)
+                                               master_params)
 
   msg = result.fail_msg
   if msg:
diff --git a/lib/server/noded.py b/lib/server/noded.py
index c701a23..2e7dcfa 100644
--- a/lib/server/noded.py
+++ b/lib/server/noded.py
@@ -697,15 +697,16 @@ class NodeHttpServer(http.server.HttpServer):
     """Activate the master IP on this node.
 
     """
-    return backend.ActivateMasterIp(params[0], params[1], params[2], params[3])
+    master_params = objects.MasterNetworkParameters.FromDict(params[0])
+    return backend.ActivateMasterIp(master_params)
 
   @staticmethod
   def perspective_node_deactivate_master_ip(params):
     """Deactivate the master IP on this node.
 
     """
-    return backend.DeactivateMasterIp(params[0], params[1], params[2],
-                                      params[3])
+    master_params = objects.MasterNetworkParameters.FromDict(params[0])
+    return backend.DeactivateMasterIp(master_params)
 
   @staticmethod
   def perspective_node_stop_master(params):
