summaryrefslogtreecommitdiff
blob: f7a664fa776de32cfa92705fa2420aba242ebbaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
From e91ae73f593115dba1f77af6a3af30cf2219f880 Mon Sep 17 00:00:00 2001
Message-Id: <e91ae73f593115dba1f77af6a3af30cf2219f880.1483650125.git.robbat2@gentoo.org>
From: "Robin H. Johnson" <robbat2@gentoo.org>
Date: Thu, 29 Sep 2016 08:57:28 -0700
Subject: [PATCH-2.17] kvm: use_guest_agent: QEMU Guest Agent support

Implement the QEMU Guest Agent sockets, so that code/scripts on the
hypervisors can communicate with guest operating systems easily.

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
---
 lib/hypervisor/hv_kvm/__init__.py | 23 +++++++++++++++++++++++
 man/gnt-instance.rst              |  7 +++++++
 src/Ganeti/Constants.hs           |  5 +++++
 3 files changed, 35 insertions(+)

diff --git a/lib/hypervisor/hv_kvm/__init__.py b/lib/hypervisor/hv_kvm/__init__.py
index ac02ff56c..b865d6f3a 100644
--- a/lib/hypervisor/hv_kvm/__init__.py
+++ b/lib/hypervisor/hv_kvm/__init__.py
@@ -497,6 +497,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     constants.HV_MIGRATION_BANDWIDTH: hv_base.REQ_NONNEGATIVE_INT_CHECK,
     constants.HV_MIGRATION_DOWNTIME: hv_base.REQ_NONNEGATIVE_INT_CHECK,
     constants.HV_MIGRATION_MODE: hv_base.MIGRATION_MODE_CHECK,
+    constants.HV_USE_GUEST_AGENT: hv_base.NO_CHECK,
     constants.HV_USE_LOCALTIME: hv_base.NO_CHECK,
     constants.HV_DISK_CACHE:
       hv_base.ParamInSet(True, constants.HT_VALID_CACHE_TYPES),
@@ -750,6 +751,13 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     """
     return utils.PathJoin(cls._CTRL_DIR, "%s.qmp" % instance_name)
 
+  @classmethod
+  def _InstanceQemuGuestAgentMonitor(cls, instance_name):
+    """Returns the instance serial QEMU Guest Agent socket name
+
+    """
+    return utils.PathJoin(cls._CTRL_DIR, "%s.qga" % instance_name)
+
   @classmethod
   def _InstanceKvmdMonitor(cls, instance_name):
     """Returns the instance kvm daemon socket name
@@ -836,6 +844,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     utils.RemoveFile(cls._InstanceMonitor(instance_name))
     utils.RemoveFile(cls._InstanceSerial(instance_name))
     utils.RemoveFile(cls._InstanceQmpMonitor(instance_name))
+    utils.RemoveFile(cls._InstanceQemuGuestAgentMonitor(instance_name))
     utils.RemoveFile(cls._InstanceKVMRuntime(instance_name))
     utils.RemoveFile(cls._InstanceKeymapFile(instance_name))
     uid_file = cls._InstanceUidFile(instance_name)
@@ -1544,6 +1553,20 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     if self._UUID_RE.search(kvmhelp):
       kvm_cmd.extend(["-uuid", instance.uuid])
 
+    # Add guest agent socket
+    if hvp[constants.HV_USE_GUEST_AGENT]:
+      qga_addr = utils.GetFreeSlot(bus_slots[_PCI_BUS], reserve=True)
+      qga_pci_info = "bus=%s,addr=%s" % (_PCI_BUS, hex(qga_addr))
+      qga_path = self._InstanceQemuGuestAgentMonitor(instance.name)
+      logging.info("KVM: Guest Agent available at %s", qga_path)
+      # The 'qga0' identified can change, but the 'org.qemu.guest_agent.0' string is
+      # the default expected by the Guest Agent.
+      kvm_cmd.extend([
+        "-chardev", "socket,path=%s,server,nowait,id=qga0" % qga_path,
+        "-device", "virtio-serial,id=qga0,%s" % qga_pci_info,
+        "-device", "virtserialport,chardev=qga0,name=org.qemu.guest_agent.0",
+        ])
+
     if hvp[constants.HV_KVM_EXTRA]:
       kvm_cmd.extend(hvp[constants.HV_KVM_EXTRA].split(" "))
 
diff --git a/man/gnt-instance.rst b/man/gnt-instance.rst
index 283392cc8..493ae929d 100644
--- a/man/gnt-instance.rst
+++ b/man/gnt-instance.rst
@@ -545,6 +545,13 @@ viridian
     viridian (Hyper-V) for this instance. The default is false,
     disabling viridian support.
 
+use\_guest\_agent
+    Valid for the KVM hypervisor.
+
+    A boolean option that specifies if the hypervisor should enable
+    the QEMU Guest Agent protocol for this instance. By default, the
+    Guest Agent is disabled.
+
 use\_localtime
     Valid for the Xen HVM and KVM hypervisors.
 
diff --git a/src/Ganeti/Constants.hs b/src/Ganeti/Constants.hs
index 13bff2e71..7f43f89f9 100644
--- a/src/Ganeti/Constants.hs
+++ b/src/Ganeti/Constants.hs
@@ -1821,6 +1821,9 @@ hvUsbMouse = "usb_mouse"
 hvUseBootloader :: String
 hvUseBootloader = "use_bootloader"
 
+hvUseGuestAgent :: String
+hvUseGuestAgent = "use_guest_agent"
+
 hvUseLocaltime :: String
 hvUseLocaltime = "use_localtime"
 
@@ -1955,6 +1958,7 @@ hvsParameterTypes = Map.fromList
   , (hvUsbDevices,                      VTypeString)
   , (hvUsbMouse,                        VTypeString)
   , (hvUseBootloader,                   VTypeBool)
+  , (hvUseGuestAgent,                   VTypeBool)
   , (hvUseLocaltime,                    VTypeBool)
   , (hvVga,                             VTypeString)
   , (hvVhostNet,                        VTypeBool)
@@ -4111,6 +4115,7 @@ hvcDefaults =
           , (hvMigrationBandwidth,              PyValueEx (32 :: Int))
           , (hvMigrationDowntime,               PyValueEx (30 :: Int))
           , (hvMigrationMode,                   PyValueEx htMigrationLive)
+          , (hvUseGuestAgent,                   PyValueEx False)
           , (hvUseLocaltime,                    PyValueEx False)
           , (hvDiskCache,                       PyValueEx htCacheDefault)
           , (hvSecurityModel,                   PyValueEx htSmNone)
-- 
2.11.0.rc2