"Fossies" - the Fresh Open Source Software Archive

Member "zun-4.0.0/zun/image/driver.py" (16 Oct 2019, 3034 Bytes) of package /linux/misc/openstack/zun-4.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "driver.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.1.0_vs_3.0.0.

    1 # Copyright 2016 Intel.
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 # not use this file except in compliance with the License. You may obtain
    5 # a copy of the License at
    6 #
    7 #      http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 # License for the specific language governing permissions and limitations
   13 # under the License.
   14 
   15 import six
   16 import sys
   17 
   18 from oslo_log import log as logging
   19 import stevedore
   20 
   21 from zun.common.i18n import _
   22 import zun.conf
   23 
   24 CONF = zun.conf.CONF
   25 LOG = logging.getLogger(__name__)
   26 
   27 
   28 def load_image_driver(image_driver=None):
   29     """Load an image driver module.
   30 
   31     Load the container image driver module specified by the image_driver
   32     configuration option or, if supplied, the driver name supplied as an
   33     argument.
   34     :param image_driver: container image driver name to override config opt
   35     :returns: a ContainerImageDriver instance
   36     """
   37     if not image_driver:
   38         image_driver = CONF.default_image_driver
   39     if not image_driver:
   40         LOG.error("Container image driver option required, "
   41                   "but not specified")
   42         sys.exit(1)
   43 
   44     LOG.info("Loading container image driver '%s'", image_driver)
   45     try:
   46         driver = stevedore.driver.DriverManager(
   47             "zun.image.driver",
   48             image_driver,
   49             invoke_on_load=True).driver
   50 
   51         if not isinstance(driver, ContainerImageDriver):
   52             raise Exception(_('Expected driver of type: %s') %
   53                             six.text_type(ContainerImageDriver))
   54 
   55         return driver
   56     except Exception:
   57         LOG.exception("Unable to load the container image driver")
   58         sys.exit(1)
   59 
   60 
   61 class ContainerImageDriver(object):
   62     """Base class for container image driver."""
   63 
   64     def pull_image(self, context, repo, tag, image_pull_policy, registry):
   65         """Pull an image."""
   66         raise NotImplementedError()
   67 
   68     def search_image(self, context, repo, tag, exact_match):
   69         """Search an image."""
   70         raise NotImplementedError()
   71 
   72     def create_image(self, context, image_name):
   73         """Create an image."""
   74         raise NotImplementedError()
   75 
   76     def update_image(self, context, img_id, container_fmt=None,
   77                      disk_fmt=None, tag=None):
   78         """Update an image."""
   79         raise NotImplementedError()
   80 
   81     def upload_image_data(self, context, img_id, data):
   82         """Upload an image."""
   83         raise NotImplementedError()
   84 
   85     def delete_image(self, context, img_id):
   86         """Delete an image."""
   87         raise NotImplementedError()
   88 
   89     def delete_committed_image(self, context, img_id, image_driver):
   90         """Delete a committed image."""
   91         raise NotImplementedError()
   92 
   93     def delete_image_tar(self, context, image):
   94         """Delete an image."""
   95         raise NotImplementedError()