⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xapi.py

📁 xen虚拟机源代码安装包
💻 PY
字号:
#!/usr/bin/python#============================================================================# This library is free software; you can redistribute it and/or# modify it under the terms of version 2.1 of the GNU Lesser General Public# License as published by the Free Software Foundation.## This library is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU# Lesser General Public License for more details.## You should have received a copy of the GNU Lesser General Public# License along with this library; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#============================================================================# Copyright (C) 2006 XenSource Ltd.# Copyright (C) 2006 IBM Corporation#============================================================================import atexitimport osimport sysfrom XmTestLib import *from xen.xm import main as xmmainfrom xen.xm import XenAPIfrom xen.xm.opts import OptionErrorfrom types import DictTypeimport xml.dom.minidomdef get_login_pwd():    if xmmain.serverType == xmmain.SERVER_XEN_API:        try:            login, password = xmmain.parseAuthentication()            return (login, password)        except:            raise OptionError("Configuration for login/pwd not found. "                              "Need to run xapi-setup.py?")    raise OptionError("Xm configuration file not using Xen-API for "                      "communication with xend.")sessions=[]def connect(*args):    try:        creds = get_login_pwd()    except Exception, e:        FAIL("%s" % str(e))    try:        session = XenAPI.Session(xmmain.serverURI)    except:        raise OptionError("Could not create XenAPI session with Xend." \                          "URI=%s" % xmmain.serverURI)    try:        session.login_with_password(*creds)    except:        raise OptionError("Could not login to Xend. URI=%s" % xmmain.serverURI)    def logout():        try:            for s in sessions:                s.xenapi.session.logout()        except:            pass    sessions.append(session)    atexit.register(logout)    return session

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -