def fill_vm_storageattach(self, list):
        list.clear() 
        refattachdisk = {}                                
        all_sr = self.connection.SR.get_all_records(self.session_uuid)['Value']
       
        for sr in all_sr:
            if all_sr[sr]['type'] != "iso" \
                    and all_sr[sr]['content_type'] != "iso":
                img = gtk.gdk.pixbuf_new_from_file(path.join(
                    utils.module_path(), "images/storage_default_16.png"))
                refattachdisk[sr] = list.append(
                    None, [img, sr, all_sr[sr]["name_label"], "", False])

        all_vdi = self.connection.VDI.get_all_records(
            self.session_uuid)['Value']
        for vdi in all_vdi:
            if not all_vdi[vdi]['VBDs'] and all_vdi[vdi]['read_only'] is False:
                img = gtk.gdk.pixbuf_new_from_file(path.join(
                    utils.module_path(), "images/user_template_16.png"))
                name_str = "%s - %s" % (
                    all_vdi[vdi]['name_description'],
                    self.convert_bytes(all_vdi[vdi]['virtual_size']))

                list.append(refattachdisk[all_vdi[vdi]['SR']],
                            [img, vdi, all_vdi[vdi]['name_label'], name_str,
                             True])
    def fill_listnewvmhosts(self, list):
        list.clear()
        vm_path = 0
        i = 0
        for host in self.all['host'].keys():
            resident_vms = self.all['host'][host]['resident_VMs']
            host_memory = 0
            for resident_vm_uuid in resident_vms:
                if self.all['vms'][resident_vm_uuid]['is_control_domain']:
                    host_memory = self.all['vms'][resident_vm_uuid]['memory_dynamic_max']

            host_metrics_uuid = self.all['host'][host]['metrics']
            host_metrics = self.all['host_metrics'][host_metrics_uuid]
            host_memory = "%s free of %s available (%s total)" % (self.convert_bytes(host_metrics['memory_free']),
                                                                  self.convert_bytes(int(host_metrics['memory_total']) - int(host_memory)),
                                                                  self.convert_bytes(host_metrics['memory_total']))
            if self.all['host'][host]['enabled']:
                vm_path = i
                list.append([gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                    "images/tree_connected_16.png")),
                             self.all['host'][host]['name_label'], host_memory, host])
            else:
                list.append([gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                    "images/tree_disconnected_16.png")),
                             self.all['host'][host]['name_label'], host_memory, host])
            i += 1
        return vm_path
Example #3
0
    def fill_importstg(self, list):
        list.clear()
        i = 0
        default_sr = 0
        for sr in self.all_storage.keys():
            storage = self.all_storage[sr]
            if storage['type'] != "iso" and storage['type'] != "udev":
                if self.default_sr == sr:
                    default_sr = i
                if len(self.all_storage[sr]['PBDs']) == 0 or self.all_pbd[self.all_storage[sr]['PBDs'][0]]['currently_attached'] == False \
                        or  len(self.all_storage[sr]['PBDs']) > 0 and self.all_storage[sr]["allowed_operations"].count("unplug") ==  0:
                            pass
                else:
                    if self.default_sr == sr:
                        list.append([gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                            "images/storage_default_16.png")), sr,
                                     storage['name_label'], self.convert_bytes(int(storage['physical_size']) -
                                                                               int(storage['virtual_allocation']))
                                     + " free of " + self.convert_bytes(storage['physical_size'])])

                    else:
                        list.append([gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                            "images/storage_shaped_16.png")), sr,
                                     storage['name_label'], self.convert_bytes(int(storage['physical_size']) -
                                                                               int(storage['virtual_allocation']))
                                     + " free of " + self.convert_bytes(storage['physical_size'])])
                        i = i + 1
        return default_sr 
    def fill_importstg(self, list):
        list.clear()
        i = 0
        default_sr = 0
        for sr in self.all['SR'].keys():
            storage = self.all['SR'][sr]
            if storage['type'] != "iso" and storage['type'] != "udev":
                if self.default_sr == sr:
                    default_sr = i
                if len(self.all['SR'][sr]['PBDs']) == 0 or self.all['PBD'][self.all['SR'][sr]['PBDs'][0]]['currently_attached'] == False \
                        or  len(self.all['SR'][sr]['PBDs']) > 0 and self.all['SR'][sr]["allowed_operations"].count("unplug") ==  0:
                            pass
                else:
                    if self.default_sr == sr:
                        list.append([gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                            "images/storage_default_16.png")), sr,
                                     storage['name_label'], self.convert_bytes(int(storage['physical_size']) -
                                                                               int(storage['virtual_allocation']))
                                     + " free of " + self.convert_bytes(storage['physical_size'])])

                    else:
                        list.append([gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                            "images/storage_shaped_16.png")), sr,
                                     storage['name_label'], self.convert_bytes(int(storage['physical_size']) -
                                                                               int(storage['virtual_allocation']))
                                     + " free of " + self.convert_bytes(storage['physical_size'])])
                        i = i + 1
        return default_sr 
Example #5
0
 def fill_vdi_location(self, ref, list):
     list.clear()
     i = 0
     selected = 0
     for sr in self.all_storage.keys():
         if self.all_storage[sr]['name_label'] != "XenServer Tools":
             if sr == ref:
                 selected = i
                 name = "<b>" + self.all_storage[sr]['name_label'] + "</b>"
             else:
                 name = self.all_storage[sr]['name_label']
             if len(self.all_storage[sr]['PBDs']) == 0 or self.all_pbd[self.all_storage[sr]['PBDs'][0]]['currently_attached'] == False \
                 or  len(self.all_storage[sr]['PBDs']) > 0 and self.all_storage[sr]["allowed_operations"].count("unplug") ==  0:
                     list.append([sr, gtk.gdk.pixbuf_new_from_file(os.path.join(utils.module_path(),
                                                                                "images/storage_broken_16.png")),
                                  name])
             else:
                 if sr == self.default_sr:
                     list.append([sr, gtk.gdk.pixbuf_new_from_file(os.path.join(utils.module_path(),
                                                                                "images/storage_default_16.png")),
                                  name])
                 else:
                     list.append([sr, gtk.gdk.pixbuf_new_from_file(os.path.join(utils.module_path(),
                                                                                "images/storage_shaped_16.png")),
                                  name])
             i = i +1
     return selected
Example #6
0
    def fill_vm_storageattach(self, list):
        list.clear()
        refattachdisk = {}
        all_sr = self.connection.SR.get_all_records(self.session_uuid)['Value']

        for sr in all_sr:
            if all_sr[sr]['type'] != "iso" \
                    and all_sr[sr]['content_type'] != "iso":
                img = gtk.gdk.pixbuf_new_from_file(
                    path.join(utils.module_path(),
                              "images/storage_default_16.png"))
                refattachdisk[sr] = list.append(
                    None, [img, sr, all_sr[sr]["name_label"], "", False])

        all_vdi = self.connection.VDI.get_all_records(
            self.session_uuid)['Value']
        for vdi in all_vdi:
            if not all_vdi[vdi]['VBDs'] and all_vdi[vdi]['read_only'] is False:
                img = gtk.gdk.pixbuf_new_from_file(
                    path.join(utils.module_path(),
                              "images/user_template_16.png"))
                name_str = "%s - %s" % (all_vdi[vdi]['name_description'],
                                        self.convert_bytes(
                                            all_vdi[vdi]['virtual_size']))

                list.append(
                    refattachdisk[all_vdi[vdi]['SR']],
                    [img, vdi, all_vdi[vdi]['name_label'], name_str, True])
 def fill_listnewvmhosts(self, list):
     list.clear()
     vm_path = 0
     i = 0
     for host in self.all_hosts.keys():
         resident_vms = self.all_hosts[host]['resident_VMs']
         host_memory = 0
         for resident_vm_uuid in resident_vms:
             if self.all_vms[resident_vm_uuid]['is_control_domain']:
                 host_memory = self.all_vms[resident_vm_uuid]['memory_dynamic_max']
         
         host_metrics_uuid = self.all_hosts[host]['metrics']
         host_metrics = self.all_host_metrics[host_metrics_uuid]
         host_memory = "%s free of %s available (%s total)" % (self.convert_bytes(host_metrics['memory_free']),
                                                               self.convert_bytes(int(host_metrics['memory_total'])
                                                                                  - int(host_memory)),
                                                               self.convert_bytes(host_metrics['memory_total']))
         if self.all_hosts[host]['enabled']:
             vm_path = i
             list.append([gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                 "images/tree_connected_16.png")),
                          self.all_hosts[host]['name_label'], host_memory, host])
         else:
             list.append([gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                 "images/tree_disconnected_16.png")),
                          self.all_hosts[host]['name_label'], host_memory, host])
         i += 1
     return vm_path
Example #8
0
    def fill_list_templates(self, list):
        list.clear()
        for vm in filter(
                self.filter_custom_template,
                sorted(self.all['vms'].values(),
                       key=itemgetter('name_label'))):
            vm_uuid = self.vm_filter_uuid(vm["uuid"])
            if vm["is_a_snapshot"]:
                list.append([
                    gtk.gdk.pixbuf_new_from_file(
                        path.join(utils.module_path(),
                                  "images/snapshots.png")), vm["name_label"],
                    vm_uuid, "Snapshots"
                ])
            else:
                list.append([
                    gtk.gdk.pixbuf_new_from_file(
                        path.join(utils.module_path(),
                                  "images/user_template_16.png")),
                    vm["name_label"], vm_uuid, "Custom"
                ])

        for vm in filter(
                self.filter_normal_template,
                sorted(self.all['vms'].values(),
                       key=itemgetter('name_label'))):
            vm_uuid = self.vm_filter_uuid(vm["uuid"])
            if vm["name_label"].lower().count("centos"):
                image = path.join(utils.module_path(), "images/centos.png")
                category = "CentOS"
            elif vm["name_label"].lower().count("windows"):
                image = path.join(utils.module_path(), "images/windows.png")
                category = "Windows"
            elif vm["name_label"].lower().count("debian"):
                image = path.join(utils.module_path(), "images/debian.png")
                category = "Debian"
            elif vm["name_label"].lower().count("red hat"):
                image = path.join(utils.module_path(), "images/redhat.png")
                category = "Red Hat"
            elif vm["name_label"].lower().count("suse"):
                image = path.join(utils.module_path(), "images/suse.png")
                category = "SuSe"
            elif vm["name_label"].lower().count("oracle"):
                image = path.join(utils.module_path(), "images/oracle.png")
                category = "Oracle"
            elif vm["name_label"].lower().count("citrix"):
                image = path.join(utils.module_path(), "images/xen.png")
                category = "Citrix"

            else:
                image = path.join(utils.module_path(),
                                  "images/template_16.png")
                category = "Misc"
            list.append([
                gtk.gdk.pixbuf_new_from_file(image), vm["name_label"], vm_uuid,
                category
            ])
 def fill_mamagement_ifs_list(self, list):
     list.clear()
     for pif in self.all_pif:
         if self.all_pif[pif]['management']:
             network = self.all_network[self.all_pif[pif]['network']]['name_label']
             if self.all_pif[pif]['device'][-1:] == "0":
                 text = "<b>Primary</b>" + "\n    <i>" + network + "</i>"
                 list.append([pif, gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                          "images/prop_networksettings.png")), text])
             else:
                 text = "<b>Interface " + str(self.all_pif[pif]['device'][-1:]) + "</b>\n     <i>" + network + "</i>"
                 list.append([pif, gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                          "images/prop_network.png")), text])
Example #10
0
 def fill_listrepairstorage(self, list, ref):
     list.clear()
     for pbd_ref in self.all_storage[ref]['PBDs']:
         host = self.all_hosts[self.all_pbd[pbd_ref]["host"]]["name_label"]
         host_ref = self.all_pbd[pbd_ref]["host"]
         if not self.all_pbd[pbd_ref]['currently_attached']:
             list.append([pbd_ref, gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                          "images/storage_broken_16.png")), host,
                          "<span foreground='red'><b>Unplugged</b></span>", host_ref, True])
         else:
             list.append([pbd_ref, gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                          "images//storage_shaped_16.png")), host,
                          "<span foreground='green'><b>Connected</b></span>", host_ref, False])
 def fill_mamagement_ifs_list(self, list):
     list.clear()
     for pif in self.all['PIF']:
         if self.all['PIF'][pif]['management']:
             network = self.all['network'][self.all['PIF'][pif]['network']]['name_label']
             if self.all['PIF'][pif]['device'][-1:] == "0":
                 text = "<b>Primary</b>" + "\n    <i>" + network + "</i>"
                 list.append([pif, gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                          "images/prop_networksettings.png")), text])
             else:
                 text = "<b>Interface " + str(self.all['PIF'][pif]['device'][-1:]) + "</b>\n     <i>" + network + "</i>"
                 list.append([pif, gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                          "images/prop_network.png")), text])
 def update_n_alerts(self):
     """
     Function called to update number of alerts
     """
     self.nelements = 0
     self.listalerts.foreach(self.count_list, self.nelements)
     self.builder.get_object("lblnalerts").set_text("System Alerts: " + str(self.nelements/2))
     if self.nelements:
         self.builder.get_object("imagealerts").set_from_file(path.join(utils.module_path(), "images/alert.png"))
         self.builder.get_object("lbltbalerts").set_markup("<span foreground='red'><b>  System Alerts: " + str(self.nelements/2) + "</b></span>")
     else:
         self.builder.get_object("imagealerts").set_from_file(path.join(utils.module_path(), "images/ok.png"))
         self.builder.get_object("lbltbalerts").set_markup("  No System Alerts: ")
 def fill_listrepairstorage(self, list, ref):
     list.clear()
     for pbd_ref in self.all['SR'][ref]['PBDs']:
         host = self.all['host'][self.all['PBD'][pbd_ref]["host"]]["name_label"]
         host_ref = self.all['PBD'][pbd_ref]["host"]
         if not self.all['PBD'][pbd_ref]['currently_attached']:
             list.append([pbd_ref, gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                          "images/storage_broken_16.png")), host,
                          "<span foreground='red'><b>Unplugged</b></span>", host_ref, True])
         else:
             list.append([pbd_ref, gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                          "images//storage_shaped_16.png")), host,
                          "<span foreground='green'><b>Connected</b></span>", host_ref, False])
Example #14
0
 def update_n_alerts(self):
     """
     Function called to update number of alerts
     """
     self.nelements = 0
     self.listalerts.foreach(self.count_list, self.nelements)
     self.builder.get_object("lblnalerts").set_text("System Alerts: " + str(self.nelements/2))
     if self.nelements:
         self.builder.get_object("imagealerts").set_from_file(path.join(utils.module_path(), "images/alert.png"))
         self.builder.get_object("lbltbalerts").set_markup("<span foreground='red'><b>  System Alerts: " +
                                                           str(self.nelements/2) + "</b></span>")
     else:
         self.builder.get_object("imagealerts").set_from_file(path.join(utils.module_path(), "images/ok.png"))
         self.builder.get_object("lbltbalerts").set_markup("  No System Alerts: ")
    def fill_list_templates(self, list):
        list.clear()
        for vm in filter(self.filter_custom_template,
                         sorted(self.all['vms'].values(),
                                key=itemgetter('name_label'))):
            vm_uuid = self.vm_filter_uuid(vm["uuid"])
            if vm["is_a_snapshot"]:
                list.append([gtk.gdk.pixbuf_new_from_file(
                    path.join(utils.module_path(), "images/snapshots.png")),
                    vm["name_label"], vm_uuid, "Snapshots"])
            else:
                list.append([gtk.gdk.pixbuf_new_from_file(
                    path.join(utils.module_path(),
                              "images/user_template_16.png")),
                            vm["name_label"], vm_uuid, "Custom"])

        for vm in filter(self.filter_normal_template,
                         sorted(self.all['vms'].values(),
                                key=itemgetter('name_label'))):
            vm_uuid = self.vm_filter_uuid(vm["uuid"])
            if vm["name_label"].lower().count("centos"):
                image = path.join(utils.module_path(), "images/centos.png")
                category = "CentOS"
            elif vm["name_label"].lower().count("windows"):
                image = path.join(utils.module_path(), "images/windows.png")
                category = "Windows"
            elif vm["name_label"].lower().count("debian"):
                image = path.join(utils.module_path(), "images/debian.png")
                category = "Debian"
            elif vm["name_label"].lower().count("red hat"):
                image = path.join(utils.module_path(), "images/redhat.png")
                category = "Red Hat"
            elif vm["name_label"].lower().count("suse"):
                image = path.join(utils.module_path(), "images/suse.png")
                category = "SuSe"
            elif vm["name_label"].lower().count("oracle"):
                image = path.join(utils.module_path(), "images/oracle.png")
                category = "Oracle"
            elif vm["name_label"].lower().count("citrix"):
                image = path.join(utils.module_path(), "images/xen.png")
                category = "Citrix"

            else:
                image = path.join(utils.module_path(),
                                  "images/template_16.png")
                category = "Misc"
            list.append([gtk.gdk.pixbuf_new_from_file(image),
                         vm["name_label"], vm_uuid, category])
