vmware_vmkernel: simplify the code (#55176)

- drop a dead branch in a condition tree
- simplify the look-up of the vnic
pull/59141/head
Gonéri Le Bouder 5 years ago committed by Abhijeet Kasurde
parent 4b9391f32a
commit a63e17cd63

@ -343,13 +343,9 @@ class PyVmomiHelper(PyVmomi):
else:
# config change (e.g. DHCP to static, or vice versa); doesn't work with virtual port change
self.vnic = self.get_vmkernel_by_portgroup_new(port_group_name=self.port_group_name)
if not self.vnic:
if self.network_type == 'static':
# vDS to vSS or vSS to vSS (static IP)
self.vnic = self.get_vmkernel_by_ip(ip_address=self.ip_address)
elif self.network_type == 'dhcp':
# vDS to vSS or vSS to vSS (DHCP)
self.vnic = self.get_vmkernel_by_device(device_name=self.device)
if not self.vnic and self.network_type == 'static':
# vDS to vSS or vSS to vSS (static IP)
self.vnic = self.get_vmkernel_by_ip(ip_address=self.ip_address)
def get_port_group_by_name(self, host_system, portgroup_name, vswitch_name):
"""
@ -423,9 +419,9 @@ class PyVmomiHelper(PyVmomi):
Returns: vmkernel managed object if vmkernel found, false if not
"""
vnics = [vnic for vnic in self.esxi_host_obj.config.network.vnic if vnic.spec.ip.ipAddress == ip_address]
if vnics:
return vnics[0]
for vnic in self.esxi_host_obj.config.network.vnic:
if vnic.spec.ip.ipAddress == ip_address:
return vnic
return None
def get_vmkernel_by_device(self, device_name):
@ -437,9 +433,9 @@ class PyVmomiHelper(PyVmomi):
Returns: vmkernel managed object if vmkernel found, false if not
"""
vnics = [vnic for vnic in self.esxi_host_obj.config.network.vnic if vnic.device == device_name]
if vnics:
return vnics[0]
for vnic in self.esxi_host_obj.config.network.vnic:
if vnic.device == device_name:
return vnic
return None
def check_state(self):
@ -448,11 +444,7 @@ class PyVmomiHelper(PyVmomi):
Returns: Present if found and absent if not found
"""
state = 'absent'
if self.vnic:
state = 'present'
return state
return 'present' if self.vnic else 'absent'
def host_vmk_delete(self):
"""
@ -493,7 +485,7 @@ class PyVmomiHelper(PyVmomi):
def host_vmk_update(self):
"""
Function to update VMKernel with given parameters
Update VMKernel with given parameters
Returns: NA
"""

Loading…
Cancel
Save