Пример #1
0
    def container_create(self, context, container):
        with docker_utils.docker_for_container(context, container) as docker:
            name = container.name
            container_uuid = container.uuid
            image = container.image
            LOG.debug('Creating container with image %s name %s', image, name)
            try:
                image_repo, image_tag = docker_utils.parse_docker_image(image)
                docker.pull(image_repo, tag=image_tag)
                docker.inspect_image(self._encode_utf8(container.image))
                kwargs = {'name': name,
                          'hostname': container_uuid,
                          'command': container.command,
                          'environment': container.environment}
                if docker_utils.is_docker_api_version_atleast(docker, '1.19'):
                    if container.memory is not None:
                        kwargs['host_config'] = {'mem_limit':
                                                 container.memory}
                else:
                    kwargs['mem_limit'] = container.memory

                docker.create_container(image, **kwargs)
                container.status = fields.ContainerStatus.STOPPED
                return container
            except errors.APIError:
                container.status = fields.ContainerStatus.ERROR
                raise
            finally:
                container.save()
Пример #2
0
    def container_create(self, context, container):
        with docker_utils.docker_for_container(context, container) as docker:
            name = container.name
            container_uuid = container.uuid
            image = container.image
            LOG.debug('Creating container with image %s name %s', image, name)
            try:
                image_repo, image_tag = docker_utils.parse_docker_image(image)
                docker.pull(image_repo, tag=image_tag)
                docker.inspect_image(self._encode_utf8(container.image))
                kwargs = {
                    'name': name,
                    'hostname': container_uuid,
                    'command': container.command,
                    'environment': container.environment
                }
                if docker_utils.is_docker_api_version_atleast(docker, '1.19'):
                    if container.memory is not None:
                        kwargs['host_config'] = {
                            'Memory':
                            magnum_utils.get_docker_quanity(container.memory)
                        }
                else:
                    kwargs['mem_limit'] = container.memory

                docker.create_container(image, **kwargs)
                container.status = fields.ContainerStatus.STOPPED
                return container
            except errors.APIError:
                container.status = fields.ContainerStatus.ERROR
                raise
            finally:
                container.save()
Пример #3
0
 def container_create(self, context, name, container_uuid, container):
     image_id = container.image_id
     LOG.debug('Creating container with image %s name %s'
               % (image_id, name))
     try:
         image_repo, image_tag = docker_utils.parse_docker_image(image_id)
         self.docker.pull(image_repo, tag=image_tag)
         self.docker.inspect_image(self._encode_utf8(container.image_id))
         self.docker.create_container(image_id, name=name,
                                      hostname=container_uuid)
         return container
     except errors.APIError as api_error:
         raise exception.ContainerException(
                   "Docker API Error : %s" % str(api_error))
Пример #4
0
 def container_create(self, context, name, container_uuid, container):
     image_id = container.image_id
     LOG.debug('Creating container with image %s name %s' %
               (image_id, name))
     try:
         image_repo, image_tag = docker_utils.parse_docker_image(image_id)
         self.docker.pull(image_repo, tag=image_tag)
         self.docker.inspect_image(self._encode_utf8(container.image_id))
         self.docker.create_container(image_id,
                                      name=name,
                                      hostname=container_uuid)
         return container
     except errors.APIError as api_error:
         raise exception.ContainerException("Docker API Error : %s" %
                                            str(api_error))
Пример #5
0
 def container_create(self, context, name, container_uuid, container):
     docker = self.get_docker_client(context, container)
     image_id = container.image_id
     LOG.debug('Creating container with image %s name %s'
               % (image_id, name))
     try:
         image_repo, image_tag = docker_utils.parse_docker_image(image_id)
         docker.pull(image_repo, tag=image_tag)
         docker.inspect_image(self._encode_utf8(container.image_id))
         docker.create_container(image_id, name=name,
                                 hostname=container_uuid,
                                 command=container.command)
         container.status = obj_container.STOPPED
         return container
     except errors.APIError as api_error:
         container.status = obj_container.ERROR
         raise exception.ContainerException(
                   "Docker API Error : %s" % str(api_error))
     finally:
         container.save()
Пример #6
0
 def container_create(self, context, name, container_uuid, container):
     docker = self.get_docker_client(context, container)
     image = container.image
     LOG.debug('Creating container with image %s name %s' % (image, name))
     try:
         image_repo, image_tag = docker_utils.parse_docker_image(image)
         docker.pull(image_repo, tag=image_tag)
         docker.inspect_image(self._encode_utf8(container.image))
         docker.create_container(image,
                                 name=name,
                                 hostname=container_uuid,
                                 command=container.command)
         container.status = obj_container.STOPPED
         return container
     except errors.APIError as api_error:
         container.status = obj_container.ERROR
         raise exception.ContainerException("Docker API Error : %s" %
                                            str(api_error))
     finally:
         container.save()
Пример #7
0
 def container_create(self, context, container):
     with docker_utils.docker_for_container(context, container) as docker:
         name = container.name
         container_uuid = container.uuid
         image = container.image
         LOG.debug('Creating container with image %s name %s'
                   % (image, name))
         try:
             image_repo, image_tag = docker_utils.parse_docker_image(image)
             docker.pull(image_repo, tag=image_tag)
             docker.inspect_image(self._encode_utf8(container.image))
             docker.create_container(image, name=name,
                                     hostname=container_uuid,
                                     command=container.command,
                                     mem_limit=container.memory)
             container.status = fields.ContainerStatus.STOPPED
             return container
         except errors.APIError:
             container.status = fields.ContainerStatus.ERROR
             raise
         finally:
             container.save()
Пример #8
0
 def container_create(self, context, container):
     with docker_utils.docker_for_container(context, container) as docker:
         name = container.name
         container_uuid = container.uuid
         image = container.image
         LOG.debug('Creating container with image %s name %s' %
                   (image, name))
         try:
             image_repo, image_tag = docker_utils.parse_docker_image(image)
             docker.pull(image_repo, tag=image_tag)
             docker.inspect_image(self._encode_utf8(container.image))
             docker.create_container(image,
                                     name=name,
                                     hostname=container_uuid,
                                     command=container.command,
                                     mem_limit=container.memory)
             container.status = fields.ContainerStatus.STOPPED
             return container
         except errors.APIError:
             container.status = fields.ContainerStatus.ERROR
             raise
         finally:
             container.save()