2016-10-19 09:29:02 -05:00
|
|
|
from Atomic.util import output_json
|
2016-12-06 15:21:55 -06:00
|
|
|
import datetime
|
2016-10-19 09:29:02 -05:00
|
|
|
|
|
|
|
|
class Container(object):
|
2016-10-24 12:46:36 +02:00
|
|
|
def __init__(self, input_name, backend=None):
|
2016-10-19 09:29:02 -05:00
|
|
|
|
|
|
|
|
# Required
|
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._name = None
|
2016-10-19 09:29:02 -05:00
|
|
|
self.id = None
|
2016-12-06 15:21:55 -06:00
|
|
|
self._created = None
|
2016-10-19 09:29:02 -05:00
|
|
|
self.status = None
|
|
|
|
|
self.input_name = input_name
|
|
|
|
|
self.original_structure = None
|
|
|
|
|
self.deep = False
|
2016-10-24 12:46:36 +02:00
|
|
|
self._backend = backend
|
2016-12-06 15:21:55 -06:00
|
|
|
self.runtime = backend.backend
|
2017-03-21 09:19:44 -05:00
|
|
|
self.image = None
|
2016-12-06 15:21:55 -06:00
|
|
|
self.image_name = None
|
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._command = None
|
2016-12-06 15:21:55 -06:00
|
|
|
self.state = None
|
|
|
|
|
self.vulnerable = False
|
2016-12-12 13:24:56 -06:00
|
|
|
self.labels = None
|
2017-02-07 15:04:49 -06:00
|
|
|
self._user_command = None
|
2017-02-28 08:06:09 -06:00
|
|
|
self.mount_path = None
|
2016-10-19 09:29:02 -05:00
|
|
|
|
|
|
|
|
# Optional
|
|
|
|
|
self.running = False
|
|
|
|
|
# Instantiate
|
|
|
|
|
self._instantiate()
|
2016-12-12 13:24:56 -06:00
|
|
|
self.stop_args = None
|
2016-10-19 09:29:02 -05:00
|
|
|
|
|
|
|
|
def _instantiate(self):
|
|
|
|
|
self._setup_common()
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
|
|
def _setup_common(self):
|
|
|
|
|
# Items common to backends can go here.
|
2016-11-23 15:14:14 -06:00
|
|
|
pass
|
2016-10-19 09:29:02 -05:00
|
|
|
|
2016-12-12 13:24:56 -06:00
|
|
|
def get_label(self, label):
|
|
|
|
|
if self.labels:
|
|
|
|
|
return self.labels.get(label.lower(), None) or self.labels.get(label.upper(), None)
|
|
|
|
|
return None
|
|
|
|
|
|
2016-10-19 09:29:02 -05:00
|
|
|
def dump(self):
|
|
|
|
|
# Helper function to dump out known variables in pretty-print style
|
|
|
|
|
class_vars = dict(vars(self))
|
2016-11-08 09:17:18 -06:00
|
|
|
foo = {x: class_vars[x] for x in class_vars if not callable(getattr(self, x)) and not x.startswith('__')
|
|
|
|
|
and not x.endswith('_backend')}
|
2016-10-24 12:46:36 +02:00
|
|
|
output_json(foo)
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def backend(self):
|
|
|
|
|
return self._backend
|
|
|
|
|
|
|
|
|
|
@backend.setter
|
|
|
|
|
def backend(self, value):
|
2016-12-06 15:21:55 -06:00
|
|
|
self._backend = value
|
|
|
|
|
|
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
|
|
|
@property
|
|
|
|
|
def type(self):
|
|
|
|
|
return 'container'
|
|
|
|
|
|
2016-12-06 15:21:55 -06:00
|
|
|
@property
|
|
|
|
|
def created(self):
|
|
|
|
|
return str(datetime.datetime.fromtimestamp(self._created))
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def created_raw(self):
|
|
|
|
|
return self._created
|
|
|
|
|
|
|
|
|
|
@created.setter
|
|
|
|
|
def created(self, value):
|
|
|
|
|
self._created = value
|
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
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def command(self):
|
|
|
|
|
cmd = self._command if self._command is not None else ['/bin/sh']
|
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
|
|
@command.setter
|
|
|
|
|
def command(self, value):
|
|
|
|
|
self._command = value
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def interactive(self):
|
|
|
|
|
config = self.original_structure['Config']
|
|
|
|
|
if all([config.get('AttachStdin', False), config.get('AttachStdout', False), config.get('AttachStderr', False)]):
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def name(self):
|
|
|
|
|
return str(self._name)
|
|
|
|
|
|
|
|
|
|
@name.setter
|
|
|
|
|
def name(self, value):
|
|
|
|
|
self._name = value[1:] if value[0] == '/' else value
|
|
|
|
|
|
2017-02-07 15:04:49 -06:00
|
|
|
@property
|
|
|
|
|
def user_command(self):
|
|
|
|
|
return self._user_command
|
2017-03-13 13:11:46 -05:00
|
|
|
|
|
|
|
|
@user_command.setter
|
|
|
|
|
def user_command(self, value):
|
2017-03-13 14:46:54 -05:00
|
|
|
self._user_command = value
|
2017-03-21 09:19:44 -05:00
|
|
|
|