def group_manage_view(request): #メニューを設定 request.session['ss_sys_menu'] = "access_adm" request.session['ss_sys_useradm_menu'] = "group_list_view" #セッションからログインユーザ情報を取得する login_user = request.session['ss_usr_user'] refresh = True if 'resource_refresh' in request.POST and request.POST['resource_refresh'] == 'no': refresh = False # get data if refresh or not 'groups' in request.session: euca_db = EucalyptusDB() account = login_user.account_number group_id = None #request.session['users'] = euca_db.getEucalyptusUser(account, login_user.id) request.session['groups'] = euca_db.group_list2(group_id,account) #request.session['groups'] = euca_db.getGroupList(account) # request.session['users'] = euca_db.getEucalyptusUser() group_manage_list = request.session['groups'] logger.info('グループ管理画面表示') return render_to_response('group_manage_view.html', {'group_manage_list': group_manage_list}, context_instance=RequestContext(request))
def volume_delete(request, vol_id): resource_admin_auth(request) acc_num = None volume = None for vol in request.session['res_volumes']: if vol.volumeid == vol_id: acc_num = vol.accountnumber volume = vol if acc_num: euca_db = EucalyptusDB() usrList = euca_db.getEucalyptusUser() errors = [] for usr in usrList: if usr.account_number == acc_num and usr.accesskey: try: get_euca_info = GetEucalyptusInfo(usr) get_euca_info.delete_volume(vol_id) volume.status = "deleting" request.session.modified = True except Exception, ex: # Eucalyptusエラー errors.append(euca_common.get_euca_error_msg('%s' % ex)) logger.warn(errors)
def user_manage_view(request): #メニューを「テンプレート」に設定 request.session['ss_sys_menu'] = "access_adm" request.session['ss_sys_useradm_menu'] = "user_list_view" #セッションからログインユーザ情報を取得する login_user = request.session['ss_usr_user'] refresh = True if 'resource_refresh' in request.POST and request.POST['resource_refresh'] == 'no': refresh = False # get data if refresh or not 'users' in request.session: euca_db = EucalyptusDB() account = login_user.account_number #request.session['users'] = euca_db.getEucalyptusUser(account, login_user.id) request.session['users'] = euca_db.getUserListInAccount(account) # request.session['users'] = euca_db.getEucalyptusUser() user_manage_list = request.session['users'] #user_manage_list = sort_user(request.session['users'],sortname,sortpath,sortgroup,sortacc) logger.info('ユーザー管理画面表示') return render_to_response('user_manage_view.html', {'user_manage_list': user_manage_list}, context_instance=RequestContext(request))
def volume_delete_db(request, vol_id): resource_admin_auth(request) vol = getVolumeFromId(request, vol_id) if vol.accountid: return volume_delete(request, vol_id) if vol and vol.status == "file not found": db = EucalyptusDB() db.deleteVolume(vol_id) vol.status = "deleting" request.session.modified = True return volume_view(request)
def group_info(request): #メニューを設定 logger.info('グループ詳細画面表示') request.session['ss_sys_menu'] = "access_adm" request.session['ss_sys_useradm_menu'] = "group_list_view" #セッションからログインユーザ情報を取得する login_user = request.session['ss_usr_user'] if 'selected_group' in request.POST: selected_group = request.POST['selected_group'] else: selected_group = "all" logger.info('グループ詳細画面表示 %s' % str(selected_group)) refresh = True if 'resource_refresh' in request.POST and request.POST['resource_refresh'] == 'no': refresh = False logger.info('グループ詳細情報取得') # get data #if refresh or not 'groups' in request.session: euca_db = EucalyptusDB() account = login_user.account_number group_id = selected_group request.session['group_user_list'] = euca_db.getGroupUserList(group_id) #request.session['selected_group_info'] = euca_db.group_list2(group_id,account) request.session['selected_group_info'] = Group.objects.filter(group_id=selected_group) logger.info('グループ詳細情報取得完了') group_infom = request.session['selected_group_info'] group_user_list = request.session['group_user_list'] logger.info('グループ情報画面表示') logger.info('グループ詳細画面表示 %s' % str(selected_group)) logger.info('グループ詳細画面表示 %s' % group_infom[0]) logger.info('グループ詳細画面表示 %s' % group_user_list) return render_to_response('group_info.html', {'selected_group':selected_group, 'group_info': group_infom, 'group_user_list':group_user_list}, context_instance=RequestContext(request))
def getData(request, login_user): logger.debug("getData begin") tool = GetEucalyptusInfoBy2ool() request.session['res_instances'] = tool.getInstanceListVerbose(login_user) request.session['res_volumes'] = tool.getVolumeListVerbose(login_user) request.session['res_snapshots'] = tool.getSnapshotListVerbose(login_user) request.session['res_nodes'] = tool.getNodeList(login_user) request.session['res_frontends'] = tool.getServices(login_user) request.session['cloud_properties'] = tool.getCloudProperties(login_user) eucadb = EucalyptusDB() acc_list = eucadb.getAccountList() acc_info_list = [] for acc in acc_list: acc_info = Account_information() acc_info.accountname = acc.name acc_info.accountid = acc.id_number acc_info_list.append(acc_info) request.session['res_accounts'] = acc_info_list boto = GetEucalyptusInfo() request.session['res_vmtypes'] = boto.get_vmtypes(login_user.db_user) eucaMetaDB = EucalyptusMetadataDB() volumeOwner = eucaMetaDB.getVolumeOwnerList() relate_frontends(request) relate_volume(request, volumeOwner) relate_snapshot(request) relate_instance(request) relate_account(request) relate_node(request) request.session.modified = True request.session['res_last_update'] = datetime.now() logger.debug("getData end")
db_group.account_name = login_user.account_id db_group.account_id = login_user.account_number db_group.group_pol = form.cleaned_data['group_polset'] db_group.group_desc = form.cleaned_data['group_desc'] db_group.save() logger.debug('グループのcooalaDBへの登録完了') #updateVolume(db_volume) """ グループリスト画面表示 """ euca_db = EucalyptusDB() account = login_user.account_number #request.session['users'] = euca_db.getEucalyptusUser(account, login_user.id) request.session['groups'] = euca_db.group_list2(account) #request.session['groups'] = euca_db.getGroupList(account) # request.session['users'] = euca_db.getEucalyptusUser() group_manage_list = request.session['groups'] logger.info('グループ管理画面表示') return render_to_response('group_manage_view.html', {'group_manage_list': group_manage_list}, context_instance=RequestContext(request))
def top(request): """レポートメニューの初期表示""" logger.info('レポート表示') #メニューを「IPアドレス」に設定 request.session['ss_sys_menu'] = "dashboard" auth_db = EucalyptusDB() #ポイントの表示/非表示 if not 'pointdisplay' in request.POST: request.session['pointdisplay'] = "no" logger.debug("pointdisplay undefined") else: request.session['pointdisplay'] = request.POST['pointdisplay'] logger.debug("pointdisplay : %s" % request.POST['pointdisplay']) #セッションからログインユーザ情報を取得する login_user = request.session['ss_usr_user'] if not 'account_selected' in request.POST: account = login_user.account_number user = auth_db.getUserInternalId(account, login_user.id) else: account = request.POST['account_selected'] if not 'user_selected' in request.POST: user = "******" else: user = request.POST['user_selected'] request.session['account_selected'] = account logger.debug("selected account : %s" % account) request.session['user_selected'] = user logger.debug("selected user : %s" % user) #レポート参照権限の設定(TODO: policy参照の必要) request.session['account_admin'] = "no" request.session['user_admin'] = "no" if login_user.id == "admin": request.session['user_admin'] = "yes" if login_user.account_id == "eucalyptus": request.session['account_admin'] = "yes" db = EucalyptusReportingDB() if not 'month_selected' in request.POST: month = datetime.datetime.now().strftime(u"%Y-%m") else: month = request.POST['month_selected'] request.session['month_selected'] = month logger.debug("selected month : %s" % month) (request.session['ss_repo_instancelist'], request.session['ss_sum_instance']) = db.getInstanceList( user, account, month) # volume report: volume_report = [] account_list = auth_db.getAccountList() if account == "all": for a in account_list: user_list = auth_db.getUserListInAccount(a.id_number) for u in user_list: volume_report.append( db.getVolumeHistory(u.user_internal_id, u.user_id, a.name, month)) else: if user == "all": user_list = auth_db.getUserListInAccount(account) for u in user_list: volume_report.append( db.getVolumeHistory(u.user_internal_id, u.user_id, "none", month)) else: volume_report.append( db.getVolumeHistory(user, "none", "none", month)) request.session['ss_repo_volumehistory'] = volume_report volume_sum = Charge_Volume_Model() for r in volume_report: volume_sum.ebs_gigabytes_by_hours += r.ebs_gigabytes_by_hours volume_sum.snapshot_gigabytes_by_hours += r.snapshot_gigabytes_by_hours # walrus report: walrus_report = [] account_list = auth_db.getAccountList() if account == "all": for a in account_list: user_list = auth_db.getUserListInAccount(a.id_number) for u in user_list: walrus_report.append( db.getWalrusHistory(u.user_internal_id, u.user_id, a.name, month)) else: if user == "all": user_list = auth_db.getUserListInAccount(account) for u in user_list: walrus_report.append( db.getWalrusHistory(u.user_internal_id, u.user_id, "none", month)) else: walrus_report.append( db.getWalrusHistory(user, "none", "none", month)) request.session['ss_repo_walrushistory'] = walrus_report walrus_sum = Charge_Walrus_Model() for r in walrus_report: walrus_sum.walrus_gigabytes_by_hours += r.walrus_gigabytes_by_hours at = Charge.objects.get(charge="デフォルト時間課金") charge = Charge_Model() charge.bootups = at.boot * request.session['ss_sum_instance'].bootups charge.cores = at.cpu * request.session['ss_sum_instance'].cores_by_hours charge.mem = at.mem * request.session[ 'ss_sum_instance'].memgigabytes_by_hours charge.disk_io = at.disk * request.session[ 'ss_sum_instance'].disk_io_gigabytes charge.net_io = at.net * request.session[ 'ss_sum_instance'].network_io_gigabytes charge.ebs = at.ebs * volume_sum.ebs_gigabytes_by_hours charge.snapshot = at.snapshot * volume_sum.snapshot_gigabytes_by_hours charge.walrus = at.walrus * walrus_sum.walrus_gigabytes_by_hours request.session['ss_sum_volume'] = volume_sum request.session['ss_sum_walrus'] = walrus_sum request.session['ss_charge_at'] = at request.session['ss_charge'] = charge request.session['ss_month_list'] = db.getMonthList() request.session['ss_account_list'] = account_list if account != "all": request.session['ss_user_list'] = auth_db.getUserListInAccount(account) logger.info('ユーザリスト:%s' % len(request.session['ss_user_list'])) #Eucalyptus基盤へのアクセサを生成する #get_euca_info=GetEucalyptusInfo(login_user) logger.info('レポート表示 完了') return render_to_response('report.html', {}, context_instance=RequestContext(request))
def dologin(request): logger.info('ログイン処理実行') message = 'アカウントID、ユーザーID、またはパスワードが違います。' form = LoginTextForm(request.POST) if form.is_valid(): try: account_id = form.cleaned_data['account_id'] user_id = form.cleaned_data['user_id'] password = form.cleaned_data['user_password'] logger.debug('account_id=%s, user_id=%s' % (account_id, user_id)) if not EucalyptusHttpAuthenticator.get_session_id_by_global_setting( account_id, user_id, password): logger.error('eucalyptus frontend auth error :%s' % user_id) raise StandardError('eucalyptus frontend auth error : ' + user_id) request.session['newuser'] = '******' if not User.objects.filter(user_id=user_id, account_id=account_id): logger.warn('user not imported to koala :%s' % user_id) db = EucalyptusDB() user_list = db.getEucalyptusUser() found = False for user in user_list: if user.user_id == user_id and user.account_id == account_id: if not user.accesskey: message = "このユーザにはアクセスキーが発行されていません。" raise StandardError('no accesskey error : ' + user_id) user.name = user_id + "@" + account_id if user_id == "admin": user.permission = "11111111" user.admin = True else: if not User.objects.filter(user_id="admin", account_id=account_id): message = "アカウント管理者(admin)の登録がありません。" raise StandardError( 'no account admin error : ' + account_id) found = True logger.info('user added to koala :' + user.name) batch = BatchCommon() if not batch.createKeyPair(user): message = "キーペアを作成できません" raise StandardError('creating keypair error : ' + user.name) if user_id == "admin": batch.setSecurityGroup(user) logger.info( 'mykey created (renewed) for account:' + user.account_id) user.save() request.session['newuser'] = '******' break if not found: raise StandardError('cannot imported user to koala : ' + user_id) login_user = User_Model( User.objects.get(user_id=user_id, account_id=account_id)) logger.debug('login_user=%s' % login_user.name) request.session['ss_usr_user'] = login_user dateStr = dateformat.format(datetime.now(), 'Y年n月d日') request.session['ss_usr_lastlogin'] = dateStr if login_user.resource_admin: logger.debug("リソース管理者としてログイン") else: logger.debug("ユーザとしてログイン") logger.info('ログイン 完了') ver = CocuumaVersion() request.session['isIE'] = ( request.META['HTTP_USER_AGENT'].upper().find("MSIE") >= 0) logger.info('Cocuuma version %s / revision %s' % (ver.getVersion(), ver.getLocalRevision())) return HttpResponseRedirect('/dashboard/') except Exception, e: logger.debug('Login Exception: %s' % e) logger.warn('ログイン失敗')