2016-09-06 12:50:45 -05:00
|
|
|
try:
|
|
|
|
|
from . import Atomic
|
|
|
|
|
except ImportError:
|
|
|
|
|
from atomic import Atomic # pylint: disable=relative-import
|
2017-05-15 13:52:55 -05:00
|
|
|
from .util import get_atomic_config, write_out, check_storage_is_available
|
Refactor Pull, Update, Install, Run
Refactor several of the atomic verbs and subverbs to take advantage
of object refactoring.
Also, do not pull images with skopeo if the local image is already
at the latest.
$ sudo python ./atomic --debug pull busybox
Namespace(_class=<class 'Atomic.pull.Pull'>, assumeyes=False, debug=True, func='pull_image', image='busybox', reg_type=None, storage='docker')
Latest version of busybox already present.
Closes: #825
Approved by: baude
2017-01-11 13:18:37 -06:00
|
|
|
from Atomic.backendutils import BackendUtils
|
2016-09-06 12:50:45 -05:00
|
|
|
|
|
|
|
|
ATOMIC_CONFIG = get_atomic_config()
|
|
|
|
|
|
2016-08-28 08:04:35 -04:00
|
|
|
|
2017-02-01 18:00:06 -06:00
|
|
|
_storage = ATOMIC_CONFIG.get('default_storage', "docker")
|
|
|
|
|
|
2016-08-28 08:04:35 -04:00
|
|
|
def cli(subparser):
|
|
|
|
|
# atomic pull
|
|
|
|
|
pullp = subparser.add_parser("pull", help=_("pull latest image from a repository"),
|
|
|
|
|
epilog="pull the latest specified image from a repository.")
|
|
|
|
|
pullp.set_defaults(_class=Pull, func='pull_image')
|
2017-02-01 18:00:06 -06:00
|
|
|
pullp.add_argument("--storage", dest="storage", default=None,
|
2016-09-06 12:50:45 -05:00
|
|
|
help=_("Specify the storage. Default is currently '%s'. You can"
|
2016-09-09 18:09:54 +08:00
|
|
|
" change the default by editing /etc/atomic.conf and changing"
|
2017-02-01 18:00:06 -06:00
|
|
|
" the 'default_storage' field." % _storage))
|
2017-10-25 09:49:53 +02:00
|
|
|
pullp.add_argument("--src-creds", dest="src_creds", default=None,
|
|
|
|
|
help=_("Use USERNAME[:PASSWORD] for accessing the source registry."))
|
2016-09-08 10:23:05 -05:00
|
|
|
pullp.add_argument("-t", "--type", dest="reg_type", default=None,
|
2016-09-20 04:59:09 -04:00
|
|
|
help=_("Pull from an alternative registry type."))
|
2016-08-28 08:04:35 -04:00
|
|
|
pullp.add_argument("image", help=_("image id"))
|
|
|
|
|
|
|
|
|
|
|
2016-09-06 12:50:45 -05:00
|
|
|
class Pull(Atomic):
|
2016-09-23 14:00:19 -04:00
|
|
|
def __init__(self, policy_filename=None):
|
|
|
|
|
"""
|
|
|
|
|
:param policy_filename: override policy filename
|
|
|
|
|
"""
|
|
|
|
|
super(Pull, self).__init__()
|
|
|
|
|
self.policy_filename=policy_filename
|
2017-02-01 11:21:06 -06:00
|
|
|
self.be_utils = BackendUtils()
|
2016-09-23 14:00:19 -04:00
|
|
|
|
2016-09-08 14:20:58 +02:00
|
|
|
def pull_image(self):
|
2017-02-01 18:00:06 -06:00
|
|
|
storage_set = False if self.args.storage is None else True
|
|
|
|
|
storage = _storage if not storage_set else self.args.storage
|
2017-05-15 13:52:55 -05:00
|
|
|
check_storage_is_available(storage)
|
Refactor Pull, Update, Install, Run
Refactor several of the atomic verbs and subverbs to take advantage
of object refactoring.
Also, do not pull images with skopeo if the local image is already
at the latest.
$ sudo python ./atomic --debug pull busybox
Namespace(_class=<class 'Atomic.pull.Pull'>, assumeyes=False, debug=True, func='pull_image', image='busybox', reg_type=None, storage='docker')
Latest version of busybox already present.
Closes: #825
Approved by: baude
2017-01-11 13:18:37 -06:00
|
|
|
if self.args.debug:
|
|
|
|
|
write_out(str(self.args))
|
|
|
|
|
|
2017-10-25 09:49:53 +02:00
|
|
|
src_creds = getattr(self.args, 'src_creds', None)
|
|
|
|
|
if src_creds == "":
|
|
|
|
|
src_creds = None
|
|
|
|
|
|
2017-02-01 18:00:06 -06:00
|
|
|
be_utils = BackendUtils()
|
|
|
|
|
be = be_utils.get_backend_from_string(storage)
|
Refactor Pull, Update, Install, Run
Refactor several of the atomic verbs and subverbs to take advantage
of object refactoring.
Also, do not pull images with skopeo if the local image is already
at the latest.
$ sudo python ./atomic --debug pull busybox
Namespace(_class=<class 'Atomic.pull.Pull'>, assumeyes=False, debug=True, func='pull_image', image='busybox', reg_type=None, storage='docker')
Latest version of busybox already present.
Closes: #825
Approved by: baude
2017-01-11 13:18:37 -06:00
|
|
|
self.args.policy_filename = self.policy_filename
|
|
|
|
|
try:
|
2017-02-01 18:00:06 -06:00
|
|
|
if be.backend == 'docker':
|
|
|
|
|
remote_image_obj = be.make_remote_image(self.args.image)
|
|
|
|
|
if remote_image_obj.is_system_type and not storage_set:
|
|
|
|
|
be = be_utils.get_backend_from_string('ostree')
|
|
|
|
|
be_utils.message_backend_change('docker', 'ostree')
|
2017-08-30 12:33:58 -05:00
|
|
|
elif be.backend == "containers-storage":
|
|
|
|
|
remote_image_obj = be.make_remote_image(self.args.image)
|
2017-02-01 18:00:06 -06:00
|
|
|
else:
|
|
|
|
|
remote_image_obj = None
|
2017-10-25 09:49:53 +02:00
|
|
|
be.pull_image(self.args.image, remote_image_obj, debug=self.args.debug, assumeyes=self.args.assumeyes, src_creds=src_creds)
|
Refactor Pull, Update, Install, Run
Refactor several of the atomic verbs and subverbs to take advantage
of object refactoring.
Also, do not pull images with skopeo if the local image is already
at the latest.
$ sudo python ./atomic --debug pull busybox
Namespace(_class=<class 'Atomic.pull.Pull'>, assumeyes=False, debug=True, func='pull_image', image='busybox', reg_type=None, storage='docker')
Latest version of busybox already present.
Closes: #825
Approved by: baude
2017-01-11 13:18:37 -06:00
|
|
|
except ValueError as e:
|
2017-02-21 13:06:06 -06:00
|
|
|
raise ValueError("Failed: {}".format(e))
|
2017-02-02 13:42:13 -06:00
|
|
|
return 0
|
Refactor Pull, Update, Install, Run
Refactor several of the atomic verbs and subverbs to take advantage
of object refactoring.
Also, do not pull images with skopeo if the local image is already
at the latest.
$ sudo python ./atomic --debug pull busybox
Namespace(_class=<class 'Atomic.pull.Pull'>, assumeyes=False, debug=True, func='pull_image', image='busybox', reg_type=None, storage='docker')
Latest version of busybox already present.
Closes: #825
Approved by: baude
2017-01-11 13:18:37 -06:00
|
|
|
|
2016-09-08 14:20:58 +02:00
|
|
|
|