+ spice_bind = hvp[constants.HV_KVM_SPICE_BIND]
+ if spice_bind:
+ if netutils.IsValidInterface(spice_bind):
+ # The user specified a network interface, we have to figure out the IP
+ # address.
+ addresses = netutils.GetInterfaceIpAddresses(spice_bind)
+ spice_ip_version = hvp[constants.HV_KVM_SPICE_IP_VERSION]
+
+ # if the user specified an IP version and the interface does not
+ # have that kind of IP addresses, throw an exception
+ if spice_ip_version != constants.IFACE_NO_IP_VERSION_SPECIFIED:
+ if not addresses[spice_ip_version]:
+ raise errors.HypervisorError("spice: unable to get an IPv%s address"
+ " for %s" % (spice_ip_version,
+ spice_bind))
+
+ # the user did not specify an IP version, we have to figure it out
+ elif (addresses[constants.IP4_VERSION] and
+ addresses[constants.IP6_VERSION]):
+ # we have both ipv4 and ipv6, let's use the cluster default IP
+ # version
+ cluster_family = ssconf.SimpleStore().GetPrimaryIPFamily()
+ spice_ip_version = netutils.IPAddress.GetVersionFromAddressFamily(
+ cluster_family)
+ elif addresses[constants.IP4_VERSION]:
+ spice_ip_version = constants.IP4_VERSION
+ else:
+ spice_ip_version = constants.IP6_VERSION
+
+ spice_address = addresses[spice_ip_version][0]
+
+ else:
+ # spice_bind is known to be a valid IP address, because
+ # ValidateParameters checked it.
+ spice_address = spice_bind
+
+ spice_arg = "addr=%s,ipv%s,port=%s" % (spice_address,
+ spice_ip_version,
+ instance.network_port)
+
+ spice_arg = "%s,disable-ticketing" % spice_arg
+
+ logging.info("KVM: SPICE will listen on port %s", instance.network_port)
+ kvm_cmd.extend(["-spice", spice_arg])
+