2013-06-09 16:25:59 +02:00
|
|
|
import base
|
2013-07-09 21:27:32 +02:00
|
|
|
from common.exceptions import ManifestError
|
2013-05-02 19:13:35 +02:00
|
|
|
|
|
|
|
|
2013-06-09 16:25:59 +02:00
|
|
|
class Manifest(base.Manifest):
|
2013-06-23 12:00:17 +02:00
|
|
|
def validate(self, data):
|
2013-06-27 00:30:07 +02:00
|
|
|
super(Manifest, self).validate(data)
|
2013-06-23 12:00:17 +02:00
|
|
|
from os import path
|
2013-07-01 23:11:18 +02:00
|
|
|
schema_path = path.join(path.dirname(__file__), 'manifest-schema.json')
|
2013-06-23 23:37:21 +02:00
|
|
|
self.schema_validate(data, schema_path)
|
2013-07-13 15:10:04 +02:00
|
|
|
if data['volume']['backing'] == 'ebs':
|
2013-10-09 00:09:34 +02:00
|
|
|
volume_size = self._calculate_volume_size(data['volume']['partitions'])
|
|
|
|
if volume_size % 1024 != 0:
|
2013-10-27 10:02:11 +01:00
|
|
|
msg = ('The volume size must be a multiple of 1024 when using EBS backing '
|
|
|
|
'(MBR partitioned volumes are 1MB larger than specified, for the post-mbr gap)')
|
2013-07-13 15:10:04 +02:00
|
|
|
raise ManifestError(msg, self)
|
|
|
|
else:
|
|
|
|
schema_path = path.join(path.dirname(__file__), 'manifest-schema-s3.json')
|
|
|
|
self.schema_validate(data, schema_path)
|
2013-06-23 12:00:17 +02:00
|
|
|
|
2013-05-02 19:13:35 +02:00
|
|
|
def parse(self, data):
|
|
|
|
super(Manifest, self).parse(data)
|
2013-06-23 12:00:17 +02:00
|
|
|
self.credentials = data['credentials']
|
|
|
|
self.virtualization = data['virtualization']
|
2013-07-07 20:28:24 +02:00
|
|
|
self.image = data['image']
|
2013-10-09 00:09:34 +02:00
|
|
|
|
|
|
|
def _calculate_volume_size(self, partitions):
|
|
|
|
if partitions['type'] == 'mbr':
|
|
|
|
size = 1
|
|
|
|
else:
|
|
|
|
size = 0
|
|
|
|
if 'boot' in partitions:
|
|
|
|
size += partitions['boot']['size']
|
|
|
|
size += partitions['root']['size']
|
|
|
|
if 'swap' in partitions:
|
|
|
|
size += partitions['swap']['size']
|
|
|
|
return size
|