Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmware_vmkernel - add enable_backup_nfc setting #1979

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/1978-vmware_vmkernel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- vmware_vmkernel - Add the function to set the enable_backup_nfc setting
(https://github.com/ansible-collections/community.vmware/pull/1978)
32 changes: 30 additions & 2 deletions plugins/modules/vmware_vmkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- Russell Teague (@mtnbikenc)
- Abhijeet Kasurde (@Akasurde)
- Christian Kotte (@ckotte)
- Nina Loser (@Nina2244)
notes:
- The option O(device) need to be used with DHCP because otherwise it's not possible to check if a VMkernel device is already present
- You can only change from DHCP to static, and vSS to vDS, or vice versa, in one step, without creating a new device, with O(device) specified.
Expand Down Expand Up @@ -139,6 +140,12 @@
- This option is only allowed if the default TCP/IP stack is used.
type: bool
default: false
enable_backup_nfc:
description:
- Enable vSphere Backup NFC traffic on the VMKernel adapter.
- This option is only allowed if the default TCP/IP stack is used.
type: bool
default: false
state:
description:
- If set to V(present), the VMKernel adapter will be created with the given specifications.
Expand Down Expand Up @@ -301,6 +308,7 @@ def __init__(self, module):
self.enable_provisioning = self.params['enable_provisioning']
self.enable_replication = self.params['enable_replication']
self.enable_replication_nfc = self.params['enable_replication_nfc']
self.enable_backup_nfc = self.params['enable_backup_nfc']

self.vswitch_name = self.params['vswitch_name']
self.vds_name = self.params['dvswitch_name']
Expand Down Expand Up @@ -494,7 +502,7 @@ def host_vmk_update(self):
"""
changed = changed_settings = changed_vds = changed_services = \
changed_service_vmotion = changed_service_mgmt = changed_service_ft = \
changed_service_vsan = changed_service_prov = changed_service_rep = changed_service_rep_nfc = False
changed_service_vsan = changed_service_prov = changed_service_rep = changed_service_rep_nfc = changed_service_backup_nfc = False
changed_list = []
results = dict(changed=False, msg='')

Expand Down Expand Up @@ -623,6 +631,11 @@ def host_vmk_update(self):
if (self.enable_replication_nfc and self.vnic.device not in service_type_vmks['vSphereReplicationNFC']) or \
(not self.enable_replication_nfc and self.vnic.device in service_type_vmks['vSphereReplicationNFC']):
changed_services = changed_service_rep_nfc = True

if (self.enable_backup_nfc and self.vnic.device not in service_type_vmks['vSphereBackupNFC']) or \
(not self.enable_backup_nfc and self.vnic.device in service_type_vmks['vSphereBackupNFC']):
changed_services = changed_service_backup_nfc = True

if changed_services:
changed_list.append("services")

Expand Down Expand Up @@ -744,6 +757,14 @@ def host_vmk_update(self):
vnic_manager=vnic_manager, vmk=self.vnic, service_type='vSphereReplicationNFC', operation=operation
)

if changed_service_backup_nfc:
if self.vnic.device in service_type_vmks['vSphereBackupNFC']:
services_previous.append('Backup_NFC')
operation = 'select' if self.enable_backup_nfc else 'deselect'
self.set_service_type(
vnic_manager=vnic_manager, vmk=self.vnic, service_type='vSphereBackupNFC', operation=operation
)

if changed_service_vsan:
if self.vnic.device in service_type_vmks['vsan']:
services_previous.append('VSAN')
Expand Down Expand Up @@ -918,7 +939,7 @@ def host_vmk_create(self):
option is False for option in [self.enable_vsan, self.enable_vmotion,
self.enable_mgmt, self.enable_ft,
self.enable_provisioning, self.enable_replication,
self.enable_replication_nfc]):
self.enable_replication_nfc, self.enable_backup_nfc]):
self.vnic = self.get_vmkernel_by_device(device_name=vmk_device)

# VSAN
Expand All @@ -945,6 +966,9 @@ def host_vmk_create(self):
if self.enable_replication_nfc:
self.set_service_type(host_vnic_manager, self.vnic, 'vSphereReplicationNFC')

if self.enable_backup_nfc:
self.set_service_type(host_vnic_manager, self.vnic, 'vSphereBackupNFC')

self.module.exit_json(**results)

def set_service_type(self, vnic_manager, vmk, service_type, operation='select'):
Expand Down Expand Up @@ -984,6 +1008,7 @@ def get_all_vmks_by_service_type(self):
vSphereProvisioning=[],
vSphereReplication=[],
vSphereReplicationNFC=[],
vSphereBackupNFC=[],
)

for service_type in list(service_type_vmk):
Expand Down Expand Up @@ -1037,6 +1062,8 @@ def create_enabled_services_string(self):
services.append('Repl')
if self.enable_replication_nfc:
services.append('Repl_NFC')
if self.enable_backup_nfc:
services.append('Backup_NFC')
return ', '.join(services)

@staticmethod
Expand Down Expand Up @@ -1075,6 +1102,7 @@ def main():
enable_provisioning=dict(type='bool', default=False),
enable_replication=dict(type='bool', default=False),
enable_replication_nfc=dict(type='bool', default=False),
enable_backup_nfc=dict(type='bool', default=False),
vswitch_name=dict(required=False, type='str', aliases=['vswitch']),
dvswitch_name=dict(required=False, type='str', aliases=['dvswitch']),
network=dict(
Expand Down