# Path: quads/config.py
# DEFAULT_CONF_PATH = os.path.join(os.path.dirname(__file__), "../conf/quads.yml")
#     LOGFMT = "%(asctime)-12s : %(levelname)-8s - %(message)s"
#     STDFMT = "- %(levelname)-8s - %(message)s"
#     API = "v2"
#     FPING_TIMEOUT = 10000
#     QUADSVERSION = "1.1.6"
#     QUADSCODENAME = "gaúcho"
#     SUPPORTED = [
#         "fc640",
#         "r620",
#         "r630",
#         "r640",
#         "640",
#         "r650",
#         "650",
#         "r720",
#         "r730xd",
#         "r930",
#         "r730",
#         "r740xd",
#         "740xd",
#         "r750xd",
#         "r750",
#         "750",
#         "r720xd",
#         "7425",
#         "7525",
#     ]
#     OFFSETS = {"em1": 0, "em2": 1, "em3": 2, "em4": 3, "em5": 4}
#     TEMPLATES_PATH = os.path.join(os.path.dirname(__file__), "templates")
#     INTERFACES = {
#         "em1": ["172.16", "172.21"],
#         "em2": ["172.17", "172.22"],
#         "em3": ["172.18", "172.23"],
#         "em4": ["172.19", "172.24"],
#         "em5": ["172.20", "172.25"],
#     }
# class _ConfigBase:
# class _Config(_ConfigBase):
#     def __init__(self):
#     def load_from_yaml(self, filepath: str = DEFAULT_CONF_PATH):
#     def __getitem__(self, item: str):
#     def API_URL(self):
# 
# Path: quads/model.py
# class Host(Document):
#     name = StringField(unique=True)
#     model = StringField()
#     default_cloud = ReferenceField(Cloud)
#     cloud = ReferenceField(Cloud)
#     host_type = StringField()
#     interfaces = ListField(EmbeddedDocumentField(Interface))
#     nullos = BooleanField(default=True)
#     build = BooleanField(default=False)
#     validated = BooleanField(default=False)
#     last_build = DateTimeField()
#     disks = ListField(EmbeddedDocumentField(Disk))
#     switch_config_applied = BooleanField(default=False)
#     broken = BooleanField(default=False)
#     retired = BooleanField(default=False)
#     meta = {"indexes": [{"fields": ["$name"]}], "strict": False}
# 
#     @staticmethod
#     def prep_data(data, fields=None):
#         if "cloud" in data:
#             _cloud_obj = Cloud.objects(name=data["cloud"]).first()
#             if _cloud_obj:
#                 data["cloud"] = _cloud_obj
#             else:
#                 return ["Cloud %s does not exist." % data["cloud"]], {}
#         if "default_cloud" in data:
#             _default_cloud_obj = Cloud.objects(name=data["default_cloud"]).first()
#             if _default_cloud_obj:
#                 data["default_cloud"] = _default_cloud_obj
#                 if "cloud" not in data:
#                     data["cloud"] = _default_cloud_obj
#             else:
#                 return ["Cloud %s does not exist." % data["default_cloud"]], {}
#         if not fields:
#             fields = ["name", "host_type"]
# 
#         result, data = param_check(data, fields)
# 
#         return result, data
# 
# class Interface(EmbeddedDocument):
#     name = StringField()
#     bios_id = StringField()
#     mac_address = StringField()
#     ip_address = StringField()
#     switch_port = StringField()
#     speed = LongField(default=-1)
#     vendor = StringField(default="")
#     pxe_boot = BooleanField(default=False)
#     maintenance = BooleanField(default=False)
#     meta = {"strict": False}
# 
#     @staticmethod
#     def prep_data(data, fields=None):
#         if not fields:
#             fields = ["name", "mac_address", "ip_address", "switch_port"]
# 
#         if data.get("vendor"):
#             data["vendor"] = data.get("vendor").upper()
# 
#         if data.get("pxe_boot"):
#             pxe_boot = data.get("pxe_boot")
#             if type(pxe_boot) == str:
#                 if pxe_boot.upper() == "TRUE":
#                     data["pxe_boot"] = True
#                 else:
#                     data["pxe_boot"] = False
# 
#         result, data = param_check(data, fields)
# 
#         return result, data
# 
# Path: quads/tools/badfish.py
# class BadfishException(Exception):
#     pass
# 
# async def badfish_factory(
#     _host, _username, _password, loop=None, _retries=RETRIES, propagate=False
# ):
#     logger.propagate = propagate
#     badfish = Badfish(_host, _username, _password, loop, _retries=RETRIES)
#     await badfish.init()
#     return badfish
# 
# Path: quads/tools/helpers.py
# def get_running_loop() -> asyncio.AbstractEventLoop:
#     loop = asyncio.get_event_loop()
#     if not loop.is_running():
#         raise RuntimeError("The object should be created within an async function")
#     return loop