Example #16
0
 def fill_vms_which_prevent_evacuation(self, ref, list):
     list.clear()
     vms = self.connection.host.get_vms_which_prevent_evacuation(self.session_uuid, ref)["Value"]
     for vm in vms.keys():
         # vms[vm][0]
         list.append([gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(), "images/tree_running_16.png")),
                      self.all_vms[vm]['name_label'], "Suspend or shutdown VM"])
Example #17
0
 def fill_listhomeserver(self, list, ref):
     list.clear()
     path = 0
     i = 0
     for host in self.all_hosts.keys():
         resident_vms = self.all_hosts[host]['resident_VMs']
         host_memory = 0
         vm_memory = 0
         for resident_vm_uuid in resident_vms:
             if self.all_vms[resident_vm_uuid]['is_control_domain']:
                host_memory =  int(self.all_vms[resident_vm_uuid]['memory_dynamic_max'])
             else:     
                vm_memory +=  int(self.all_vms[resident_vm_uuid]['memory_dynamic_max'])
         
         host_metrics_uuid = self.all_hosts[host]['metrics']
         host_metrics = self.all_host_metrics[host_metrics_uuid]
         hostmemory = "%s free of %s available (%s total)"  % \
             (self.convert_bytes(int(host_metrics['memory_total'])-vm_memory-host_memory), \
             self.convert_bytes(int(host_metrics['memory_total']) - host_memory), \
             self.convert_bytes(host_metrics['memory_total']))
         if self.all_hosts[host]['enabled']:
             if host == ref:
                 path = i 
             list.append([host, gtk.gdk.pixbuf_new_from_file(os.path.join(utils.module_path(),
                                                                          "images/tree_connected_16.png")),
                          self.all_hosts[host]['name_label'], hostmemory, ])
         i = i + 1
     return path
Example #18
0
    def recover(self):
        app_path = utils.module_path()
        bk_dir = unicode(QFileDialog.getExistingDirectory(self, u"选择备份路径"))
        files = [ i for i in os.listdir(bk_dir) if i.endswith(".db3")]

        ret = QMessageBox.question(self, u"温度监测系统", 
                                   u"备份数据将覆盖现有数据, 确认要恢复数据?",
                                   QMessageBox.Yes, QMessageBox.No)
        if QMessageBox.Yes != ret:
            return

        proc_dlg = QProgressDialog(u"恢复中...", u"取消", 0, len(files))
        proc_dlg.setWindowModality(Qt.WindowModal)
        proc_dlg.setWindowTitle(u"数据恢复")
        proc_dlg.show()

        for idx, i in enumerate(files):
            fpath = os.path.join(bk_dir, i)
            proc_dlg.setLabelText(fpath)
            shutil.copy(fpath, app_path)
            proc_dlg.setValue(idx)
            if proc_dlg.wasCanceled():
                return
        proc_dlg.setValue(len(files))
        QMessageBox.information(self, u"温度监测系统", 
                                u"成功从 %s 恢复数据!" % bk_dir)
Example #19
0
    def __init__(self):

        self._dir = os.path.dirname(module_path())
        file = os.path.join(self._dir, 'SAMView.glade')

        self.glade = gtk.glade.XML(file)

        self.window = self.glade.get_widget('main-window')
        self.window.connect('delete-event', self._on_window_delete_event)

        self._register_iconsets()

        self.connection = ConnectionController(self)
        self.visual = VisualisationController(self)
        self.logger = LoggingController(self)

        menu = gtk.Menu()
        menu_item = gtk.ImageMenuItem(gtk.STOCK_QUIT)
        menu_item.connect('activate', self._on_quit_menu_item_activate)
        menu.append(menu_item)

        self.status_icon = gtk.StatusIcon()
        self.status_icon.set_from_stock('com-vollast')
        self.status_icon.set_visible(True)
        self.status_icon.connect('activate', self._status_icon_activated)
        self.status_icon.connect('popup-menu', self._popup_menu_cb, menu)
    def fill_list_report(self, ref, list):
        list.clear()
        result = self.connection.host.get_system_status_capabilities(
            self.session_uuid, ref)['Value']
        privacy = {"yes": "1", "maybe": "2", "if_customized": "3", "no": "4"}
        dom = xml.dom.minidom.parseString(result)
        nodes = dom.getElementsByTagName("capability")
        capabilities = {}
        for node in nodes:
            attr = node.attributes
            key, checked, pii, minsize, maxsize, mintime, maxtime = \
                [attr.getNamedItem(k).value for k
                    in ["key", "default-checked", "pii", "min-size",
                        "max-size", "min-time", "max-time"]]
            capabilities[privacy[pii] + "_" + key] = [checked, minsize,
                                                      maxsize, mintime,
                                                      maxtime]

        for key in sorted(capabilities.keys()):
            if key.split("_", 2)[1] in capabilities_text:
                confidentiality, ref = key.split("_", 2)
                name, desc = capabilities_text[key.split("_", 2)[1]]
                checked, minsize, maxsize, mintime, maxtime = \
                    [value for value in capabilities[key]]
                size1, time1 = 0, 0
                if minsize == maxsize:
                    if maxsize != "-1" and checked:
                        size1 = int(maxsize)
                    size = self.convert_bytes(maxsize)
                elif minsize == "-1":
                    if checked:
                        size1 = int(maxsize)
                    size = "< %s" % self.convert_bytes(maxsize)
                else:
                    size1 = int(maxsize)
                    size = "%s-%s" % (self.convert_bytes(minsize),
                                      self.convert_bytes(maxsize))

                if mintime == maxtime:
                    if maxtime == "-1":
                        time = "Negligible"
                    else:
                        if checked:
                            time1 = int(maxtime)
                        time = maxtime
                elif mintime == "-1":
                    if checked:
                        time1 = int(maxtime)
                    time = "< %s" % maxtime
                else:
                    if checked:
                        time1 = int(maxtime)
                    time = "%s-%s" % (mintime, maxtime)

                list.append([ref, checked == "yes", name,
                             gtk.gdk.pixbuf_new_from_file(
                                 path.join(utils.module_path(),
                                           "images/confidentiality%s.png" %
                                           confidentiality)), desc, size,
                             time, size1, time1, int(confidentiality)])
Example #21
0
    def __init__(self, channel_id):
        super().__init__(channel_id)

        # Load pre-trained model and set-up the bot
        self.REPEAT_FRAMES = 1
        self.model = load(
            os.path.join(module_path(__file__), "imitator1.joblib"))
        self.recent_frames = []
        self.frames_passed = 0
