Commit 4d2cdb5a authored by Andrea Spadaccini's avatar Andrea Spadaccini
Browse files

Add SPICE support to gnt-instance console



Also update related unit tests.
Signed-off-by: default avatarAndrea Spadaccini <spadaccio@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 2ebdfbb5
......@@ -934,6 +934,9 @@ def _DoConsole(console, show_command, cluster_name, feedback_fn=ToStdout,
" URL <vnc://%s:%s/>",
console.instance, console.host, console.port,
console.display, console.host, console.port)
elif console.kind == constants.CONS_SPICE:
feedback_fn("Instance %s has SPICE listening on %s:%s", console.instance,
console.host, console.port)
elif console.kind == constants.CONS_SSH:
# Convert to string if not already one
if isinstance(console.command, basestring):
......
......@@ -255,11 +255,14 @@ CONS_SSH = "ssh"
#: Console as VNC server
CONS_VNC = "vnc"
#: Console as SPICE server
CONS_SPICE = "spice"
#: Display a message for console access
CONS_MESSAGE = "msg"
#: All console types
CONS_ALL = frozenset([CONS_SSH, CONS_VNC, CONS_MESSAGE])
CONS_ALL = frozenset([CONS_SSH, CONS_VNC, CONS_SPICE, CONS_MESSAGE])
# For RSA keys more bits are better, but they also make operations more
# expensive. NIST SP 800-131 recommends a minimum of 2048 bits from the year
......
......@@ -1527,6 +1527,13 @@ class KVMHypervisor(hv_base.BaseHypervisor):
port=instance.network_port,
display=display)
spice_bind = hvparams[constants.HV_KVM_SPICE_BIND]
if spice_bind:
return objects.InstanceConsole(instance=instance.name,
kind=constants.CONS_SPICE,
host=spice_bind,
port=instance.network_port)
return objects.InstanceConsole(instance=instance.name,
kind=constants.CONS_MESSAGE,
message=("No serial shell for instance %s" %
......
......@@ -1523,15 +1523,20 @@ class InstanceConsole(ConfigObject):
"""
assert self.kind in constants.CONS_ALL, "Unknown console type"
assert self.instance, "Missing instance name"
assert self.message or self.kind in [constants.CONS_SSH, constants.CONS_VNC]
assert self.message or self.kind in [constants.CONS_SSH,
constants.CONS_SPICE,
constants.CONS_VNC]
assert self.host or self.kind == constants.CONS_MESSAGE
assert self.port or self.kind in [constants.CONS_MESSAGE,
constants.CONS_SSH]
assert self.user or self.kind in [constants.CONS_MESSAGE,
constants.CONS_SPICE,
constants.CONS_VNC]
assert self.command or self.kind in [constants.CONS_MESSAGE,
constants.CONS_SPICE,
constants.CONS_VNC]
assert self.display or self.kind in [constants.CONS_MESSAGE,
constants.CONS_SPICE,
constants.CONS_SSH]
return True
......
......@@ -173,6 +173,7 @@ class TestConsole(unittest.TestCase):
hvparams = {
constants.HV_SERIAL_CONSOLE: True,
constants.HV_VNC_BIND_ADDRESS: None,
constants.HV_KVM_SPICE_BIND: None,
}
cons = self._Test(instance, hvparams)
self.assertEqual(cons.kind, constants.CONS_SSH)
......@@ -187,6 +188,7 @@ class TestConsole(unittest.TestCase):
hvparams = {
constants.HV_SERIAL_CONSOLE: False,
constants.HV_VNC_BIND_ADDRESS: "192.0.2.1",
constants.HV_KVM_SPICE_BIND: None,
}
cons = self._Test(instance, hvparams)
self.assertEqual(cons.kind, constants.CONS_VNC)
......@@ -194,6 +196,20 @@ class TestConsole(unittest.TestCase):
self.assertEqual(cons.port, constants.VNC_BASE_PORT + 10)
self.assertEqual(cons.display, 10)
def testSpice(self):
instance = objects.Instance(name="kvm.example.com",
primary_node="node7235",
network_port=11000)
hvparams = {
constants.HV_SERIAL_CONSOLE: False,
constants.HV_VNC_BIND_ADDRESS: None,
constants.HV_KVM_SPICE_BIND: "192.0.2.1",
}
cons = self._Test(instance, hvparams)
self.assertEqual(cons.kind, constants.CONS_SPICE)
self.assertEqual(cons.host, "192.0.2.1")
self.assertEqual(cons.port, 11000)
def testNoConsole(self):
instance = objects.Instance(name="kvm.example.com",
primary_node="node24325",
......@@ -201,6 +217,7 @@ class TestConsole(unittest.TestCase):
hvparams = {
constants.HV_SERIAL_CONSOLE: False,
constants.HV_VNC_BIND_ADDRESS: None,
constants.HV_KVM_SPICE_BIND: None,
}
cons = self._Test(instance, hvparams)
self.assertEqual(cons.kind, constants.CONS_MESSAGE)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment