Contents
#!/usr/bin/python2 import libvirt conn = libvirt.openReadOnly("qemu:///system") or die("Failed to open connection to the hypervisor") # List of attributes ## print dir ( conn ) print ( conn.numOfDefinedDomains() )
#!/usr/bin/env python # Copyright © Evaggelos Balaskas (2011+) # v 0.0.11 from gi.repository import Gtk from configparser import ConfigParser import webbrowser import os def quit( data = None ): Gtk.main_quit() def about(data = None): ad = Gtk.AboutDialog() ad.set_name("About") ad.set_program_name("simple virt manager") ad.set_authors(["Evaggelos Balaskas <ebalaskas@ebalaskas.gr>"]) ad.set_website("https://balaskas.gr") ad.set_website_label("https://balaskas.gr") ad.run() ad.destroy() def config_file( hc = 'qemu:///system', vc = 'vncviewer' , button = None): fileconf = os.environ['HOME'] + '/.svm.prefs' config = ConfigParser() if not button: if config.read(fileconf): hc = config['Default']['hypervisor'] vc = config['Default']['vncclient'] config['Default'] = {'hypervisor': hc, 'vncclient': vc } with open(fileconf, 'w') as configfile: config.write(configfile) return config def reset_clicked( button, var, entry ): config = config_file() var.set_text( config['Default'][entry] ) def help_clicked( button ): webbrowser.open("help.html") def save_clicked( button, hc, vc, window ): config_file( hc=hc.get_text(), vc = vc.get_text(), button = 1 ) window.destroy() def Pref(button): config = config_file() window = Gtk.Window() window.set_size_request(300, 100) window.set_title("Preferences") label = Gtk.Label("Plz provide") hclabel = Gtk.Label("Hypervisor Connection: ") hc = Gtk.Entry() hc.set_text( config['Default']['hypervisor'] ) hcreset = Gtk.Button("Reset") vclabel = Gtk.Label("VNC Client:") vc = Gtk.Entry() vc.set_text( config['Default']['vncclient'] ) vcreset = Gtk.Button("Reset") help = Gtk.Button("Help") save = Gtk.Button("Save") hcreset.connect ("clicked", reset_clicked, hc, 'hypervisor' ) vcreset.connect ("clicked", reset_clicked, vc, 'vncclient' ) help.connect ("clicked", help_clicked) save.connect ("clicked", save_clicked, hc, vc, window ) vbox = Gtk.VBox() vbox.add(label) grid = Gtk.Grid() grid.attach(hclabel, 0, 0, 1 ,1) grid.attach(hc, 1, 0, 1, 1) grid.attach(hcreset, 2, 0, 1, 1) grid.attach(vclabel, 0, 1, 1 ,1) grid.attach(vc, 1, 1, 1, 1) grid.attach(vcreset, 2, 1, 1, 1) vbox.add(grid) hbox2 = Gtk.HBox() hbox2.add(help) hbox2.add(save) vbox.add(hbox2) window.add(vbox) window.show_all() def right_click_event( icon, button, time, menu ): menu.show_all() menu.popup(None, None, icon.position_menu, icon, button, time) def left_click_event( icon, menu ): menu.show_all() menu.popup(None, None, icon.position_menu, icon, 1, Gtk.get_current_event_time()) left_click_menu = Gtk.Menu() menuItemQuit = Gtk.MenuItem('Quit') menuItemQuit.connect('activate', quit) left_click_menu.append(menuItemQuit) right_click_menu = Gtk.Menu() menuItemPref = Gtk.MenuItem('Preferences') menuItemPref.connect("activate", Pref) right_click_menu.append(menuItemPref) menuItemAbout = Gtk.MenuItem('About') menuItemAbout.connect("activate", about) right_click_menu.append(menuItemAbout) menuItemQuit = Gtk.MenuItem('Quit') menuItemQuit.connect('activate', quit) right_click_menu.append(menuItemQuit) si = Gtk.StatusIcon() # si.set_from_stock(Gtk.STOCK_HOME) si.set_from_file("libvirt.png") si.set_tooltip_text("simple virt manager") si.connect("activate", left_click_event, left_click_menu ) si.connect("popup-menu", right_click_event, right_click_menu) # print ( dir ( si ) ) Gtk.main()