Skip to content

Commit ddfd72d

Browse files
authored
Use hvf on macOS instead of falling back to tcg (#853)
* Use hvf on macOS instead of falling back to tcg * Display userport instead of IP, if it's not available
1 parent 9148a22 commit ddfd72d

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

kvirt/cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,9 @@ def _parse_vms_list(_list, overrides={}):
783783
name = vm.get('name')
784784
status = vm.get('status')
785785
ip = vm.get('ip', '')
786+
userport = vm.get('userport')
787+
if not ip and userport is not None:
788+
ip = f'127.0.0.1:{userport}'
786789
source = vm.get('image', '')
787790
plan = vm.get('plan', '')
788791
profile = vm.get('profile', '')
@@ -813,6 +816,9 @@ def list_vms(args):
813816
name = vm.get('name')
814817
status = vm.get('status')
815818
ip = vm.get('ip', '')
819+
userport = vm.get('userport')
820+
if not ip and userport is not None:
821+
ip = f'127.0.0.1:{userport}'
816822
source = vm.get('image', '')
817823
plan = vm.get('plan', '')
818824
profile = vm.get('profile', '')
@@ -833,6 +839,9 @@ def list_vms(args):
833839
name = vm.get('name')
834840
status = vm.get('status')
835841
ip = vm.get('ip', '')
842+
userport = vm.get('userport')
843+
if not ip and userport is not None:
844+
ip = f'127.0.0.1:{userport}'
836845
source = vm.get('image', '')
837846
plan = vm.get('plan', '')
838847
profile = vm.get('profile', '')

kvirt/kmcp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def _parse_vms_list(_list, overrides={}):
3131
name = vm.get('name')
3232
status = vm.get('status')
3333
ip = vm.get('ip', '')
34+
userport = vm.get('userport')
35+
if not ip and userport is not None:
36+
ip = f'127.0.0.1:{userport}'
3437
source = vm.get('image', '')
3538
plan = vm.get('plan', '')
3639
profile = vm.get('profile', '')

kvirt/providers/kvm/__init__.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def disk_exists(self, pool, name):
179179
return False
180180

181181
def get_capabilities(self, arch=None):
182-
results = {'kvm': False, 'nestedfeature': None, 'machines': [], 'arch': arch}
182+
results = {'kvm': False, 'hvf': False, 'nestedfeature': None, 'machines': [], 'arch': arch}
183183
capabilitiesxml = self.conn.getCapabilities()
184184
root = ET.fromstring(capabilitiesxml)
185185
cpuxml = ''
@@ -200,7 +200,8 @@ def get_capabilities(self, arch=None):
200200
for domain in list(guest.iter('domain')):
201201
if domain.get('type') == 'kvm':
202202
results['kvm'] = True
203-
break
203+
elif domain.get('type') == 'hvf':
204+
results['hvf'] = True
204205
for machine in list(guest.iter('machine')):
205206
results['machines'].append(machine.text)
206207
if 'vmx' in cpuxml:
@@ -270,7 +271,7 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt'
270271
uefi_legacy = overrides.get('uefi_legacy', False) or (uefi and self._rhel_legacy(capabilities['machines']))
271272
iommu_model = 'smmuv3' if arch == 'aarch64' else 'intel'
272273
aarch64 = arch == 'aarch64'
273-
aarch64_full = aarch64 and capabilities['kvm']
274+
aarch64_full = aarch64 and (capabilities['kvm'] or capabilities['hvf'])
274275
as390x = arch == 's390x'
275276
if aarch64:
276277
if custom_emulator is not None:
@@ -946,13 +947,15 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt'
946947
else:
947948
cpuxml = f"<cpu mode='custom' match='exact'><model fallback='allow'>{cpumodel}</model>"
948949
if virttype is None:
949-
if not capabilities['kvm']:
950+
if capabilities['kvm']:
951+
virttype = 'kvm'
952+
elif capabilities['hvf']:
953+
virttype = 'hvf'
954+
else:
950955
warning("No acceleration available with this hypervisor")
951956
virttype = 'qemu'
952957
nested = False
953-
else:
954-
virttype = 'kvm'
955-
elif virttype not in ['qemu', 'kvm', 'xen', 'lxc']:
958+
elif virttype not in ['qemu', 'kvm', 'hvf', 'xen', 'lxc']:
956959
msg = f"Incorrect virttype {virttype}"
957960
return {'result': 'failure', 'reason': msg}
958961
nestedfeature = capabilities['nestedfeature']

0 commit comments

Comments
 (0)