[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [virt-tools-list] [RFC PATCH] add shh option to VM context menu



On 08/12/2011 05:25 AM, Gerhard Stenzel wrote:
> 
> Occasionally I have the need to ssh into on of my VMs. To simplify that,
> I made the attached patch. I realize, that it will not work in all 
> configurations, but maybe someone else will find it useful or have some
> ideas to make it more generic.
> One will will also probably need to change the variable user.
> 

I can understand how this is convenient in some cases but I don't think
this is something we want to add to the UI: fundamentally I don't like
the idea of having virt-manager launch another terminal, we should be a
self contained app.

Maybe you could propose this a 'virsh ssh' command? I'd bring it up on
libvirt-list before starting to implement it though.

Thanks,
Cole

> Signed-off-by: Gerhard Stenzel <stenzel at de.ibm.com>
> 
> ===================================================================
> Index: virt-manager/src/virtManager/manager.py
> ===================================================================
> --- virt-manager.orig/src/virtManager/manager.py
> +++ virt-manager/src/virtManager/manager.py
> @@ -19,6 +19,8 @@
>  #
>  
>  import gtk
> +import os
> +import logging
>  
>  import virtManager.uihelpers as uihelpers
>  from virtManager.connection import vmmConnection
> @@ -333,6 +335,7 @@ class vmmManager(vmmGObjectUI):
>  
>          add_sep(self.vmmenu, self.vmmenu_items, "hsep2")
>          add_vm_menu("open", gtk.STOCK_OPEN, None, self.show_vm)
> +        add_vm_menu("ssh",  _("_ssh"), None, self.ssh_vm)
>          self.vmmenu.show()
>  
>          # Build connection context menu
> @@ -632,6 +635,28 @@ class vmmManager(vmmGObjectUI):
>              self.emit("action-migrate-domain",
>                        vm.conn.get_uri(), vm.get_uuid())
>  
> +    def ssh_vm(self, ignore, ignore2=None, ignore3=None):
> +        conn = self.current_conn()
> +        vm = self.current_vm()
> +        if conn is None:
> +            return
> +
> +        if vm:
> +            logging.debug("ssh to %s" % vm.get_name())
> +            # get mac address and search for it in the leases file
> +            for netdev in vm.get_network_devices(refresh_if_necc=False):
> +                mac = netdev.macaddr
> +                logging.debug("mac %s" % mac)
> +                f=open('/var/lib/libvirt/dnsmasq/default.leases', 'r')
> +                for line in f.readlines():
> +                    logging.debug("line %s" % line)
> +                    words = line.split()
> +                    if mac == words[1]:
> +                        user = "user"
> +                        logging.debug("user is %s" % user)
> +                        logging.debug("ip is %s" % words[2])
> +                        os.system("terminal -x ssh -X " + user + "@" + words[2] + " &")
> +
>      def close_conn(self, ignore):
>          conn = self.current_conn()
>          if conn.get_state() != vmmConnection.STATE_DISCONNECTED:
> ===================================================================
> 
> Best regards, 
> 
> Gerhard Stenzel
> -------------------------------------------------------------------------------------
> IBM Deutschland Research & Development GmbH
> Vorsitzender des Aufsichtsrats: Martin Jetter
> Geschaeftsfuehrung: Dirk Wittkopp
> Sitz der Gesellschaft: Boeblingen
> Registergericht: Amtsgericht Stuttgart, HRB 243294


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]