3.14. 가상 NIC 생성
새로 생성된 가상 머신에 네트워크 액세스 권한이 있도록 하려면 가상 NIC를 생성하고 연결해야 합니다.
예 3.12. 가상 NIC 생성
이 예에서는 NIC, NIC1
을 생성하여 가상 머신 vm1
에 연결합니다. 이 예제의 NIC는 virtio
네트워크 장치이며 NetNamespace 관리 네트워크에
연결되어 있습니다.
V4
import ovirtsdk4 as sdk import ovirtsdk4.types as types connection = sdk.Connection( url='https://engine.example.com/ovirt-engine/api', username='admin@internal', password='password', ca_file='ca.pem', ) # Locate the virtual machines service and use it to find the virtual # machine: vms_service = connection.system_service().vms_service() vm = vms_service.list(search='name=vm1')[0] # Locate the service that manages the network interface cards of the # virtual machine: nics_service = vms_service.vm_service(vm.id).nics_service() # Locate the vnic profiles service and use it to find the ovirmgmt # network's profile id: profiles_service = connection.system_service().vnic_profiles_service() profile_id = None for profile in profiles_service.list(): if profile.name == 'ovirtmgmt': profile_id = profile.id break # Use the "add" method of the network interface cards service to add the # new network interface card: nic = nics_service.add( types.Nic( name='nic1', interface=types.NicInterface.VIRTIO, vnic_profile=types.VnicProfile(id=profile_id), ), ) print("Network interface '%s' added to '%s'." % (nic.name, vm.name)) connection.close()
추가
요청이 성공하면 예제에 텍스트가 출력됩니다.
Network interface 'nic1' added to 'vm1'.