Example #22
0
def Init():
    global app
    global prefs, prefsfile, AppDataDir, AppDir, BitmapDir
    global PLATFORM_IS_WIN, PLATFORM_IS_GTK, PLATFORM_IS_MAC
    global pythexec, pythexecw

    app = wx.GetApp()

    #System constants
    PLATFORM_IS_WIN = wx.Platform == '__WXMSW__'  # (sys.platform == "win32") or #wx.PLATFORM_WINDOWS or wx.PLATFORM_WINDOWS
    PLATFORM_IS_GTK = wx.Platform == '__WXGTK__'
    PLATFORM_IS_MAC = wx.Platform == '__WXMAC__'

    if PLATFORM_IS_WIN:
        pythexec = sys.prefix.replace("\\", "/") + "/python.exe"
        pythexecw = sys.prefix.replace("\\", "/") + "/python.exe"
    else:
        pythexec = sys.executable

    #Preferences
    AppDir = utils.module_path()
    AppDataDir = os.path.join(AppDir, "data")
    if not os.path.exists(AppDataDir):
        os.mkdir(AppDataDir)

    BitmapDir = os.path.join(AppDir, "bitmaps")
    if not os.path.exists(BitmapDir):
        utils.ShowMessage(
            "Bitmap Directory (" + BitmapDir + ") does Not Exist.",
            "EasyPython Fatal Error")
        sys.exit(1)

    prefsfile = os.path.join(AppDataDir, "preferences.dat")

    prefs = drPreferences(PLATFORM_IS_WIN, AppDir)

    LoadPreferences()

    utils.Init()

    if prefs.defaultdirectory:
        EpyGlob.CurrDir = prefs.defaultdirectory
    else:
        #add limodou 2004/04/17
        #if defaultdirectory is empty, then use the last recently file's dir
        if EpyGlob.recentfiles:
            EpyGlob.CurrDir = os.path.dirname(EpyGlob.recentfiles[0])
        #end limodou
        else:
            EpyGlob.CurrDir = AppDir

    try:
        os.chdir(EpyGlob.CurrDir)
    except:
        EpyGlob.CurrDir = AppDir
        os.chdir(EpyGlob.CurrDir)
 def fill_vms_which_prevent_evacuation(self, ref, list):
     list.clear()
     vms = self.connection.host.get_vms_which_prevent_evacuation(
         self.session_uuid, ref)["Value"]
     for vm in vms.keys():
         # vms[vm][0]
         list.append([gtk.gdk.pixbuf_new_from_file(path.join(
             utils.module_path(), "images/tree_running_16.png")),
             self.all['vms'][vm]['name_label'],
             "Suspend or shutdown VM"])
Example #24
0
    def fill_listcopystg(self, list_ref, host):
        list_ref.clear()
        i = 0
        default_sr = 0
        for sr in self.all['SR'].keys():
            storage = self.all['SR'][sr]
            if storage['type'] != "iso" and storage['type'] != "udev":
                if self.default_sr == sr:
                    default_sr = i
                if not self.all['SR'][sr]['PBDs'] \
                        or not self.all['PBD'][self.all['SR'][sr]['PBDs'][0]]['currently_attached'] \
                        or self.all['SR'][sr]['PBDs'] \
                        and self.all['SR'][sr]["allowed_operations"].count("unplug") == 0:
                    pass
                else:
                    phys_size = int(storage['physical_size'])
                    phys_size_bytes = self.convert_bytes(phys_size)
                    virt_alloc = int(storage['virtual_allocation'])
                    free = self.convert_bytes(phys_size - virt_alloc)

                    if self.default_sr == sr:
                        image = path.join(utils.module_path(),
                                          "images/storage_default_16.png")
                    else:
                        image = path.join(utils.module_path(),
                                          "images/storage_shaped_16.png")

                    list_ref.append([
                        gtk.gdk.pixbuf_new_from_file(image), sr,
                        storage['name_label'],
                        "%s free of %s" % (free, phys_size_bytes)
                    ])

                # else:  FIXME: set_sensitive(False) row
                #    list.append([gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                #                                                        "images/storage_broken_16.png")), sr,
                #                 storage['name_label'],
                #         self.convert_bytes(int(storage['physical_size'])-int(storage['virtual_allocation'])) + " free of " + \
                #         self.convert_bytes(storage['physical_size'])])
                # else:

                i += 1
        return default_sr
    def fill_listcopystg(self, list_ref, host):
        list_ref.clear()
        i = 0
        default_sr = 0
        for sr in self.all['SR'].keys():
            storage = self.all['SR'][sr]
            if storage['type'] != "iso" and storage['type'] != "udev":
                if self.default_sr == sr:
                    default_sr = i
                if not self.all['SR'][sr]['PBDs'] \
                        or not self.all['PBD'][self.all['SR'][sr]['PBDs'][0]]['currently_attached'] \
                        or self.all['SR'][sr]['PBDs'] \
                        and self.all['SR'][sr]["allowed_operations"].count("unplug") == 0:
                    pass
                else:
                    phys_size = int(storage['physical_size'])
                    phys_size_bytes = self.convert_bytes(phys_size)
                    virt_alloc = int(storage['virtual_allocation'])
                    free = self.convert_bytes(phys_size - virt_alloc)

                    if self.default_sr == sr:
                        image = path.join(utils.module_path(),
                                          "images/storage_default_16.png")
                    else:
                        image = path.join(utils.module_path(),
                                          "images/storage_shaped_16.png")

                    list_ref.append(
                        [gtk.gdk.pixbuf_new_from_file(image), sr,
                         storage['name_label'],
                         "%s free of %s" % (free, phys_size_bytes)])

                # else:  FIXME: set_sensitive(False) row
                #    list.append([gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                #                                                        "images/storage_broken_16.png")), sr,
                #                 storage['name_label'],
                #         self.convert_bytes(int(storage['physical_size'])-int(storage['virtual_allocation'])) + " free of " + \
                #         self.convert_bytes(storage['physical_size'])])
                # else:

                i += 1
        return default_sr
Example #26
0
def Init() :   
        global app
        global prefs, prefsfile, AppDataDir, AppDir,BitmapDir
        global PLATFORM_IS_WIN, PLATFORM_IS_GTK, PLATFORM_IS_MAC
        global pythexec, pythexecw
        
        app = wx.GetApp()
        
        #System constants
        PLATFORM_IS_WIN = wx.Platform == '__WXMSW__' # (sys.platform == "win32") or #wx.PLATFORM_WINDOWS or wx.PLATFORM_WINDOWS
        PLATFORM_IS_GTK = wx.Platform == '__WXGTK__'
        PLATFORM_IS_MAC = wx.Platform == '__WXMAC__'
        
        if PLATFORM_IS_WIN:
            pythexec = sys.prefix.replace("\\", "/") + "/python.exe"
            pythexecw = sys.prefix.replace("\\", "/") + "/python.exe"
        else:
            pythexec = sys.executable

        #Preferences
        AppDir = utils.module_path()
        AppDataDir = os.path.join(AppDir,"data")
        if not os.path.exists(AppDataDir):
            os.mkdir(AppDataDir)

        BitmapDir = os.path.join(AppDir,"bitmaps")
        if not os.path.exists(BitmapDir):
            utils.ShowMessage("Bitmap Directory (" + BitmapDir + ") does Not Exist.", "EasyPython Fatal Error")
            sys.exit(1)
        
        prefsfile = os.path.join(AppDataDir,"preferences.dat")
      
        prefs = drPreferences(PLATFORM_IS_WIN, AppDir)
        
        LoadPreferences()
        
        utils.Init()
        
        if prefs.defaultdirectory:
            EpyGlob.CurrDir = prefs.defaultdirectory
        else:
            #add limodou 2004/04/17
            #if defaultdirectory is empty, then use the last recently file's dir
            if EpyGlob.recentfiles:
                EpyGlob.CurrDir = os.path.dirname(EpyGlob.recentfiles[0])
            #end limodou
            else:
                EpyGlob.CurrDir = AppDir

        try:
            os.chdir(EpyGlob.CurrDir)
        except:
            EpyGlob.CurrDir = AppDir
            os.chdir(EpyGlob.CurrDir)
Example #27
0
File: config.py Project: pjq/gmb
 def __init__(self):
     '''初始化'''
     self.item = {}
     userhome = os.path.expanduser('~')
     self.config_folder = os.path.join(userhome,'.gmbox')
     self.config_file = os.path.join(self.config_folder,'config.xml')
     if not os.path.isdir(self.config_folder):
         os.mkdir(self.config_folder)
     if not os.path.exists(self.config_file):
         config_sample_file = find_image_or_data('config.xml.sample', module_path(), 'data')
         print module_path()
         print config_sample_file
         shutil.copy(config_sample_file, self.config_file)
         if not os.path.exists(self.config_file):
             print u'创建配置文件失败!', self.config_file
         else:
             print u'创建配置文件成功!', self.config_file
             self.read_config()
             
             self.savedir_changed(self.item['savedir'])
             if os.name != 'posix':
                 self.id3utf8_changed('False')
     else:
         self.read_config()
Example #28
0
    def fill_list_report(self, ref, list):
        list.clear()
        result = self.connection.host.get_system_status_capabilities(self.session_uuid, ref)['Value']
        privacy = {"yes": "1", "maybe": "2", "if_customized": "3", "no": "4"}
        dom = xml.dom.minidom.parseString(result)
        nodes = dom.getElementsByTagName("capability")
        capabilities = {}
        for node in nodes:
           attr = node.attributes
           key, checked, pii, minsize, maxsize, mintime, maxtime = [attr.getNamedItem(k).value for k \
                   in ["key", "default-checked", "pii", "min-size", "max-size", "min-time", "max-time"]]
           capabilities[privacy[pii] + "_" + key] = [checked, minsize, maxsize, mintime, maxtime]

        for key in sorted(capabilities.keys()):
           if key.split("_",2)[1] in capabilities_text:
               confidentiality, ref = key.split("_",2)
               name, desc = capabilities_text[key.split("_",2)[1]]
               checked, minsize, maxsize, mintime, maxtime = [value for value in capabilities[key]]
               size1, time1 = 0, 0
               if minsize == maxsize:
                  if maxsize != "-1" and checked: 
                      size1 = int(maxsize)
                  size = self.convert_bytes(maxsize)
               elif minsize == "-1":
                  if checked: size1 = int(maxsize)
                  size = "< %s" % self.convert_bytes(maxsize)
               else:
                  size1 = int(maxsize)
                  size = "%s-%s" % (self.convert_bytes(minsize), self.convert_bytes(maxsize))

               if mintime == maxtime:
                  if maxtime == "-1":
                      time = "Negligible"
                  else:
                      if checked: time1 = int(maxtime)
                      time = maxtime
               elif mintime == "-1":
                  if checked: time1 = int(maxtime)
                  time= "< %s" % maxtime
               else:
                  if checked: time1 = int(maxtime)
                  time= "%s-%s" % (mintime, maxtime)

               list.append([ref, checked == "yes", name,  gtk.gdk.pixbuf_new_from_file(path.join(
                   utils.module_path(), "images/confidentiality%s.png" % confidentiality)), desc, size, time, size1,
                   time1, int(confidentiality)])
Example #29
0
    def backup(self):
        app_path = utils.module_path()
        files = [i for i in os.listdir(app_path) if i.endswith(".db3")]
        bk_dir = unicode(QFileDialog.getExistingDirectory(self, u"选择备份路径"))

        proc_dlg = QProgressDialog(u"备份中...", u"取消", 0, len(files))
        proc_dlg.setWindowModality(Qt.WindowModal)
        proc_dlg.setWindowTitle(u"数据备份")
        proc_dlg.show()

        for idx, i in enumerate(files):
            fpath = os.path.join(app_path, i)
            proc_dlg.setLabelText(fpath)
            shutil.copy(fpath, bk_dir)
            proc_dlg.setValue(idx)
            if proc_dlg.wasCanceled():
                return
        proc_dlg.setValue(len(files))
        QMessageBox.information(self, u"温度监测系统", u"数据成功备份到 %s !" % bk_dir)
Example #30
0
    def backup(self):
        app_path = utils.module_path()
        files = [ i for i in os.listdir(app_path) if i.endswith(".db3")]
        bk_dir = unicode(QFileDialog.getExistingDirectory(self, u"选择备份路径"))

        proc_dlg = QProgressDialog(u"备份中...", u"取消", 0, len(files))
        proc_dlg.setWindowModality(Qt.WindowModal)
        proc_dlg.setWindowTitle(u"数据备份")
        proc_dlg.show()

        for idx, i in enumerate(files):
            fpath = os.path.join(app_path, i)
            proc_dlg.setLabelText(fpath)
            shutil.copy(fpath, bk_dir)
            proc_dlg.setValue(idx)
            if proc_dlg.wasCanceled():
                return
        proc_dlg.setValue(len(files))
        QMessageBox.information(self, u"温度监测系统", 
                                u"数据成功备份到 %s !" % bk_dir)
Example #31
0
    def on_btundockconsole_clicked(self, widget, data=None):
        """
        Function called when you press "undock"
        """
        #create a new window and append the vnc
        if self.selected_ref not in self.vnc_builders.keys():
            self.noclosevnc = True
            self.builder.get_object("console_area").remove(
                self.vnc[self.selected_ref])
            glade_dir = os.path.join(utils.module_path(), 'ui')
            self.vnc_builders[self.selected_ref] = gtk.Builder()
            self.vnc_builders[self.selected_ref].add_from_file(
                os.path.join(glade_dir, "window_vnc.glade"))
            self.vnc_builders[self.selected_ref].get_object(
                "console_area3").add(self.vnc[self.selected_ref])
            self.vnc_builders[self.selected_ref].get_object(
                "btredockconsole").connect("clicked",
                                           self.on_btredockconsole_clicked,
                                           self.selected_ref)
            self.vnc_builders[self.selected_ref].get_object(
                "btredockconsole").connect("destroy",
                                           self.on_btredockconsole_clicked,
                                           self.selected_ref)
            self.vnc_builders[self.selected_ref].get_object(
                "btsendctrlaltdel1").connect("clicked",
                                             self.on_btsendctraltdel_clicked,
                                             self.selected_ref)
            self.vnc_builders[self.selected_ref].get_object(
                "windowvncundock").set_title(self.selected_name)
            self.vnc_builders[self.selected_ref].get_object(
                "windowvncundock").show_all()

        else:
            #If the vnc window already exists (partially covered or minimized), present it to the user.
            self.vnc_builders[self.selected_ref].get_object(
                "windowvncundock").present()
Example #32
0
    def recover(self):
        app_path = utils.module_path()
        bk_dir = unicode(QFileDialog.getExistingDirectory(self, u"选择备份路径"))
        files = [i for i in os.listdir(bk_dir) if i.endswith(".db3")]

        ret = QMessageBox.question(self, u"温度监测系统", u"备份数据将覆盖现有数据, 确认要恢复数据?",
                                   QMessageBox.Yes, QMessageBox.No)
        if QMessageBox.Yes != ret:
            return

        proc_dlg = QProgressDialog(u"恢复中...", u"取消", 0, len(files))
        proc_dlg.setWindowModality(Qt.WindowModal)
        proc_dlg.setWindowTitle(u"数据恢复")
        proc_dlg.show()

        for idx, i in enumerate(files):
            fpath = os.path.join(bk_dir, i)
            proc_dlg.setLabelText(fpath)
            shutil.copy(fpath, app_path)
            proc_dlg.setValue(idx)
            if proc_dlg.wasCanceled():
                return
        proc_dlg.setValue(len(files))
        QMessageBox.information(self, u"温度监测系统", u"成功从 %s 恢复数据!" % bk_dir)
