def upload_appliance(fpath): fname = os.path.basename(fpath) fsize = os.stat(fpath).st_size fhash = _md5sum(fpath) old = db.query(Appliance).filter_by(checksum=fhash).count() if old: logging.warning(_('%s already exists in LuoYunCloud DB.') % fpath) return users = [ db.query(User).get(1), db.query(User).filter_by(username='******').first(), None ] for user in users: if user and _isadmin(user): break catalog = db.query(ApplianceCatalog).order_by(ApplianceCatalog.id).first() if user: r = _save_upfile(fpath, fhash) if r: dpath = os.path.join(appdir, 'appliance_%s' % fhash) if os.path.exists(dpath): logging.warning(_('%s already exists !') % dpath) else: logging.error(r) return else: logging.debug(_('Save appliance %s success.') % fpath) new = Appliance(name=fname.replace('.', ' '), user=user, filesize=fsize, checksum=fhash) new.isprivate = False new.isuseable = True new.islocked = False new.catalog_id = catalog.id db.add(new) db.commit() logging.debug( _('Insert appliance to DB success, owner is %s') % user.username) else: logging.error(_('Have not found admin user, please check DB !'))
def upload_appliance(fpath): fname = os.path.basename(fpath) fsize = os.stat(fpath).st_size fhash = _md5sum(fpath) old = db.query(Appliance).filter_by(checksum = fhash).count() if old: logging.warning(_('%s already exists in LuoYunCloud DB.') % fpath) return users = [ db.query(User).get(1), db.query(User).filter_by(username='******').first(), None ] for user in users: if user and _isadmin(user): break catalog = db.query(ApplianceCatalog).order_by(ApplianceCatalog.id).first() if user: r = _save_upfile(fpath, fhash) if r: dpath = os.path.join(appdir, 'appliance_%s' % fhash) if os.path.exists(dpath): logging.warning(_('%s already exists !') % dpath) else: logging.error(r) return else: logging.debug(_('Save appliance %s success.') % fpath) new = Appliance( name = fname.replace('.', ' '), user = user, filesize = fsize, checksum = fhash ) new.isprivate = False new.isuseable = True new.islocked = False new.catalog_id = catalog.id db.add(new) db.commit() logging.debug(_('Insert appliance to DB success, owner is %s') % user.username) else: logging.error(_('Have not found admin user, please check DB !'))
def default_value(db): from app.auth.models import Group, Permission, User from yweb.locale import LANGUAGES from app.language.models import Language # languages for L in LANGUAGES: lang = db.query(Language).filter_by(codename=L['codename']).first() if lang: continue lang = Language(name=L['name'], name_en=L['name_en'], codename=L['codename']) db.add(lang) # Permission for codename, name in settings.default_permission: p = db.query(Permission).filter_by(codename=codename).first() if p: continue p = Permission(codename=codename, name=name) db.add(p) # Group for name in settings.default_group: g = db.query(Group).filter_by(name=name).first() if g: continue g = Group(name=name, islocked=True) db.add(g) # User for username, password in settings.default_user: u = db.query(User).filter_by(username=username).first() if u: continue enc_password = enc_login_passwd(password) u = User(username=username, password=enc_password) db.add(u) # User Group for groupname, username in settings.default_user_group: u = db.query(User).filter_by(username=username).first() g = db.query(Group).filter_by(name=groupname).first() if u and (g not in u.groups): u.groups.append(g) # Group Permission for groupname, codename in settings.default_group_permission: g = db.query(Group).filter_by(name=groupname).first() p = db.query(Permission).filter_by(codename=codename).first() if p not in g.permissions: g.permissions.append(p) db.commit()
def default_value(db): from app.auth.models import Group, Permission, User from yweb.locale import LANGUAGES from app.language.models import Language # languages for L in LANGUAGES: lang = db.query(Language).filter_by(codename = L['codename']).first() if lang: continue lang = Language( name = L['name'], name_en = L['name_en'], codename = L['codename'] ) db.add(lang) # Permission for codename, name in settings.default_permission: p = db.query(Permission).filter_by(codename = codename).first() if p: continue p = Permission(codename = codename, name = name) db.add(p) # Group for name in settings.default_group: g = db.query(Group).filter_by(name=name).first() if g: continue g = Group(name = name, islocked = True) db.add(g) # User for username, password in settings.default_user: u = db.query(User).filter_by(username=username).first() if u: continue enc_password = enc_login_passwd(password) u = User(username = username, password = enc_password) db.add(u) # User Group for groupname, username in settings.default_user_group: u = db.query(User).filter_by(username=username).first() g = db.query(Group).filter_by(name=groupname).first() if u and (g not in u.groups): u.groups.append(g) # Group Permission for groupname, codename in settings.default_group_permission: g = db.query(Group).filter_by(name=groupname).first() p = db.query(Permission).filter_by(codename=codename).first() if p not in g.permissions: g.permissions.append(p) db.commit()
def default_value2(db): from app.site.models import SiteNav for T, L, N in [ [1, 61, '产品'], [1, 61, '解决方案'], [1, 61, '新闻'], [1, 61, '文档'], [1, 61, '下载'], [1, 14, 'Products'], [1, 14, 'Solutions'], [2, 14, 'News'], [1, 14, 'Docs'], [1, 14, 'Download'], ]: e = SiteNav(type=T, language_id=L, name=N) db.add(e) from app.site.models import SiteEntry for slug in ['contact', 'about', 'what-is-cloud']: E = SiteEntry(slug=slug) db.add(E) from app.cms.models import CMSCategory for name in [u'中文', 'English']: C = CMSCategory(name=name) db.add(C) db.commit()
def default_value2(db): from app.site.models import SiteNav for T, L, N in [ [1, 61, '产品'], [1, 61, '解决方案'], [1, 61, '新闻'], [1, 61, '文档'], [1, 61, '下载'], [1, 14, 'Products'], [1, 14, 'Solutions'], [2, 14, 'News'], [1, 14, 'Docs'], [1, 14, 'Download'], ]: e = SiteNav( type = T, language_id = L, name = N ) db.add(e) from app.site.models import SiteEntry for slug in ['contact', 'about', 'what-is-cloud']: E = SiteEntry(slug = slug) db.add(E) from app.cms.models import CMSCategory for name in [ u'中文', 'English' ]: C = CMSCategory(name = name) db.add(C) db.commit()
print "Just ommit." if ERROR or EXIST_ERROR: import sys sys.exit(1) if OK: print "The following ip->instance binding success:" for x, y in OK: newip = db.query(IPPool).filter_by(ip=x).first() newip.instance_id = y print " %s -> %s" % (x, y) db.commit() print "Done !" # insert new permission from app.auth.models import Permission if db.query(Permission).filter_by(codename="network.add").first(): print '"network.add" permission is exist already!' else: p = Permission("Can add another NIC configure", "network.add") db.add(p) db.commit() print 'Add "network.add" permission success.'
if EXIST_OK: print 'The following ip->instance binding is ok:' for x, y in EXIST_OK: print ' %s -> %s' % (x, y) print 'Just ommit.' if ERROR or EXIST_ERROR: import sys sys.exit(1) if OK: print 'The following ip->instance binding success:' for x, y in OK: newip = db.query(IPPool).filter_by(ip=x).first() newip.instance_id = y print ' %s -> %s' % (x, y) db.commit() print 'Done !' # insert new permission from app.auth.models import Permission if db.query(Permission).filter_by(codename='network.add').first(): print '"network.add" permission is exist already!' else: p = Permission('Can add another NIC configure', 'network.add') db.add(p) db.commit() print 'Add "network.add" permission success.'