import argparse
import asyncio
import logging
from quads.config import Config
from quads.model import Host, Interface
from quads.tools.badfish import BadfishException, badfish_factory
from quads.tools.helpers import get_running_loop
    def __init__(self, _loop=None):
        self.loop = _loop if _loop else get_running_loop()

    @staticmethod
    async def list_interfaces(badfish):
        data = None
        na_supported = await badfish.check_supported_network_interfaces(
            "NetworkAdapters"
        )
        ei_supported = await badfish.check_supported_network_interfaces(
            "EthernetInterfaces"
        )
        if na_supported:
            logger.debug("  Getting Network Adapters")
            data = await badfish.get_network_adapters()
        elif ei_supported:
            logger.debug("  Getting Ethernet interfaces")
            data = await badfish.get_ethernet_interfaces()
        else:
            logger.error("  Server does not support this functionality")
        return data

    async def populate(self, host):
        logger.info(host.name)
        badfish = None
        interfaces = None
        try:
            badfish = await badfish_factory(
                "mgmt-" + host.name,
                str(Config["ipmi_username"]),

# Path: quads/config.py
# DEFAULT_CONF_PATH = os.path.join(os.path.dirname(__file__), "../conf/quads.yml")
#     LOGFMT = "%(asctime)-12s : %(levelname)-8s - %(message)s"
#     STDFMT = "- %(levelname)-8s - %(message)s"
#     API = "v2"
#     FPING_TIMEOUT = 10000
#     QUADSVERSION = "1.1.6"
#     QUADSCODENAME = "gaúcho"
#     SUPPORTED = [
#         "fc640",
#         "r620",
#         "r630",
#         "r640",
#         "640",
#         "r650",
#         "650",
#         "r720",
#         "r730xd",
#         "r930",
#         "r730",
#         "r740xd",
#         "740xd",
#         "r750xd",
#         "r750",
#         "750",
#         "r720xd",
#         "7425",
#         "7525",
#     ]
#     OFFSETS = {"em1": 0, "em2": 1, "em3": 2, "em4": 3, "em5": 4}
#     TEMPLATES_PATH = os.path.join(os.path.dirname(__file__), "templates")
#     INTERFACES = {
#         "em1": ["172.16", "172.21"],
#         "em2": ["172.17", "172.22"],
#         "em3": ["172.18", "172.23"],
#         "em4": ["172.19", "172.24"],
#         "em5": ["172.20", "172.25"],
#     }
# class _ConfigBase:
# class _Config(_ConfigBase):
#     def __init__(self):
#     def load_from_yaml(self, filepath: str = DEFAULT_CONF_PATH):
#     def __getitem__(self, item: str):
#     def API_URL(self):
# 
# Path: quads/model.py
# class Host(Document):
#     name = StringField(unique=True)
#     model = StringField()
#     default_cloud = ReferenceField(Cloud)
#     cloud = ReferenceField(Cloud)
#     host_type = StringField()
#     interfaces = ListField(EmbeddedDocumentField(Interface))
#     nullos = BooleanField(default=True)
#     build = BooleanField(default=False)
#     validated = BooleanField(default=False)
#     last_build = DateTimeField()
#     disks = ListField(EmbeddedDocumentField(Disk))
#     switch_config_applied = BooleanField(default=False)
#     broken = BooleanField(default=False)
#     retired = BooleanField(default=False)
#     meta = {"indexes": [{"fields": ["$name"]}], "strict": False}
# 
#     @staticmethod
#     def prep_data(data, fields=None):
#         if "cloud" in data:
#             _cloud_obj = Cloud.objects(name=data["cloud"]).first()
#             if _cloud_obj:
#                 data["cloud"] = _cloud_obj
#             else:
#                 return ["Cloud %s does not exist." % data["cloud"]], {}
#         if "default_cloud" in data:
#             _default_cloud_obj = Cloud.objects(name=data["default_cloud"]).first()
#             if _default_cloud_obj:
#                 data["default_cloud"] = _default_cloud_obj
#                 if "cloud" not in data:
#                     data["cloud"] = _default_cloud_obj
#             else:
#                 return ["Cloud %s does not exist." % data["default_cloud"]], {}
#         if not fields:
#             fields = ["name", "host_type"]
# 
#         result, data = param_check(data, fields)
# 
#         return result, data
# 
# class Interface(EmbeddedDocument):
#     name = StringField()
#     bios_id = StringField()
#     mac_address = StringField()
#     ip_address = StringField()
#     switch_port = StringField()
#     speed = LongField(default=-1)
#     vendor = StringField(default="")
#     pxe_boot = BooleanField(default=False)
#     maintenance = BooleanField(default=False)
#     meta = {"strict": False}
# 
#     @staticmethod
#     def prep_data(data, fields=None):
#         if not fields:
#             fields = ["name", "mac_address", "ip_address", "switch_port"]
# 
#         if data.get("vendor"):
#             data["vendor"] = data.get("vendor").upper()
# 
#         if data.get("pxe_boot"):
#             pxe_boot = data.get("pxe_boot")
#             if type(pxe_boot) == str:
#                 if pxe_boot.upper() == "TRUE":
#                     data["pxe_boot"] = True
#                 else:
#                     data["pxe_boot"] = False
# 
#         result, data = param_check(data, fields)
# 
#         return result, data
# 
# Path: quads/tools/badfish.py
# class BadfishException(Exception):
#     pass
# 
# async def badfish_factory(
#     _host, _username, _password, loop=None, _retries=RETRIES, propagate=False
# ):
#     logger.propagate = propagate
#     badfish = Badfish(_host, _username, _password, loop, _retries=RETRIES)
#     await badfish.init()
#     return badfish
# 
# Path: quads/tools/helpers.py
# def get_running_loop() -> asyncio.AbstractEventLoop:
#     loop = asyncio.get_event_loop()
#     if not loop.is_running():
#         raise RuntimeError("The object should be created within an async function")
#     return loop


# Path: quads/tools/populate_interfaces.py
import argparse
import asyncio
import logging
from quads.config import Config
from quads.model import Host, Interface
from quads.tools.badfish import BadfishException, badfish_factory
from quads.tools.helpers import get_running_loop

    def __init__(self, _loop=None):
        self.loop = _loop if _loop else get_running_loop()

    @staticmethod
    async def list_interfaces(badfish):
        data = None
        na_supported = await badfish.check_supported_network_interfaces(
            "NetworkAdapters"
        )
        ei_supported = await badfish.check_supported_network_interfaces(
            "EthernetInterfaces"
        )
        if na_supported:
            logger.debug("  Getting Network Adapters")
            data = await badfish.get_network_adapters()
        elif ei_supported:
            logger.debug("  Getting Ethernet interfaces")
            data = await badfish.get_ethernet_interfaces()
        else:
            logger.error("  Server does not support this functionality")
        return data

    async def populate(self, host):
        logger.info(host.name)
        badfish = None
        interfaces = None
        try:
            badfish = await badfish_factory(
                "mgmt-" + host.name,
                str(Config["ipmi_username"]),

                str(Config["ipmi_password"]),