Example #33
0
    def server_sync_update_tree(self, server):
        """
        Method called when connection loading is finished
        """
        try:
            self.server_sync_progress(server, "")

            # Remove the server from tree; it will be created again below
            # FIXME: csun: this won't be necessary when we have controllers
            def remove_helper(model, path, iter):
                if self.treestore.get(iter, 1,
                                      3) == (server.hostname, "server"):
                    self.treestore.remove(iter)
                    return True
                return False

            self.treestore.foreach(remove_helper)

            # TODO: csun: clean this up

            poolroot = None
            hostroot = {}
            root = ""
            server.treestore = self.treestore
            server.default_sr = ""

            for pool in server.all['pool'].keys():
                server.default_sr = server.all['pool'][pool]['default_SR']
                if server.all['pool'][pool]['name_label']:
                    poolroot = self.treestore.append(self.treeroot, [
                        gtk.gdk.pixbuf_new_from_file(
                            path.join(utils.module_path(),
                                      "images/poolconnected_16.png")),
                        server.all['pool'][pool]['name_label'], pool, "pool",
                        "Running", server.host, pool,
                        ['newvm', 'newstorage', 'importvm', 'disconnect'
                         ], server.host
                    ])
            if poolroot:
                relacion = {}
                for ref in server.all['host'].keys():
                    relacion[str(server.all['host'][ref]['name_label'] + "_" +
                                 ref)] = ref
                server.all_hosts_keys = []
                rkeys = relacion.keys()
                rkeys.sort(key=str.lower)
                for ref in rkeys:
                    server.all_hosts_keys.append(relacion[ref])
                for h in server.all_hosts_keys:
                    host_uuid = server.all['host'][h]['uuid']
                    host = server.all['host'][h]['name_label']
                    host_enabled = server.all['host'][h]['enabled']
                    host_address = server.all['host'][h]['address']
                    if host_enabled:
                        hostroot[h] = self.treestore.append(
                            poolroot, [
                                gtk.gdk.pixbuf_new_from_file(
                                    path.join(utils.module_path(),
                                              "images/tree_connected_16.png")),
                                host, host_uuid, "host", "Running",
                                server.host, h,
                                [
                                    'newvm', 'importvm', 'newstorage',
                                    'clean_reboot', 'clean_shutdown',
                                    'shutdown'
                                ], host_address
                            ])
                    else:
                        hostroot[h] = self.treestore.append(
                            poolroot, [
                                gtk.gdk.pixbuf_new_from_file(
                                    path.join(utils.module_path(),
                                              "images/tree_disabled_16.png")),
                                host, host_uuid, "host", "Disconnected",
                                server.host, h, [], host_address
                            ])
                root = poolroot
            else:
                host_uuid = server.all['host'][server.all['host'].keys()
                                               [0]]['uuid']
                host = server.all['host'][server.all['host'].keys()
                                          [0]]['name_label']
                host_address = server.all['host'][server.all['host'].keys()
                                                  [0]]['address']
                host_enabled = server.all['host'][server.all['host'].keys()
                                                  [0]]['enabled']
                if host_enabled:
                    hostroot[server.all['host'].keys(
                    )[0]] = self.treestore.append(self.treeroot, [
                        gtk.gdk.pixbuf_new_from_file(
                            path.join(utils.module_path(),
                                      "images/tree_connected_16.png")), host,
                        host_uuid, "host", "Running", server.host,
                        server.all['host'].keys()[0],
                        [
                            'newvm', 'importvm', 'newstorage', 'clean_reboot',
                            'clean_shutdown', 'shutdown', 'disconnect'
                        ], host_address
                    ])
                else:
                    hostroot[server.all['host'].keys(
                    )[0]] = self.treestore.append(self.treeroot, [
                        gtk.gdk.pixbuf_new_from_file(
                            path.join(utils.module_path(),
                                      "images/tree_disabled_16.png")), host,
                        host_uuid, "host", "Running", server.host,
                        server.all['host'].keys()[0],
                        [
                            'newvm', 'importvm', 'newstorage', 'clean_reboot',
                            'clean_shutdown', 'shutdown', 'disconnect'
                        ], host_address
                    ])

                root = hostroot[server.all['host'].keys()[0]]

            server.hostname = host
            server.hostroot = hostroot
            server.poolroot = poolroot
            relacion = {}
            for ref in server.all['vms'].keys():
                relacion[str(server.all['vms'][ref]['name_label'] + "_" +
                             ref)] = ref
            server.all_vms_keys = []
            rkeys = relacion.keys()
            rkeys.sort(key=str.lower)
            for ref in rkeys:
                server.all_vms_keys.insert(0, relacion[ref])

            for vm in server.all_vms_keys:
                if not server.all['vms'][vm]['is_a_template']:
                    if not server.all['vms'][vm]['is_control_domain']:
                        server.add_vm_to_tree(vm)
                        for operation in server.all['vms'][vm][
                                "current_operations"]:
                            server.track_tasks[operation] = vm
                    else:
                        server.host_vm[server.all['vms'][vm]
                                       ['resident_on']] = [
                                           vm, server.all['vms'][vm]['uuid']
                                       ]

            # Get all storage record
            for sr in server.all['SR'].keys():
                if server.all['SR'][sr]['name_label'] != "XenServer Tools":
                    if len(server.all['SR'][sr]['PBDs']) == 0:
                        server.last_storage_iter = self.treestore.append(
                            root, [
                                gtk.gdk.pixbuf_new_from_file(
                                    path.join(
                                        utils.module_path(),
                                        "images/storage_detached_16.png")),
                                server.all['SR'][sr]['name_label'],
                                server.all['SR'][sr]['uuid'], "storage", None,
                                server.host, sr,
                                server.all['SR'][sr]['allowed_operations'],
                                None
                            ])
                        continue
                    broken = False
                    for pbd_ref in server.all['SR'][sr]['PBDs']:
                        if not server.all['PBD'][pbd_ref]['currently_attached']:
                            broken = True
                            server.last_storage_iter = self.treestore.append(
                                root, [
                                    gtk.gdk.pixbuf_new_from_file(
                                        path.join(
                                            utils.module_path(),
                                            "images/storage_broken_16.png")),
                                    server.all['SR'][sr]['name_label'],
                                    server.all['SR'][sr]['uuid'], "storage",
                                    None, server.host, sr,
                                    server.all['SR'][sr]['allowed_operations'],
                                    None
                                ])
                    if not broken:
                        if server.all['SR'][sr]['shared']:
                            if sr == server.default_sr:
                                server.last_storage_iter = self.treestore.append(
                                    root, [
                                        gtk.gdk.pixbuf_new_from_file(
                                            path.join(
                                                utils.module_path(),
                                                "images/storage_default_16.png"
                                            )),
                                        server.all['SR'][sr]['name_label'],
                                        server.all['SR'][sr]['uuid'],
                                        "storage", None, server.host, sr,
                                        server.all['SR'][sr]
                                        ['allowed_operations'], None
                                    ])
                            else:
                                server.last_storage_iter = self.treestore.append(
                                    root, [
                                        gtk.gdk.pixbuf_new_from_file(
                                            path.join(
                                                utils.module_path(),
                                                "images/storage_shaped_16.png")
                                        ), server.all['SR'][sr]['name_label'],
                                        server.all['SR'][sr]['uuid'],
                                        "storage", None, server.host, sr,
                                        server.all['SR'][sr]
                                        ['allowed_operations'], None
                                    ])

                        else:
                            for pbd in server.all['SR'][sr]['PBDs']:
                                if sr == server.default_sr:
                                    if server.all['PBD'][pbd][
                                            'host'] in hostroot:
                                        server.last_storage_iter = self.treestore.append(
                                            hostroot[server.all['PBD'][pbd]
                                                     ['host']],
                                            [
                                                gtk.gdk.pixbuf_new_from_file(
                                                    path.join(
                                                        utils.module_path(),
                                                        "images/storage_default_16.png"
                                                    )), server.all['SR'][sr]
                                                ['name_label'],
                                                server.all['SR'][sr]['uuid'],
                                                "storage", None, server.host,
                                                sr, server.all['SR'][sr]
                                                ['allowed_operations'], None
                                            ])
                                    else:
                                        server.last_storage_iter = self.treestore.append(
                                            root, [
                                                gtk.gdk.pixbuf_new_from_file(
                                                    path.join(
                                                        utils.module_path(),
                                                        "images/storage_shaped_16.png"
                                                    )), server.all['SR'][sr]
                                                ['name_label'],
                                                server.all['SR'][sr]['uuid'],
                                                "storage", None, server.host,
                                                sr, server.all['SR'][sr]
                                                ['allowed_operations'], None
                                            ])

                                else:
                                    if server.all['PBD'][pbd][
                                            'host'] in hostroot:
                                        server.last_storage_iter = self.treestore.append(
                                            hostroot[server.all['PBD'][pbd]
                                                     ['host']],
                                            [
                                                gtk.gdk.pixbuf_new_from_file(
                                                    path.join(
                                                        utils.module_path(),
                                                        "images/storage_shaped_16.png"
                                                    )), server.all['SR'][sr]
                                                ['name_label'],
                                                server.all['SR'][sr]['uuid'],
                                                "storage", None, server.host,
                                                sr, server.all['SR'][sr]
                                                ['allowed_operations'], None
                                            ])
                                    else:
                                        server.last_storage_iter = self.treestore.append(
                                            root, [
                                                gtk.gdk.pixbuf_new_from_file(
                                                    path.join(
                                                        utils.module_path(),
                                                        "images/storage_shaped_16.png"
                                                    )), server.all['SR'][sr]
                                                ['name_label'],
                                                server.all['SR'][sr]['uuid'],
                                                "storage", None, server.host,
                                                sr, server.all['SR'][sr]
                                                ['allowed_operations'], None
                                            ])

            for tpl in server.all_vms_keys:
                if server.all['vms'][tpl]['is_a_template'] and not server.all[
                        'vms'][tpl]['is_a_snapshot']:
                    if server.all['vms'][tpl]['last_booted_record'] == "":
                        self.treestore.append(root, [
                            gtk.gdk.pixbuf_new_from_file(
                                path.join(utils.module_path(),
                                          "images/template_16.png")),
                            server.all['vms'][tpl]['name_label'],
                            server.all['vms'][tpl]['uuid'], "template", None,
                            server.host, tpl,
                            server.all['vms'][tpl]['allowed_operations'], None
                        ])
                    else:
                        tpl_affinity = server.all['vms'][tpl]['affinity']

                        if tpl_affinity in hostroot:
                            self.treestore.append(hostroot[tpl_affinity], [
                                gtk.gdk.pixbuf_new_from_file(
                                    path.join(utils.module_path(),
                                              "images/user_template_16.png")),
                                server.all['vms'][tpl]['name_label'],
                                server.all['vms'][tpl]['uuid'],
                                "custom_template", None, server.host, tpl,
                                server.all['vms'][tpl]['allowed_operations'],
                                None
                            ])
                        else:
                            self.treestore.append(root, [
                                gtk.gdk.pixbuf_new_from_file(
                                    path.join(utils.module_path(),
                                              "images/user_template_16.png")),
                                server.all['vms'][tpl]['name_label'],
                                server.all['vms'][tpl]['uuid'],
                                "custom_template", None, server.host, tpl,
                                server.all['vms'][tpl]['allowed_operations'],
                                None
                            ])

            self.treeview.expand_all()

            # Create a new thread it receives updates
            self.xc_servers[self.selected_host].thread_event_next()
            # Fill alerts list on "alerts" window
            self.xc_servers[self.selected_host].fill_alerts(self.listalerts)
            self.update_n_alerts()
        finally:
            self.server_sync_finish(server)
Example #34
0
####################

import re
import glob
from os.path import join
from subprocess import call
from shutil import copy2

import threading
from time import sleep

#make dir of this script the current dir such that stuff is found with relative addressing:
#in case called from other dirs
import utils
this_scripts_path = utils.module_path()
origWorkDir = os.getcwd()
print("changing working dir to '%s'" % (this_scripts_path))
os.chdir(this_scripts_path)


#we must add TestSuite2 to python lib path to use it
#fixme: maybe do it in runTestSuite2.py
sys.path = [os.path.abspath(settings.TestSuite2Dir)] + sys.path
import runTestSuite2
import analyseOutput

#####################################################


#we should delete ini files in target dir for OH to have just one
Example #35
0
 "packages_json_url": "http://iquality.itayb.net/packages.json",
 "use_local_json_files": False,  # for dev only
 "local_json_files_path": r"C:\Scripts\iquality-misc\json",  # for dev only
 ### Script ###
 "temp_dir": os.path.join(os.environ["Temp"], "iQuality"),
 "id3tags_whitemark": "Downloaded by iQuality v%s (grab at http://iquality.itayb.net). If you've liked this track, please consider purchasing it and support the artists."
 % __version__,
 "logfile_enable": True,
 "logfile_path": os.path.join(os.getenv("APPDATA"), "iQuality", "debug.log"),
 "logfile_maxsize": 100 * 1024,  # 100KB
 "logfile_backupCount": 0,
 "logfile2_enable": True,
 "logfile2_path": os.path.join(os.getenv("APPDATA"), "iQuality", "debug.calcScore.log"),
 "logfile2_maxsize": 250 * 1024,  # 250KB
 "logfile2_backupCount": 0,
 "pubkey_path": r"%s\public.key" % utils.module_path(__file__),
 "ext_bin_path": r"%s\iQuality-binutils.win32" % utils.module_path(__file__),
 ### Thread Counts ###
 "buildSongObjs_processes": 7,
 "search_processes": 3,
 "DownloadFile_Parall_processes": 6,
 "GoogleImagesGrabber_processes": 3,
 ### Processes & Timeouts ###
 "is_ServerSupportHTTPRange_timeout": 8,
 "get_filesize_timeout": 6,
 "LinksGrabber_timeout": 8,
 "metadata_timeout": 5,
 "webservices_timeout": 4,
 "GoogleImagesGrabber_timeout": 5,
 "GoogleImagesGrabber_maxsize": 650 * 1024,  # 650KB
 "get_id3info_timeout": 4,
Example #36
0
		'packages_json_url': 'http://iquality.itayb.net/packages.json',
		'packages_json_stage_url': 'http://iquality.itayb.net/packages-stage.json',
		'packages_json_stagelocal_url': 'http://localhost:8070/packages-stage.json',

		### Script ###
		'temp_dir': os.path.join(os.environ["Temp"], "iQuality"),
		'id3tags_whitemark': "Downloaded by iQuality v%s (grab at http://iquality.itayb.net). If you've liked this track, please consider purchasing it and support the artists." % __version__,
		'logfile_enable': True,
		'logfile_path': os.path.join(os.getenv('APPDATA'), 'iQuality', 'debug.log'),
		'logfile_maxsize': 100*1024, # 100KB
		'logfile_backupCount': 0,
		'logfile2_enable': True,
		'logfile2_path': os.path.join(os.getenv('APPDATA'), 'iQuality', 'debug.calcScore.log'),
		'logfile2_maxsize': 250*1024, # 250KB
		'logfile2_backupCount': 0,
		'pubkey_path': r"%s\public.key" % utils.module_path(__file__),
		'ext_bin_path': r"%s\iQuality-binutils.win32" % utils.module_path(__file__),
		
		### Thread Counts ###
		'buildSongObjs_processes': 7,
		'search_processes': 3,
		'DownloadFile_Parall_processes': 6,
		'GoogleImagesGrabber_processes': 3,
		
		### Processes & Timeouts ###
		'is_ServerSupportHTTPRange_timeout': 8,
		'get_filesize_timeout': 6,
		'LinksGrabber_timeout': 8,
		'metadata_timeout': 5,
		'webservices_timeout': 4,
		'GoogleImagesGrabber_timeout': 5,
