Beispiel #1
0
def login(user, password):
    user = str(user)
    pwd = get_md5(str(password))
    addr = get_frontend()
    rpcclient = RPCClient(addr, FRONTEND_PORT)
    uid, key = rpcclient.request('login', user=user, pwd=pwd)
    return (str(uid), str(key))
Beispiel #2
0
 def install(self, uid, package, version, typ):
     self._print('start to install')
     try:
         if SHOW_TIME:
             start_time = datetime.utcnow()
         addr = self._get_installer(uid)
         rpcclient = RPCClient(addr, INSTALLER_PORT)
         res = rpcclient.request('install', uid=uid, package=package, version=version, typ=typ)
         if not res:
             show_error(self, 'failed to install')
             return
         if typ == APP:
             addr = self._get_recorder(package)
             rpcclient = RPCClient(addr, RECORDER_PORT)
             info = rpcclient.request('install', package=package)
             if not info:
                 show_error(self, 'failed to install, invalid update install table')
                 return
         if SHOW_TIME:
             self._print('install, time=%d sec' % (datetime.utcnow() - start_time).seconds)
         if DEBUG:
             self._install_cnt += 1
             self._print('install, count=%d' % self._install_cnt)
         return res
     except:
         show_error(self, 'failed to install')
Beispiel #3
0
def login(user, password):
    user = str(user)
    pwd = get_md5(str(password))
    addr = get_frontend()
    rpcclient = RPCClient(addr, FRONTEND_PORT)
    uid, key = rpcclient.request('login', user=user, pwd=pwd)
    return (str(uid), str(key))
Beispiel #4
0
 def register(self, user, password, email):
     self._print('register starts')
     self._lock.acquire()
     try:
         if SHOW_TIME:
             start_time = datetime.utcnow()
         pwd = get_md5(password)
         addr = self._get_user_backend(user)
         rpcclient = RPCClient(addr, BACKEND_PORT)
         res = rpcclient.request('register',
                                 user=user,
                                 pwd=pwd,
                                 email=email)
         if SHOW_TIME:
             self._print('register , time=%d sec' %
                         (datetime.utcnow() - start_time).seconds)
         if res:
             if DEBUG:
                 self._register_cnt += 1
                 self._print('register, count=%d' % self._register_cnt)
             return True
         else:
             show_error(self, 'failed to register %s' % str(user))
             return False
     finally:
         self._lock.release()
Beispiel #5
0
def install(uid, package, version, typ):
    addr = get_frontend()
    rpcclient = RPCClient(addr, FRONTEND_PORT)
    ret = rpcclient.request('install', uid=uid, package=package, version=version, typ=typ)
    if not ret:
        log_err('util', 'failed to install, uid=%s, package=%s, version=%s, typ=%s' % (str(uid), str(package), str(version), str(typ)))
        return
    return ret
Beispiel #6
0
def add_installer(allocator, installer):
    log_debug('manage', 'add_installer, allocator=%s' % str(allocator))
    rpcclient = RPCClient(allocator, ALLOCATOR_PORT)
    res = rpcclient.request('add_installer', addr=installer)
    if res:
        log_debug('manage', 'add_installer, installer=%s' % str(installer))
        return True
    return False
Beispiel #7
0
 def has_package(self, uid, package, typ):
     self._print('has_package, package=%s' % str(package))
     addr = self._get_installer(uid)
     rpcclient = RPCClient(addr, INSTALLER_PORT)
     return rpcclient.request('has_package',
                              uid=uid,
                              package=package,
                              typ=typ)
Beispiel #8
0
 def has_package(self, uid, package):
     self._print('has_package starts , package=%s' % str(package))
     addr = self._get_backend()
     rpcclient = RPCClient(addr, BACKEND_PORT)
     res = rpcclient.request('has_package', uid=uid, package=package, typ=APP)
     if res:
         return True
     return False
Beispiel #9
0
 def _alloc_installer(self, uid):
     self._print('alloc_installer->uid=%s' % str(uid))
     addr = self._get_allocator(uid)
     rpcclient = RPCClient(addr, ALLOCATOR_PORT)
     if rpcclient.request('alloc_installer', uid=uid):
         return True
     else:
         show_error(self, 'failed to allocate installer')
         return False
Beispiel #10
0
 def _alloc_installer(self, uid):
     self._print('alloc_installer->uid=%s' % str(uid))
     addr = self._get_allocator(uid)
     rpcclient = RPCClient(addr, ALLOCATOR_PORT)
     if  rpcclient.request('alloc_installer', uid=uid):
         return True
     else:
         show_error(self, 'failed to allocate installer')
         return False
Beispiel #11
0
Datei: util.py Projekt: tx626/dpm
def uninstall(uid, package, typ):
    addr = _get_frontend()
    rpcclient = RPCClient(addr, FRONTEND_PORT)
    ret = rpcclient.request('uninstall', uid=uid, package=package, typ=typ)
    if not ret:
        log_err(
            'util', 'failed to uninstall, uid=%s, package=%s, typ=%s' %
            (str(uid), str(package), str(typ)))
        return
    return ret
Beispiel #12
0
 def _update(self, uid, category, package, title, description):
     self._print('update, cat=%s, desc=%s' %
                 (str(category), str(description)))
     addr = self._get_recorder(package)
     rpcclient = RPCClient(addr, RECORDER_PORT)
     return rpcclient.request('upload',
                              uid=uid,
                              category=category,
                              package=package,
                              title=title,
                              description=description)
Beispiel #13
0
 def has_package(self, uid, package):
     self._print('has_package starts , package=%s' % str(package))
     addr = self._get_backend()
     rpcclient = RPCClient(addr, BACKEND_PORT)
     res = rpcclient.request('has_package',
                             uid=uid,
                             package=package,
                             typ=APP)
     if res:
         return True
     return False
Beispiel #14
0
 def install(self, uid, package, version):
     addr = self._get_repo(package)
     rpcclient = RPCClient(addr, REPOSITORY_PORT)
     if not version:
         version = rpcclient.request("version", package=package)
         if not version:
             show_error(self, "failed to install, invalid version, uid=%s, package=%s" % (uid, package))
             return
     ret = rpcclient.request("download", package=package, version=version)
     self._print("finished installing driver %s, version=%s" % (package, version))
     return ret
Beispiel #15
0
 def uninstall(self, uid, package, typ):
     self._print('start to uninstall')
     addr = self._get_installer(uid)
     rpcclient = RPCClient(addr, INSTALLER_PORT)
     res = rpcclient.request('uninstall', uid=uid, package=package, typ=typ)
     if not res:
         show_error(self, 'failed to uninstall')
         return
     if DEBUG:
         self._uninstall_cnt += 1
         self._print('uninstall, count=%d' % self._uninstall_cnt)
     return res
Beispiel #16
0
 def get_author(self, package):
     self._print('get_author starts, package=%s' % str(package))
     try:
         uid = self._recorder.get_uid(package)
         if uid:
             addr = self._get_backend()
             rpcclient = RPCClient(addr, BACKEND_PORT)
             name = rpcclient.request('get_name', uid=uid)
             if name:
                 return str(name)
     except:
         show_error(self, 'get_author failed')
Beispiel #17
0
 def uninstall(self, uid, package, typ):
     self._print('start to uninstall')
     addr = self._get_installer(uid)
     rpcclient = RPCClient(addr, INSTALLER_PORT)
     res = rpcclient.request('uninstall', uid=uid, package=package, typ=typ)
     if not res:
         show_error(self, 'failed to uninstall')
         return
     if DEBUG:
         self._uninstall_cnt += 1
         self._print('uninstall, count=%d' % self._uninstall_cnt)
     return res
Beispiel #18
0
 def get_author(self, package):
     self._print('get_author starts, package=%s' % str(package))
     try:
         uid = self._recorder.get_uid(package)
         if uid:
             addr = self._get_backend()
             rpcclient = RPCClient(addr, BACKEND_PORT)
             name = rpcclient.request('get_name', uid=uid)
             if name:
                 return str(name)
     except:
          show_error(self, 'get_author failed')
Beispiel #19
0
 def uninstall(self, uid, package):
     try:
         addr = self._get_backend()
         rpcclient = RPCClient(addr, BACKEND_PORT)
         res = rpcclient.request('uninstall', uid=uid, package=package, typ=APP)
         if not res:
             show_error(self, 'failed to uninstall, invalid return res')
             return
         if DEBUG:
             self._uninstall_cnt += 1
             self._print('uninstall, count=%d' % self._uninstall_cnt)
         return res
     except:
         show_error(self, 'failed to uninstall')
Beispiel #20
0
 def install(self, uid, package, version):
     addr = self._get_repo(package)
     rpcclient = RPCClient(addr, REPOSITORY_PORT)
     if not version:
         version = rpcclient.request('version', package=package)
         if not version:
             show_error(
                 self,
                 'failed to install, invalid version, uid=%s, package=%s' %
                 (uid, package))
             return
     ret = rpcclient.request('download', package=package, version=version)
     self._print('finished installing driver %s, version=%s' %
                 (package, version))
     return ret
Beispiel #21
0
def upload(path, uid, package, version, typ, key):
    zipfilename = '%s-%s.zip' % (str(package), str(version))
    zipfilepath = os.path.join('/tmp', zipfilename)
    zip_dir(path, zipfilepath)
    with open(zipfilepath) as f:
        buf = f.read()
    os.remove(zipfilepath)
    addr = get_frontend()
    rpcclient = RPCClient(addr, FRONTEND_PORT, uid, key)
    ret  = rpcclient.request('upload', uid=uid, package=package, version=version, buf=buf, typ=typ)
    if ret:
        return True
    else:
        log_err('util', 'failed to upload, uid=%s, package=%s, version=%s, typ=%s' % (str(uid), str(package), str(version), str(typ)))
        return False
Beispiel #22
0
 def get_installed_packages(self, uid):
     self._print('get_installed_packages starts')
     try:
         addr = self._get_backend()
         rpcclient = RPCClient(addr, BACKEND_PORT)
         res = rpcclient.request('get_installed_packages', uid=uid, typ=APP)
         if res:
             result = []
             for i in res:
                 result.append(str(i))
             return result
         else:
             return ''
     except:
         show_error(self, 'failed to get installed packages')
Beispiel #23
0
 def get_installed_packages(self, uid):
     self._print('get_installed_packages starts')
     try:
         addr = self._get_backend()
         rpcclient = RPCClient(addr, BACKEND_PORT)
         res = rpcclient.request('get_installed_packages', uid=uid, typ=APP)
         if res:
             result = []
             for i in res:
                 result.append(str(i))
             return result
         else:
             return ''
     except:
         show_error(self, 'failed to get installed packages')
Beispiel #24
0
 def _get_installer(self, uid):
     self._print('start to get instsaller addr')
     try:
         cache = self._cache
         addr = cache.get(uid)
         if addr:
             return addr
         else:
             address = self._get_allocator(uid)
             rpcclient = RPCClient(address, ALLOCATOR_PORT)
             addr = rpcclient.request('get_installer', uid=uid)
             if len(cache) >= CACHE_MAX:
                 cache.popitem()
             cache.update({uid:addr})
             return addr
     except:
         show_error(self, 'failed to get instsaller addr')
Beispiel #25
0
 def _get_installer(self, uid):
     self._print('start to get instsaller addr')
     try:
         cache = self._cache
         addr = cache.get(uid)
         if addr:
             return addr
         else:
             address = self._get_allocator(uid)
             rpcclient = RPCClient(address, ALLOCATOR_PORT)
             addr = rpcclient.request('get_installer', uid=uid)
             if len(cache) >= CACHE_MAX:
                 cache.popitem()
             cache.update({uid: addr})
             return addr
     except:
         show_error(self, 'failed to get instsaller addr')
Beispiel #26
0
 def upload(self, uid, package, version, buf, typ):
     self._print('start to upload, uid=%s, package=%s' %
                 (str(uid), str(package)))
     try:
         if SHOW_TIME:
             start_time = datetime.utcnow()
         addr = self._get_repo(package)
         rpcclient = RPCClient(addr, REPOSITORY_PORT)
         res = rpcclient.request('upload',
                                 uid=uid,
                                 package=package,
                                 version=version,
                                 buf=buf)
         if SHOW_TIME:
             self._print('upload, upload package to repo, time=%d sec' %
                         (datetime.utcnow() - start_time).seconds)
             start_time = datetime.utcnow()
         if not res:
             show_error(
                 self, '%s failed to upload %s to repo' %
                 (str(uid), str(package)))
             return
         if typ == APP:
             cat, title, desc = self._sandbox.evaluate(OP_SCAN, buf)
             if not cat or not title or not desc:
                 show_error(self, 'invalid package')
                 return
             cat = check_category(cat)
             if not cat:
                 show_error(self, 'invalid category')
                 return
             if SHOW_TIME:
                 self._print('upload, analyze yaml, time=%d sec' %
                             (datetime.utcnow() - start_time).seconds)
                 start_time = datetime.utcnow()
             res = self._update(uid, cat, package, title, desc)
         if res:
             if DEBUG:
                 self._upload_cnt += 1
                 self._print('upload, count=%d' % self._upload_cnt)
             if SHOW_TIME:
                 self._print('upload, update recorder, time=%d sec' %
                             (datetime.utcnow() - start_time).seconds)
             return res
     except:
         show_error(self, 'failed to upload')
Beispiel #27
0
 def uninstall(self, uid, package):
     try:
         addr = self._get_backend()
         rpcclient = RPCClient(addr, BACKEND_PORT)
         res = rpcclient.request('uninstall',
                                 uid=uid,
                                 package=package,
                                 typ=APP)
         if not res:
             show_error(self, 'failed to uninstall, invalid return res')
             return
         if DEBUG:
             self._uninstall_cnt += 1
             self._print('uninstall, count=%d' % self._uninstall_cnt)
         return res
     except:
         show_error(self, 'failed to uninstall')
Beispiel #28
0
 def login(self, user, password):
     self._print('login starts')
     try:
         if SHOW_TIME:
             start_time = datetime.utcnow()
         pwd = get_md5(password)
         addr = self._get_user_backend(user)
         rpcclient = RPCClient(addr, BACKEND_PORT)
         uid, key = rpcclient.request('login', user=user, pwd=pwd)
         if SHOW_TIME:
             self._print('login , time=%d sec' % (datetime.utcnow() - start_time).seconds)
         if uid and key:
             if DEBUG:
                 self._login_cnt += 1
                 self._print('login, count=%d' % self._login_cnt)
             return (uid, key)
     except:
         show_error(self, 'failed to login')
Beispiel #29
0
def install(uid, package, version, typ):
    addr = get_frontend()
    rpcclient = RPCClient(addr, FRONTEND_PORT)
    if typ == DRIVER:
        content = None
    ret = rpcclient.request('install',
                            uid=uid,
                            package=package,
                            version=version,
                            typ=typ,
                            content=content)
    if not ret:
        log_err(
            'util',
            'failed to install, uid=%s, package=%s, version=%s, typ=%s' %
            (str(uid), str(package), str(version), str(typ)))
        return
    return ret
