mirror of
https://github.com/gryf/boxpy.git
synced 2025-12-18 21:10:17 +01:00
Bump the version.
Also, clean up raising exceptions.
This commit is contained in:
19
box.py
19
box.py
@@ -18,7 +18,7 @@ import requests
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
__version__ = "1.9.2"
|
__version__ = "1.10.0"
|
||||||
|
|
||||||
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"
|
||||||
@@ -673,7 +673,7 @@ class VBoxManage:
|
|||||||
dom = xml.dom.minidom.parse(path)
|
dom = xml.dom.minidom.parse(path)
|
||||||
if len(dom.getElementsByTagName('HardDisk')) != 1:
|
if len(dom.getElementsByTagName('HardDisk')) != 1:
|
||||||
# don't know what to do with multiple discs
|
# don't know what to do with multiple discs
|
||||||
raise BoxError()
|
raise BoxError
|
||||||
|
|
||||||
disk = dom.getElementsByTagName('HardDisk')[0]
|
disk = dom.getElementsByTagName('HardDisk')[0]
|
||||||
location = disk.getAttribute('location')
|
location = disk.getAttribute('location')
|
||||||
@@ -816,7 +816,8 @@ class VBoxManage:
|
|||||||
self.uuid = line.split('UUID:')[1].strip()
|
self.uuid = line.split('UUID:')[1].strip()
|
||||||
|
|
||||||
if not self.uuid:
|
if not self.uuid:
|
||||||
raise BoxVBoxFailure(f'Cannot create VM "{self.name_or_uuid}".')
|
msg = f'Cannot create VM "{self.name_or_uuid}".'
|
||||||
|
raise BoxVBoxFailure(msg)
|
||||||
|
|
||||||
port = conf.port if conf.port else self._find_unused_port()
|
port = conf.port if conf.port else self._find_unused_port()
|
||||||
|
|
||||||
@@ -839,14 +840,14 @@ class VBoxManage:
|
|||||||
|
|
||||||
if Run(cmd).returncode != 0:
|
if Run(cmd).returncode != 0:
|
||||||
LOG.fatal(f'Cannot modify VM "{self.name_or_uuid}"')
|
LOG.fatal(f'Cannot modify VM "{self.name_or_uuid}"')
|
||||||
raise BoxVBoxFailure()
|
raise BoxVBoxFailure
|
||||||
|
|
||||||
if conf.disable_nested == 'False':
|
if conf.disable_nested == 'False':
|
||||||
if Run(['vboxmanage', 'modifyvm', self.name_or_uuid,
|
if Run(['vboxmanage', 'modifyvm', self.name_or_uuid,
|
||||||
'--nested-hw-virt', 'on']).returncode != 0:
|
'--nested-hw-virt', 'on']).returncode != 0:
|
||||||
LOG.fatal(f'Cannot set nested virtualization for VM '
|
LOG.fatal(f'Cannot set nested virtualization for VM '
|
||||||
f'"{self.name_or_uuid}"')
|
f'"{self.name_or_uuid}"')
|
||||||
raise BoxVBoxFailure()
|
raise BoxVBoxFailure
|
||||||
|
|
||||||
return self.uuid
|
return self.uuid
|
||||||
|
|
||||||
@@ -882,7 +883,7 @@ class VBoxManage:
|
|||||||
if Run(['vboxmanage', 'modifymedium', 'disk', src, '--resize',
|
if Run(['vboxmanage', 'modifymedium', 'disk', src, '--resize',
|
||||||
str(size), '--move', fullpath]).returncode != 0:
|
str(size), '--move', fullpath]).returncode != 0:
|
||||||
LOG.fatal('Resizing and moving image %s has failed', dst)
|
LOG.fatal('Resizing and moving image %s has failed', dst)
|
||||||
raise BoxVBoxFailure()
|
raise BoxVBoxFailure
|
||||||
return fullpath
|
return fullpath
|
||||||
|
|
||||||
def storageattach(self, controller_name, port, type_, image):
|
def storageattach(self, controller_name, port, type_, image):
|
||||||
@@ -906,7 +907,7 @@ class VBoxManage:
|
|||||||
if Run(['vboxmanage', 'startvm', self.name_or_uuid, '--type',
|
if Run(['vboxmanage', 'startvm', self.name_or_uuid, '--type',
|
||||||
type_]).returncode != 0:
|
type_]).returncode != 0:
|
||||||
LOG.fatal('Failed to start: %s', self.name_or_uuid)
|
LOG.fatal('Failed to start: %s', self.name_or_uuid)
|
||||||
raise BoxVBoxFailure()
|
raise BoxVBoxFailure
|
||||||
|
|
||||||
def setextradata(self, key, val):
|
def setextradata(self, key, val):
|
||||||
res = Run(['vboxmanage', 'setextradata', self.name_or_uuid, key, val])
|
res = Run(['vboxmanage', 'setextradata', self.name_or_uuid, key, val])
|
||||||
@@ -920,7 +921,7 @@ class VBoxManage:
|
|||||||
if Run(['vboxmanage', 'modifyvm', self.name_or_uuid, f'--{nic}',
|
if Run(['vboxmanage', 'modifyvm', self.name_or_uuid, f'--{nic}',
|
||||||
kind]).returncode != 0:
|
kind]).returncode != 0:
|
||||||
LOG.fatal('Cannot modify VM "%s"', self.name_or_uuid)
|
LOG.fatal('Cannot modify VM "%s"', self.name_or_uuid)
|
||||||
raise BoxVBoxFailure()
|
raise BoxVBoxFailure
|
||||||
|
|
||||||
def is_port_in_use(self, port):
|
def is_port_in_use(self, port):
|
||||||
used_ports = self._get_defined_ports()
|
used_ports = self._get_defined_ports()
|
||||||
@@ -1057,7 +1058,7 @@ class Image:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def _get_checksum(self, fname):
|
def _get_checksum(self, fname):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class Ubuntu(Image):
|
class Ubuntu(Image):
|
||||||
|
|||||||
Reference in New Issue
Block a user