driver.py 及 config 修改

  1. 切換工作目錄。
    [root@ip110 ~]# cd /usr/lib/python2.7/site-packages/nova/virt/libvirt/
    [root@ip110 libvirt]#
    
  2. 修改 driver.py:self._guest_add_video_device 函式增加引數 instance,判斷 instance.metadata 是否設定 hw:port,有則使用且 graphics.autoport=False。判斷 instance.metadata 是否設定 hw:posswd,有則使用此密碼。
    [root@ip110 libvirt]# diff -uN driver.py.orig driver.py
    --- driver.py.orig	2020-06-03 14:29:50.404375116 +0800
    +++ driver.py	2020-06-06 17:17:49.127199302 +0800
    @@ -5200,7 +5200,7 @@
     
             self._guest_add_spice_channel(guest)
     
    -        if self._guest_add_video_device(guest):
    +        if self._guest_add_video_device(guest,instance):
                 self._add_video_driver(guest, image_meta, flavor)
     
                 # We want video == we want graphical console. Some architectures
    @@ -5285,7 +5285,7 @@
                     raise exception.PciDeviceUnsupportedHypervisor(type=virt_type)
     
         @staticmethod
    -    def _guest_add_video_device(guest):
    +    def _guest_add_video_device(guest,instance):
             # NB some versions of libvirt support both SPICE and VNC
             # at the same time. We're not trying to second guess which
             # those versions are. We'll just let libvirt report the
    @@ -5310,6 +5310,10 @@
                     # necessitate deprecating this option entirely in the future.
                     # Refer to bug #1682020 for more information.
                     graphics.keymap = CONF.spice.keymap
    +            graphics.port = instance.metadata.get('hw:port')
    +            if graphics.port: graphics.autoport = False
    +            else: graphics.autoport = True
    +            graphics.passwd = instance.metadata.get('hw:passwd')
                 graphics.listen = CONF.spice.server_listen
                 guest.add_device(graphics)
                 add_video_driver = True
    
  3. 修改 config.py:增加 port 及 passwd 的設定。
    [root@ip110 libvirt]# diff -uN config.py.orig config.py
    --- config.py.orig	2020-06-03 14:19:38.122154902 +0800
    +++ config.py	2020-06-05 16:50:30.358531089 +0800
    @@ -1542,6 +1542,8 @@
     
             self.type = "vnc"
             self.autoport = True
    +        self.port = None
    +        self.passwd = None
             self.keymap = None
             self.listen = None
     
    @@ -1553,6 +1555,9 @@
                 dev.set("autoport", "yes")
             else:
                 dev.set("autoport", "no")
    +            dev.set("port", self.port)
    +        if self.passwd:
    +            dev.set("passwd", self.passwd)
             if self.keymap:
                 dev.set("keymap", self.keymap)
             if self.listen:
    
  4. 修改後必須重新啟動 openstack-nova-compute 服務才會生效。
    [root@ip110 libvirt]# systemctl restart openstack-nova-compute.service