mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-07-27 23:21:31 -07:00
Merge pull request #688 from thekad/feature/compute_instance_gvnic
GVNIC support
This commit is contained in:
commit
f977bc67bf
3 changed files with 122 additions and 0 deletions
|
@ -395,6 +395,19 @@ options:
|
|||
field to "{{ name-of-resource }}"'
|
||||
required: false
|
||||
type: dict
|
||||
nic_type:
|
||||
description:
|
||||
- Type of network interface card attached to instance.
|
||||
- If unspecified it will use the default provided by GCP.
|
||||
- As the next generation network interface which succeeds VirtIO, gVNIC
|
||||
replaces VirtIO-Net as the only supported network interface in Compute
|
||||
Engine for all new machine types (Generation 3 and onwards).
|
||||
- Newer machine series and networking features require gVNIC instead of VirtIO.
|
||||
required: false
|
||||
type: str
|
||||
choices:
|
||||
- VIRTIO_NET
|
||||
- GVNIC
|
||||
scheduling:
|
||||
description:
|
||||
- Sets the scheduling options for this instance.
|
||||
|
@ -1174,6 +1187,7 @@ def main():
|
|||
network=dict(type='dict'),
|
||||
network_ip=dict(type='str'),
|
||||
subnetwork=dict(type='dict'),
|
||||
nic_type=dict(type='str', choices=['VIRTIO_NET', 'GVNIC']),
|
||||
),
|
||||
),
|
||||
scheduling=dict(
|
||||
|
@ -1715,6 +1729,7 @@ class InstanceNetworkinterfacesArray(object):
|
|||
u'network': replace_resource_dict(item.get(u'network', {}), 'selfLink'),
|
||||
u'networkIP': item.get('network_ip'),
|
||||
u'subnetwork': replace_resource_dict(item.get(u'subnetwork', {}), 'selfLink'),
|
||||
u'nicType': item.get('nic_type'),
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -1726,6 +1741,7 @@ class InstanceNetworkinterfacesArray(object):
|
|||
u'network': item.get(u'network'),
|
||||
u'networkIP': item.get(u'networkIP'),
|
||||
u'subnetwork': item.get(u'subnetwork'),
|
||||
u'nicType': item.get(u'nicType'),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
---
|
||||
- name: Debug
|
||||
ansible.builtin.debug:
|
||||
msg: "Testing {{ item.key }} scenario"
|
||||
|
||||
- block:
|
||||
- name: Create disk
|
||||
google.cloud.gcp_compute_disk:
|
||||
name: "{{ resource_prefix }}-{{ item.key }}"
|
||||
size_gb: 50
|
||||
source_image: projects/rhel-cloud/global/images/rhel-9-v20250513
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||
state: present
|
||||
register: _disk
|
||||
|
||||
- name: Create instance
|
||||
google.cloud.gcp_compute_instance:
|
||||
name: "{{ resource_name }}-{{ item.key }}"
|
||||
machine_type: n1-standard-1
|
||||
disks:
|
||||
- auto_delete: "true"
|
||||
boot: "true"
|
||||
source: "{{ _disk }}"
|
||||
network_interfaces:
|
||||
- network: "{{ _network }}"
|
||||
nic_type: "{{ item.value if item.value != 'default' else omit }}"
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||
state: present
|
||||
register: _result
|
||||
|
||||
- name: Verify instance was created
|
||||
google.cloud.gcp_compute_instance_info:
|
||||
filters:
|
||||
- name = {{ resource_name }}-{{ item.key }}
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||
scopes:
|
||||
- https://www.googleapis.com/auth/compute
|
||||
register: _info
|
||||
|
||||
# The default option won't expose nicType via API, param will be missing
|
||||
- name: Pass assertions
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- _result.changed == true
|
||||
- _result.networkInterfaces[0].nicType | default('default') == item.value
|
||||
- _info.resources[0].networkInterfaces[0].nicType | default('default') == item.value
|
||||
|
||||
always:
|
||||
- name: Delete instance
|
||||
google.cloud.gcp_compute_instance:
|
||||
name: "{{ resource_name }}-{{ item.key }}"
|
||||
machine_type: n1-standard-1
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||
state: absent
|
||||
|
||||
- name: Delete disk
|
||||
google.cloud.gcp_compute_disk:
|
||||
name: "{{ resource_prefix }}-{{ item.key }}"
|
||||
zone: us-central1-a
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||
state: absent
|
|
@ -1,3 +1,34 @@
|
|||
---
|
||||
- name: Generated tests
|
||||
ansible.builtin.include_tasks: autogen.yml
|
||||
|
||||
- name: Test nic_type scenarios
|
||||
block:
|
||||
- name: Create network
|
||||
google.cloud.gcp_compute_network:
|
||||
name: "{{ resource_prefix }}"
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||
auto_create_subnetworks: true
|
||||
state: present
|
||||
register: _network
|
||||
|
||||
- name: Loop over testcase
|
||||
ansible.builtin.include_tasks: gvnic.yml
|
||||
loop: "{{ testcases | dict2items }}"
|
||||
vars:
|
||||
testcases:
|
||||
gvnic: GVNIC
|
||||
virtio: VIRTIO_NET
|
||||
default: default
|
||||
|
||||
always:
|
||||
- name: Delete network
|
||||
google.cloud.gcp_compute_network:
|
||||
name: "{{ resource_prefix }}"
|
||||
project: "{{ gcp_project }}"
|
||||
auth_kind: "{{ gcp_cred_kind }}"
|
||||
service_account_file: "{{ gcp_cred_file | default(omit) }}"
|
||||
auto_create_subnetworks: true
|
||||
state: absent
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue