Пример #1
0
def create_project_from_filebrowser(username, password, project_name):
    if database_update.project_exists(username, password, project_name):
        return False, "Project: %s already exists! try another name and try again" % project_name

    database_update.create_project(username, password, project_name, "create from filebrowser")

    return create_project_from_file(username, password, project_name)
Пример #2
0
def create_project_from_file_browser(username, project_name):
    if database_update.project_exists(username, project_name):
        return False, "Project: %s already exists! try another name and try again" % project_name

    url = "create from file browser"
    database_update.create_project(username, project_name, url)

    return create_project_from_file(username, project_name)
Пример #3
0
def create_project_from_table(username, project_name, table):
    if database_update.project_exists(username, project_name):
        return False, "Project: %s already exists! try another name and try again" % project_name

    if os.path.exists('%s/%s/%s' % (config.base_path, username, project_name)):
        return False, "File: %s already exists! try another name and try again" % project_name

    os.mkdir("%s/%s/%s" % (config.base_path, username, project_name))
    project_path = config.base_path + '/' + username + '/' + project_name

    database_update.create_project(username, project_name, 'create from table')

    return create_project_exceptions(username, project_path, table, project_name, 'table')
Пример #4
0
def create_project_from_table(username, project_name, table):
    if database_update.project_exists(username, project_name):
        return False, "Project: %s already exists! try another name and try again" % project_name

    if os.path.exists('%s/%s/%s' % (config.base_path, username, project_name)):
        return False, "File: %s already exists! try another name and try again" % project_name

    os.mkdir("%s/%s/%s" % (config.base_path, username, project_name))
    project_path = config.base_path + '/' + username + '/' + project_name

    database_update.create_project(username, project_name, 'create from table')

    return create_project_exceptions(username, project_path, table,
                                     project_name, 'table')
Пример #5
0
def create_project_from_url(username, password, project_name, url):
    if database_update.project_exists(username, password, project_name):
        return False, "Project: %s already exists! try another name and try again" % project_name

    if os.path.exists('%s/%s/%s' % (config.base_path, username, project_name)):
        return False, "File: %s already exists! try another name and try again" % project_name

    os.mkdir("%s/%s/%s" % (config.base_path, username, project_name))
    project_path = config.base_path + '/' + username + '/' + project_name

    try:
        Repo.clone_from(url, project_path)
    except GitCommandError as e:
        shutil.rmtree(project_path)
        return False, "gitcommanderror, please check url: %s" % url
    except:
        return False, "git clone error, please connect administrator for information"

    database_update.create_project(username, password, project_name, url)

    return create_project_from_file(username, password, project_name)
Пример #6
0
def create_project_from_url(username, project_name, url):
    if database_update.project_exists(username, project_name):
        return False, "Project: %s already exists! try another name and try again" % project_name

    if os.path.exists('%s/%s/%s' % (config.base_path, username, project_name)):
        return False, "File: %s already exists! try another name and try again" % project_name

    os.mkdir("%s/%s/%s" % (config.base_path, username, project_name))
    project_path = config.base_path + '/' + username + '/' + project_name

    try:
        Repo.clone_from(url, project_path)
    except GitCommandError:
        shutil.rmtree(project_path)
        return False, "git command error, please check url: %s" % url
    # except:
    #     return False, "git clone error, please connect administrator for information"

    database_update.create_project(username, project_name, url)

    return create_project_from_file(username, project_name)
Пример #7
0
def create_project_from_table(username, password, project_name, table):
    if database_update.project_exists(username, password, project_name):
        return False, "Project: %s already exists! try another name and try again" % project_name

    if os.path.exists('%s/%s/%s' % (config.base_path, username, project_name)):
        return False, "File: %s already exists! try anoter name and try again" % project_name

    project_path = config.base_path + '/' + username + '/' + project_name
    os.mkdir(project_path)

    compose_file = open(project_path + '/docker-compose.yml', 'w')
    for service in table:
        print(service)
        if not "type" in service:
            shutil.rmtree(project_path)
            return False, "service does not has a name"

        if not "service_name" in service:
            print(service['type'])
            if service['type'] == 'mpi':
                service['service_name'] = 'master'

            elif service['type'] == 'mapreduce':
                service['service_name'] = 'master'

            elif service['type'] == 'hbase':
                service['service_name'] = 'master'

            else:
                shutil.rmtree(project_path)
                return False, "service does not has a name"

        compose_file.write(service["service_name"] + ":\n")

        if service["type"] == "mpi":
            compose_file.write("  image: docker.iwanna.xyz:5000/mpi:v1\n")
            compose_file.write("  container_name: %s\n" %
                               service["service_name"])

            if not 'command' in service:
                service['command'] = '/user/sbin/sshd -D'

            if "slaves" in service:
                slaves = service['slaves']
            else:
                slaves = 1

            links = []
            for i in range(int(slaves)):
                links.append('slave%d' % (i))
            service['links'] = links

            write_yml(compose_file, project_path, service)

            for i in range(int(slaves)):
                compose_file.write("slave" + str(i) + ':\n')
                compose_file.write("  image: docker.iwanna.xyz:5000/mpi:v1\n")
                compose_file.write("  command: \'/usr/sbin/sshd -D\'\n")
                compose_file.write("  container_name: slave%d\n" % (i))
            continue

        if service["type"] == "mapreduce":
            continue

        if service["type"] == "hbase":
            continue

        if service["type"] == "apache":
            compose_file.write("  image: docker.iwanna.xyz:5000/apache2:v1\n")
            write_yml(compose_file, project_path, service)
            continue

        if service["type"] == "mysql":
            compose_file.write(
                "  image: docker.iwanna.xyz:5000/user_mysql:v1\n")
            write_yml(compose_file, project_path, service)
            continue

        if service["type"] == "maven":
            compose_file.write("  image: docker.iwanna.xyz:5000/maven:v1\n")
            write_yml(compose_file, project_path, service)
            continue

    compose_file.close()

    create_project_from_filebrowser(username, password, project_name)
Пример #8
0
from orchestration.database import database_update
# import MySQLdb
# from orchestration import config

config = {'name': 'hello', 'scale': 2}
# if __name__ == '__main__':
# ip_list = ['114.212.189.147:2376', '114.212.189.140:2376']
# database_update.create_machine(ip_list)
# database_update.create_user('test', '*****@*****.**')
# database_update.create_project()
database_update.create_project('test', 'project', '*****@*****.**')
# print database_update.get_machine()
print database_update.project_list('test', 0, 2)
print database_update.project_exists('test', 'project')
print database_update.project_exists('test', 'projects')
database_update.create_service('test', 'project', 'service', config, 2)
print database_update.service_list('test', 'project')
database_update.create_container('test', 'project', 'service', 'service0',
                                 '114.212.189.147:2376')
print database_update.container_list('test', 'project', 'service')
print database_update.container_ip('test', 'project', 'service', 'service0')
# print database_update.delete_container_by_name('test', 'project', 'service', 'service0')
print database_update.container_list('test', 'project', 'service')
# print database_update.service_list('test', 'project')
# print database_update.project_list('test', 0, 2)
# database_update.delete_project('test', 'project')
print database_update.project_list('test', 0, 10)

# db = MySQLdb.connect(config.database_url, config.database_user, config.database_passwd, config.database)
# cursor = db.cursor()
# cursor.execute("select name from user")
Пример #9
0
from orchestration.database import database_update
# import MySQLdb
# from orchestration import config

config = {'name': 'hello', 'scale': 2}
# if __name__ == '__main__':
    # ip_list = ['114.212.189.147:2376', '114.212.189.140:2376']
    # database_update.create_machine(ip_list)
    # database_update.create_user('test', '*****@*****.**')
    # database_update.create_project()
database_update.create_project('test', 'project', '*****@*****.**')
    # print database_update.get_machine()
print database_update.project_list('test', 0, 2)
print database_update.project_exists('test', 'project')
print database_update.project_exists('test', 'projects')
database_update.create_service('test', 'project', 'service', config, 2)
print database_update.service_list('test', 'project')
database_update.create_container('test', 'project', 'service', 'service0', '114.212.189.147:2376')
print database_update.container_list('test', 'project', 'service')
print database_update.container_ip('test', 'project', 'service', 'service0')
# print database_update.delete_container_by_name('test', 'project', 'service', 'service0')
print database_update.container_list('test', 'project', 'service')
    # print database_update.service_list('test', 'project')
    # print database_update.project_list('test', 0, 2)
# database_update.delete_project('test', 'project')
print database_update.project_list('test', 0, 10)

# db = MySQLdb.connect(config.database_url, config.database_user, config.database_passwd, config.database)
# cursor = db.cursor()
# cursor.execute("select name from user")
#
Пример #10
0
def create_project_from_table(username, password, project_name, table):
    if database_update.project_exists(username, password, project_name):
        return False, "Project: %s already exists! try another name and try again" % project_name

    if os.path.exists('%s/%s/%s' % (config.base_path, username, project_name)):
        return False, "File: %s already exists! try anoter name and try again" % project_name

    project_path = config.base_path + '/' + username + '/' + project_name
    os.mkdir(project_path)

    compose_file = open(project_path + '/docker-compose.yml', 'w')
    for service in table:
        print(service)
        if not "type" in service:
            shutil.rmtree(project_path)
            return False, "service does not has a name"

        if not "service_name" in service:
            print(service['type'])
            if service['type'] == 'mpi':
                service['service_name'] = 'master'

            elif service['type'] == 'mapreduce':
                service['service_name'] = 'master'

            elif service['type'] == 'hbase':
                service['service_name'] = 'master'

            else:
                shutil.rmtree(project_path)
                return False, "service does not has a name"

        compose_file.write(service["service_name"] + ":\n")

        if service["type"] == "mpi":
            compose_file.write("  image: docker.iwanna.xyz:5000/mpi:v1\n")
            compose_file.write("  container_name: %s\n" % service["service_name"])

            if not 'command' in service:
                service['command'] = '/user/sbin/sshd -D'

            if "slaves" in service:
                slaves = service['slaves']
            else:
                slaves = 1

            links = []
            for i in range(int(slaves)):
                links.append('slave%d' % (i))
            service['links'] = links

            write_yml(compose_file, project_path, service)

            for i in range(int(slaves)):
                compose_file.write("slave" + str(i) + ':\n')
                compose_file.write("  image: docker.iwanna.xyz:5000/mpi:v1\n")
                compose_file.write("  command: \'/usr/sbin/sshd -D\'\n")
                compose_file.write("  container_name: slave%d\n" % (i))
            continue

        if service["type"] == "mapreduce":
            continue

        if service["type"] == "hbase":
            continue

        if service["type"] == "apache":
            compose_file.write("  image: docker.iwanna.xyz:5000/apache2:v1\n")
            write_yml(compose_file, project_path, service)
            continue

        if service["type"] == "mysql":
            compose_file.write("  image: docker.iwanna.xyz:5000/user_mysql:v1\n")
            write_yml(compose_file, project_path, service)
            continue

        if service["type"] == "maven":
            compose_file.write("  image: docker.iwanna.xyz:5000/maven:v1\n")
            write_yml(compose_file, project_path, service)
            continue

    compose_file.close()

    create_project_from_filebrowser(username, password, project_name)