vmware_vmkernel: simplify the code (#55176)
- drop a dead branch in a condition tree - simplify the look-up of the vnic
This commit is contained in:
parent
4b9391f32a
commit
a63e17cd63
1 changed files with 11 additions and 19 deletions
|
@ -343,13 +343,9 @@ class PyVmomiHelper(PyVmomi):
|
||||||
else:
|
else:
|
||||||
# config change (e.g. DHCP to static, or vice versa); doesn't work with virtual port change
|
# 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)
|
self.vnic = self.get_vmkernel_by_portgroup_new(port_group_name=self.port_group_name)
|
||||||
if not self.vnic:
|
if not self.vnic and self.network_type == 'static':
|
||||||
if self.network_type == 'static':
|
# vDS to vSS or vSS to vSS (static IP)
|
||||||
# vDS to vSS or vSS to vSS (static IP)
|
self.vnic = self.get_vmkernel_by_ip(ip_address=self.ip_address)
|
||||||
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)
|
|
||||||
|
|
||||||
def get_port_group_by_name(self, host_system, portgroup_name, vswitch_name):
|
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
|
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]
|
for vnic in self.esxi_host_obj.config.network.vnic:
|
||||||
if vnics:
|
if vnic.spec.ip.ipAddress == ip_address:
|
||||||
return vnics[0]
|
return vnic
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_vmkernel_by_device(self, device_name):
|
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
|
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]
|
for vnic in self.esxi_host_obj.config.network.vnic:
|
||||||
if vnics:
|
if vnic.device == device_name:
|
||||||
return vnics[0]
|
return vnic
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def check_state(self):
|
def check_state(self):
|
||||||
|
@ -448,11 +444,7 @@ class PyVmomiHelper(PyVmomi):
|
||||||
Returns: Present if found and absent if not found
|
Returns: Present if found and absent if not found
|
||||||
|
|
||||||
"""
|
"""
|
||||||
state = 'absent'
|
return 'present' if self.vnic else 'absent'
|
||||||
if self.vnic:
|
|
||||||
state = 'present'
|
|
||||||
|
|
||||||
return state
|
|
||||||
|
|
||||||
def host_vmk_delete(self):
|
def host_vmk_delete(self):
|
||||||
"""
|
"""
|
||||||
|
@ -493,7 +485,7 @@ class PyVmomiHelper(PyVmomi):
|
||||||
|
|
||||||
def host_vmk_update(self):
|
def host_vmk_update(self):
|
||||||
"""
|
"""
|
||||||
Function to update VMKernel with given parameters
|
Update VMKernel with given parameters
|
||||||
Returns: NA
|
Returns: NA
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue