本文整理汇总了Python中XenAPI.xapi_local方法的典型用法代码示例。如果您正苦于以下问题:Python XenAPI.xapi_local方法的具体用法?Python XenAPI.xapi_local怎么用?Python XenAPI.xapi_local使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XenAPI
的用法示例。
在下文中一共展示了XenAPI.xapi_local方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: canonicaliseOtherConfig
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def canonicaliseOtherConfig(vm_uuid):
session = XenAPI.xapi_local()
session.login_with_password("", "")
try:
vm = session.xenapi.VM.get_by_uuid(vm_uuid)
other_config = session.xenapi.VM.get_other_config(vm)
finally:
session.logout()
def collect(d, k, default = None):
if d.has_key(k):
return d[k]
else:
return default
rc = { 'install-repository': collect(other_config, 'install-repository'),
'install-vnc': collect(other_config, 'install-vnc', "false") in ["1", "true"],
'install-vncpasswd': collect(other_config, 'install-vncpasswd'),
'install-distro': collect(other_config, 'install-distro', 'rhlike'),
'install-round': collect(other_config, 'install-round', '1'),
'install-arch': collect(other_config, 'install-arch', 'i386'),
'install-kernel': collect(other_config, 'install-kernel', None),
'install-ramdisk': collect(other_config, 'install-ramdisk', None),
'install-proxy': collect(other_config, 'install-proxy', None),
'debian-release': collect(other_config, 'debian-release') }
return rc
示例2: mount
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def mount(dbg, dev_path):
# Ensure corosync+dlm are configured and running
inventory = xcp.environ.readInventory()
session = XenAPI.xapi_local()
session.xenapi.login_with_password("root", "")
this_host = session.xenapi.host.get_by_uuid(
inventory.get("INSTALLATION_UUID"))
log.debug("%s: setting up corosync and dlm on this host" % (dbg))
session.xenapi.host.call_plugin(
this_host, "gfs2setup", "gfs2Setup", {})
mnt_path = os.path.abspath(mountpoint_root + dev_path)
try:
os.makedirs(mnt_path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(mnt_path):
pass
else:
raise
if not os.path.ismount(mnt_path):
cmd = ["/usr/sbin/modprobe", "gfs2"]
call(dbg, cmd)
cmd = ["/usr/bin/mount", "-t", "gfs2", "-o",
"noatime,nodiratime", dev_path, mnt_path]
call(dbg, cmd)
return mnt_path
示例3: attach
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def attach(self, dbg, uri):
log.debug("%s: SR.attach: uri=%s" % (dbg, uri))
# Notify other pool members we have arrived
inventory = xcp.environ.readInventory()
session = XenAPI.xapi_local()
session.xenapi.login_with_password("root", "")
this_host = session.xenapi.host.get_by_uuid(
inventory.get("INSTALLATION_UUID"))
# FIXME: Do not notify offline hosts
# FIXME: See ffs.call_plugin_in_pool()
for host in session.xenapi.host.get_all():
if host != this_host:
log.debug("%s: notifying host %s we have arrived" % (dbg, session.xenapi.host.get_name_label(host)))
session.xenapi.host.call_plugin(
host, "gfs2setup", "gfs2Reload", {})
# Zone in the LUN on this host
dev_path = plug_device(dbg, uri)
# Mount the gfs2 filesystem
mnt_path = mount(dbg, dev_path)
log.debug("%s: mounted on %s" % (dbg, mnt_path))
uri = "file://" + mnt_path
return uri
示例4: from_cli
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def from_cli(cls):
import XenAPI
session = XenAPI.xapi_local()
session.xenapi.login_with_password('root', '', '', 'SM')
return cls.from_session(session)
示例5: get_api_session
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def get_api_session(conf):
if not api:
raise ImportError(_('XenAPI not installed'))
url = conf.xenapi.connection_url
username = conf.xenapi.connection_username
password = conf.xenapi.connection_password
if not url or password is None:
raise XenapiException(_('Must specify connection_url, and '
'connection_password to use'))
try:
session = (api.xapi_local() if url == 'unix://local'
else api.Session(url))
session.login_with_password(username, password)
except api.Failure as e:
if e.details[0] == 'HOST_IS_SLAVE':
master = e.details[1]
url = swap_xapi_host(url, master)
try:
session = api.Session(url)
session.login_with_password(username, password)
except api.Failure as es:
raise XenapiException(_('Could not connect slave host: %s ') %
es.details[0])
else:
msg = _("Could not connect to XenAPI: %s") % e.details[0]
raise XenapiException(msg)
return session
示例6: main
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def main():
try:
myopts, args = getopt.getopt(sys.argv[1:], "huncw:",["help", "follow", "names", "uuid"])
except getopt.GetoptError:
print "Unknown options"
systax()
sys.exit(1)
minspace = 4
mode = "name"
follow = False
for opt, arg in myopts:
if opt in ("-h", "--help"):
syntax()
sys.exit(1)
elif opt in ("-f", "--follow"):
follow = True
elif opt in ("-n", "--name"):
mode = "name"
elif opt in ("-u", "--uuid"):
mode = "uuid"
session = XenAPI.xapi_local()
session.xenapi.login_with_password("", "")
hosts = gethosts(session)
hostscpus = getcpus(session, hosts)
gethostcpus(session, hostscpus)
示例7: OpenSession
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def OpenSession(self):
session = None
if not self.masterConnectionBroken:
try:
# Try the local Unix domain socket first
session = XenAPI.xapi_local()
session.login_with_password('root','')
except socket.timeout:
session = None
self.masterConnectionBroken = True
self.error = 'The master connection has timed out.'
except Exception, e:
session = None
self.error = e
if session is None and self.testingHost is not None:
# Local session couldn't connect, so try remote.
session = XenAPI.Session("https://"+self.testingHost)
try:
session.login_with_password('root', self.defaultPassword)
except XenAPI.Failure, e:
if e.details[0] != 'HOST_IS_SLAVE': # Ignore slave errors when testing
session = None
self.error = e
except socket.timeout:
session = None
self.masterConnectionBroken = True
self.error = 'The master connection has timed out.'
示例8: main
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def main():
try:
myopts, args = getopt.getopt(sys.argv[1:], "huncw:",["help", "uuid", "name", "csv", "wspace"])
except getopt.GetoptError:
print "Unknown options"
syntax()
sys.exit(1)
minspace = 4
CSV = False
mode = "name"
for opt, arg in myopts:
if opt in ("-h", "--help"):
syntax()
sys.exit(1)
elif opt in ("-u", "--uuid"):
mode = "uuid"
elif opt in ("-n", "--name"):
mode = "name"
elif opt in ("-c", "--csv"):
CSV = True
elif opt in ("-w", "--wspace"):
minspace = int(arg)
session = XenAPI.xapi_local()
session.xenapi.login_with_password("", "")
hosts = gethostdata(session)
headings = defineheadings(mode)
print formatdarray(hosts, headings, CSV, minspace)
session.xenapi.session.logout()
示例9: get_xenapi_session
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def get_xenapi_session():
try:
session = XenAPI.xapi_local()
session.xenapi.login_with_password('', '')
return session
except XenAPI.Failure:
sys.exit(1)
示例10: __init__
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def __init__(self, srcmd, sr_uuid):
"""Base class initializer. All subclasses should call SR.__init__
in their own
initializers.
Arguments:
srcmd: SRCommand instance, contains parsed arguments
"""
try:
self.srcmd = srcmd
self.dconf = srcmd.dconf
if srcmd.params.has_key('session_ref'):
self.session_ref = srcmd.params['session_ref']
self.session = XenAPI.xapi_local()
self.session._session = self.session_ref
if 'subtask_of' in self.srcmd.params:
self.session.transport.add_extra_header('Subtask-of', self.srcmd.params['subtask_of'])
else:
self.session = None
if 'host_ref' not in self.srcmd.params:
self.host_ref = ""
else:
self.host_ref = self.srcmd.params['host_ref']
self.sr_ref = self.srcmd.params.get('sr_ref')
if 'device_config' in self.srcmd.params:
if self.dconf.get("SRmaster") == "true":
os.environ['LVM_SYSTEM_DIR'] = MASTER_LVM_CONF
except Exception, e:
raise e
raise xs_errors.XenError('SRBadXML')
示例11: __init__
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def __init__(self, srcmd, sr_uuid):
"""Base class initializer. All subclasses should call SR.__init__
in their own
initializers.
Arguments:
srcmd: SRCommand instance, contains parsed arguments
"""
try:
self.srcmd = srcmd
self.dconf = srcmd.dconf
if srcmd.params.has_key('session_ref'):
self.session_ref = srcmd.params['session_ref']
self.session = XenAPI.xapi_local()
self.session._session = self.session_ref
if 'subtask_of' in self.srcmd.params:
self.session.transport.add_extra_header('Subtask-of', self.srcmd.params['subtask_of'])
else:
self.session = None
if 'host_ref' not in self.srcmd.params:
self.host_ref = ""
else:
self.host_ref = self.srcmd.params['host_ref']
if 'sr_ref' in self.srcmd.params:
self.sr_ref = self.srcmd.params['sr_ref']
except Exception, e:
raise e
raise xs_errors.XenError('SRBadXML')
示例12: __init__
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def __init__(self, session_ref=None, cache_file=None):
if session_ref and cache_file:
raise Error("can't specify session reference and cache file")
if cache_file == None:
import XenAPI
session = XenAPI.xapi_local()
if not session_ref:
log("No session ref given on command line, logging in.")
session.xenapi.login_with_password("root", "")
else:
session._session = session_ref
try:
inventory = self.__read_xensource_inventory()
assert(inventory.has_key('INSTALLATION_UUID'))
log("host uuid is %s" % inventory['INSTALLATION_UUID'])
host = session.xenapi.host.get_by_uuid(inventory['INSTALLATION_UUID'])
self.__get_pif_records_from_xapi(session, host)
try:
self.__get_tunnel_records_from_xapi(session)
except XenAPI.Failure, e:
error,details = e.details
if error == "MESSAGE_METHOD_UNKNOWN" and details == "tunnel.get_all":
pass
self.__get_vlan_records_from_xapi(session)
self.__get_bond_records_from_xapi(session)
self.__get_network_records_from_xapi(session)
finally:
示例13: call_plugin_on_host
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def call_plugin_on_host(dbg, host_name, plugin_name, plugin_function, args):
log.debug("%s: calling plugin '%s' function '%s' with args %s on %s" % (dbg, plugin_name, plugin_function, args, host_name))
session = XenAPI.xapi_local()
try:
session.xenapi.login_with_password('root', '')
except:
# ToDo: We ought to raise something else
raise
try:
for host_ref in get_online_host_refs(dbg, session):
log.debug("%s: host_ref %s - host_name %s)" % (dbg, session.xenapi.host.get_name_label(host_ref), host_name))
if session.xenapi.host.get_name_label(host_ref) == host_name:
log.debug("%s: calling plugin '%s' function '%s' with args %s on host %s - %s)" % (dbg, plugin_name, plugin_function, args, host_ref, host_name))
resulttext = session.xenapi.host.call_plugin(
host_ref,
plugin_name,
plugin_function,
args)
log.debug("%s: resulttext = %s" % (dbg, resulttext))
if resulttext != "True":
# ToDo: We ought to raise something else
raise xapi.storage.api.volume.Unimplemented(
"Failed to get hostref %s to run %s(%s)" %
(host_ref, plugin_name, plugin_function, args))
except:
# ToDo: We ought to raise something else
raise
finally:
session.xenapi.session.logout()
示例14: get_localAPI_session
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def get_localAPI_session():
# First acquire a valid session
session = XenAPI.xapi_local()
try:
session.xenapi.login_with_password('root','')
except:
raise xs_errors.XenError('APISession')
return session
示例15: main
# 需要导入模块: import XenAPI [as 别名]
# 或者: from XenAPI import xapi_local [as 别名]
def main(argv):
session = XenAPI.xapi_local()
session.xenapi.login_with_password("", "", "1.0", "xen-api-scripts-linkvmsbysr.py")
try:
opts, args = getopt.getopt(sys.argv[1:], "hd:", [])
except getopt.GetoptError, err:
print str(err)
usage()