本文整理汇总了Python中CadVlan.Auth.AuthSession.AuthSession类的典型用法代码示例。如果您正苦于以下问题:Python AuthSession类的具体用法?Python AuthSession怎么用?Python AuthSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AuthSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search_list
def search_list(request):
try:
lists = dict()
lists['delete_form'] = DeleteForm()
# Get user
auth = AuthSession(request.session)
client = auth.get_clientFactory()
# Get all environments from NetworkAPI
env_list = client.create_ambiente().list_all()
# Get all equipment types from NetworkAPI
type_equip_list = client.create_tipo_equipamento().listar()
# Get all groups from NetworkAPI
group_list = client.create_grupo_equipamento().listar()
search_form = SearchEquipmentForm(
env_list, type_equip_list, group_list)
lists['search_form'] = search_form
except NetworkAPIClientError, e:
logger.error(e)
messages.add_message(request, messages.ERROR, e)
示例2: ajax_modelo_equip
def ajax_modelo_equip(request, id_marca):
try:
lists = dict()
# Get user
auth = AuthSession(request.session)
client = auth.get_clientFactory()
marca = int(id_marca)
if marca > 0:
modelos = client.create_modelo().listar_por_marca(marca)
lists['modelos'] = modelos.get('model')
# Returns HTML
response = HttpResponse(loader.render_to_string(
EQUIPMENT_MODELO, lists, context_instance=RequestContext(request)))
# Send response status with error
response.status_code = 200
return response
else:
# Returns HTML
response = HttpResponse(loader.render_to_string(
EQUIPMENT_MODELO, lists, context_instance=RequestContext(request)))
# Send response status with error
response.status_code = 200
return response
except NetworkAPIClientError, e:
logger.error(e)
messages.add_message(request, messages.ERROR, e)
示例3: ajax_view_real_shared
def ajax_view_real_shared(request, id_equip, lists):
try:
lists['equip_id'] = id_equip
# Get user
auth = AuthSession(request.session)
client = auth.get_clientFactory()
# Get reals related
vips_reals = client.create_equipamento().get_real_related(id_equip)
lists['vips'] = [vips_reals.get('vips'), ] if type(
vips_reals.get('vips')) is dict else vips_reals.get('vips')
lists['equip_name'] = vips_reals.get('equip_name')
# Returns HTML
response = HttpResponse(loader.render_to_string(
EQUIPMENT_VIEW_AJAX, lists, context_instance=RequestContext(request)))
response.status_code = 200
return response
except NetworkAPIClientError, e:
logger.error(e)
messages.add_message(request, messages.ERROR, e)
示例4: ajax_acl_name_suggest
def ajax_acl_name_suggest(request):
lists = dict()
try:
nome = request.GET['nome']
id_ambiente = request.GET['id_ambiente']
auth = AuthSession(request.session)
client = auth.get_clientFactory()
environment = client.create_ambiente().buscar_por_id(
id_ambiente).get('ambiente')
suggest_name = str(
nome + environment['nome_ambiente_logico']).replace(" ", "")
lists['suggest_name'] = suggest_name
# Returns HTML
response = HttpResponse(loader.render_to_string(
AJAX_SUGGEST_NAME, lists, context_instance=RequestContext(request)))
# Send response status with error
response.status_code = 200
return response
except:
lists['suggest_name'] = ''
# Returns HTML
response = HttpResponse(loader.render_to_string(
AJAX_SUGGEST_NAME, lists, context_instance=RequestContext(request)))
# Send response status with error
response.status_code = 200
return response
示例5: show_form
def show_form(request):
try:
if request.method == "POST":
# Get user
auth = AuthSession(request.session)
client = auth.get_clientFactory()
# Um form com os dados de POST
form = ScriptTypeForm(request.POST)
if form.is_valid():
tipo = form.cleaned_data['script_type']
descricao = form.cleaned_data['description']
try:
client.create_tipo_roteiro().inserir(
tipo, descricao)
messages.add_message(
request, messages.SUCCESS, script_type_messages.get("success_insert"))
return redirect('script.type.list')
except NomeTipoRoteiroDuplicadoError, e:
messages.add_message(
request, messages.ERROR, script_type_messages.get("error_equal_name") % tipo)
else:
示例6: add_form
def add_form(request):
try:
# Get user
auth = AuthSession(request.session)
client = auth.get_clientFactory()
# Enviar listas para formar os Selects do formulário
forms_aux = dict()
# Get all script_types from NetworkAPI
forms_aux['tipo_roteiro'] = client.create_tipo_roteiro().listar()
forms_aux['modelos'] = client.create_modelo().listar().get('model')
# If form was submited
if request.method == 'POST':
form = ScriptForm(forms_aux, request.POST)
if form.is_valid():
name = form.cleaned_data['name']
script_type = form.cleaned_data['script_type']
modelo = form.cleaned_data['model']
description = form.cleaned_data['description']
try:
client.create_roteiro().inserir(script_type, name, modelo, description)
messages.add_message(request, messages.SUCCESS, script_messages.get("success_insert"))
return redirect('script.list')
except NomeRoteiroDuplicadoError, e:
messages.add_message(request, messages.ERROR, e)
else:
示例7: dissociate_channel_interface
def dissociate_channel_interface(request, channel_id, interface_id):
auth = AuthSession(request.session)
client = auth.get_clientFactory()
fields_get = ['id',
'protected',
'type__details',
'native_vlan',
'equipment__details',
'front_interface__basic',
'back_interface',
'channel__basic']
data = dict()
data["start_record"] = 0
data["end_record"] = 50
data["extends_search"] = []
data["asorting_cols"] = []
data["searchable_columns"] = ["channel__id"]
data["custom_search"] = channel_id
try:
sw_ids = list()
interfaces = client.create_api_interface_request().search(search=data, fields=fields_get).get('interfaces')
interface_obj = interfaces[0]
for i in interfaces:
sw_ids.append(int(i.get('id')))
except NetworkAPIClientError, e:
logger.error(e)
messages.add_message(request, messages.WARNING, 'Erro ao buscar o channel de Id %s.' % channel_id)
url = request.META.get('HTTP_REFERER') if request.META.get('HTTP_REFERER') else reverse('interface.list')
return HttpResponseRedirect(url)
示例8: insert_vrf
def insert_vrf(request):
try:
lists = {}
auth = AuthSession(request.session)
client = auth.get_clientFactory()
lists["form_vrf"] = VrfForm() # TODO Alterar depois de edit pra ""
if request.method == 'POST':
# Set data in form
vrf_form = VrfForm(request.POST)
# Return data to form in case of error
lists["form_vrf"] = vrf_form
# Validate
if vrf_form.is_valid():
vrf = vrf_form.cleaned_data["vrf"]
internal_name = vrf_form.cleaned_data["internal_name"]
list_vrf = [{
"vrf": vrf,
"internal_name": internal_name
}]
client.create_api_vrf().create(list_vrf)
messages.add_message(
request, messages.SUCCESS, vrf_messages.get("success_insert"))
return redirect('vrf.list')
except NetworkAPIClientError, e:
logger.error(e)
messages.add_message(request, messages.ERROR, e)
示例9: access_type_form
def access_type_form(request):
lists = dict()
try:
auth = AuthSession(request.session)
client = auth.get_clientFactory()
if request.method == 'POST':
form = TipoAcessoForm(request.POST)
lists['form'] = form
if form.is_valid():
protocolo = form.cleaned_data['nome']
client.create_tipo_acesso().inserir(protocolo)
messages.add_message(
request, messages.SUCCESS, access_type_messages.get('success_create'))
lists['form'] = TipoAcessoForm()
# GET METHOD
else:
lists['form'] = TipoAcessoForm()
except NetworkAPIClientError, e:
logger.error(e)
messages.add_message(request, messages.ERROR, e)
示例10: save_pool
def save_pool(request):
"""
Method to call shared_save_pool
"""
auth = AuthSession(request.session)
client = auth.get_clientFactory()
return facade.shared_save_pool(request, client)
示例11: ajax_popular_environment
def ajax_popular_environment(request):
"""
Method to call popular_environment_shared
"""
auth = AuthSession(request.session)
client_api = auth.get_clientFactory()
return facade.popular_environment_shared(request, client_api)
示例12: healthcheck_expect_form
def healthcheck_expect_form(request):
lists = dict()
try:
auth = AuthSession(request.session)
client = auth.get_clientFactory()
ambientes = client.create_ambiente().list_all()
if request.method == 'POST':
form = HealthckeckExpectForm(ambientes, request.POST)
lists['form'] = form
if form.is_valid():
match_list = form.cleaned_data['match_list']
expect_string = form.cleaned_data['expect_string']
environment_id = form.cleaned_data['environment']
client.create_ambiente().add_healthcheck_expect(
environment_id, expect_string, match_list)
messages.add_message(
request, messages.SUCCESS, healthcheck_messages.get('success_create'))
lists['form'] = HealthckeckExpectForm(ambientes)
# GET METHOD
else:
lists['form'] = HealthckeckExpectForm(ambientes)
except NetworkAPIClientError, e:
logger.error(e)
messages.add_message(request, messages.ERROR, e)
示例13: delete_individ_perms_of_object
def delete_individ_perms_of_object(request):
try:
if request.method == 'POST':
auth = AuthSession(request.session)
client = auth.get_clientFactory()
form = DeletePermsForm(request.POST)
if form.is_valid():
ids_perms = split_to_array(form.cleaned_data['ids_perms'])
id_ugroup = form.cleaned_data['id_ugroup']
id_type_obj = form.cleaned_data['id_type_obj']
client.create_api_object_group_permission().delete(ids_perms)
messages.add_message(
request, messages.SUCCESS, object_group_perm_messages.
get('success_delete'))
except NetworkAPIClientError, e:
logger.error(e)
messages.add_message(request, messages.ERROR, e)
示例14: ajax_ldap_users_by_group
def ajax_ldap_users_by_group(request, ldap_group, id_user):
try:
lists = dict()
# Get user
auth = AuthSession(request.session)
client = auth.get_clientFactory()
exclude_list = []
user_list = client.create_usuario().listar().get('usuario')
for usr in user_list:
if usr['user_ldap'] is not None and usr['user_ldap'] != '' and usr['id'] != id_user:
exclude_list.append(usr['user_ldap'])
ldap_users = Ldap(auth).get_users_group(ldap_group, exclude_list)
lists['ldap_users'] = ldap_users
# Returns HTML
response = HttpResponse(loader.render_to_string(
AJAX_LDAP_USERS_BY_GROUP, lists, context_instance=RequestContext(request)))
response.status_code = 200
return response
except LDAPError:
lists[
'error'] = 'O LDAP não está disponível, não será possível associar o usuário CadVlan a um usuário do LDAP.'
# Returns HTML
response = HttpResponse(loader.render_to_string(
AJAX_LDAP_USERS_BY_GROUP, lists, context_instance=RequestContext(request)))
# Send response status with error
response.status_code = 278
return response
示例15: remove_environment
def remove_environment(request):
if request.method == 'POST':
auth = AuthSession(request.session)
client = auth.get_clientFactory()
ids = request.POST.getlist('ids[]')
error_not_found = list()
error_associated = list()
have_errors = False
try:
client.create_api_environment().delete_environment(';'.join(str(id) for id in ids))
except DetailedEnvironmentError, e:
# Detailed message for VLAN errors
logger.error(e)
have_errors = True
messages.add_message(request, messages.ERROR, e)
except AmbienteNaoExisteError, e:
# Environment doesn't exist.
logger.error(e)
have_errors = True
error_not_found.append(id_env)