当前位置: 首页>>代码示例>>Python>>正文


Python KaresansuiVirtConnection.search_guests方法代码示例

本文整理汇总了Python中karesansui.lib.virt.virt.KaresansuiVirtConnection.search_guests方法的典型用法代码示例。如果您正苦于以下问题:Python KaresansuiVirtConnection.search_guests方法的具体用法?Python KaresansuiVirtConnection.search_guests怎么用?Python KaresansuiVirtConnection.search_guests使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在karesansui.lib.virt.virt.KaresansuiVirtConnection的用法示例。


在下文中一共展示了KaresansuiVirtConnection.search_guests方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _GET

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import search_guests [as 别名]
    def _GET(self, *param, **params):
        _prep_console()

        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None: return web.notfound()

        model = findbyguest1(self.orm, guest_id)
        kvc = KaresansuiVirtConnection()
        try:
            domname = kvc.uuid_to_domname(model.uniq_key)
            if not domname: return web.notfound()

            dom = kvc.search_guests(domname)[0]

            document = XMLParse(dom.XMLDesc(1))

            self.view.graphics_port = XMLXpath(document,
                                          '/domain/devices/graphics/@port')
            self.view.xenname = XMLXpath(document,
                                         '/domain/name/text()')
        finally:
            kvc.close()

        h_model = findbyhost1(self.orm, host_id)
        try:
            from karesansui.lib.utils import get_ifconfig_info
            device = KVM_BRIDGE_PREFIX + "0"
            self.view.host_ipaddr = get_ifconfig_info(device)[device]["ipaddr"]
        except:
            try:
                self.view.host_ipaddr = h_model.hostname.split(":")[0].strip()
            except:
                self.view.host_ipaddr = socket.gethostbyname(socket.gethostname())

        return True
开发者ID:fkei,项目名称:karesansui,代码行数:37,代码来源:console.py

示例2: process

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import search_guests [as 别名]
 def process(self):
     conn = KaresansuiVirtConnection()
     try:
         guests = conn.search_guests()
 
         nodeinfo = conn.get_nodeinfo()
         
         infos = []
         for guest in guests:
             id = guest.ID()
             if id > -1:
                 name = guest.name()
                 print name
                 info = guest.info()
                 maxMem = info[1]
                 memory = info[2]
                 
                 pcentCurrMem = memory * 100.0 / (nodeinfo["memory"]*1024)
                 pcentMaxMem  = maxMem * 100.0 / (nodeinfo["memory"]*1024)
                 
                 print "%.3f%%" % pcentCurrMem
                 #print pcentMaxMem
                 
         return True
     
     finally:
         conn.close()
开发者ID:AdUser,项目名称:karesansui,代码行数:29,代码来源:get_memory_usage.py

示例3: _GET

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import search_guests [as 别名]
    def _GET(self, *param, **params):

        java_dir = karesansui.dirname + "/static/java"
        self.view.applet_dst_path = java_dir + "/VncViewer.jar"
        self.view.applet_src_path = _get_applet_source_path()
        self.view.found_applet_located = os.path.exists(self.view.applet_dst_path)

        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None:
            return web.notfound()

        model = findbyguest1(self.orm, guest_id)
        kvc = KaresansuiVirtConnection()
        try:
            domname = kvc.uuid_to_domname(model.uniq_key)
            if not domname:
                return web.notfound()

            dom = kvc.search_guests(domname)[0]

            document = XMLParse(dom.XMLDesc(1))

            self.view.graphics_port = XMLXpath(document, "/domain/devices/graphics/@port")
            self.view.xenname = XMLXpath(document, "/domain/name/text()")
        finally:
            kvc.close()

        h_model = findbyhost1(self.orm, host_id)
        try:
            from karesansui.lib.utils import get_ifconfig_info

            device = KVM_BRIDGE_PREFIX + "0"
            self.view.host_ipaddr = get_ifconfig_info(device)[device]["ipaddr"]
        except:
            try:
                self.view.host_ipaddr = h_model.hostname.split(":")[0].strip()
            except:
                self.view.host_ipaddr = socket.gethostbyname(socket.gethostname())

        return True
开发者ID:karesansui,项目名称:karesansui,代码行数:42,代码来源:console.py

示例4: __init__

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import search_guests [as 别名]
class KaresansuiVirtSnapshot:

    def __init__(self,uri=None,readonly=True):
        self.__prep()
        self.logger.debug(get_inspect_stack())
        try:
            self.kvc = KaresansuiVirtConnection(uri=uri, readonly=readonly)
        except:
            raise KaresansuiVirtSnapshotException(_("Cannot open '%s'") % uri)
        try:
            from libvirtmod import virDomainRevertToSnapshot
            from libvirtmod import virDomainSnapshotCreateXML
            from libvirtmod import virDomainSnapshotCurrent
            from libvirtmod import virDomainSnapshotDelete
            from libvirtmod import virDomainSnapshotGetXMLDesc
            from libvirtmod import virDomainSnapshotLookupByName
        except:
            raise KaresansuiVirtSnapshotException(_("Snapshot is not supported by this version of libvirt"))
        self.error_msg = []


    def __del__(self):
        self.finish()

    def __prep(self):
        self.logger = logging.getLogger('karesansui.virt.snapshot')

    def finish(self):
        try:
            self.kvc.close()
        except:
            pass

    def append_error_msg(self,string):
        self.error_msg.append(string)

    def reset_error_msg(self):
        self.error_msg = []

    def generateXML(self, doc):
        out = StringIO()
        out.write(doc,toxml())
        return out.getvalue()

    def isSupportedDomain(self,domain=None):
        retval = True

        inactives = self.kvc.list_inactive_guest()
        actives   = self.kvc.list_active_guest()

        if domain is not None:
            if domain in inactives + actives:
                guest = self.kvc.search_guests(domain)[0]

                param = ConfigParam(domain)
                param.load_xml_config(guest.XMLDesc(1))

                for info in param.disks:
                    """
                    { 'bus'        :'ide',
                      'device'     :'disk',
                      'disk_type'  :'file',
                      'driver_name':'qemu',
                      'driver_type':'qcow2',
                      'path'       :'/path/to/disk_image.img',
                      'target'     :'hda'}
                    """
                    try:
                        if info['driver_type'] == "qcow2":
                            pass
                        elif info['device'] == "cdrom":
                            pass
                        else:
                            if info['disk_type'] != "block":
                                self.append_error_msg(_("%s: unsupported image format %s") % (info['target'],info['driver_type']))
                                retval = False
                                #break
                    except:
                        retval = False
                        #break
            else:
                retval = False

        return retval

    def _snapshotListNames(self,domain=None):
        retval = []

        if domain is not None:
            for xml_path in glob.glob("%s/%s/*.xml" % (VIRT_SNAPSHOT_DIR,domain,)):
                retval.append(os.path.basename(xml_path)[0:-4])

        return retval

    def listNames(self,domain=None,all=False):
        retval = {}

        inactives = self.kvc.list_inactive_guest()
        actives   = self.kvc.list_active_guest()

#.........这里部分代码省略.........
开发者ID:AdUser,项目名称:karesansui,代码行数:103,代码来源:snapshot.py

示例5: process

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import search_guests [as 别名]
    def process(self):
        conn = KaresansuiVirtConnection()
        try:
            guests = conn.search_guests()
    
            infos = []
            for guest in guests:
              id = guest.ID()
              if id > -1:
                name = guest.name()
                info = guest.info()
        
                now = gettimeofday()
                sec = now[0]
                usec = now[1]
                infos.append({"id": id, "cpu_time": info[4], "real_time_sec": long(sec), "real_time_usec": long(usec)})
    
            #print infos
            time.sleep(1.1)
    
            cnt = 0
            for guest in guests:
              id = guest.ID()
              if id > -1:
                name = guest.name()
                print name
                info = guest.info()
    
                now = gettimeofday()
                sec = now[0]
                usec = now[1]
    
                # calculate the usage of cpu
                #print infos[cnt]
                cpu_diff = (info[4] - infos[cnt]["cpu_time"]) / 10000
                #print info[4]
                #print infos[cnt]["cpu_time"]
                #print cpu_diff
    
                #real_diff = 1000 *(long(sec) - infos[cnt]["real_time_sec"]) + (usec - infos[cnt]["real_time_usec"])
                real_diff = ((long(sec) - infos[cnt]["real_time_sec"]) * 1000) + ((usec - infos[cnt]["real_time_usec"]) / 1000);
    
                #real_diff = 1000 *(sec - infos[cnt]["real_time_sec"])
                #real_diff2 = (usec - infos[cnt]["real_time_usec"])
    
                #print "realTime.tv_sec:%10ld" % sec
                #print "infos.real_time.tv_sec:%10ld" % infos[cnt]["real_time_sec"]
                #print "realTime.tv_usec:%10ld" % usec
                #print "infos.real_time.tv_usec:%10ld" % infos[cnt]["real_time_usec"]
                #print "real_diff:%10ld" % real_diff
                #print "cpu_diff:%10ld" % cpu_diff
    
                usage = cpu_diff / float(real_diff);  
                print "%.3f%%" % usage
     
                # print the results
                #printf("%d\t%.3f%\t%lu\t%lu\t%hu\t%0X\t%s\n", id, usage, info.memory / 1024,  
                #info.maxMem / 1024, info.nrVirtCpu, info.state, virDomainGetName(dom));  
                cnt = cnt + 1

                return True
        finally:
            conn.close()
开发者ID:AdUser,项目名称:karesansui,代码行数:65,代码来源:get_cpu_usage.py

示例6: KaresansuiVirtConnection

# 需要导入模块: from karesansui.lib.virt.virt import KaresansuiVirtConnection [as 别名]
# 或者: from karesansui.lib.virt.virt.KaresansuiVirtConnection import search_guests [as 别名]
#curses.start_color()
#curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)

# timeout getch after 1s
stdscr.timeout(1000)

(maxy, maxx) = stdscr.getmaxyx()

vtop_start = time.time()
first_run = True

conn = KaresansuiVirtConnection()
shares = {}
while True:
    guests = conn.search_guests()
    idx = 1
    cpusum=0
    if first_run:
        for guest in guests:
            id = guest.ID()
            if id > -1:
                name = guest.name()
                info = guest.info()
                shares[name] = info[4]
        first_run = False
    else:
        stdscr.addstr(idx, 1, "Domain\t\tID\tVCPU\t%CPU\t%CPUSUM   ", curses.A_REVERSE)
        idx += 1
        for guest in guests:
            id = guest.ID()
开发者ID:AdUser,项目名称:karesansui,代码行数:32,代码来源:cputop.py


注:本文中的karesansui.lib.virt.virt.KaresansuiVirtConnection.search_guests方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。