Beispiel #1
0
    def __init__(self, taskmgr):
        logger.info("Init jobmgr...")
        try:
            Batchjob.query.all()
        except:
            db.create_all(bind='__all__')
        self.job_map = {}
        self.taskmgr = taskmgr
        self.fspath = env.getenv('FS_PREFIX')
        self.lock = threading.Lock()
        self.userpoint = "http://" + env.getenv('USER_IP') + ":" + str(env.getenv('USER_PORT'))
        self.auth_key = env.getenv('AUTH_KEY')

        self.recover_jobs()
Beispiel #2
0
    def __init__(self, nodemgr, networkmgr, etcdclient, addr, mode, distributedgw='False'):
        self.mode = mode
        self.distributedgw = distributedgw
        self.nodemgr = nodemgr
        self.imgmgr = imagemgr.ImageMgr()
        self.networkmgr = networkmgr
        self.addr = addr
        self.etcd = etcdclient
        self.defaultsize = env.getenv("CLUSTER_SIZE")
        self.fspath = env.getenv("FS_PREFIX")
        self.clusterid_locks = threading.Lock()

        # check database
        try:
            Container.query.all()
            PortMapping.query.all()
            VCluster.query.all()
        except:
            # create database
            db.create_all()

        logger.info ("vcluster start on %s" % (self.addr))
        if self.mode == 'new':
            logger.info ("starting in new mode on %s" % (self.addr))
            # check if all clusters data are deleted in httprest.py
            clean = True
            usersdir = self.fspath+"/global/users/"
            vclusters = VCluster.query.all()
            if len(vclusters) != 0:
                clean = False
            for user in os.listdir(usersdir):
                if len(os.listdir(usersdir+user+"/hosts")) > 0:
                    clean = False
            if not clean:
                logger.error ("clusters files not clean, start failed")
                sys.exit(1)
        elif self.mode == "recovery":
            logger.info ("starting in recovery mode on %s" % (self.addr))
            self.recover_allclusters()
        else:
            logger.error ("not supported mode:%s" % self.mode)
            sys.exit(1)
Beispiel #3
0
    def __init__(self, nodemgr, networkmgr, etcdclient, addr, mode, distributedgw='False'):
        self.mode = mode
        self.distributedgw = distributedgw
        self.nodemgr = nodemgr
        self.imgmgr = imagemgr.ImageMgr()
        self.networkmgr = networkmgr
        self.addr = addr
        self.etcd = etcdclient
        self.defaultsize = env.getenv("CLUSTER_SIZE")
        self.fspath = env.getenv("FS_PREFIX")
        self.clusterid_locks = threading.Lock()

        # check database
        try:
            Container.query.all()
            PortMapping.query.all()
            VCluster.query.all()
        except:
            # create database
            db.create_all()

        logger.info ("vcluster start on %s" % (self.addr))
        if self.mode == 'new':
            logger.info ("starting in new mode on %s" % (self.addr))
            # check if all clusters data are deleted in httprest.py
            clean = True
            usersdir = self.fspath+"/global/users/"
            vclusters = VCluster.query.all()
            if len(vclusters) != 0:
                clean = False
            for user in os.listdir(usersdir):
                if len(os.listdir(usersdir+user+"/hosts")) > 0:
                    clean = False
            if not clean:
                logger.error ("clusters files not clean, start failed")
                sys.exit(1)
        elif self.mode == "recovery":
            logger.info ("starting in recovery mode on %s" % (self.addr))
            self.recover_allclusters()
        else:
            logger.error ("not supported mode:%s" % self.mode)
            sys.exit(1)
Beispiel #4
0
 def __init__(self):
     logger.info("Notification Manager init...")
     try:
         Notification.query.all()
     except:
         db.create_all()
     try:
         NotificationGroups.query.all()
     except:
         db.create_all()
     try:
         UserNotificationPair.query.all()
     except:
         db.create_all()
     logger.info("Notification Manager init done!")
 def __init__(self):
     logger.info("Notification Manager init...")
     try:
         Notification.query.all()
     except:
         db.create_all()
     try:
         NotificationGroups.query.all()
     except:
         db.create_all()
     try:
         UserNotificationPair.query.all()
     except:
         db.create_all()
     logger.info("Notification Manager init done!")
 def __init__(self):
     # create database
     try:
         ApplyMsg.query.all()
     except:
         db.create_all()
