Skip to content

Commit

Permalink
Get VM primary mac address after VM power on (vmware#529)
Browse files Browse the repository at this point in the history
Signed-off-by: Qi Zhang <qi-keira.zhang@broadcom.com>
  • Loading branch information
keirazhang authored and ZouYuhua committed Jan 18, 2024
1 parent 7c77f29 commit a977f3b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
3 changes: 0 additions & 3 deletions common/vm_get_vm_info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
vm_hardware_version_num: "{{ vm_config.config.version.split('-')[-1] }}"
vm_firmware: "{{ vm_config.config.firmware }}"

- name: "Wait for mac address is available"
include_tasks: vm_wait_primary_nic_mac.yml

- name: "Display VM's basic information"
ansible.builtin.debug:
msg:
Expand Down
11 changes: 7 additions & 4 deletions common/vm_wait_primary_nic_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
- gather_network_facts.network_data['0'].mac_addr is defined
- gather_network_facts.network_data['0'].mac_addr

- name: "Display VM's primary network adapter MAC address"
ansible.builtin.debug:
msg:
- "VM primary network adapter MAC address: {{ vm_primary_nic_mac }}"
- name: "Assert VM primary network adapter has MAC address"
ansible.builtin.assert:
that:
- vm_primary_nic_mac
- vm_primary_nic_mac | ansible.utils.hwaddr
fail_msg: "VM primary network adapter has No MAC address"
success_msg: "VM primary network adapter MAC address is {{ vm_primary_nic_mac }}"
12 changes: 12 additions & 0 deletions env_setup/env_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@

- name: "Get existing VM info"
include_tasks: ../common/vm_get_vm_info.yml

- name: "Get VM's power state"
include_tasks: ../common/vm_get_power_state.yml

- name: "Power on VM"
include_tasks: ../common/vm_set_power_state.yml
vars:
vm_power_state_set: "powered-on"
when: vm_power_state_get == "poweredOff"

- name: "Wait for VM primary network adapter has MAC address"
include_tasks: ../common/vm_wait_primary_nic_mac.yml
when: vm_exists is defined and vm_exists

- name: Set fact of the VM datastore path
Expand Down
5 changes: 5 additions & 0 deletions linux/deploy_vm/deploy_vm_from_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@
vars:
vm_take_screenshot_local_path: "{{ current_test_log_folder }}"

# For only ESXi managed VM, its MAC address is generated after power on
# not at VM creation
- name: "Get VM's primary network adapter MAC address"
include_tasks: ../../common/vm_wait_primary_nic_mac.yml

# VMware Photon OS kickstart file can't add shutdown action,
# so here needs to shutdown it separately
- name: "Shutdown VMware Photon OS VM after auto install completes"
Expand Down
3 changes: 3 additions & 0 deletions linux/deploy_vm/deploy_vm_from_ova.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
- name: "Add a serial port for VM"
include_tasks: ../../common/vm_add_serial_port.yml

- name: "Get VM's primary network adapter MAC address"
include_tasks: ../../common/vm_wait_primary_nic_mac.yml

- name: "Reconfigure VM with cloud-init"
include_tasks: reconfigure_vm_with_cloudinit.yml
when: ova_guest_os_type in ['photon', 'ubuntu', 'amazon']
Expand Down
1 change: 0 additions & 1 deletion windows/deploy_vm/deploy_vm_from_iso.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@

- name: "Get VM's primary network adapter MAC address after poweron VM"
include_tasks: ../../common/vm_wait_primary_nic_mac.yml
when: vm_primary_nic_mac is undefined or not vm_primary_nic_mac

- name: "Get VM IP address"
include_tasks: ../../common/vm_get_ip.yml
Expand Down
3 changes: 3 additions & 0 deletions windows/deploy_vm/deploy_vm_from_ova.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@

- name: "Get VM info"
include_tasks: ../../common/vm_get_vm_info.yml

#- name: "Get VM's primary network adapter MAC address"
# include_tasks: ../../common/vm_wait_primary_nic_mac.yml
# - include_tasks: ../../common/vm_get_ip_from_vmtools.yml

# Copy script ConfigureRemotingForAnsible.ps1 to guest OS
Expand Down

0 comments on commit a977f3b

Please sign in to comment.