def __init__(self, working_dir, input_disk_path):
        self.working_dir = working_dir
        self.disk = BaseDisk(input_disk_path, working_dir)

        self.cloud_disk_url = None
        self.prepared_image_names = []
        self.created_objects = []
Exemple #2
0
 def extract(self):
     """Extract the vmdk disk out of zip."""
     LOGGER.debug("Extracting '.vmdk' disk file from [%s].",
                  self.input_disk_path)
     self.disk_to_upload = BaseDisk.decompress(self.input_disk_path,
                                               '.vmdk', self.working_dir)
     LOGGER.info("AWS disk_to_upload = '%s'", self.disk_to_upload)
Exemple #3
0
    def upload(self):
        """
        Upload tar.gz stored at self.disk_to_upload to Google storage
        """
        try:
            # Populate the bucket if not already.
            if self.bucket is None:
                self.init_bucket()

            # form blob name
            prefix = datetime.datetime.now().strftime('%Y%m%d') + '/'
            self.uploaded_disk_name = prefix + BaseDisk.decorate_disk_name(self.disk_to_upload)

            # delete the blob if it exists
            self.delete_blob()

            # create blob
            blob = self.bucket.blob(self.uploaded_disk_name)
            if blob is None:
                raise RuntimeError("Factory constructor for blob '{}' failed."
                                   .format(self.uploaded_disk_name))

            # upload blob
            LOGGER.info("Started to upload '%s' at '%s'.", self.uploaded_disk_name,
                        datetime.datetime.now().strftime('%H:%M:%S'))
            blob.upload_from_filename(self.disk_to_upload)
            LOGGER.info("Finished to upload '%s' at '%s'.", self.uploaded_disk_name,
                        datetime.datetime.now().strftime('%H:%M:%S'))
            if not blob.exists():
                raise RuntimeError("Uploading blob '{}' failed.".format(self.uploaded_disk_name))
        except RuntimeError as exception:
            LOGGER.exception(exception)
            raise exception
 def extract(self):
     """Extract the vhd disk out of tar.gz."""
     try:
         self.disk_to_upload = BaseDisk.decompress(self.input_disk_path,
                                                   '.vhd',
                                                   self.working_dir)
         LOGGER.info("Azure disk_to_upload = '%s'", self.disk_to_upload)
     except RuntimeError as runtime_error:
         raise runtime_error
 def extract(self):
     """Extract the vmdk disk out of zip."""
     try:
         LOGGER.debug("Extracting '.vmdk' disk file from [%s].",
                      self.input_disk_path)
         self.disk_to_upload = BaseDisk.decompress(self.input_disk_path,
                                                   '.vmdk',
                                                   self.working_dir)
         LOGGER.info("AWS disk_to_upload = '%s'", self.disk_to_upload)
     except RuntimeError as runtime_error:
         raise runtime_error
class BaseImage():
    """
    Base class for all platform specific derivations
    """
    def __init__(self, working_dir, input_disk_path):
        self.working_dir = working_dir
        self.disk = BaseDisk(input_disk_path, working_dir)

        self.cloud_disk_url = None
        self.prepared_image_names = []
        self.created_objects = []

    def clean_up(self):
        """Walk through objects created in the cloud and clean
           them up if the clean up flag is True.
        """
        raise NotImplementedError("clean_up() unimplemented.")

    def extract_disk(self):
        """Extract disk for upload"""
        self.disk.extract()

    def set_uploaded_disk_name(self, uploaded_disk_name):
        """Set the name of the uploaded disk name"""
        self.disk.set_uploaded_disk_name(uploaded_disk_name)

    def update_image_name(self):
        """Validate and fix up image name"""

    def upload_disk(self):
        """Upload the disk to cloud"""
        self.disk.upload()

    def prep_disk(self):
        """Perform any processing needed for disk"""

    def create_image(self, image_name):
        """Create cloud image"""

    def copy_image(self):
        """Make image copy"""

    def share_image(self):
        """Share image with other accounts"""

    def get_prepared_image_names(self):
        """Get list of prepared images"""
        return self.prepared_image_names

    def create_metadata(self):
        """Create metadata file"""

    def dry_run(self):
        """Perform environment checks"""
    def upload(self):
        """Upload the disk to the s3 bucket represented by AWS_BUCKET"""
        try:
            if self.is_bucket_exist() is False:
                LOGGER.debug("Creating '%s' bucket as it doesn't exist.",
                             self.bucket_name)
                self.create_bucket()

            self.uploaded_disk_name = BaseDisk.decorate_disk_name(
                self.disk_to_upload)

            LOGGER.info("Uploading '%s' to the bucket '%s'.",
                        self.uploaded_disk_name, self.bucket_name)
            self.s3_client.upload_file(self.disk_to_upload, self.bucket_name,
                                       self.uploaded_disk_name)
            LOGGER.info("Successfully uploaded '%s'.", self.uploaded_disk_name)
        except ClientError as client_error:
            LOGGER.exception(client_error)
            raise RuntimeError("AWS upload disk operation failed.")
Exemple #8
0
 def extract(self):
     """Extract the vhd disk out of tar.gz."""
     self.disk_to_upload = BaseDisk.decompress(self.input_disk_path, '.vhd',
                                               self.working_dir)
     LOGGER.info("Azure disk_to_upload = '%s'", self.disk_to_upload)