Beispiel #30
0
 def install(self, uid, package, version, typ):
     self._print('install->package=%s' %str(package))
     try:
         if SHOW_TIME:
             start_time = datetime.utcnow()
         addr = self._get_backend()
         rpcclient = RPCClient(addr, BACKEND_PORT)
         info = rpcclient.request('install', uid=uid, package=package, version=version, typ=typ)
         if not info:
             show_error(self, 'failed to install, invalid return info')
             return
         if SHOW_TIME:
             self._print('install , time=%d sec' % (datetime.utcnow() - start_time).seconds)
         if DEBUG:
             self._install_cnt += 1
             self._print('install, count=%d' % self._install_cnt)
         return info
     except:
         show_error(self, 'failed to install')
Beispiel #31
0
 def login(self, user, password):
     self._print('login starts')
     try:
         if SHOW_TIME:
             start_time = datetime.utcnow()
         pwd = get_md5(password)
         addr = self._get_user_backend(user)
         rpcclient = RPCClient(addr, BACKEND_PORT)
         uid, key = rpcclient.request('login', user=user, pwd=pwd)
         if SHOW_TIME:
             self._print('login , time=%d sec' %
                         (datetime.utcnow() - start_time).seconds)
         if uid and key:
             if DEBUG:
                 self._login_cnt += 1
                 self._print('login, count=%d' % self._login_cnt)
             return (uid, key)
     except:
         show_error(self, 'failed to login')
Beispiel #32
0
def upload(path, uid, package, version, typ, key):
    content = dump_content(path)
    buf = zlib.compress(json.dumps(content))
    addr = get_frontend()
    rpcclient = RPCClient(addr, FRONTEND_PORT, uid, key)
    ret = rpcclient.request('upload',
                            uid=uid,
                            package=package,
                            version=version,
                            buf=buf,
                            typ=typ)
    if ret:
        return True
    else:
        log_err(
            'util',
            'failed to upload, uid=%s, package=%s, version=%s, typ=%s' %
            (str(uid), str(package), str(version), str(typ)))
        return False
Beispiel #33
0
 def install(self, uid, package, version, typ):
     self._print('start to install')
     try:
         if SHOW_TIME:
             start_time = datetime.utcnow()
         addr = self._get_installer(uid)
         rpcclient = RPCClient(addr, INSTALLER_PORT)
         res = rpcclient.request('install',
                                 uid=uid,
                                 package=package,
                                 version=version,
                                 typ=typ)
         if not res:
             show_error(self, 'failed to install')
             return
         if typ == APP:
             addr = self._get_recorder(package)
             rpcclient = RPCClient(addr, RECORDER_PORT)
             info = rpcclient.request('install', package=package)
             if not info:
                 show_error(
                     self,
                     'failed to install, invalid update install table')
                 return
         if SHOW_TIME:
             self._print('install, time=%d sec' %
                         (datetime.utcnow() - start_time).seconds)
         if DEBUG:
             self._install_cnt += 1
             self._print('install, count=%d' % self._install_cnt)
         return res
     except:
         show_error(self, 'failed to install')
Beispiel #34
0
 def register(self, user, password, email):
     self._print('register starts')
     self._lock.acquire()
     try:
         if SHOW_TIME:
             start_time = datetime.utcnow()
         pwd = get_md5(password)
         addr = self._get_user_backend(user)
         rpcclient = RPCClient(addr, BACKEND_PORT)
         res = rpcclient.request('register', user=user, pwd=pwd, email=email)
         if SHOW_TIME:
             self._print('register , time=%d sec' % (datetime.utcnow() - start_time).seconds)
         if res:
             if DEBUG:
                 self._register_cnt += 1
                 self._print('register, count=%d' % self._register_cnt)
             return True
         else:
             show_error(self, 'failed to register %s' % str(user))
             return False
     finally:
         self._lock.release()
Beispiel #35
0
Datei: util.py Projekt: tx626/dpm
def upload(path, uid, package, version, typ, key):
    zipfilename = get_filename(package, version)
    zipfilepath = os.path.join('/tmp', zipfilename)
    zip_dir(path, zipfilepath)
    with open(zipfilepath) as f:
        buf = f.read()
    os.remove(zipfilepath)
    addr = _get_frontend()
    rpcclient = RPCClient(addr, FRONTEND_PORT, uid, key)
    ret = rpcclient.request('upload',
                            uid=uid,
                            package=package,
                            version=version,
                            buf=buf,
                            typ=typ)
    if ret:
        return True
    else:
        log_err(
            'util',
            'failed to upload, uid=%s, package=%s, version=%s, typ=%s' %
            (str(uid), str(package), str(version), str(typ)))
        return False
