mirror of
https://github.com/vmware/vsphere-automation-sdk-python.git
synced 2024-11-24 10:19:59 -05:00
update ethernet sample and add opaque network
Signed-off-by: Tianhao He <het@vmware.com>
This commit is contained in:
parent
4032e4cbb0
commit
912fb0bcbf
@ -19,9 +19,10 @@ from com.vmware.vcenter_client import Network
|
|||||||
from samples.vsphere.vcenter.helper import datacenter_helper
|
from samples.vsphere.vcenter.helper import datacenter_helper
|
||||||
|
|
||||||
|
|
||||||
def get_standard_network_backing(client,
|
def get_network_backing(client,
|
||||||
std_porggroup_name,
|
porggroup_name,
|
||||||
datacenter_name):
|
datacenter_name,
|
||||||
|
portgroup_type):
|
||||||
"""
|
"""
|
||||||
Gets a standard portgroup network backing for a given Datacenter
|
Gets a standard portgroup network backing for a given Datacenter
|
||||||
Note: The method assumes that there is only one standard portgroup
|
Note: The method assumes that there is only one standard portgroup
|
||||||
@ -33,45 +34,16 @@ def get_standard_network_backing(client,
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
filter = Network.FilterSpec(datacenters=set([datacenter]),
|
filter = Network.FilterSpec(datacenters=set([datacenter]),
|
||||||
names=set([std_porggroup_name]),
|
names=set([porggroup_name]),
|
||||||
types=set([Network.Type.STANDARD_PORTGROUP]))
|
types=set([portgroup_type]))
|
||||||
network_summaries = client.vcenter.Network.list(filter=filter)
|
network_summaries = client.vcenter.Network.list(filter=filter)
|
||||||
|
|
||||||
if len(network_summaries) > 0:
|
if len(network_summaries) > 0:
|
||||||
network = network_summaries[0].network
|
network = network_summaries[0].network
|
||||||
print("Selecting Standard Portgroup Network '{}' ({})".
|
print("Selecting {} Portgroup Network '{}' ({})".
|
||||||
format(std_porggroup_name, network))
|
format(portgroup_type, porggroup_name, network))
|
||||||
return network
|
return network
|
||||||
else:
|
else:
|
||||||
print("Standard Portgroup Network not found in Datacenter '{}'".
|
print("Portgroup Network not found in Datacenter '{}'".
|
||||||
format(datacenter_name))
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_distributed_network_backing(client,
|
|
||||||
dv_portgroup_name,
|
|
||||||
datacenter_name):
|
|
||||||
"""
|
|
||||||
Gets a distributed portgroup network backing for a given Datacenter
|
|
||||||
Note: The method assumes that there is only one distributed portgroup
|
|
||||||
and datacenter with the mentioned names.
|
|
||||||
"""
|
|
||||||
datacenter = datacenter_helper.get_datacenter(client, datacenter_name)
|
|
||||||
if not datacenter:
|
|
||||||
print("Datacenter '{}' not found".format(datacenter_name))
|
|
||||||
return None
|
|
||||||
|
|
||||||
filter = Network.FilterSpec(datacenters=set([datacenter]),
|
|
||||||
names=set([dv_portgroup_name]),
|
|
||||||
types=set([Network.Type.DISTRIBUTED_PORTGROUP]))
|
|
||||||
network_summaries = client.vcenter.Network.list(filter=filter)
|
|
||||||
|
|
||||||
if len(network_summaries) > 0:
|
|
||||||
network = network_summaries[0].network
|
|
||||||
print("Selecting Distributed Portgroup Network '{}' ({})".
|
|
||||||
format(dv_portgroup_name, network))
|
|
||||||
return network
|
|
||||||
else:
|
|
||||||
print("Distributed Portgroup Network not found in Datacenter '{}'".
|
|
||||||
format(datacenter_name))
|
format(datacenter_name))
|
||||||
return None
|
return None
|
||||||
|
@ -42,8 +42,8 @@ config["CLUSTER1_NAME"] = "Cluster1"
|
|||||||
|
|
||||||
config["VDSWITCH1_NAME"] = "DSwitch1"
|
config["VDSWITCH1_NAME"] = "DSwitch1"
|
||||||
config["VDPORTGROUP1_NAME"] = "Static_Portgroup_on_DSwitch_1"
|
config["VDPORTGROUP1_NAME"] = "Static_Portgroup_on_DSwitch_1"
|
||||||
|
|
||||||
config["STDPORTGROUP_NAME"] = "VM Network"
|
config["STDPORTGROUP_NAME"] = "VM Network"
|
||||||
|
config["OPAQUEPORTGROUP1_NAME"] = ""
|
||||||
|
|
||||||
# The main datacenter and datastore that will be used for the VM tests
|
# The main datacenter and datastore that will be used for the VM tests
|
||||||
config["VM_DATACENTER_NAME"] = config["DATACENTER2_NAME"]
|
config["VM_DATACENTER_NAME"] = config["DATACENTER2_NAME"]
|
||||||
|
@ -19,6 +19,8 @@ __vcenter_version__ = '6.5+'
|
|||||||
from vmware.vapi.vsphere.client import create_vsphere_client
|
from vmware.vapi.vsphere.client import create_vsphere_client
|
||||||
|
|
||||||
from com.vmware.vcenter.vm.hardware_client import Ethernet
|
from com.vmware.vcenter.vm.hardware_client import Ethernet
|
||||||
|
from com.vmware.vcenter_client import Network
|
||||||
|
|
||||||
from samples.vsphere.common.sample_util import parse_cli_args_vm
|
from samples.vsphere.common.sample_util import parse_cli_args_vm
|
||||||
from samples.vsphere.common.sample_util import pp
|
from samples.vsphere.common.sample_util import pp
|
||||||
from samples.vsphere.vcenter.helper import network_helper
|
from samples.vsphere.vcenter.helper import network_helper
|
||||||
@ -69,16 +71,27 @@ def run():
|
|||||||
print("Using VM '{}' ({}) for Disk Sample".format(vm_name, vm))
|
print("Using VM '{}' ({}) for Disk Sample".format(vm_name, vm))
|
||||||
|
|
||||||
# Get standard portgroup to use as backing for sample
|
# Get standard portgroup to use as backing for sample
|
||||||
standard_network = network_helper.get_standard_network_backing(
|
standard_network = network_helper.get_network_backing(
|
||||||
client,
|
client,
|
||||||
testbed.config['STDPORTGROUP_NAME'],
|
testbed.config['STDPORTGROUP_NAME'],
|
||||||
testbed.config['VM_DATACENTER_NAME'])
|
testbed.config['VM_DATACENTER_NAME'],
|
||||||
|
Network.Type.STANDARD_PORTGROUP)
|
||||||
|
|
||||||
# Get distributed portgroup to use as backing for sample
|
# Get distributed portgroup to use as backing for sample
|
||||||
distributed_network = network_helper.get_distributed_network_backing(
|
distributed_network = network_helper.get_network_backing(
|
||||||
client,
|
client,
|
||||||
testbed.config['VDPORTGROUP1_NAME'],
|
testbed.config['VDPORTGROUP1_NAME'],
|
||||||
testbed.config['VM_DATACENTER_NAME'])
|
testbed.config['VM_DATACENTER_NAME'],
|
||||||
|
Network.Type.DISTRIBUTED_PORTGROUP)
|
||||||
|
|
||||||
|
# Get opaque portgroup to use as backing for sample
|
||||||
|
opaque_network = None
|
||||||
|
if testbed.config['OPAQUEPORTGROUP1_NAME']:
|
||||||
|
opaque_network = network_helper.get_network_backing(
|
||||||
|
client,
|
||||||
|
testbed.config['OPAQUEPORTGROUP1_NAME'],
|
||||||
|
testbed.config['VM_DATACENTER_NAME'],
|
||||||
|
Network.Type.OPAQUE_NETWORK)
|
||||||
|
|
||||||
print('\n# Example: List all Ethernet adapters for a VM')
|
print('\n# Example: List all Ethernet adapters for a VM')
|
||||||
nic_summaries = client.vcenter.vm.hardware.Ethernet.list(vm=vm)
|
nic_summaries = client.vcenter.vm.hardware.Ethernet.list(vm=vm)
|
||||||
@ -168,6 +181,21 @@ def run():
|
|||||||
print('vm.hardware.Ethernet.get({}, {}) -> {}'.
|
print('vm.hardware.Ethernet.get({}, {}) -> {}'.
|
||||||
format(vm, nic, pp(nic_info)))
|
format(vm, nic, pp(nic_info)))
|
||||||
|
|
||||||
|
if opaque_network:
|
||||||
|
print('\n# Example: Create Ethernet Nic using OPAQUE PORTGROUP with '
|
||||||
|
'default settings')
|
||||||
|
nic_create_spec = Ethernet.CreateSpec(
|
||||||
|
backing=Ethernet.BackingSpec(
|
||||||
|
type=Ethernet.BackingType.OPAQUE_NETWORK,
|
||||||
|
network=opaque_network))
|
||||||
|
nic = client.vcenter.vm.hardware.Ethernet.create(vm, nic_create_spec)
|
||||||
|
print('vm.hardware.Ethernet.create({}, {}) -> {}'.
|
||||||
|
format(vm, nic_create_spec, nic))
|
||||||
|
nics_to_delete.append(nic)
|
||||||
|
nic_info = client.vcenter.vm.hardware.Ethernet.get(vm, nic)
|
||||||
|
print('vm.hardware.Ethernet.get({}, {}) -> {}'.
|
||||||
|
format(vm, nic, pp(nic_info)))
|
||||||
|
|
||||||
# Change the last nic that was created
|
# Change the last nic that was created
|
||||||
print('\n# Example: Update Ethernet Nic with different backing')
|
print('\n# Example: Update Ethernet Nic with different backing')
|
||||||
nic_update_spec = Ethernet.UpdateSpec(
|
nic_update_spec = Ethernet.UpdateSpec(
|
||||||
|
Loading…
Reference in New Issue
Block a user