Ejemplo n.º 1
0
def server(request):
    class Server(object):
        def __init__(self, auth_url, container_name, tenant_name, username,
                     password, container, ip):
            self.auth_url = auth_url
            self.container_name = container_name
            self.tenant_name = tenant_name
            self.username = username
            self.password = password
            self.container = container
            self.ip = ip

        def list(self, file_id):
            cmd = 'list {0} -p {1}'.format(self.container_name, file_id)
            cmd = swift.SWIFT_COMMAND.format(self.ip, cmd).split()
            res = docker.exec_(self.container, cmd, output=True, stdout=sys.stderr)
            return res.split()

    container_name = 'onedata'
    result = swift.up('onedata/dockswift', [container_name], 'storage',
                      common.generate_uid())
    [container] = result['docker_ids']
    auth_url = 'http://{0}:{1}/v2.0/tokens'.format(result['host_name'],
                                                   result['keystone_port'])

    def fin():
        docker.remove([container], force=True, volumes=True)

    request.addfinalizer(fin)

    print("AuthUrl: {0}".format(auth_url))

    return Server(auth_url, container_name, result['tenant_name'],
                  result['user_name'], result['password'], container,
                  result['host_name'])
Ejemplo n.º 2
0
def client(request):
    class SwiftClient(object):
        def __init__(self, auth_url, container_name, tenant_name, user_name,
                     password, container, ip):
            self.auth_url = auth_url
            self.container_name = container_name
            self.tenant_name = tenant_name
            self.user_name = user_name
            self.password = password
            self.container = container
            self.ip = ip

        def list(self, file_id):
            res = docker.exec_(self.container,
                               swift_server.SWIFT_COMMAND.format(
                                   self.ip, 'list {0} -p {1}'.format(
                                       self.container_name, file_id)).split(),
                               output=True,
                               stdout=sys.stderr)
            return res.split()

        def cleanup(self):
            assert '' == docker.exec_(self.container,
                                      swift_server.SWIFT_COMMAND.format(
                                          self.ip, 'delete {0} -q'.format(
                                              self.container_name)).split(),
                                      output=True,
                                      stdout=sys.stderr)
            assert '' == docker.exec_(self.container,
                                      swift_server.SWIFT_COMMAND.format(
                                          self.ip, 'post ' +
                                          self.container_name).split(),
                                      output=True,
                                      stdout=sys.stderr)

    container_name = 'onedata'
    result = swift_server.up('predicsis/dockswift', [container_name],
                             'storage', '1')
    [container] = result['docker_ids']

    def fin():
        docker.remove([container], force=True, volumes=True)

    request.addfinalizer(fin)

    return SwiftClient(
        'http://{0}:{1}/v2.0/tokens'.format(result['host_name'],
                                            result['keystone_port']),
        container_name, result['tenant_name'], result['user_name'],
        result['password'], container, result['host_name'])
Ejemplo n.º 3
0
def client(request):
    class SwiftClient(object):
        def __init__(self, auth_url, container_name, tenant_name, user_name,
                     password, container, ip):
            self.auth_url = auth_url
            self.container_name = container_name
            self.tenant_name = tenant_name
            self.user_name = user_name
            self.password = password
            self.container = container
            self.ip = ip

        def list(self, file_id):
            res = docker.exec_(self.container,
                               swift_server.SWIFT_COMMAND.format(
                                   self.ip, 'list {0} -p {1}'.format(
                                       self.container_name, file_id)).split(),
                               output=True, stdout=sys.stderr)
            return res.split()

    container_name = 'onedata'
    result = swift_server.up('onedata/dockswift', [container_name],
                             'storage', '1')
    [container] = result['docker_ids']

    def fin():
        docker.remove([container], force=True, volumes=True)

    request.addfinalizer(fin)

    return SwiftClient('http://{0}:{1}/v2.0/tokens'.format(result['host_name'],
                                                           result[
                                                               'keystone_port']),
                       container_name, result['tenant_name'],
                       result['user_name'], result['password'],
                       container, result['host_name'])
Ejemplo n.º 4
0
parser = argparse.ArgumentParser(
    formatter_class=argparse.ArgumentDefaultsHelpFormatter, description="Bring up Swift storage."
)

parser.add_argument(
    "-i",
    "--image",
    action="store",
    default="onedata/dockswift",
    help="docker image to use for the container",
    dest="image",
)

parser.add_argument("-c", "--container", action="append", default=[], help="container name", dest="containers")

parser.add_argument(
    "-u",
    "--uid",
    action="store",
    default=common.generate_uid(),
    help="uid that will be concatenated to docker names",
    dest="uid",
)

args = parser.parse_args()

config = swift.up(args.image, args.containers, "storage", args.uid)

print(json.dumps(config))
Ejemplo n.º 5
0
parser = argparse.ArgumentParser(
    formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    description='Bring up Swift storage.')

parser.add_argument('-i',
                    '--image',
                    action='store',
                    default='predicsis/dockswift',
                    help='docker image to use for the container',
                    dest='image')

parser.add_argument('-c',
                    '--container',
                    action='append',
                    default=[],
                    help='container name',
                    dest='containers')

parser.add_argument('-u',
                    '--uid',
                    action='store',
                    default=common.generate_uid(),
                    help='uid that will be concatenated to docker names',
                    dest='uid')

args = parser.parse_args()

config = swift.up(args.image, args.containers, 'storage', args.uid)

print(json.dumps(config))