mirror of
https://github.com/gryf/boxpy.git
synced 2025-12-19 05:30:18 +01:00
Improve detecting VM Operating System.
This commit is contained in:
51
box.py
51
box.py
@@ -18,7 +18,7 @@ import requests
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
__version__ = "1.3"
|
__version__ = "1.8"
|
||||||
|
|
||||||
CACHE_DIR = os.environ.get('XDG_CACHE_HOME', os.path.expanduser('~/.cache'))
|
CACHE_DIR = os.environ.get('XDG_CACHE_HOME', os.path.expanduser('~/.cache'))
|
||||||
CLOUD_IMAGE = "ci.iso"
|
CLOUD_IMAGE = "ci.iso"
|
||||||
@@ -587,14 +587,45 @@ class Config:
|
|||||||
|
|
||||||
|
|
||||||
class OsTypes:
|
class OsTypes:
|
||||||
def ubuntu(conf):
|
def __init__(self, conf):
|
||||||
return "Ubuntu%s_64" % conf.version.replace('.', '_')
|
self._conf = conf
|
||||||
|
self._ostypes = []
|
||||||
|
|
||||||
def fedora(conf):
|
self._gather_os_types()
|
||||||
|
|
||||||
|
def _gather_os_types(self):
|
||||||
|
out = Run(['vboxmanage', 'list', 'ostypes']).stdout
|
||||||
|
for line in out.split('\n'):
|
||||||
|
if not line.startswith('ID:'):
|
||||||
|
continue
|
||||||
|
self._ostypes.append(line.split(':')[1].strip())
|
||||||
|
|
||||||
|
def ubuntu(self):
|
||||||
|
lts = ''
|
||||||
|
major, minor = [int(x) for x in self._conf.version.split('.')]
|
||||||
|
|
||||||
|
if major % 2 == 0 and minor == 4:
|
||||||
|
lts = '_LTS'
|
||||||
|
name = "Ubuntu%s%s_64" % (major, lts)
|
||||||
|
|
||||||
|
if name not in self._ostypes:
|
||||||
|
return 'Ubuntu_64'
|
||||||
|
|
||||||
|
return name
|
||||||
|
|
||||||
|
def fedora(self):
|
||||||
return "Fedora_64"
|
return "Fedora_64"
|
||||||
|
|
||||||
def debian(conf):
|
def debian(self):
|
||||||
return "Debian%s_64" % conf.version
|
name = "Debian%s_64" % self._conf.version
|
||||||
|
if name not in self._ostypes:
|
||||||
|
return 'Debian_64'
|
||||||
|
|
||||||
|
def get(self):
|
||||||
|
if not hasattr(self, self._conf.distro):
|
||||||
|
return "Linux_64"
|
||||||
|
|
||||||
|
return getattr(self, self._conf.distro)()
|
||||||
|
|
||||||
|
|
||||||
class VBoxManage:
|
class VBoxManage:
|
||||||
@@ -779,12 +810,8 @@ class VBoxManage:
|
|||||||
'--nic1', 'nat',
|
'--nic1', 'nat',
|
||||||
'--natpf1', f'boxpyssh,tcp,,{port},,22',
|
'--natpf1', f'boxpyssh,tcp,,{port},,22',
|
||||||
'--graphicscontroller', 'vmsvga',
|
'--graphicscontroller', 'vmsvga',
|
||||||
'--vram', '16']
|
'--vram', '16',
|
||||||
|
'--ostype', OsTypes(conf).get()]
|
||||||
if hasattr(OsTypes, conf.distro):
|
|
||||||
cmd.extend(['--ostype', getattr(OsTypes, conf.distro)(conf)])
|
|
||||||
else:
|
|
||||||
cmd.extend(['--ostype', 'Linux_64'])
|
|
||||||
|
|
||||||
for count, (hostport, vmport) in enumerate(conf.forwarding.items(),
|
for count, (hostport, vmport) in enumerate(conf.forwarding.items(),
|
||||||
start=1):
|
start=1):
|
||||||
|
|||||||
Reference in New Issue
Block a user