2021-11-23 06:09:18 +00:00
|
|
|
# vim: ts=4 et:
|
|
|
|
|
2022-08-17 15:20:49 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from subprocess import Popen, PIPE
|
|
|
|
|
|
|
|
|
2021-11-23 06:09:18 +00:00
|
|
|
class CloudAdapterInterface:
|
2022-08-17 15:20:49 +00:00
|
|
|
CONVERT_CMD = {
|
|
|
|
'qcow2': ['ln', '-f'],
|
|
|
|
'vhd': ['qemu-img', 'convert', '-f', 'qcow2', '-O', 'vpc', '-o', 'force_size=on'],
|
|
|
|
}
|
2021-11-23 06:09:18 +00:00
|
|
|
|
|
|
|
def __init__(self, cloud, cred_provider=None):
|
|
|
|
self._sdk = None
|
|
|
|
self._sessions = {}
|
2022-08-17 15:20:49 +00:00
|
|
|
self._clients = {}
|
2021-11-23 06:09:18 +00:00
|
|
|
self.cloud = cloud
|
|
|
|
self.cred_provider = cred_provider
|
|
|
|
self._default_region = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def sdk(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2021-11-28 23:04:28 +00:00
|
|
|
@property
|
2021-11-23 06:09:18 +00:00
|
|
|
def regions(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2021-11-28 23:04:28 +00:00
|
|
|
@property
|
2021-11-23 06:09:18 +00:00
|
|
|
def default_region(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def credentials(self, region=None):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def session(self, region=None):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2022-08-17 15:20:49 +00:00
|
|
|
def client(self, client, region=None):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
# get information about the latest released image
|
2021-11-28 23:04:28 +00:00
|
|
|
def latest_build_image(self, project, image_key):
|
2021-11-23 06:09:18 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2022-08-17 15:20:49 +00:00
|
|
|
# convert local QCOW2 to format appropriate for a cloud
|
|
|
|
def convert_image(self, ic):
|
|
|
|
log = logging.getLogger('import')
|
|
|
|
local_path = ic.local_path
|
|
|
|
image_path = ic.local_dir / ic.image_file
|
|
|
|
|
|
|
|
log.info('Converting %s to %s', image_path, image_path)
|
|
|
|
p = Popen(self.CONVERT_CMD[ic.image_format] + [ic.local_path, ic.image_path], stdout=PIPE, stdin=PIPE, encoding='utf8')
|
|
|
|
out, err = p.communicate()
|
|
|
|
if p.returncode:
|
|
|
|
log.error('Unable to convert %s to %s format (%s)', ic.local_path, ic.image_path, p.returncode)
|
|
|
|
log.error('EXIT: %d', p.returncode)
|
|
|
|
log.error('STDOUT:\n%s', out)
|
|
|
|
log.error('STDERR:\n%s', err)
|
|
|
|
raise RuntimeError
|
|
|
|
|
|
|
|
# import local image to cloud provider
|
2021-11-23 06:09:18 +00:00
|
|
|
def import_image(self, config):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2022-08-17 15:20:49 +00:00
|
|
|
# remove unpublished image from cloud provider
|
2021-11-23 06:09:18 +00:00
|
|
|
def remove_image(self, config, image_id):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2022-08-17 15:20:49 +00:00
|
|
|
# upload cloud image for testing, if upload_path
|
|
|
|
def upload_image(self, config):
|
|
|
|
raise NotImplementedError
|
|
|
|
# TODO: implement here
|
|
|
|
|
|
|
|
# publish image to cloud provider regions
|
2021-11-23 06:09:18 +00:00
|
|
|
def publish_image(self, config):
|
|
|
|
raise NotImplementedError
|
2022-08-17 15:20:49 +00:00
|
|
|
|
|
|
|
# generate image checksum, save metadata, sign image, make downloadable, if download_path
|
|
|
|
def release_image(self, config):
|
|
|
|
raise NotImplementedError
|
|
|
|
# TODO: implement here!
|