예제 #1
0
파일: handler.py 프로젝트: dx9/python-agent
    def _reply(self, req, response_data):
        if req is None:
            return None
        resp = utils.reply(req)
        resp.data = JsonObject(response_data)

        return resp
예제 #2
0
    def _create_container(self, client, create_config, image_tag, instance,
                          name, progress):
        container = self.get_container(client, instance)
        if container is None:
            log.info('Creating docker container [%s] from config %s', name,
                     create_config)

            labels = create_config['labels']
            if labels.get('io.rancher.container.pull_image', None) == 'always':
                self._do_instance_pull(
                    JsonObject({
                        'image': instance.image,
                        'tag': None,
                        'mode': 'all',
                        'complete': False,
                    }), progress)
            try:
                del create_config['name']
                command = ''
                try:
                    command = create_config['command']
                    del create_config['command']
                except KeyError:
                    pass
                config = client.create_container_config(
                    image_tag, command, **create_config)
                try:
                    id = instance.data
                    config['VolumeDriver'] = id.fields['volumeDriver']
                except (KeyError, AttributeError):
                    pass
                container = client.create_container_from_config(config, name)
            except APIError as e:
                if e.message.response.status_code == 404:
                    pull_image(instance.image, progress)
                    container = client.create_container_from_config(
                        config, name)
                else:
                    raise
        return container
예제 #3
0
 def from_string(self, string):
     obj = json.loads(string)
     return JsonObject(obj)