Beispiel #7
0
 def __init__(self):
     try:
         VNode.query.all()
         History.query.all()
     except:
         db.create_all(bind='__all__')
Beispiel #8
0
 def __init__(self):
     # create database
     try:
         ApplyMsg.query.all()
     except:
         db.create_all()
Beispiel #9
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()
            LoginMsg.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 + "/master/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',
                    'portmapping': '8',
                    'input_rate_limit': '10000',
                    'output_rate_limit': '10000'
                }
            })
            groups.append({
                'name': 'admin',
                'quotas': {
                    'cpu': '4',
                    'disk': '2000',
                    'data': '100',
                    'memory': '2000',
                    'image': '10',
                    'idletime': '24',
                    'vnode': '8',
                    'portmapping': '8',
                    'input_rate_limit': '10000',
                    'output_rate_limit': '10000'
                }
            })
            groups.append({
                'name': 'primary',
                'quotas': {
                    'cpu': '4',
                    'disk': '2000',
                    'data': '100',
                    'memory': '2000',
                    'image': '10',
                    'idletime': '24',
                    'vnode': '8',
                    'portmapping': '8',
                    'input_rate_limit': '10000',
                    'output_rate_limit': '10000'
                }
            })
            groups.append({
                'name': 'foundation',
                'quotas': {
                    'cpu': '4',
                    'disk': '2000',
                    'data': '100',
                    'memory': '2000',
                    'image': '10',
                    'idletime': '24',
                    'vnode': '8',
                    'portmapping': '8',
                    'input_rate_limit': '10000',
                    'output_rate_limit': '10000'
                }
            })
            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'
            })
            quotas['quotainfo'].append({
                'name':
                'portmapping',
                'hint':
                'how many ports the user can map, e.g. 8'
            })
            quotas['quotainfo'].append({
                'name':
                'input_rate_limit',
                'hint':
                'the ingress speed of the network, number of kbps. 0 means the rate are unlimited.'
            })
            quotas['quotainfo'].append({
                'name':
                'output_rate_limit',
                'hint':
                'the egress speed of the network, number of kbps. 0 means the rate are unlimited.'
            })
            quotafile.write(json.dumps(quotas))
            quotafile.close()
        if not os.path.exists(fspath + "/global/sys/lxc.default"):
            settingfile = open(fspath + "/global/sys/lxc.default", 'w')
            settings = {}
            settings['cpu'] = "2"
            settings["memory"] = "2000"
            settings["disk"] = "2000"
            settingfile.write(json.dumps(settings))
            settingfile.close()

        try:
            UserUsage.query.all()
        except:
            db.create_all()
Beispiel #10
0
 def __init__(self):
     try:
         VNode.query.all()
         History.query.all()
     except:
         db.create_all(bind='__all__')
Beispiel #11
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+"/master/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', 'portmapping': '8', 'input_rate_limit':'10000', 'output_rate_limit':'10000'}})
            groups.append({'name':'admin', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8', 'portmapping': '8', 'input_rate_limit':'10000', 'output_rate_limit':'10000'}})
            groups.append({'name':'primary', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8', 'portmapping': '8', 'input_rate_limit':'10000', 'output_rate_limit':'10000'}})
            groups.append({'name':'foundation', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8', 'portmapping': '8', 'input_rate_limit':'10000', 'output_rate_limit':'10000'}})
            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'})
            quotas['quotainfo'].append({'name':'portmapping', 'hint':'how many ports the user can map, e.g. 8'})
            quotas['quotainfo'].append({'name':'input_rate_limit', 'hint':'the ingress speed of the network, number of kbps. 0 means the rate are unlimited.'})
            quotas['quotainfo'].append({'name':'output_rate_limit', 'hint':'the egress speed of the network, number of kbps. 0 means the rate are unlimited.'})
            quotafile.write(json.dumps(quotas))
            quotafile.close()
        if not os.path.exists(fspath+"/global/sys/lxc.default"):
            settingfile = open(fspath+"/global/sys/lxc.default", 'w')
            settings = {}
            settings['cpu'] = "2"
            settings["memory"] = "2000"
            settings["disk"] = "2000"
            settingfile.write(json.dumps(settings))
            settingfile.close()

        try:
            UserUsage.query.all()
            LoginMsg.query.all()
            LoginFailMsg.query.all()
        except:
            db.create_all()