Beispiel #1
0
    def put_file(self, container_id, path, file_data, ticket_id=None):

        config = {
            'AttachStdin': False,
            'Cmd': ['bash', '-c', 'echo %(data)s | base64 -d | tee %(path)s && chmod +x %(path)s' % {
                'data': base64.encodestring(file_data).strip(),
                'path': path
            }]
        }

        response = yield self._post('containers/%s/exec' % bytes(container_id),
                                    headers={'Content-Type': 'application/json'}, data=json.dumps(config), response_handler=None)

        data = yield self.collect_json_or_none(response)

        print data
        print config

        response = yield self._post('exec/%s/start' % bytes(data['Id']),
                                    headers={'Content-Type': 'application/json'}, data=json.dumps({
                 "Detach": False,
                 "Tty": False,
                }), response_handler=None)

        resp = yield txhttp.content(response)
        print resp
Beispiel #2
0
    def collect_to_exception(self, e, response):
        def on_collected(content):
            raise e(content)

        d = txhttp.content(response)
        d.addCallback(on_collected)
        return d
Beispiel #3
0
 def resize(self, container_id, width, height):
     assert not id is None
     r = yield self._post(str("containers/%s/resize" % container_id),
                          params={
                              'h': height,
                              'w': width
                          })
     logger.info({'h': height, 'w': width})
     r = yield txhttp.content(r)
     defer.returnValue(r)
Beispiel #4
0
    def collect_json_or_none(self, response):
        def on_collected(result):
            if response.code == 404:
                return None
            else:
                return json.loads(result)

        d = txhttp.content(response)
        d.addCallback(on_collected)

        return d
Beispiel #5
0
    def collect_json_or_none(self, response):

        def on_collected(result):
            if response.code == 404:
                return None
            else:
                return json.loads(result)

        d = txhttp.content(response)
        d.addCallback(on_collected)

        return d
Beispiel #6
0
    def put_file(self, container_id, path, file_data, ticket_id=None):

        config = {
            'AttachStdin':
            False,
            'Cmd': [
                'bash', '-c',
                'echo %(data)s | base64 -d | tee %(path)s && chmod +x %(path)s'
                % {
                    'data': base64.encodestring(file_data).strip(),
                    'path': path
                }
            ]
        }

        response = yield self._post(
            'containers/%s/exec' % bytes(container_id),
            headers={'Content-Type': 'application/json'},
            data=json.dumps(config),
            response_handler=None)

        data = yield self.collect_json_or_none(response)

        print data
        print config

        response = yield self._post(
            'exec/%s/start' % bytes(data['Id']),
            headers={'Content-Type': 'application/json'},
            data=json.dumps({
                "Detach": False,
                "Tty": False,
            }),
            response_handler=None)

        resp = yield txhttp.content(response)
        print resp
Beispiel #7
0
 def resize(self, container_id, width, height):
     assert not id is None
     r = yield self._post(str("containers/%s/resize" % container_id), params={'h': height, 'w': width})
     logger.info({'h': height, 'w': width})
     r = yield txhttp.content(r)
     defer.returnValue(r)
Beispiel #8
0
 def collect_to_exception(self, e, response):
     def on_collected(content):
         raise e(content)
     d = txhttp.content(response)
     d.addCallback(on_collected)
     return d