Fix X509CertError definition in Haskell codebase
[ganeti-local] / lib / rpc.py
index f1a470e..87fd81f 100644 (file)
@@ -47,6 +47,8 @@ from ganeti import ssconf
 from ganeti import runtime
 from ganeti import compat
 from ganeti import rpc_defs
+from ganeti import pathutils
+from ganeti import vcluster
 
 # Special module generated at build time
 from ganeti import _generated_rpc
@@ -55,22 +57,11 @@ from ganeti import _generated_rpc
 import ganeti.http.client  # pylint: disable=W0611
 
 
-# Timeout for connecting to nodes (seconds)
-_RPC_CONNECT_TIMEOUT = 5
-
 _RPC_CLIENT_HEADERS = [
   "Content-type: %s" % http.HTTP_APP_JSON,
   "Expect:",
   ]
 
-# Various time constants for the timeout table
-_TMO_URGENT = 60 # one minute
-_TMO_FAST = 5 * 60 # five minutes
-_TMO_NORMAL = 15 * 60 # 15 minutes
-_TMO_SLOW = 3600 # one hour
-_TMO_4HRS = 4 * 3600
-_TMO_1DAY = 86400
-
 #: Special value to describe an offline host
 _OFFLINE = object()
 
@@ -104,7 +95,7 @@ def Shutdown():
 
 
 def _ConfigRpcCurl(curl):
-  noded_cert = str(constants.NODED_CERT_FILE)
+  noded_cert = str(pathutils.NODED_CERT_FILE)
 
   curl.setopt(pycurl.FOLLOWLOCATION, False)
   curl.setopt(pycurl.CAINFO, noded_cert)
@@ -114,7 +105,7 @@ def _ConfigRpcCurl(curl):
   curl.setopt(pycurl.SSLCERT, noded_cert)
   curl.setopt(pycurl.SSLKEYTYPE, "PEM")
   curl.setopt(pycurl.SSLKEY, noded_cert)
-  curl.setopt(pycurl.CONNECTTIMEOUT, _RPC_CONNECT_TIMEOUT)
+  curl.setopt(pycurl.CONNECTTIMEOUT, constants.RPC_CONNECT_TIMEOUT)
 
 
 def RunWithRPC(fn):
@@ -534,7 +525,9 @@ def _PrepareFileUpload(getents_fn, filename):
 
   getents = getents_fn()
 
-  return [filename, data, st.st_mode, getents.LookupUid(st.st_uid),
+  virt_filename = vcluster.MakeVirtualPath(filename)
+
+  return [virt_filename, data, st.st_mode, getents.LookupUid(st.st_uid),
           getents.LookupGid(st.st_gid), st.st_atime, st.st_mtime]
 
 
@@ -575,6 +568,20 @@ def _EncodeBlockdevRename(value):
   return [(d.ToDict(), uid) for d, uid in value]
 
 
+def MakeLegacyNodeInfo(data):
+  """Formats the data returned by L{rpc.RpcRunner.call_node_info}.
+
+  Converts the data into a single dictionary. This is fine for most use cases,
+  but some require information from more than one volume group or hypervisor.
+
+  """
+  (bootid, (vg_info, ), (hv_info, )) = data
+
+  return utils.JoinDisjointDicts(utils.JoinDisjointDicts(vg_info, hv_info), {
+    "bootid": bootid,
+    })
+
+
 def _AnnotateDParamsDRBD(disk, (drbd_params, data_params, meta_params)):
   """Annotates just DRBD disks layouts.
 
@@ -618,11 +625,7 @@ def AnnotateDiskParams(template, disks, disk_params):
   else:
     annotation_fn = _AnnotateDParamsGeneric
 
-  new_disks = []
-  for disk in disks:
-    new_disks.append(annotation_fn(disk.Copy(), ld_params))
-
-  return new_disks
+  return [annotation_fn(disk.Copy(), ld_params) for disk in disks]
 
 
 #: Generic encoders
@@ -735,9 +738,7 @@ class RpcRunner(_RpcClientBase,
     """Wrapper for L{_InstDict}.
 
     """
-    updated_inst = self._InstDict(instance, osp=osparams)
-    updated_inst["disks"] = self._DisksDictDP((instance.disks, instance))
-    return updated_inst
+    return self._InstDict(instance, osp=osparams)
 
   def _DisksDictDP(self, (disks, instance)):
     """Wrapper for L{AnnotateDiskParams}.