本文整理汇总了Python中pyVmomi.vim.DistributedVirtualSwitch方法的典型用法代码示例。如果您正苦于以下问题:Python vim.DistributedVirtualSwitch方法的具体用法?Python vim.DistributedVirtualSwitch怎么用?Python vim.DistributedVirtualSwitch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyVmomi.vim
的用法示例。
在下文中一共展示了vim.DistributedVirtualSwitch方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_vdportgroup
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import DistributedVirtualSwitch [as 别名]
def create_vdportgroup(context, vdswitch_name, vdportgroup_name):
"""Create Distributed Switch portgroup"""
vdportgroup_type = "earlyBinding"
vdswitch = context.testbed.entities['DISTRIBUTED_SWITCH_IDS'][vdswitch_name]
vdswitch_mo = vim.DistributedVirtualSwitch(vdswitch, context.soap_stub)
vdportgroup_spec = vim.dvs.DistributedVirtualPortgroup.ConfigSpec(
name=vdportgroup_name, type=vdportgroup_type)
vdportgroup_specs = [vdportgroup_spec]
task = vdswitch_mo.AddPortgroups(vdportgroup_specs)
pyVim.task.WaitForTask(task)
# The AddPortgroup operation doesn't return any information about the
# created portgroup, so look it up.
vdportgroup = None
for vdportgroup_mo in vdswitch_mo.portgroup:
if vdportgroup_mo.name == vdportgroup_name:
vdportgroup = vdportgroup_mo._moId
print(
"Created Distributed Portgroup '{}' ({}) on Distributed Switch '{}' ({})".
format(vdportgroup_name, vdportgroup, vdswitch_name, vdswitch))
return vdportgroup
示例2: remove_host_from_vdswitch
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import DistributedVirtualSwitch [as 别名]
def remove_host_from_vdswitch(context, vdswitch_mo, host_name):
"""Remove host from Distributed Switch"""
for host_member in vdswitch_mo.config.host:
if host_member.config.host.name == host_name:
dvs_member_config = vim.dvs.HostMember.ConfigSpec(
operation="remove",
host=host_member.config.host)
dvs_config = vim.DistributedVirtualSwitch.ConfigSpec(
configVersion=vdswitch_mo.config.configVersion,
host=[dvs_member_config])
task = vdswitch_mo.Reconfigure(dvs_config)
pyVim.task.WaitForTask(task)
print("Removed Host '{}' ({}) from Distributed Switch '{}' ({})".
format(host_name, host_member.config.host._moId,
vdswitch_mo.summary.name, vdswitch_mo._moId))
示例3: create_vdswitch
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import DistributedVirtualSwitch [as 别名]
def create_vdswitch(context, datacenter_name, vdswitch_name):
"""Create Distributed Switch in given datacenter"""
datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
datacenter_mo = vim.Datacenter(datacenter, context.soap_stub)
spec = vim.DistributedVirtualSwitch.CreateSpec()
spec.configSpec = vim.DistributedVirtualSwitch.ConfigSpec(
name=vdswitch_name)
task = datacenter_mo.networkFolder.CreateDistributedVirtualSwitch(spec)
pyVim.task.WaitForTask(task)
vdswitch_mo = task.info.result
print("Created Distributed Switch '{}' ({})".
format(vdswitch_name, vdswitch_mo._moId))
return vdswitch_mo._moId
示例4: find_dvs_by_name
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import DistributedVirtualSwitch [as 别名]
def find_dvs_by_name(content, switch_name):
return find_object_by_name(content, switch_name, [vim.DistributedVirtualSwitch])
示例5: find_vdswitch
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import DistributedVirtualSwitch [as 别名]
def find_vdswitch(context, datacenter_name, vdswitch_name):
""" Retrieve an existing Distributed Switch"""
# TODO Ugly deep nesting.
for datacenter_mo in context.service_instance.content.rootFolder \
.childEntity:
if (isinstance(datacenter_mo, vim.Datacenter) and
datacenter_mo.name == datacenter_name):
for vdswitch_mo in datacenter_mo.networkFolder.childEntity:
if (isinstance(vdswitch_mo, vim.DistributedVirtualSwitch) and
vdswitch_mo.summary.name == vdswitch_name):
print("Found VDSwitch '{}' ({}) in Datacenter '{}' ({})".
format(vdswitch_name, vdswitch_mo._moId,
datacenter_name, datacenter_mo._moId))
return vdswitch_mo
return None
示例6: add_host_to_vdswitch
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import DistributedVirtualSwitch [as 别名]
def add_host_to_vdswitch(context, vdswitch_name, host_name, pnic_names=None):
"""Add host to Distributed Switch"""
host = context.testbed.entities['HOST_IDS'][host_name]
host_mo = vim.HostSystem(host, context.soap_stub)
vdswitch = context.testbed.entities['DISTRIBUTED_SWITCH_IDS'][vdswitch_name]
vdswitch_mo = vim.DistributedVirtualSwitch(vdswitch, context.soap_stub)
pnic_specs = []
if pnic_names:
for pnic in pnic_names:
pnic_specs.append(vim.dvs.HostMember.PnicSpec(pnicDevice=pnic))
dvs_member_config = vim.dvs.HostMember.ConfigSpec(
operation="add",
host=host_mo,
backing=vim.dvs.HostMember.PnicBacking(pnicSpec=pnic_specs))
dvs_config = vim.DistributedVirtualSwitch.ConfigSpec(
configVersion=vdswitch_mo.config.configVersion,
host=[dvs_member_config])
task = vdswitch_mo.Reconfigure(dvs_config)
pyVim.task.WaitForTask(task)
print("Added Host '{}' ({}) to Distributed Switch '{}' ({})".
format(host_name, host, vdswitch_name, vdswitch))
示例7: create_network
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import DistributedVirtualSwitch [as 别名]
def create_network(self, name, cidr=None, dhcp=True, nat=True, domain=None, plan='kvirt', overrides={}):
return {'result': 'failure', 'reason': "Not implemented yet..."}
si = self.si
cluster = self.clu
networkFolder = self.dc.networkFolder
rootFolder = self.rootFolder
net = find(si, rootFolder, vim.Network, name)
if net is not None:
return {'result': 'failure', 'reason': "Network %s already there" % name}
if self.distributed:
pnic_specs = []
dvs_host_configs = []
uplink_port_names = []
dvs_create_spec = vim.DistributedVirtualSwitch.CreateSpec()
dvs_config_spec = vim.DistributedVirtualSwitch.ConfigSpec()
dvs_config_spec.name = name
dvs_config_spec.uplinkPortPolicy = vim.DistributedVirtualSwitch.NameArrayUplinkPortPolicy()
for x in range(len(cluster.host)):
uplink_port_names.append("dvUplink%d" % x)
for host in cluster.host:
dvs_config_spec.uplinkPortPolicy.uplinkPortName = uplink_port_names
dvs_config_spec.maxPorts = 2000
pnic_spec = vim.dvs.HostMember.PnicSpec()
pnic_spec.pnicDevice = 'vmnic1'
pnic_specs.append(pnic_spec)
dvs_host_config = vim.dvs.HostMember.ConfigSpec()
dvs_host_config.operation = vim.ConfigSpecOperation.add
dvs_host_config.host = host
dvs_host_configs.append(dvs_host_config)
dvs_host_config.backing = vim.dvs.HostMember.PnicBacking()
dvs_host_config.backing.pnicSpec = pnic_specs
dvs_config_spec.host = dvs_host_configs
dvs_create_spec.configSpec = dvs_config_spec
dvs_create_spec.productInfo = vim.dvs.ProductSpec(version='5.1.0')
networkFolder.CreateDistributedVirtualSwitch()
return {'result': 'success'}
示例8: create_dvSwitch
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import DistributedVirtualSwitch [as 别名]
def create_dvSwitch(si, content, network_folder, cluster):
pnic_specs = []
dvs_host_configs = []
uplink_port_names = []
dvs_create_spec = vim.DistributedVirtualSwitch.CreateSpec()
dvs_config_spec = vim.DistributedVirtualSwitch.ConfigSpec()
dvs_config_spec.name = inputs['dvs_name']
dvs_config_spec.uplinkPortPolicy = vim.DistributedVirtualSwitch.NameArrayUplinkPortPolicy()
hosts = cluster.host
for x in range(len(hosts)):
uplink_port_names.append("dvUplink%d" % x)
for host in hosts:
dvs_config_spec.uplinkPortPolicy.uplinkPortName = uplink_port_names
dvs_config_spec.maxPorts = 2000
pnic_spec = vim.dvs.HostMember.PnicSpec()
pnic_spec.pnicDevice = 'vmnic1'
pnic_specs.append(pnic_spec)
dvs_host_config = vim.dvs.HostMember.ConfigSpec()
dvs_host_config.operation = vim.ConfigSpecOperation.add
dvs_host_config.host = host
dvs_host_configs.append(dvs_host_config)
dvs_host_config.backing = vim.dvs.HostMember.PnicBacking()
dvs_host_config.backing.pnicSpec = pnic_specs
dvs_config_spec.host = dvs_host_configs
dvs_create_spec.configSpec = dvs_config_spec
dvs_create_spec.productInfo = vim.dvs.ProductSpec(version='5.1.0')
task = network_folder.CreateDVS_Task(dvs_create_spec)
wait_for_task(task, si)
print "Successfully created DVS ", inputs['dvs_name']
return get_obj(content, [vim.DistributedVirtualSwitch], inputs['dvs_name'])
示例9: main
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import DistributedVirtualSwitch [as 别名]
def main():
args = get_args()
try:
if is_xenial_or_above():
ssl = __import__("ssl")
context = ssl._create_unverified_context()
si = connect.SmartConnect(host=args.host,
user=args.user,
pwd=args.password,
port=args.port, sslContext=context)
else:
si = connect.SmartConnect(host=args.host,
user=args.user,
pwd=args.password,
port=args.port)
si_content = si.RetrieveContent()
except:
print "Unable to connect to %s" % args.host
exit(1)
# check if PG exists else return error
dv_switch = get_obj(si_content, [vim.DistributedVirtualSwitch], args.dvs_name)
if not dv_switch:
print "dv switch %s not pressent" %(args.dvs_name)
exit(1)
dv_pg = get_dvs_pg_obj(si_content, [vim.dvs.DistributedVirtualPortgroup], args.dv_pg_name, args.dvs_name)
if not dv_pg:
print "port-group %s not present in dvs %s" %(args.dv_pg_name, args.dvs_name)
exit(1)
update_dv_pg(args, dv_pg)
add_pvlan_config(dv_switch)
connect.Disconnect(si)
示例10: core
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import DistributedVirtualSwitch [as 别名]
def core(module):
vim_type = module.params['vcenter_vim_type']
vcenter_object_name = module.params['vcenter_object_name']
vim_rec_type = {
'cluster': vim.ClusterComputeResource,
'datacenter': vim.Datacenter,
'datastore': vim.Datastore,
'vds': vim.DistributedVirtualSwitch,
'dvs-port': vim.Network,
'vm': vim.VirtualMachine
}
try:
vimtype = vim_rec_type[vim_type]
except KeyError:
module.fail_json(msg="Please specify valid vim type: cluster, datacenter, datastore, vds, vm")
si = si_connect(module)
vcenter_id = get_id(module, si,
[vimtype],
vcenter_object_name,
False, True)
return False, vcenter_id
示例11: configure_dvs_pg
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import DistributedVirtualSwitch [as 别名]
def configure_dvs_pg(service_instance, dvs_name, dv_pg_name):
"""
Configures the distributed port group
:param service_instance: Vcenter service instance
:param dvs_name: Name of the distributed virtual switch
:param dv_pg_name: Name of distributed virtual port group
"""
# Retrieve the content
content = service_instance.RetrieveContent()
# get distributed Switch and its port group objects
dvs = get_obj(content, [vim.DistributedVirtualSwitch], dvs_name)
dv_pg = get_obj(content, [vim.dvs.DistributedVirtualPortgroup], dv_pg_name)
print("The distributed virtual Switch is {0}" .format(dvs))
print("The distributed port group is {0}".format(dv_pg))
# construct selection sets
selection_sets = []
dv_pg_ss = vim.dvs.DistributedVirtualPortgroupSelection()
dv_pg_ss.dvsUuid = dvs.uuid
dv_pg_ss.portgroupKey.append(dv_pg.key)
selection_sets.append(dv_pg_ss)
print("The selected port group configurations are {0}"
.format(selection_sets))
# Backup/Export the configuration
entity_backup_config = service_instance.content\
.dvSwitchManager\
.DVSManagerExportEntity_Task(selection_sets)
export_result = entity_backup_config.info.result
print("The result of export configuration are {0}".format(export_result))
# Destroy the port group configuration
dv_pg.Destroy_Task()
# Restore/Import port group configuration
entity_restore_config = service_instance.content\
.dvSwitchManager\
.DVSManagerImportEntity_Task(export_result,
'createEntityWithOriginalIdentifier')
print("The result of restore configuration is {0}"
.format(entity_restore_config.info.result))