本文整理汇总了Python中pyVmomi.vim.Description方法的典型用法代码示例。如果您正苦于以下问题:Python vim.Description方法的具体用法?Python vim.Description怎么用?Python vim.Description使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyVmomi.vim
的用法示例。
在下文中一共展示了vim.Description方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_nic
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Description [as 别名]
def create_nic(self, device_type, device_label, device_infos):
nic = vim.vm.device.VirtualDeviceSpec()
nic.device = self.get_device(device_type, device_infos['name'])
nic.device.wakeOnLanEnabled = bool(device_infos.get('wake_on_lan', True))
nic.device.deviceInfo = vim.Description()
nic.device.deviceInfo.label = device_label
nic.device.deviceInfo.summary = device_infos['name']
nic.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
nic.device.connectable.startConnected = bool(device_infos.get('start_connected', True))
nic.device.connectable.allowGuestControl = bool(device_infos.get('allow_guest_control', True))
nic.device.connectable.connected = True
if 'mac' in device_infos and self.is_valid_mac_addr(device_infos['mac']):
nic.device.addressType = 'manual'
nic.device.macAddress = device_infos['mac']
else:
nic.device.addressType = 'generated'
return nic
示例2: gen_nic
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Description [as 别名]
def gen_nic(num, network):
"""
Get a nic for the specified network
"""
nic = vim.vm.device.VirtualDeviceSpec()
nic.operation = vim.vm.device.VirtualDeviceSpec.Operation.add # or edit if a device exists
nic.device = vim.vm.device.VirtualVmxnet3()
nic.device.wakeOnLanEnabled = True
nic.device.addressType = 'assigned'
nic.device.key = 4000 # 4000 seems to be the value to use for a vmxnet3 device
nic.device.deviceInfo = vim.Description()
nic.device.deviceInfo.label = "Network Adapter %d" % num
nic.device.deviceInfo.summary = "Net summary"
nic.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
nic.device.backing.network = network
nic.device.backing.deviceName = "Device%d" % num
nic.device.backing.useAutoDetect = False
nic.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
nic.device.connectable.startConnected = True
nic.device.connectable.allowGuestControl = True
return nic
示例3: create_ide_controller
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Description [as 别名]
def create_ide_controller():
ide_ctl = vim.vm.device.VirtualDeviceSpec()
ide_ctl.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
ide_ctl.device = vim.vm.device.VirtualIDEController()
ide_ctl.device.deviceInfo = vim.Description()
# While creating a new IDE controller, temporary key value
# should be unique negative integers
ide_ctl.device.key = -randint(200, 299)
ide_ctl.device.busNumber = 0
return ide_ctl
示例4: createnicspec
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Description [as 别名]
def createnicspec(nicname, netname):
nicspec = vim.vm.device.VirtualDeviceSpec()
nicspec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
nic = vim.vm.device.VirtualVmxnet3()
desc = vim.Description()
desc.label = nicname
nicbacking = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
desc.summary = netname
nicbacking.deviceName = netname
nic.backing = nicbacking
# nic.key = 0
nic.deviceInfo = desc
nic.addressType = 'generated'
nicspec.device = nic
return nicspec
示例5: get_snapshot_info
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Description [as 别名]
def get_snapshot_info(self, name=None):
"""Human-readable info on a snapshot.
:param str name: Name of the snapshot to get
[defaults to the current snapshot]
:return: Info on the snapshot found
:rtype: str
"""
snap = self.get_snapshot(name)
return "\nName: %s; Description: %s; CreateTime: %s; State: %s" % \
(snap.name, snap.description, snap.createTime, snap.state)
示例6: add_nic
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Description [as 别名]
def add_nic(vm, mac, port):
spec = vim.vm.ConfigSpec()
nic_changes = []
nic_spec = vim.vm.device.VirtualDeviceSpec()
nic_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
nic_spec.device = vim.vm.device.VirtualE1000()
nic_spec.device.deviceInfo = vim.Description()
nic_spec.device.deviceInfo.summary = 'vCenter API'
nic_spec.device.backing = \
vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo()
nic_spec.device.backing.port = vim.dvs.PortConnection()
nic_spec.device.backing.port.portgroupKey = port.portgroupKey
nic_spec.device.backing.port.switchUuid = port.dvsUuid
nic_spec.device.backing.port.portKey = port.key
nic_spec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
nic_spec.device.connectable.startConnected = True
nic_spec.device.connectable.allowGuestControl = True
nic_spec.device.connectable.connected = False
nic_spec.device.connectable.status = 'untried'
nic_spec.device.wakeOnLanEnabled = True
nic_spec.device.addressType = 'assigned'
nic_spec.device.macAddress = mac
nic_changes.append(nic_spec)
spec.deviceChange = nic_changes
e = vm.ReconfigVM_Task(spec=spec)
print("Nic card added success ...")
示例7: serialize_spec
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Description [as 别名]
def serialize_spec(clonespec):
"""Serialize a clonespec or a relocation spec"""
data = {}
attrs = dir(clonespec)
attrs = [x for x in attrs if not x.startswith('_')]
for x in attrs:
xo = getattr(clonespec, x)
if callable(xo):
continue
xt = type(xo)
if xo is None:
data[x] = None
elif isinstance(xo, vim.vm.ConfigSpec):
data[x] = serialize_spec(xo)
elif isinstance(xo, vim.vm.RelocateSpec):
data[x] = serialize_spec(xo)
elif isinstance(xo, vim.vm.device.VirtualDisk):
data[x] = serialize_spec(xo)
elif isinstance(xo, vim.vm.device.VirtualDeviceSpec.FileOperation):
data[x] = to_text(xo)
elif isinstance(xo, vim.Description):
data[x] = {
'dynamicProperty': serialize_spec(xo.dynamicProperty),
'dynamicType': serialize_spec(xo.dynamicType),
'label': serialize_spec(xo.label),
'summary': serialize_spec(xo.summary),
}
elif hasattr(xo, 'name'):
data[x] = to_text(xo) + ':' + to_text(xo.name)
elif isinstance(xo, vim.vm.ProfileSpec):
pass
elif issubclass(xt, list):
data[x] = []
for xe in xo:
data[x].append(serialize_spec(xe))
elif issubclass(xt, string_types + integer_types + (float, bool)):
if issubclass(xt, integer_types):
data[x] = int(xo)
else:
data[x] = to_text(xo)
elif issubclass(xt, bool):
data[x] = xo
elif issubclass(xt, dict):
data[to_text(x)] = {}
for k, v in xo.items():
k = to_text(k)
data[x][k] = serialize_spec(v)
else:
data[x] = str(xt)
return data
示例8: add_nic
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Description [as 别名]
def add_nic(si, vm, network_name):
"""
:param si: Service Instance
:param vm: Virtual Machine Object
:param network_name: Name of the Virtual Network
"""
spec = vim.vm.ConfigSpec()
nic_changes = []
nic_spec = vim.vm.device.VirtualDeviceSpec()
nic_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
nic_spec.device = vim.vm.device.VirtualE1000()
nic_spec.device.deviceInfo = vim.Description()
nic_spec.device.deviceInfo.summary = 'vCenter API test'
content = si.RetrieveContent()
network = get_obj(content, [vim.Network], network_name)
if isinstance(network, vim.OpaqueNetwork):
nic_spec.device.backing = \
vim.vm.device.VirtualEthernetCard.OpaqueNetworkBackingInfo()
nic_spec.device.backing.opaqueNetworkType = \
network.summary.opaqueNetworkType
nic_spec.device.backing.opaqueNetworkId = \
network.summary.opaqueNetworkId
else:
nic_spec.device.backing = \
vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
nic_spec.device.backing.useAutoDetect = False
nic_spec.device.backing.deviceName = network
nic_spec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
nic_spec.device.connectable.startConnected = True
nic_spec.device.connectable.allowGuestControl = True
nic_spec.device.connectable.connected = False
nic_spec.device.connectable.status = 'untried'
nic_spec.device.wakeOnLanEnabled = True
nic_spec.device.addressType = 'assigned'
nic_changes.append(nic_spec)
spec.deviceChange = nic_changes
e = vm.ReconfigVM_Task(spec=spec)
print("NIC CARD ADDED")