本文整理汇总了Python中XendNode类的典型用法代码示例。如果您正苦于以下问题:Python XendNode类的具体用法?Python XendNode怎么用?Python XendNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XendNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_ncpu
def set_ncpu(self, ncpu):
_ncpu = int(ncpu)
if _ncpu < 1:
raise PoolError(XEND_ERROR_POOL_PARAM, 'ncpu')
self.ncpu = _ncpu
if self._managed:
XendNode.instance().save_cpu_pools()
示例2: add_host_CPU_live
def add_host_CPU_live(self, cpu_ref):
""" Add cpu to pool, if it is currently not assigned to a pool.
@param cpu_ref: reference of host_cpu instance to add
@type cpu_ref: str
"""
if not self.get_activated():
raise PoolError(XEND_ERROR_BAD_POOL_STATE, 'deactivated')
node = XendNode.instance()
number = node.get_host_cpu_field(cpu_ref, 'number')
self.pool_lock.acquire()
try:
pool_id = self.query_pool_id()
other_pool_ref = self.get_cpu_pool_by_cpu_ref(cpu_ref)
if len(other_pool_ref) != 0:
raise PoolError(XEND_ERROR_INVALID_CPU,
'cpu already assigned to pool "%s"' % other_pool_ref[0])
xc.cpupool_addcpu(pool_id, number)
finally:
self.pool_lock.release()
if number not in self.proposed_cpus:
self.proposed_cpus.append(number)
self._update_ncpu(pool_id)
if self._managed:
XendNode.instance().save_cpu_pools()
示例3: set_MAC
def set_MAC(self, new_mac):
success = linux_set_mac(self.device, new_mac)
if success:
self.MAC = new_mac
import XendNode
XendNode.instance().save_PIFs()
return success
示例4: set_MTU
def set_MTU(self, new_mtu):
success = linux_set_mtu(self.device, new_mtu)
if success:
self.MTU = new_mtu
import XendNode
XendNode.instance().save_PIFs()
return success
示例5: remove_from_proposed_CPUs
def remove_from_proposed_CPUs(self, cpu):
if self.get_activated():
raise PoolError(XEND_ERROR_BAD_POOL_STATE, 'activated')
_cpu = int(cpu)
if _cpu in self.proposed_cpus:
self.proposed_cpus.remove(_cpu)
if self._managed:
XendNode.instance().save_cpu_pools()
示例6: create_VLAN
def create_VLAN(self, device, network_uuid, host_ref, vlan):
"""Exposed via API - create a new VLAN from existing VIF"""
ifs = [name for name, _, _ in linux_get_phy_ifaces()]
vlan = int(vlan)
# Check VLAN tag is valid
if vlan < 0 or vlan >= 4096:
raise VLANTagInvalid(vlan)
# Check device exists
if device not in ifs:
raise InvalidDeviceError(device)
# Check VLAN doesn't already exist
if "%s.%d" % (device, vlan) in ifs:
raise DeviceExistsError("%s.%d" % (device, vlan))
# Check network ref is valid
from XendNetwork import XendNetwork
if network_uuid not in XendNetwork.get_all():
raise InvalidHandleError("Network", network_uuid)
# Check host_ref is this host
import XendNode
if host_ref != XendNode.instance().get_uuid():
raise InvalidHandleError("Host", host_ref)
# Create the VLAN
_create_VLAN(device, vlan)
# Create new uuids
pif_uuid = genuuid.createString()
metrics_uuid = genuuid.createString()
# Create the record
record = {
"device": device,
"MAC": linux_get_mac("%s.%d" % (device, vlan)),
"MTU": linux_get_mtu("%s.%d" % (device, vlan)),
"network": network_uuid,
"VLAN": vlan,
}
# Create instances
metrics = XendPIFMetrics(metrics_uuid, pif_uuid)
pif = XendPIF(record, pif_uuid, metrics_uuid)
# Not sure if they should be created plugged or not...
pif.plug()
XendNode.instance().save_PIFs()
return pif_uuid
示例7: destroy
def destroy(self):
""" In order to destroy a cpu pool, it must be deactivated """
self.pool_lock.acquire()
try:
if self.get_activated():
raise PoolError(XEND_ERROR_BAD_POOL_STATE, 'activated')
XendBase.destroy(self)
finally:
self.pool_lock.release()
XendNode.instance().save_cpu_pools()
示例8: add_to_proposed_CPUs
def add_to_proposed_CPUs(self, cpu):
if self.get_activated():
raise PoolError(XEND_ERROR_BAD_POOL_STATE, 'activated')
_cpu = int(cpu)
if _cpu not in self.proposed_cpus:
self.proposed_cpus.append(_cpu)
self.proposed_cpus.sort()
if self._managed:
XendNode.instance().save_cpu_pools()
示例9: create
def create(cls, record):
""" Create a new managed pool instance.
@param record: attributes of pool
@type record: dict
@return: uuid of created pool
@rtype: str
"""
new_uuid = genuuid.createString()
XendCPUPool(record, new_uuid)
XendNode.instance().save_cpu_pools()
return new_uuid
示例10: destroy
def destroy(self):
# check no VIFs or PIFs attached
if len(self.get_VIFs()) > 0:
raise NetworkError("Cannot destroy network with VIFs attached",
self.get_name_label())
if len(self.get_PIFs()) > 0:
raise NetworkError("Cannot destroy network with PIFs attached",
self.get_name_label())
XendBase.destroy(self)
Brctl.bridge_del(self.get_name_label())
XendNode.instance().save_networks()
示例11: destroy
def destroy(self):
# Figure out if this is a physical device
if self.get_interface_name() == \
self.get_device():
raise PIFIsPhysical()
self.unplug()
if _destroy_VLAN(self.get_device(), self.get_VLAN()):
XendBase.destroy(self)
import XendNode
XendNode.instance().save_PIFs()
else:
raise NetworkError("Unable to delete VLAN", self.get_uuid())
示例12: get_host_CPUs
def get_host_CPUs(self):
""" Query all cpu refs of this pool currently asisgned .
- Read pool id of this pool from xenstore
- Read cpu configuration from hypervisor
- lookup cpu number -> cpu ref
@return: host_cpu refs
@rtype: list of str
"""
if self.get_activated():
node = XendNode.instance()
pool_id = self.query_pool_id()
if pool_id == None:
raise PoolError(XEND_ERROR_INTERNAL,
[self.getClass(), 'get_host_CPUs'])
cpus = []
for pool_rec in xc.cpupool_getinfo():
if pool_rec['cpupool'] == pool_id:
cpus = pool_rec['cpulist']
# query host_cpu ref for any cpu of the pool
host_CPUs = [ cpu_ref
for cpu_ref in node.get_host_cpu_refs()
if node.get_host_cpu_field(cpu_ref, 'number')
in cpus ]
else:
# pool not active, so it couldn't have any assigned cpus
host_CPUs = []
return host_CPUs
示例13: get_by_name_label_pool_func
def get_by_name_label_pool_func(self, host_ref, name):
poolapi = _get_BNPoolAPI()
if poolapi._isMaster:
if cmp(host_ref, XendNode.instance().uuid) == 0:
return self.get_by_name_label(name)
else:
remote_ip = poolapi.get_host_ip(host_ref)
return xen_rpc_call(remote_ip, 'network_get_by_name_label_pool_func', host_ref, name)
else:
return self.get_by_name_label(name)
示例14: get_all_records_by_host
def get_all_records_by_host(self, host_ref):
poolapi = _get_BNPoolAPI()
if poolapi._isMaster:
if cmp(host_ref, XendNode.instance().uuid) == 0:
return self.get_all_records()
else:
remote_ip = poolapi.get_host_ip(host_ref)
return xen_rpc_call(remote_ip, 'network_get_all_records_by_host', host_ref)
else:
return self.get_all_records()
示例15: create
def create(self, record):
"""
Called from API, to create a new network
"""
# Create new uuids
uuid = genuuid.createString()
# Create instance (do this first, to check record)
network = XendNetwork(record, uuid)
# Check network doesn't already exist
name_label = network.name_label
if bridge_exists(name_label):
del network
raise UniqueNameError(name_label, "network")
# Create the bridge
Brctl.bridge_create(network.name_label)
XendNode.instance().save_networks()
return uuid