# Path: sdn/helpers/session_flash.py
# def set_flash(request, message, message_type = "success"):
# def clear_flash(request):
# def get_flash(request):
# 
# Path: sdn/models/host.py
# class Host(BaseModel):
#     mac_address = models.CharField(max_length=100, db_index=True)
#     ipv4_address = models.CharField(max_length=100, db_index=True)
#     port = models.ForeignKey(Port, null=True)
# 
#     # Foreign key to controller
#     controller = models.ForeignKey(Controller)
# 
#     def sync(self, host_description):
#         # TODO for more interfaces
#         if (len(host_description['mac']) > 0):
#             self.mac_address = host_description['mac'][0]
#         else:
#             self.mac_address = 'none'
#         if (len(host_description['ipv4']) > 0):
#             self.ipv4_address = host_description['ipv4'][0]
#         else:
#             self.ipv4_address = 'none'
#         if (len(host_description['attachmentPoint']) > 0):
#             prt_num = host_description['attachmentPoint'][0]['port']
#             if (prt_num > 0):
#                 dpid = host_description['attachmentPoint'][0]['switchDPID']
#                 self.port = Port.objects.get(port_number=prt_num, switch__dpid=dpid)
# 
#                 try:
#                     # Verify if host exists
#                     h = Host.objects.get(mac_address=self.mac_address, controller=self.controller)
#                     h.mac_address = self.mac_address
#                     h.ipv4_address = self.ipv4_address
#                     h.port = self.port
#                     h.save()
#                 except Host.DoesNotExist:
#                     self.save()


import logging
from django.http import HttpResponse
from django.template import Context, loader
from django.contrib.auth.decorators import login_required
from sdn.helpers import session_flash
from sdn.models.host import Host

# Configure logging for the module name
logger = logging.getLogger(__name__)
active_menu = "Resources"

@login_required
def index(request):
    t = loader.get_template('hosts.html')
    host_list = Host.objects.all()
    view_vars = {
        'active_menu': active_menu,
        'title': "Hosts List"
    }
    c = Context({

# Path: sdn/helpers/session_flash.py
# def set_flash(request, message, message_type = "success"):
# def clear_flash(request):
# def get_flash(request):
# 
# Path: sdn/models/host.py
# class Host(BaseModel):
#     mac_address = models.CharField(max_length=100, db_index=True)
#     ipv4_address = models.CharField(max_length=100, db_index=True)
#     port = models.ForeignKey(Port, null=True)
# 
#     # Foreign key to controller
#     controller = models.ForeignKey(Controller)
# 
#     def sync(self, host_description):
#         # TODO for more interfaces
#         if (len(host_description['mac']) > 0):
#             self.mac_address = host_description['mac'][0]
#         else:
#             self.mac_address = 'none'
#         if (len(host_description['ipv4']) > 0):
#             self.ipv4_address = host_description['ipv4'][0]
#         else:
#             self.ipv4_address = 'none'
#         if (len(host_description['attachmentPoint']) > 0):
#             prt_num = host_description['attachmentPoint'][0]['port']
#             if (prt_num > 0):
#                 dpid = host_description['attachmentPoint'][0]['switchDPID']
#                 self.port = Port.objects.get(port_number=prt_num, switch__dpid=dpid)
# 
#                 try:
#                     # Verify if host exists
#                     h = Host.objects.get(mac_address=self.mac_address, controller=self.controller)
#                     h.mac_address = self.mac_address
#                     h.ipv4_address = self.ipv4_address
#                     h.port = self.port
#                     h.save()
#                 except Host.DoesNotExist:
#                     self.save()


# Path: sdn/views/resources/hosts.py
import logging
from django.http import HttpResponse
from django.template import Context, loader
from django.contrib.auth.decorators import login_required
from sdn.helpers import session_flash
from sdn.models.host import Host


# Configure logging for the module name
logger = logging.getLogger(__name__)
active_menu = "Resources"

@login_required
def index(request):
    t = loader.get_template('hosts.html')
    host_list = Host.objects.all()
    view_vars = {
        'active_menu': active_menu,
        'title': "Hosts List"
    }
    c = Context({

        'host_list': host_list,