mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 07:26:29 +00:00
Zerofree can be installed as a Debian package
Show alternate message when package string for host_dependencies starts with http:// or https://
This commit is contained in:
parent
210d3261c0
commit
cdd372ca3b
5 changed files with 23 additions and 61 deletions
|
@ -11,14 +11,20 @@ class CheckExternalCommands(Task):
|
|||
def run(cls, info):
|
||||
from common.tools import log_check_call
|
||||
from subprocess import CalledProcessError
|
||||
import re
|
||||
missing_packages = []
|
||||
for command, package in info.host_dependencies.items():
|
||||
try:
|
||||
log_check_call(['type ' + command], shell=True)
|
||||
except CalledProcessError:
|
||||
msg = ('The command `{command}\' is not available, '
|
||||
'it is located in the package `{package}\'.'
|
||||
.format(command=command, package=package))
|
||||
if re.match('^https?:\/\/', package):
|
||||
msg = ('The command `{command}\' is not available, '
|
||||
'you can download the software at `{package}\'.'
|
||||
.format(command=command, package=package))
|
||||
else:
|
||||
msg = ('The command `{command}\' is not available, '
|
||||
'it is located in the package `{package}\'.'
|
||||
.format(command=command, package=package))
|
||||
missing_packages.append(msg)
|
||||
if len(missing_packages) > 0:
|
||||
msg = '\n'.join(missing_packages)
|
||||
|
|
|
@ -5,9 +5,6 @@ def validate_manifest(data, validator, error):
|
|||
import os.path
|
||||
schema_path = os.path.join(os.path.dirname(__file__), 'manifest-schema.json')
|
||||
validator(data, schema_path)
|
||||
if 'zerofree' in data['plugins']['minimize_size']:
|
||||
zerofree_schema_path = os.path.join(os.path.dirname(__file__), 'manifest-schema-zerofree.json')
|
||||
validator(data, zerofree_schema_path)
|
||||
if data['plugins']['minimize_size'].get('shrink', False) and data['volume']['backing'] != 'vmdk':
|
||||
error('Can only shrink vmdk images', ['plugins', 'minimize_size', 'shrink'])
|
||||
|
||||
|
@ -16,11 +13,11 @@ def resolve_tasks(taskset, manifest):
|
|||
taskset.update([tasks.AddFolderMounts,
|
||||
tasks.RemoveFolderMounts,
|
||||
])
|
||||
if 'zerofree' in manifest.plugins['minimize_size']:
|
||||
taskset.add(tasks.CheckZerofreePath)
|
||||
if manifest.plugins['minimize_size'].get('zerofree', False):
|
||||
taskset.add(tasks.AddRequiredCommands)
|
||||
taskset.add(tasks.Zerofree)
|
||||
if manifest.plugins['minimize_size'].get('shrink', False):
|
||||
taskset.add(tasks.CheckVMWareDMCommand)
|
||||
taskset.add(tasks.AddRequiredCommands)
|
||||
taskset.add(tasks.ShrinkVolume)
|
||||
|
||||
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "Minimize size plugin manifest",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"volume": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"partitions": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": { "enum": ["none"] }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,16 +10,10 @@
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"shrink": { "type": "boolean" },
|
||||
"zerofree": { "$ref": "#/definitions/absolute_path" }
|
||||
"zerofree": { "type": "boolean" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"absolute_path": {
|
||||
"type": "string",
|
||||
"pattern": "^/[^\\0]+$"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ from common import phases
|
|||
from common.tasks import apt
|
||||
from common.tasks import bootstrap
|
||||
from common.tasks import filesystem
|
||||
from common.tasks import host
|
||||
from common.tasks import partitioning
|
||||
from common.tasks import volume
|
||||
import os
|
||||
|
@ -46,22 +47,20 @@ class RemoveFolderMounts(Task):
|
|||
del info.minimize_size_folder
|
||||
|
||||
|
||||
class CheckZerofreePath(Task):
|
||||
description = 'Checking path to zerofree tool'
|
||||
class AddRequiredCommands(Task):
|
||||
description = 'Adding commands required for reducing volume size'
|
||||
phase = phases.preparation
|
||||
successors = [host.CheckExternalCommands]
|
||||
|
||||
@classmethod
|
||||
def run(cls, info):
|
||||
from common.exceptions import TaskError
|
||||
import os
|
||||
zerofree = info.manifest.plugins['minimize_size']['zerofree']
|
||||
if not os.path.isfile(zerofree):
|
||||
raise TaskError('The path `{path}\' does not exist or is not a file'.format(path=zerofree))
|
||||
if not os.access(zerofree, os.X_OK):
|
||||
raise TaskError('The path `{path}\' is not executable'.format(path=zerofree))
|
||||
if info.manifest.plugins['minimize_size'].get('zerofree', False):
|
||||
info.host_dependencies['zerofree'] = 'zerofree'
|
||||
if info.manifest.plugins['minimize_size'].get('shrink', False):
|
||||
link = 'https://my.vmware.com/web/vmware/info/slug/desktop_end_user_computing/vmware_workstation/10_0'
|
||||
info.host_dependencies['vmware-vdiskmanager'] = link
|
||||
|
||||
|
||||
# Get zerofree here: http://intgat.tigress.co.uk/rmy/uml/index.html
|
||||
class Zerofree(Task):
|
||||
description = 'Zeroing unused blocks on the volume'
|
||||
phase = phases.volume_unmounting
|
||||
|
@ -71,23 +70,7 @@ class Zerofree(Task):
|
|||
@classmethod
|
||||
def run(cls, info):
|
||||
from common.tools import log_check_call
|
||||
zerofree = info.manifest.plugins['minimize_size']['zerofree']
|
||||
log_check_call([zerofree, info.volume.device_path])
|
||||
|
||||
|
||||
class CheckVMWareDMCommand(Task):
|
||||
description = 'Checking path to vmware-vdiskmanager tool'
|
||||
phase = phases.preparation
|
||||
|
||||
@classmethod
|
||||
def run(cls, info):
|
||||
from common.exceptions import TaskError
|
||||
import os
|
||||
vdiskmngr = '/usr/bin/vmware-vdiskmanager'
|
||||
if not os.path.isfile(vdiskmngr):
|
||||
raise TaskError('Unable to find vmware-vdiskmanager at `{path}\''.format(path=vdiskmngr))
|
||||
if not os.access(vdiskmngr, os.X_OK):
|
||||
raise TaskError('vmware-vdiskmanager at `{path}\' is not executable'.format(path=vdiskmngr))
|
||||
log_check_call(['zerofree', info.volume.device_path])
|
||||
|
||||
|
||||
class ShrinkVolume(Task):
|
||||
|
|
Loading…
Add table
Reference in a new issue