Beispiel #36
0
 def install(self, uid, package, version, typ):
     self._print('install->package=%s' % str(package))
     try:
         if SHOW_TIME:
             start_time = datetime.utcnow()
         addr = self._get_backend()
         rpcclient = RPCClient(addr, BACKEND_PORT)
         info = rpcclient.request('install',
                                  uid=uid,
                                  package=package,
                                  version=version,
                                  typ=typ)
         if not info:
             show_error(self, 'failed to install, invalid return info')
             return
         if SHOW_TIME:
             self._print('install , time=%d sec' %
                         (datetime.utcnow() - start_time).seconds)
         if DEBUG:
             self._install_cnt += 1
             self._print('install, count=%d' % self._install_cnt)
         return info
     except:
         show_error(self, 'failed to install')
Beispiel #37
0
 def upload(self, uid, package, version, buf, typ):
     self._print('start to upload, uid=%s, package=%s' % (str(uid), str(package)))
     try:
         if SHOW_TIME:
             start_time = datetime.utcnow()
         addr = self._get_repo(package)
         rpcclient = RPCClient(addr, REPOSITORY_PORT)
         res = rpcclient.request('upload', uid=uid, package=package, version=version, buf=buf)
         if SHOW_TIME:
             self._print('upload, upload package to repo, time=%d sec' % (datetime.utcnow() - start_time).seconds)
             start_time = datetime.utcnow()
         if not res:
             show_error(self, '%s failed to upload %s to repo' % (str(uid), str(package)))
             return
         if typ == APP:
             cat, title, desc = self._sandbox.evaluate(OP_SCAN, buf)
             if not cat or not title or not desc:
                 show_error(self, 'invalid package')
                 return
             cat = check_category(cat)
             if not cat:
                 show_error(self, 'invalid category')
                 return
             if SHOW_TIME:
                 self._print('upload, analyze yaml, time=%d sec' % (datetime.utcnow() - start_time).seconds)
                 start_time = datetime.utcnow()
             res = self._update(uid, cat, package, title, desc)
         if res:
             if DEBUG:
                 self._upload_cnt += 1
                 self._print('upload, count=%d' % self._upload_cnt)
             if SHOW_TIME:
                 self._print('upload, update recorder, time=%d sec' % (datetime.utcnow() - start_time).seconds)
             return res
     except:
         show_error(self, 'failed to upload')
Beispiel #38
0
 def has_package(self, uid, package, typ):
     self._print('has_package, package=%s' % str(package))
     addr = self._get_installer(uid)
     rpcclient = RPCClient(addr, INSTALLER_PORT)
     return rpcclient.request('has_package', uid=uid, package=package, typ=typ)
Beispiel #39
0
 def get_installed_packages(self, uid, typ):
     self._print('start to get installed packages')
     addr = self._get_installer(uid)
     rpcclient = RPCClient(addr, INSTALLER_PORT)
     return rpcclient.request('get_packages', uid=uid, typ=typ)
Beispiel #40
0
 def get_installed_packages(self, uid, typ):
     self._print('start to get installed packages')
     addr = self._get_installer(uid)
     rpcclient = RPCClient(addr, INSTALLER_PORT)
     return rpcclient.request('get_packages', uid=uid, typ=typ)
Beispiel #41
0
 def _update(self, uid, category, package, title, description):
     self._print('update, cat=%s, desc=%s' % (str(category), str(description)))
     addr = self._get_recorder(package)
     rpcclient = RPCClient(addr, RECORDER_PORT)
     return rpcclient.request('upload', uid=uid, category=category, package=package, title=title, description=description)