Example #37
0
        'logfile_path':
        os.path.join(os.getenv('APPDATA'), 'iQuality', 'debug.log'),
        'logfile_maxsize':
        100 * 1024,  # 100KB
        'logfile_backupCount':
        0,
        'logfile2_enable':
        True,
        'logfile2_path':
        os.path.join(os.getenv('APPDATA'), 'iQuality', 'debug.calcScore.log'),
        'logfile2_maxsize':
        250 * 1024,  # 250KB
        'logfile2_backupCount':
        0,
        'pubkey_path':
        r"%s\public.key" % utils.module_path(__file__),
        'ext_bin_path':
        r"%s\iQuality-binutils.win32" % utils.module_path(__file__),

        ### Thread Counts ###
        'buildSongObjs_processes':
        7,
        'search_processes':
        3,
        'DownloadFile_Parall_processes':
        6,
        'GoogleImagesGrabber_processes':
        3,

        ### Processes & Timeouts ###
        'is_ServerSupportHTTPRange_timeout':
    def server_sync_update_tree(self, server):
        """Method called when connection loading is finished
        """
        try:
            self.server_sync_progress(server, "")
            
            # Remove the server from tree; it will be created again below
            # FIXME: csun: this won't be necessary when we have controllers
            def remove_helper(model, path, iter):
                if self.treestore.get(iter, 1, 3) == (server.hostname, "server"):
                    self.treestore.remove(iter)
                    return True
                return False
            self.treestore.foreach(remove_helper)
            
            # TODO: csun: clean this up
            
            poolroot = None 
            hostroot = {}
            root = ""
            server.treestore = self.treestore
            server.default_sr = ""
            
            for pool in server.all_pools.keys():
                server.default_sr = server.all_pools[pool]['default_SR']
                if server.all_pools[pool]['name_label']:
                    poolroot = self.treestore.append(self.treeroot,
                                                      [gtk.gdk.pixbuf_new_from_file(path.join(
                                                          utils.module_path(), "images/poolconnected_16.png")),
                                                       server.all_pools[pool]['name_label'], pool, "pool", "Running",
                                                       server.host, pool,
                                                       ['newvm', 'newstorage', 'importvm', 'disconnect'], server.host])
            if poolroot:
                relacion = {}
                for ref in server.all_hosts.keys():
                    relacion[str(server.all_hosts[ref]['name_label'] + "_" + ref)] = ref
                server.all_hosts_keys = []
                rkeys = relacion.keys()
                rkeys.sort(key=str.lower)
                for ref in rkeys:
                    server.all_hosts_keys.append(relacion[ref])
                for h in server.all_hosts_keys:
                    host_uuid = server.all_hosts[h]['uuid']
                    host = server.all_hosts[h]['name_label']
                    host_enabled = server.all_hosts[h]['enabled']
                    host_address = server.all_hosts[h]['address']
                    if host_enabled:
                        hostroot[h] = self.treestore.append(
                            poolroot, [gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                              "images/tree_connected_16.png")), host,
                                       host_uuid, "host", "Running", server.host, h, ['newvm', 'importvm', 'newstorage',
                                                                                      'clean_reboot', 'clean_shutdown',
                                                                                      'shutdown'], host_address])
                    else:
                        hostroot[h] = self.treestore.append(
                            poolroot,
                            [gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                    "images/tree_disabled_16.png")), host, host_uuid,
                             "host", "Disconnected", server.host, h, [], host_address])
                root = poolroot
            else:
                host_uuid = server.all_hosts[server.all_hosts.keys()[0]]['uuid']
                host = server.all_hosts[server.all_hosts.keys()[0]]['name_label']
                host_address = server.all_hosts[server.all_hosts.keys()[0]]['address']
                host_enabled = server.all_hosts[server.all_hosts.keys()[0]]['enabled']
                if host_enabled:
                    hostroot[server.all_hosts.keys()[0]] = self.treestore.append(
                        self.treeroot, [gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                               "images/tree_connected_16.png")), host,
                                        host_uuid, "host", "Running", server.host, server.all_hosts.keys()[0],
                                        ['newvm', 'importvm', 'newstorage', 'clean_reboot', 'clean_shutdown',
                                         'shutdown', 'disconnect'], host_address])
                else:
                    hostroot[server.all_hosts.keys()[0]] = self.treestore.append(
                        self.treeroot, [gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                               "images/tree_disabled_16.png")), host,
                                        host_uuid, "host", "Running", server.host, server.all_hosts.keys()[0],
                                        ['newvm', 'importvm', 'newstorage', 'clean_reboot', 'clean_shutdown',
                                         'shutdown', 'disconnect'], host_address])

                root = hostroot[server.all_hosts.keys()[0]]

            server.hostname = host
            server.hostroot = hostroot
            server.poolroot = poolroot
            relacion = {}
            for ref in server.all_vms.keys():
                relacion[str(server.all_vms[ref]['name_label'] + "_" + ref)] = ref
            server.all_vms_keys = []
            rkeys = relacion.keys()
            rkeys.sort(key=str.lower)
            for ref in rkeys:
                server.all_vms_keys.insert(0, relacion[ref])

            for vm in server.all_vms_keys:
                if not server.all_vms[vm]['is_a_template']:
                    if not server.all_vms[vm]['is_control_domain']:
                        server.add_vm_to_tree(vm)
                        for operation in server.all_vms[vm]["current_operations"]:
                            server.track_tasks[operation] = vm
                    else:
                        server.host_vm[server.all_vms[vm]['resident_on']] = [vm,  server.all_vms[vm]['uuid']]
      
            # Get all storage record 
            for sr in server.all_storage.keys():
                if server.all_storage[sr]['name_label'] != "XenServer Tools":
                    if len(server.all_storage[sr]['PBDs']) == 0:
                        server.last_storage_iter = self.treestore.append(
                            root, [gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                          "images/storage_detached_16.png")),
                                   server.all_storage[sr]['name_label'], server.all_storage[sr]['uuid'], "storage",
                                   None, server.host, sr, server.all_storage[sr]['allowed_operations'], None])
                        continue
                    broken = False
                    for pbd_ref in server.all_storage[sr]['PBDs']:
                        if not server.all_pbd[pbd_ref]['currently_attached']:
                            broken = True
                            server.last_storage_iter = self.treestore.append(
                                root, [gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                              "images/storage_broken_16.png")),
                                       server.all_storage[sr]['name_label'], server.all_storage[sr]['uuid'],"storage",
                                       None, server.host, sr, server.all_storage[sr]['allowed_operations'], None])
                    if not broken:
                        if server.all_storage[sr]['shared']:
                            if sr == server.default_sr:
                                server.last_storage_iter = self.treestore.append(
                                    root, [gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                                  "images/storage_default_16.png")),
                                           server.all_storage[sr]['name_label'], server.all_storage[sr]['uuid'],
                                           "storage", None, server.host, sr,
                                           server.all_storage[sr]['allowed_operations'], None])
                            else:
                                server.last_storage_iter = self.treestore.append(
                                    root, [gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                                  "images/storage_shaped_16.png")),
                                           server.all_storage[sr]['name_label'], server.all_storage[sr]['uuid'],
                                           "storage", None, server.host, sr,
                                           server.all_storage[sr]['allowed_operations'], None])

                        else:
                            for pbd in server.all_storage[sr]['PBDs']:
                                if sr == server.default_sr:
                                    if server.all_pbd[pbd]['host'] in hostroot:
                                        server.last_storage_iter = self.treestore.append(
                                            hostroot[server.all_pbd[pbd]['host']],
                                            [gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                                    "images/storage_default_16.png")),
                                             server.all_storage[sr]['name_label'], server.all_storage[sr]['uuid'],
                                             "storage", None, server.host, sr,
                                             server.all_storage[sr]['allowed_operations'], None])
                                    else:
                                        server.last_storage_iter = self.treestore.append(
                                            root, [gtk.gdk.pixbuf_new_from_file(path.join(
                                                utils.module_path(), "images/storage_shaped_16.png")),
                                                server.all_storage[sr]['name_label'], server.all_storage[sr]['uuid'],
                                                "storage", None, server.host, sr,
                                                server.all_storage[sr]['allowed_operations'], None])

                                else:
                                    if server.all_pbd[pbd]['host'] in hostroot:
                                        server.last_storage_iter = self.treestore.append(
                                            hostroot[server.all_pbd[pbd]['host']],
                                            [gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                                    "images/storage_shaped_16.png")),
                                             server.all_storage[sr]['name_label'], server.all_storage[sr]['uuid'],
                                             "storage", None, server.host, sr,
                                             server.all_storage[sr]['allowed_operations'], None])
                                    else:
                                        server.last_storage_iter = self.treestore.append(
                                            root, [gtk.gdk.pixbuf_new_from_file(path.join(
                                                utils.module_path(), "images/storage_shaped_16.png")),
                                                server.all_storage[sr]['name_label'], server.all_storage[sr]['uuid'],
                                                "storage", None, server.host, sr,
                                                server.all_storage[sr]['allowed_operations'], None])

            for tpl in server.all_vms_keys:
                if server.all_vms[tpl]['is_a_template'] and not server.all_vms[tpl]['is_a_snapshot']: 
                    if server.all_vms[tpl]['last_booted_record'] == "":
                        self.treestore.append(root, [gtk.gdk.pixbuf_new_from_file(path.join(utils.module_path(),
                                                                                            "images/template_16.png")),
                                                     server.all_vms[tpl]['name_label'], server.all_vms[tpl]['uuid'],
                                                     "template", None, server.host, tpl,
                                                     server.all_vms[tpl]['allowed_operations'], None])
                    else:
                        tpl_affinity = server.all_vms[tpl]['affinity']
                        
                        if tpl_affinity in hostroot:
                            self.treestore.append(hostroot[tpl_affinity],
                                                  [gtk.gdk.pixbuf_new_from_file(
                                                      path.join(utils.module_path(), "images/user_template_16.png")),
                                                   server.all_vms[tpl]['name_label'], server.all_vms[tpl]['uuid'],
                                                   "custom_template", None, server.host, tpl,
                                                   server.all_vms[tpl]['allowed_operations'], None])
                        else:
                            self.treestore.append(root, [gtk.gdk.pixbuf_new_from_file(path.join(
                                utils.module_path(), "images/user_template_16.png")),
                                server.all_vms[tpl]['name_label'], server.all_vms[tpl]['uuid'], "custom_template", None,
                                server.host, tpl, server.all_vms[tpl]['allowed_operations'], None])

            self.treeview.expand_all()
            
            # Create a new thread it receives updates
            self.xc_servers[self.selected_host].thread_event_next()
            # Fill alerts list on "alerts" window
            self.xc_servers[self.selected_host].fill_alerts(self.listalerts)
            self.update_n_alerts()
        finally:
            self.server_sync_finish(server)