1
0
mirror of https://github.com/gryf/boxpy.git synced 2025-12-19 13:37:58 +01:00

Adeded generating of cloud image

This commit is contained in:
2021-04-08 19:34:02 +02:00
parent f61652a98d
commit 3332177ab7

21
box.py
View File

@@ -148,6 +148,27 @@ class VMCreate:
self._vm_base_path = path self._vm_base_path = path
def _create_cloud_image(self):
# meta-data
with open(os.path.join(self._tmp, 'meta-data'), 'w') as fobj:
fobj.write(META_DATA_TPL
.substitute({'instance_id': str(uuid.uuid4()),
'vmhostname': self.hostname}))
# user-data
with open(self.ssh_key_path) as fobj:
ssh_pub_key = fobj.read().strip()
with open(os.path.join(self._tmp, 'user-data'), 'w') as fobj:
fobj.write(USER_DATA_TPL.substitute({'ssh_key': ssh_pub_key}))
# create ISO image
if subprocess.call(['mkisofs', '-J', '-R', '-V', 'cidata', '-o',
os.path.join(self._tmp, self.CLOUD_IMAGE),
os.path.join(self._tmp, 'user-data'),
os.path.join(self._tmp, 'meta-data')]) != 0:
raise AttributeError('Cannot create ISO image for config drive')
def _prepare_temp(self): def _prepare_temp(self):
self._tmp = tempfile.mkdtemp() self._tmp = tempfile.mkdtemp()