prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): p<|fim_middle|> def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
ilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True)
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): o<|fim_middle|> def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
pciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): i<|fim_middle|> def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
f self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): s<|fim_middle|> def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
elf.menu.x = [-500] self.trans.x = [-500] self.donde = "historia"
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): s<|fim_middle|> def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
elf.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones"
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): s<|fim_middle|> def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
elf.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar"
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): s<|fim_middle|> def salir_del_juego(self): pilas.terminar() <|fim▁end|>
elf.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda"
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): p<|fim_middle|> <|fim▁end|>
ilas.terminar()
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": <|fim_middle|> else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
from modulos.ES import *
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: <|fim_middle|> class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
from modulos.EN import *
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: i <|fim_middle|> return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
f self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones())
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": s <|fim_middle|> elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
elf.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": s <|fim_middle|> elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
elf.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia())
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": s <|fim_middle|> elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
elf.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda())
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": s <|fim_middle|> return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
elf.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones())
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def _<|fim_middle|>self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
_init__(
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def i<|fim_middle|>self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
niciar(
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def c<|fim_middle|>self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
rear_el_menu_principal(
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def a<|fim_middle|>self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
ct(
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def m<|fim_middle|>self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
ostrar_historia(
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def m<|fim_middle|>self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
ostrar_opciones(
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def c<|fim_middle|>self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
omenzar_a_jugar(
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def m<|fim_middle|>self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def salir_del_juego(self): pilas.terminar() <|fim▁end|>
ostrar_ayuda_del_juego(
<|file_name|>escena_menu.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- import pilas archi = open('datos.txt', 'r') nivel = archi.readline() pantalla = archi.readline() idioma = archi.readline() archi.close() if idioma == "ES": from modulos.ES import * else: from modulos.EN import * class EscenaMenu(pilas.escena.Base): "Es la escena de presentación donde se elijen las opciones del juego." def __init__(self, musica=False): pilas.escena.Base.__init__(self) self.musica = musica def iniciar(self): pilas.fondos.Fondo("data/guarida.jpg") pilas.avisar(menu_aviso) self.crear_el_menu_principal() pilas.mundo.agregar_tarea(0.1, self.act) self.sonido = pilas.sonidos.cargar("data/menu.ogg") self.sonido.reproducir(repetir=True) def crear_el_menu_principal(self): opciones = [ (menu1, self.comenzar_a_jugar), (menu2, self.mostrar_ayuda_del_juego), (menu3, self.mostrar_historia), (menu4, self.mostrar_opciones), (menu5, self.salir_del_juego) ] self.trans = pilas.actores.Actor("data/trans.png") self.trans.x = -155 self.trans.arriba = 85 self.menu = pilas.actores.Menu(opciones, x=-150, y=70, color_normal= pilas.colores.negro, color_resaltado=pilas.colores.rojo) self.menu.x = -150 def act(self): if self.menu.x == -500: if self.donde == "jugar": self.sonido.detener() import escena_niveles pilas.cambiar_escena(escena_niveles.EscenaNiveles()) return False elif self.donde == "historia": self.sonido.detener() import escena_historia pilas.cambiar_escena(escena_historia.Historia()) elif self.donde == "ayuda": self.sonido.detener() import escena_ayuda pilas.cambiar_escena(escena_ayuda.Ayuda()) elif self.donde == "opciones": self.sonido.detener() import escena_opciones pilas.cambiar_escena(escena_opciones.Opciones()) return True def mostrar_historia(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "historia" def mostrar_opciones(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "opciones" def comenzar_a_jugar(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "jugar" def mostrar_ayuda_del_juego(self): self.menu.x = [-500] self.trans.x = [-500] self.donde = "ayuda" def s<|fim_middle|>self): pilas.terminar() <|fim▁end|>
alir_del_juego(
<|file_name|>setup.py<|end_file_name|><|fim▁begin|>import cx_Freeze import sys import os executables = [cx_Freeze.Executable("MusicCompiler.py", base=None)] cx_Freeze.setup( name= "MusicCompiler", description = "Best Program Ever Known To Humanity.", author = "Space Sheep Enterprises", options = {"build_exe":{"excludes":["urllib","html","http","tkinter","socket","multiprocessing","threading","email","htmllib"]}}, version = "1.0", executables = executables <|fim▁hole|><|fim▁end|>
)
<|file_name|>S_PARTY_MEMBER_INTERVAL_POS_UPDATE.py<|end_file_name|><|fim▁begin|><|fim▁hole|> def __init__(self, tracker, time, direction, opcode, data): print(str(type(self)).split('.')[3]+'('+str(len(data))+'): '+ str(data.get_array_hex(1))[1:-1])<|fim▁end|>
from util.tipo import tipo class S_PARTY_MEMBER_INTERVAL_POS_UPDATE(object):
<|file_name|>S_PARTY_MEMBER_INTERVAL_POS_UPDATE.py<|end_file_name|><|fim▁begin|>from util.tipo import tipo class S_PARTY_MEMBER_INTERVAL_POS_UPDATE(object): <|fim_middle|> <|fim▁end|>
def __init__(self, tracker, time, direction, opcode, data): print(str(type(self)).split('.')[3]+'('+str(len(data))+'): '+ str(data.get_array_hex(1))[1:-1])
<|file_name|>S_PARTY_MEMBER_INTERVAL_POS_UPDATE.py<|end_file_name|><|fim▁begin|>from util.tipo import tipo class S_PARTY_MEMBER_INTERVAL_POS_UPDATE(object): def __init__(self, tracker, time, direction, opcode, data): <|fim_middle|> <|fim▁end|>
print(str(type(self)).split('.')[3]+'('+str(len(data))+'): '+ str(data.get_array_hex(1))[1:-1])
<|file_name|>S_PARTY_MEMBER_INTERVAL_POS_UPDATE.py<|end_file_name|><|fim▁begin|>from util.tipo import tipo class S_PARTY_MEMBER_INTERVAL_POS_UPDATE(object): def <|fim_middle|>(self, tracker, time, direction, opcode, data): print(str(type(self)).split('.')[3]+'('+str(len(data))+'): '+ str(data.get_array_hex(1))[1:-1]) <|fim▁end|>
__init__
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id<|fim▁hole|> network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork)<|fim▁end|>
try: # Retrieve the network list.
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): <|fim_middle|> class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
"""Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. <|fim_middle|> class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
if datum and datum.shared: return False return True
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): <|fim_middle|> class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
@staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect)
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): <|fim_middle|> @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
return ungettext_lazy( u"Delete Network", u"Delete Networks", count )
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): <|fim_middle|> policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count )
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): <|fim_middle|> class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect)
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): <|fim_middle|> class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): <|fim_middle|> class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): <|fim_middle|> class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),)
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): <|fim_middle|> def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): <|fim_middle|> def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): <|fim_middle|> DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context)
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): <|fim_middle|> class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN")))
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): <|fim_middle|> <|fim▁end|>
name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork)
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): <|fim_middle|> <|fim▁end|>
name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork)
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: <|fim_middle|> return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
return False
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: <|fim_middle|> else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)")
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: <|fim_middle|> else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)")
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: <|fim_middle|> return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"]
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: <|fim_middle|> else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)')
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: <|fim_middle|> else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)')
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: <|fim_middle|> return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled']
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def <|fim_middle|>(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
allowed
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def <|fim_middle|>(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
action_present
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def <|fim_middle|>(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
action_past
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def <|fim_middle|>(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
delete
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def <|fim_middle|>(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
allowed
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def <|fim_middle|>(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def get_subnets(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
allowed
<|file_name|>tables.py<|end_file_name|><|fim▁begin|># Copyright 2012 NEC Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import logging from django.core.urlresolvers import reverse from django import template from django.template import defaultfilters as filters from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext_lazy from horizon import exceptions from horizon import tables from openstack_dashboard import api from openstack_dashboard import policy from openstack_dashboard.usage import quotas LOG = logging.getLogger(__name__) class CheckNetworkEditable(object): """Mixin class to determine the specified network is editable.""" def allowed(self, request, datum=None): # Only administrator is allowed to create and manage shared networks. if datum and datum.shared: return False return True class DeleteNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.DeleteAction): @staticmethod def action_present(count): return ungettext_lazy( u"Delete Network", u"Delete Networks", count ) @staticmethod def action_past(count): return ungettext_lazy( u"Deleted Network", u"Deleted Networks", count ) policy_rules = (("network", "delete_network"),) def delete(self, request, network_id): network_name = network_id try: # Retrieve the network list. network = api.neutron.network_get(request, network_id, expand_subnet=False) network_name = network.name LOG.debug('Network %(network_id)s has subnets: %(subnets)s', {'network_id': network_id, 'subnets': network.subnets}) for subnet_id in network.subnets: api.neutron.subnet_delete(request, subnet_id) LOG.debug('Deleted subnet %s', subnet_id) api.neutron.network_delete(request, network_id) LOG.debug('Deleted network %s successfully', network_id) except Exception: msg = _('Failed to delete network %s') LOG.info(msg, network_id) redirect = reverse("horizon:project:networks:index") exceptions.handle(request, msg % network_name, redirect=redirect) class CreateNetwork(tables.LinkAction): name = "create" verbose_name = _("Create Network") url = "horizon:project:networks:create" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_network"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["networks"] is empty if usages.get('networks', {}).get('available', 1) <= 0: if "disabled" not in self.classes: self.classes = [c for c in self.classes] + ["disabled"] self.verbose_name = _("Create Network (Quota exceeded)") else: self.verbose_name = _("Create Network") self.classes = [c for c in self.classes if c != "disabled"] return True class EditNetwork(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "update" verbose_name = _("Edit Network") url = "horizon:project:networks:update" classes = ("ajax-modal",) icon = "pencil" policy_rules = (("network", "update_network"),) class CreateSubnet(policy.PolicyTargetMixin, CheckNetworkEditable, tables.LinkAction): name = "subnet" verbose_name = _("Add Subnet") url = "horizon:project:networks:addsubnet" classes = ("ajax-modal",) icon = "plus" policy_rules = (("network", "create_subnet"),) # neutron has used both in their policy files, supporting both policy_target_attrs = (("network:tenant_id", "tenant_id"), ("network:project_id", "tenant_id"),) def allowed(self, request, datum=None): usages = quotas.tenant_quota_usages(request) # when Settings.OPENSTACK_NEUTRON_NETWORK['enable_quotas'] = False # usages["subnets'] is empty if usages.get('subnets', {}).get('available', 1) <= 0: if 'disabled' not in self.classes: self.classes = [c for c in self.classes] + ['disabled'] self.verbose_name = _('Add Subnet (Quota exceeded)') else: self.verbose_name = _('Add Subnet') self.classes = [c for c in self.classes if c != 'disabled'] return True def <|fim_middle|>(network): template_name = 'project/networks/_network_ips.html' context = {"subnets": network.subnets} return template.loader.render_to_string(template_name, context) DISPLAY_CHOICES = ( ("up", pgettext_lazy("Admin state of a Network", u"UP")), ("down", pgettext_lazy("Admin state of a Network", u"DOWN")), ) STATUS_DISPLAY_CHOICES = ( ("active", pgettext_lazy("Current status of a Network", u"Active")), ("build", pgettext_lazy("Current status of a Network", u"Build")), ("down", pgettext_lazy("Current status of a Network", u"Down")), ("error", pgettext_lazy("Current status of a Network", u"Error")), ) class ProjectNetworksFilterAction(tables.FilterAction): name = "filter_project_networks" filter_type = "server" filter_choices = (('name', _("Name ="), True), ('shared', _("Shared ="), True, _("e.g. Yes / No")), ('router:external', _("External ="), True, _("e.g. Yes / No")), ('status', _("Status ="), True), ('admin_state_up', _("Admin State ="), True, _("e.g. UP / DOWN"))) class NetworksTable(tables.DataTable): name = tables.WrappingColumn("name_or_id", verbose_name=_("Name"), link='horizon:project:networks:detail') subnets = tables.Column(get_subnets, verbose_name=_("Subnets Associated"),) shared = tables.Column("shared", verbose_name=_("Shared"), filters=(filters.yesno, filters.capfirst)) external = tables.Column("router:external", verbose_name=_("External"), filters=(filters.yesno, filters.capfirst)) status = tables.Column("status", verbose_name=_("Status"), display_choices=STATUS_DISPLAY_CHOICES) admin_state = tables.Column("admin_state", verbose_name=_("Admin State"), display_choices=DISPLAY_CHOICES) class Meta(object): name = "networks" verbose_name = _("Networks") table_actions = (CreateNetwork, DeleteNetwork, ProjectNetworksFilterAction) row_actions = (EditNetwork, CreateSubnet, DeleteNetwork) <|fim▁end|>
get_subnets
<|file_name|>test_long_acl.py<|end_file_name|><|fim▁begin|>''' Access Control Lists testing based on newpynfs framework Aurelien Charbon - Bull SA ''' from random_gen import * from optparse import OptionParser import commands import os import threading import time import random alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789_-() ~' t_alphabet=len(alphabet) def test_longacl(l,path): # mesures sur le getfacl test = RandomGen() u = commands.getoutput('rm ' + path + "/*") # clean directory print "test acl getfacl\n" for i in range(l): test.getUserList() testfile = 'testfile' + str(i) u = commands.getoutput('touch ' + path + "/" + testfile) print "setfacl with " + str(i) + " entries\n " + u for j in range(i):<|fim▁hole|> print "setfacl -m u:" + user + ':' + mode + " " + path + "/" + testfile print u def main(): parser = OptionParser() parser.add_option("-l", "--length", dest="length",type="int",help="max lentgh of ACL") parser.add_option("-p", "--path", dest="path",help="path of test file") (options, args) = parser.parse_args() test_longacl(options.length,options.path) main()<|fim▁end|>
user = test.uList.pop() mode = test.createRandomMode() u = commands.getoutput('setfacl -m u:' + user + ':' + mode + " " + path + "/" + testfile) if u != "":
<|file_name|>test_long_acl.py<|end_file_name|><|fim▁begin|>''' Access Control Lists testing based on newpynfs framework Aurelien Charbon - Bull SA ''' from random_gen import * from optparse import OptionParser import commands import os import threading import time import random alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789_-() ~' t_alphabet=len(alphabet) def test_longacl(l,path): # mesures sur le getfacl <|fim_middle|> def main(): parser = OptionParser() parser.add_option("-l", "--length", dest="length",type="int",help="max lentgh of ACL") parser.add_option("-p", "--path", dest="path",help="path of test file") (options, args) = parser.parse_args() test_longacl(options.length,options.path) main() <|fim▁end|>
test = RandomGen() u = commands.getoutput('rm ' + path + "/*") # clean directory print "test acl getfacl\n" for i in range(l): test.getUserList() testfile = 'testfile' + str(i) u = commands.getoutput('touch ' + path + "/" + testfile) print "setfacl with " + str(i) + " entries\n " + u for j in range(i): user = test.uList.pop() mode = test.createRandomMode() u = commands.getoutput('setfacl -m u:' + user + ':' + mode + " " + path + "/" + testfile) if u != "": print "setfacl -m u:" + user + ':' + mode + " " + path + "/" + testfile print u
<|file_name|>test_long_acl.py<|end_file_name|><|fim▁begin|>''' Access Control Lists testing based on newpynfs framework Aurelien Charbon - Bull SA ''' from random_gen import * from optparse import OptionParser import commands import os import threading import time import random alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789_-() ~' t_alphabet=len(alphabet) def test_longacl(l,path): # mesures sur le getfacl test = RandomGen() u = commands.getoutput('rm ' + path + "/*") # clean directory print "test acl getfacl\n" for i in range(l): test.getUserList() testfile = 'testfile' + str(i) u = commands.getoutput('touch ' + path + "/" + testfile) print "setfacl with " + str(i) + " entries\n " + u for j in range(i): user = test.uList.pop() mode = test.createRandomMode() u = commands.getoutput('setfacl -m u:' + user + ':' + mode + " " + path + "/" + testfile) if u != "": print "setfacl -m u:" + user + ':' + mode + " " + path + "/" + testfile print u def main(): <|fim_middle|> main() <|fim▁end|>
parser = OptionParser() parser.add_option("-l", "--length", dest="length",type="int",help="max lentgh of ACL") parser.add_option("-p", "--path", dest="path",help="path of test file") (options, args) = parser.parse_args() test_longacl(options.length,options.path)
<|file_name|>test_long_acl.py<|end_file_name|><|fim▁begin|>''' Access Control Lists testing based on newpynfs framework Aurelien Charbon - Bull SA ''' from random_gen import * from optparse import OptionParser import commands import os import threading import time import random alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789_-() ~' t_alphabet=len(alphabet) def test_longacl(l,path): # mesures sur le getfacl test = RandomGen() u = commands.getoutput('rm ' + path + "/*") # clean directory print "test acl getfacl\n" for i in range(l): test.getUserList() testfile = 'testfile' + str(i) u = commands.getoutput('touch ' + path + "/" + testfile) print "setfacl with " + str(i) + " entries\n " + u for j in range(i): user = test.uList.pop() mode = test.createRandomMode() u = commands.getoutput('setfacl -m u:' + user + ':' + mode + " " + path + "/" + testfile) if u != "": <|fim_middle|> def main(): parser = OptionParser() parser.add_option("-l", "--length", dest="length",type="int",help="max lentgh of ACL") parser.add_option("-p", "--path", dest="path",help="path of test file") (options, args) = parser.parse_args() test_longacl(options.length,options.path) main() <|fim▁end|>
print "setfacl -m u:" + user + ':' + mode + " " + path + "/" + testfile print u
<|file_name|>test_long_acl.py<|end_file_name|><|fim▁begin|>''' Access Control Lists testing based on newpynfs framework Aurelien Charbon - Bull SA ''' from random_gen import * from optparse import OptionParser import commands import os import threading import time import random alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789_-() ~' t_alphabet=len(alphabet) def <|fim_middle|>(l,path): # mesures sur le getfacl test = RandomGen() u = commands.getoutput('rm ' + path + "/*") # clean directory print "test acl getfacl\n" for i in range(l): test.getUserList() testfile = 'testfile' + str(i) u = commands.getoutput('touch ' + path + "/" + testfile) print "setfacl with " + str(i) + " entries\n " + u for j in range(i): user = test.uList.pop() mode = test.createRandomMode() u = commands.getoutput('setfacl -m u:' + user + ':' + mode + " " + path + "/" + testfile) if u != "": print "setfacl -m u:" + user + ':' + mode + " " + path + "/" + testfile print u def main(): parser = OptionParser() parser.add_option("-l", "--length", dest="length",type="int",help="max lentgh of ACL") parser.add_option("-p", "--path", dest="path",help="path of test file") (options, args) = parser.parse_args() test_longacl(options.length,options.path) main() <|fim▁end|>
test_longacl
<|file_name|>test_long_acl.py<|end_file_name|><|fim▁begin|>''' Access Control Lists testing based on newpynfs framework Aurelien Charbon - Bull SA ''' from random_gen import * from optparse import OptionParser import commands import os import threading import time import random alphabet='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789_-() ~' t_alphabet=len(alphabet) def test_longacl(l,path): # mesures sur le getfacl test = RandomGen() u = commands.getoutput('rm ' + path + "/*") # clean directory print "test acl getfacl\n" for i in range(l): test.getUserList() testfile = 'testfile' + str(i) u = commands.getoutput('touch ' + path + "/" + testfile) print "setfacl with " + str(i) + " entries\n " + u for j in range(i): user = test.uList.pop() mode = test.createRandomMode() u = commands.getoutput('setfacl -m u:' + user + ':' + mode + " " + path + "/" + testfile) if u != "": print "setfacl -m u:" + user + ':' + mode + " " + path + "/" + testfile print u def <|fim_middle|>(): parser = OptionParser() parser.add_option("-l", "--length", dest="length",type="int",help="max lentgh of ACL") parser.add_option("-p", "--path", dest="path",help="path of test file") (options, args) = parser.parse_args() test_longacl(options.length,options.path) main() <|fim▁end|>
main
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|>from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) :<|fim▁hole|> """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ #<|fim▁end|>
""" Wait for given unit(s) to enter given state
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : <|fim_middle|> # ------------------------------------------------------------------------------ # <|fim▁end|>
""" UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__)
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : <|fim_middle|> # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
Attributes.__init__ (self)
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : <|fim_middle|> # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
""" add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__)
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : <|fim_middle|> # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
""" List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__)
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : <|fim_middle|> # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
""" Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__)
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : <|fim_middle|> # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
""" Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__)
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : <|fim_middle|> # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
""" List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__)
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : <|fim_middle|> # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
""" Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__)
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : <|fim_middle|> # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
""" Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__)
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : <|fim_middle|> # ------------------------------------------------------------------------------ # <|fim▁end|>
""" Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__)
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def <|fim_middle|> (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
__init__
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def <|fim_middle|> (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
add_pilot
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def <|fim_middle|> (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
list_pilots
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def <|fim_middle|> (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
remove_pilot
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def <|fim_middle|> (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
submit_unit
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def <|fim_middle|> (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
list_units
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def <|fim_middle|> (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
get_unit
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def <|fim_middle|> (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def cancel_units (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
wait_unit
<|file_name|>unit_manager.py<|end_file_name|><|fim▁begin|> from attributes import * from constants import * # ------------------------------------------------------------------------------ # class UnitManager (Attributes) : """ UnitManager class -- manages a pool """ # -------------------------------------------------------------------------- # def __init__ (self, url=None, scheduler='default', session=None) : Attributes.__init__ (self) # -------------------------------------------------------------------------- # def add_pilot (self, pid) : """ add (Compute or Data)-Pilot(s) to the pool """ raise Exception ("%s.add_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_pilots (self, ptype=ANY) : """ List IDs of data and/or compute pilots """ raise Exception ("%s.list_pilots() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def remove_pilot (self, pid, drain=False) : """ Remove pilot(s) (does not cancel the pilot(s), but removes all units from the pilot(s). `drain` determines what happens to the units which are managed by the removed pilot(s). If `True`, the pilot removal is delayed until all units reach a final state. If `False` (the default), then `RUNNING` units will be canceled, and `PENDING` units will be re-assinged to the unit managers for re-scheduling to other pilots. """ raise Exception ("%s.remove_pilot() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def submit_unit (self, description) : """ Instantiate and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.submit_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def list_units (self, utype=ANY) : """ List IDs of data and/or compute units """ raise Exception ("%s.list_units() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def get_unit (self, uids) : """ Reconnect to and return (Compute or Data)-Unit object(s) """ raise Exception ("%s.get_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def wait_unit (self, uids, state=[DONE, FAILED, CANCELED], timeout=-1.0) : """ Wait for given unit(s) to enter given state """ raise Exception ("%s.wait_unit() is not implemented" % self.__class__.__name__) # -------------------------------------------------------------------------- # def <|fim_middle|> (self, uids) : """ Cancel given unit(s) """ raise Exception ("%s.cancel_unit() is not implemented" % self.__class__.__name__) # ------------------------------------------------------------------------------ # <|fim▁end|>
cancel_units
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def req(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True<|fim▁hole|> # Post-processor def postp(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def shn_rms_req_rheader(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def ritem(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def store_for_req(): store_table = None return dict(store_table = store_table)<|fim▁end|>
response.s3.prep = prep
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): <|fim_middle|> def req(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True response.s3.prep = prep # Post-processor def postp(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def shn_rms_req_rheader(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def ritem(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def store_for_req(): store_table = None return dict(store_table = store_table) <|fim▁end|>
""" Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1)
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def req(): <|fim_middle|> def shn_rms_req_rheader(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def ritem(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def store_for_req(): store_table = None return dict(store_table = store_table) <|fim▁end|>
""" RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True response.s3.prep = prep # Post-processor def postp(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader)
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def req(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): <|fim_middle|> response.s3.prep = prep # Post-processor def postp(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def shn_rms_req_rheader(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def ritem(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def store_for_req(): store_table = None return dict(store_table = store_table) <|fim▁end|>
response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def req(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True response.s3.prep = prep # Post-processor def postp(r, output): <|fim_middle|> response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def shn_rms_req_rheader(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def ritem(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def store_for_req(): store_table = None return dict(store_table = store_table) <|fim▁end|>
if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def req(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True response.s3.prep = prep # Post-processor def postp(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def shn_rms_req_rheader(r): <|fim_middle|> def ritem(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def store_for_req(): store_table = None return dict(store_table = store_table) <|fim▁end|>
""" Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def req(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True response.s3.prep = prep # Post-processor def postp(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def shn_rms_req_rheader(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def ritem(): <|fim_middle|> def store_for_req(): store_table = None return dict(store_table = store_table) <|fim▁end|>
""" RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename)
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def req(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True response.s3.prep = prep # Post-processor def postp(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def shn_rms_req_rheader(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def ritem(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def store_for_req(): <|fim_middle|> <|fim▁end|>
store_table = None return dict(store_table = store_table)
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def <|fim_middle|>(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def req(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True response.s3.prep = prep # Post-processor def postp(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def shn_rms_req_rheader(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def ritem(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def store_for_req(): store_table = None return dict(store_table = store_table) <|fim▁end|>
index
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def <|fim_middle|>(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True response.s3.prep = prep # Post-processor def postp(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def shn_rms_req_rheader(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def ritem(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def store_for_req(): store_table = None return dict(store_table = store_table) <|fim▁end|>
req
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def req(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def <|fim_middle|>(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True response.s3.prep = prep # Post-processor def postp(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def shn_rms_req_rheader(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def ritem(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def store_for_req(): store_table = None return dict(store_table = store_table) <|fim▁end|>
prep
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def req(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True response.s3.prep = prep # Post-processor def <|fim_middle|>(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def shn_rms_req_rheader(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def ritem(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def store_for_req(): store_table = None return dict(store_table = store_table) <|fim▁end|>
postp
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def req(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True response.s3.prep = prep # Post-processor def postp(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def <|fim_middle|>(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def ritem(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def store_for_req(): store_table = None return dict(store_table = store_table) <|fim▁end|>
shn_rms_req_rheader
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def req(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True response.s3.prep = prep # Post-processor def postp(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def shn_rms_req_rheader(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def <|fim_middle|>(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def store_for_req(): store_table = None return dict(store_table = store_table) <|fim▁end|>
ritem
<|file_name|>rms.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- """ Request Management System - Controllers """ prefix = request.controller resourcename = request.function if prefix not in deployment_settings.modules: session.error = T("Module disabled!") redirect(URL(r=request, c="default", f="index")) # Options Menu (available in all Functions' Views) menu = [ [T("Home"), False, URL(r=request, f="index")], [T("Requests"), False, URL(r=request, f="req"), [ [T("List"), False, URL(r=request, f="req")], [T("Add"), False, URL(r=request, f="req", args="create")], # @ToDo Search by priority, status, location #[T("Search"), False, URL(r=request, f="req", args="search")], ]], [T("All Requested Items"), False, URL(r=request, f="ritem")], ] if session.rcvars: if "hms_hospital" in session.rcvars: hospital = db.hms_hospital query = (hospital.id == session.rcvars["hms_hospital"]) selection = db(query).select(hospital.id, hospital.name, limitby=(0, 1)).first() if selection: menu_hospital = [ [selection.name, False, URL(r=request, c="hms", f="hospital", args=[selection.id])] ] menu.extend(menu_hospital) if "cr_shelter" in session.rcvars: shelter = db.cr_shelter query = (shelter.id == session.rcvars["cr_shelter"]) selection = db(query).select(shelter.id, shelter.name, limitby=(0, 1)).first() if selection: menu_shelter = [ [selection.name, False, URL(r=request, c="cr", f="shelter", args=[selection.id])] ] menu.extend(menu_shelter) response.menu_options = menu def index(): """ Module's Home Page Default to the rms_req list view. """ request.function = "req" request.args = [] return req() #module_name = deployment_settings.modules[prefix].name_nice #response.title = module_name #return dict(module_name=module_name, a=1) def req(): """ RESTful CRUD controller """ resourcename = request.function # check again in case we're coming from index() tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] # Pre-processor def prep(r): response.s3.cancel = r.here() if r.representation in shn_interactive_view_formats and r.method != "delete": # Don't send the locations list to client (pulled by AJAX instead) r.table.location_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, "gis_location.id")) #if r.method == "create" and not r.component: # listadd arrives here as method=None if not r.component: table.datetime.default = request.utcnow table.person_id.default = s3_logged_in_person() # @ToDo Default the Organisation too return True response.s3.prep = prep # Post-processor def postp(r, output): if r.representation in shn_interactive_view_formats: #if r.method == "create" and not r.component: # listadd arrives here as method=None if r.method != "delete" and not r.component: # Redirect to the Assessments tabs after creation r.next = r.other(method="ritem", record_id=s3xrc.get_session(prefix, resourcename)) # Custom Action Buttons if not r.component: response.s3.actions = [ dict(label=str(T("Open")), _class="action-btn", url=str(URL(r=request, args=["[id]", "update"]))), dict(label=str(T("Items")), _class="action-btn", url=str(URL(r=request, args=["[id]", "ritem"]))), ] return output response.s3.postp = postp s3xrc.model.configure(table, #listadd=False, #@todo: List add is causing errors with JS - FIX editable=True) return s3_rest_controller(prefix, resourcename, rheader=shn_rms_req_rheader) def shn_rms_req_rheader(r): """ Resource Header for Requests """ if r.representation == "html": if r.name == "req": req_record = r.record if req_record: _next = r.here() _same = r.same() try: location = db(db.gis_location.id == req_record.location_id).select(limitby=(0, 1)).first() location_represent = shn_gis_location_represent(location.id) except: location_represent = None rheader_tabs = shn_rheader_tabs( r, [(T("Edit Details"), None), (T("Items"), "ritem"), ] ) rheader = DIV( TABLE( TR( TH( T("Message") + ": "), TD(req_record.message, _colspan=3) ), TR( TH( T("Time of Request") + ": "), req_record.datetime, TH( T( "Location") + ": "), location_represent, ), TR( TH( T("Priority") + ": "), req_record.priority, TH( T("Document") + ": "), document_represent(req_record.document_id) ), ), rheader_tabs ) return rheader return None def ritem(): """ RESTful CRUD controller """ tablename = "%s_%s" % (prefix, resourcename) table = db[tablename] s3xrc.model.configure(table, insertable=False) return s3_rest_controller(prefix, resourcename) def <|fim_middle|>(): store_table = None return dict(store_table = store_table) <|fim▁end|>
store_for_req