Exemplo n.º 1
0
 def __init__(self, username = '******', password = None):
     '''
     Try to create the database when there is none
     initialize 'root' user and 'root' & 'primary' group
     '''
     try:
         User.query.all()
     except:
         db.create_all()
         if password == None:
             #set a random password
             password = os.urandom(16)
             password = b64encode(password).decode('utf-8')
             fsdir = env.getenv('FS_PREFIX')
             f = open(fsdir + '/local/generated_password.txt', 'w')
             f.write("User=%s\nPass=%s\n"%(username, password))
             f.close()
         sys_admin = User(username, hashlib.sha512(password.encode('utf-8')).hexdigest())
         sys_admin.status = 'normal'
         sys_admin.nickname = 'root'
         sys_admin.description = 'Root_User'
         sys_admin.user_group = 'root'
         sys_admin.auth_method = 'local'
         db.session.add(sys_admin)
         path = env.getenv('DOCKLET_LIB')
         subprocess.call([path+"/userinit.sh", username])
         db.session.commit()
     if not os.path.exists(fspath+"/global/sys/quota"):
         groupfile = open(fspath+"/global/sys/quota",'w')
         groups = []
         groups.append({'name':'root', 'quotas':{ 'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8' }})
         groups.append({'name':'admin', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}})
         groups.append({'name':'primary', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}})
         groups.append({'name':'foundation', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}})
         groupfile.write(json.dumps(groups))
         groupfile.close()
     if not os.path.exists(fspath+"/global/sys/quotainfo"):
         quotafile = open(fspath+"/global/sys/quotainfo",'w')
         quotas = {}
         quotas['default'] = 'foundation'
         quotas['quotainfo'] = []
         quotas['quotainfo'].append({'name':'cpu', 'hint':'the cpu quota, number of cores, e.g. 4'})
         quotas['quotainfo'].append({'name':'memory', 'hint':'the memory quota, number of MB , e.g. 4000'})
         quotas['quotainfo'].append({'name':'disk', 'hint':'the disk quota, number of MB, e.g. 4000'})
         quotas['quotainfo'].append({'name':'data', 'hint':'the quota of data space, number of GB, e.g. 100'})
         quotas['quotainfo'].append({'name':'image', 'hint':'how many images the user can save, e.g. 10'})
         quotas['quotainfo'].append({'name':'idletime', 'hint':'will stop cluster after idletime, number of hours, e.g. 24'})
         quotas['quotainfo'].append({'name':'vnode', 'hint':'how many containers the user can have, e.g. 8'})
         quotafile.write(json.dumps(quotas))
         quotafile.close()
Exemplo n.º 2
0
 def __init__(self, username='******', password=None):
     '''
     Try to create the database when there is none
     initialize 'root' user and 'root' & 'primary' group
     '''
     try:
         User.query.all()
         UserGroup.query.all()
     except:
         db.create_all()
         root = UserGroup('root')
         db.session.add(root)
         db.session.commit()
         if password == None:
             #set a random password
             password = os.urandom(16)
             password = b64encode(password).decode('utf-8')
             fsdir = env.getenv('FS_PREFIX')
             f = open(fsdir + '/local/generated_password.txt', 'w')
             f.write("User=%s\nPass=%s\n" % (username, password))
             f.close()
         sys_admin = User(
             username,
             hashlib.sha512(password.encode('utf-8')).hexdigest())
         sys_admin.status = 'normal'
         sys_admin.nickname = 'root'
         sys_admin.description = 'Root_User'
         sys_admin.user_group = 'root'
         sys_admin.auth_method = 'local'
         db.session.add(sys_admin)
         path = env.getenv('DOCKLET_LIB')
         subprocess.call([path + "/userinit.sh", username])
         db.session.commit()
         admin = UserGroup('admin')
         primary = UserGroup('primary')
         db.session.add(admin)
         db.session.add(primary)
         db.session.commit()
Exemplo n.º 3
0
 def __init__(self, username = '******', password = None):
     '''
     Try to create the database when there is none
     initialize 'root' user and 'root' & 'primary' group
     '''
     try:
         User.query.all()
         UserGroup.query.all()
     except:
         db.create_all()
         root = UserGroup('root')
         db.session.add(root)
         db.session.commit()
         if password == None:
             #set a random password
             password = os.urandom(16)
             password = b64encode(password).decode('utf-8')
             fsdir = env.getenv('FS_PREFIX')
             f = open(fsdir + '/local/generated_password.txt', 'w')
             f.write("User=%s\nPass=%s\n"%(username, password))
             f.close()
         sys_admin = User(username, hashlib.sha512(password.encode('utf-8')).hexdigest())
         sys_admin.status = 'normal'
         sys_admin.nickname = 'root'
         sys_admin.description = 'Root_User'
         sys_admin.user_group = 'root'
         sys_admin.auth_method = 'local'
         db.session.add(sys_admin)
         path = env.getenv('DOCKLET_LIB')
         subprocess.call([path+"/userinit.sh", username])
         db.session.commit()
         admin = UserGroup('admin')
         primary = UserGroup('primary')
         db.session.add(admin)
         db.session.add(primary)
         db.session.commit()
