Ce contenu n'est pas disponible dans la langue sélectionnée.
2.14. Example: Creating a Virtual Machine NIC using Python
To ensure a newly created virtual machine has network access you must create and attach a virtual NIC.
Example 2.13. Creating a virtual machine NIC using Python
This Python example creates an NIC named
These options are combined into an NIC parameter object, before using the
nic1
and attaches it to the virtual machine named vm1
. The NIC in this example:
- Must be a
virtio
network device.nic_interface = "virtio"
nic_interface = "virtio"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Must be linked to the
ovirtmgmt
management network.nic_network = api.networks.get(name="ovirtmgmt")
nic_network = api.networks.get(name="ovirtmgmt")
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
add
method of the virtual machine's nics
collection to create the NIC.
If the
add
request is successful then the script will output:
Network interface 'nic1' added to 'vm1'.
Network interface 'nic1' added to 'vm1'.