Exemplo n.º 4
0
 def __init__(self, username='******', password=None):
     '''
     Try to create the database when there is none
     initialize 'root' user and 'root' & 'primary' group
     '''
     try:
         User.query.all()
     except:
         db.create_all()
         if password == None:
             #set a random password
             password = os.urandom(16)
             password = b64encode(password).decode('utf-8')
             fsdir = env.getenv('FS_PREFIX')
             f = open(fsdir + '/local/generated_password.txt', 'w')
             f.write("User=%s\nPass=%s\n" % (username, password))
             f.close()
         sys_admin = User(
             username,
             hashlib.sha512(password.encode('utf-8')).hexdigest())
         sys_admin.status = 'normal'
         sys_admin.nickname = 'root'
         sys_admin.description = 'Root_User'
         sys_admin.user_group = 'root'
         sys_admin.auth_method = 'local'
         db.session.add(sys_admin)
         path = env.getenv('DOCKLET_LIB')
         subprocess.call([path + "/userinit.sh", username])
         db.session.commit()
     if not os.path.exists(fspath + "/global/sys/quota"):
         groupfile = open(fspath + "/global/sys/quota", 'w')
         groups = []
         groups.append({
             'name': 'root',
             'quotas': {
                 'cpu': '100000',
                 'disk': '2000',
                 'memory': '2000',
                 'image': '10',
                 'idletime': '24',
                 'network': '8'
             }
         })
         groups.append({
             'name': 'admin',
             'quotas': {
                 'cpu': '100000',
                 'disk': '2000',
                 'memory': '2000',
                 'image': '10',
                 'idletime': '24',
                 'network': '8'
             }
         })
         groups.append({
             'name': 'primary',
             'quotas': {
                 'cpu': '100000',
                 'disk': '2000',
                 'memory': '2000',
                 'image': '10',
                 'idletime': '24',
                 'network': '8'
             }
         })
         groups.append({
             'name': 'fundation',
             'quotas': {
                 'cpu': '100000',
                 'disk': '2000',
                 'memory': '2000',
                 'image': '10',
                 'idletime': '24',
                 'network': '8'
             }
         })
         groupfile.write(json.dumps(groups))
         groupfile.close()
Exemplo n.º 5
0
 def __init__(self, username='******', password=None):
     '''
     Try to create the database when there is none
     initialize 'root' user and 'root' & 'primary' group
     '''
     try:
         User.query.all()
     except:
         db.create_all()
         if password == None:
             #set a random password
             password = os.urandom(16)
             password = b64encode(password).decode('utf-8')
             fsdir = env.getenv('FS_PREFIX')
             f = open(fsdir + '/local/generated_password.txt', 'w')
             f.write("User=%s\nPass=%s\n" % (username, password))
             f.close()
         sys_admin = User(
             username,
             hashlib.sha512(password.encode('utf-8')).hexdigest())
         sys_admin.status = 'normal'
         sys_admin.nickname = 'root'
         sys_admin.description = 'Root_User'
         sys_admin.user_group = 'root'
         sys_admin.auth_method = 'local'
         db.session.add(sys_admin)
         path = env.getenv('DOCKLET_LIB')
         subprocess.call([path + "/userinit.sh", username])
         db.session.commit()
     if not os.path.exists(fspath + "/global/sys/quota"):
         groupfile = open(fspath + "/global/sys/quota", 'w')
         groups = []
         groups.append({
             'name': 'root',
             'quotas': {
                 'cpu': '4',
                 'disk': '2000',
                 'data': '100',
                 'memory': '2000',
                 'image': '10',
                 'idletime': '24',
                 'vnode': '8'
             }
         })
         groups.append({
             'name': 'admin',
             'quotas': {
                 'cpu': '4',
                 'disk': '2000',
                 'data': '100',
                 'memory': '2000',
                 'image': '10',
                 'idletime': '24',
                 'vnode': '8'
             }
         })
         groups.append({
             'name': 'primary',
             'quotas': {
                 'cpu': '4',
                 'disk': '2000',
                 'data': '100',
                 'memory': '2000',
                 'image': '10',
                 'idletime': '24',
                 'vnode': '8'
             }
         })
         groups.append({
             'name': 'foundation',
             'quotas': {
                 'cpu': '4',
                 'disk': '2000',
                 'data': '100',
                 'memory': '2000',
                 'image': '10',
                 'idletime': '24',
                 'vnode': '8'
             }
         })
         groupfile.write(json.dumps(groups))
         groupfile.close()
     if not os.path.exists(fspath + "/global/sys/quotainfo"):
         quotafile = open(fspath + "/global/sys/quotainfo", 'w')
         quotas = {}
         quotas['default'] = 'foundation'
         quotas['quotainfo'] = []
         quotas['quotainfo'].append({
             'name':
             'cpu',
             'hint':
             'the cpu quota, number of cores, e.g. 4'
         })
         quotas['quotainfo'].append({
             'name':
             'memory',
             'hint':
             'the memory quota, number of MB , e.g. 4000'
         })
         quotas['quotainfo'].append({
             'name':
             'disk',
             'hint':
             'the disk quota, number of MB, e.g. 4000'
         })
         quotas['quotainfo'].append({
             'name':
             'data',
             'hint':
             'the quota of data space, number of GB, e.g. 100'
         })
         quotas['quotainfo'].append({
             'name':
             'image',
             'hint':
             'how many images the user can save, e.g. 10'
         })
         quotas['quotainfo'].append({
             'name':
             'idletime',
             'hint':
             'will stop cluster after idletime, number of hours, e.g. 24'
         })
         quotas['quotainfo'].append({
             'name':
             'vnode',
             'hint':
             'how many containers the user can have, e.g. 8'
         })
         quotafile.write(json.dumps(quotas))
         quotafile.close()