# Path: cirque/capabilities/basecapability.py
# class BaseCapability:
# 
#   @property
#   def name(self):
#     return ''
# 
#   def get_docker_run_args(self, docker_node):
#     return {}
# 
#   def enable_capability(self, docker_node):
#     pass
# 
#   def disable_capability(self, docker_node):
#     pass
# 
#   @property
#   def description(self):
#     return {}
# 
# Path: cirque/common/cirquelog.py
# class CirqueLog:
# 
#   logger = None
# 
#   @classmethod
#   def setup_cirque_logger(cls, level=logging.INFO):
#     if cls.logger:
#       return
#     cls.logger = logging.getLogger('cirque')
#     cls.logger.setLevel(level)
#     sh = logging.StreamHandler()
#     sh.setFormatter(
#         logging.Formatter('%(asctime)s [%(name)s] %(levelname)s %(message)s'))
#     cls.logger.addHandler(sh)
# 
#   @classmethod
#   def get_cirque_logger(cls, name=None):
#     name = 'cirque' if not name else 'cirque.{}'.format(name)
#     return logging.getLogger(name)
# 
# Path: cirque/common/exceptions.py
# class ConnectivityError(BaseException):
#   pass
# 
# class ContainerExecError(BaseException):
#   pass
# 
# class IpNetnsExecError(BaseException):
#   pass
# 
# class LoadKernelError(BaseException):
#   pass
# 
# class NameSpaceOperatingError(BaseException):
#   pass
# 
# class PHYDeviceError(BaseException):
#   pass


import os
import time
import cirque.common.utils as utils
from subprocess import PIPE
from pyroute2 import NetNS
from cirque.capabilities.basecapability import BaseCapability
from cirque.common.cirquelog import CirqueLog
from cirque.common.exceptions import (
    ConnectivityError,
    ContainerExecError,
    IpNetnsExecError,
    LoadKernelError,
    NameSpaceOperatingError,
    PHYDeviceError,
)
    return {
        "privileged": True,
    }

  def enable_capability(self, docker_node):
    if not WiFiCapability.is_mac80211_hwsim_loaded():
      WiFiCapability.load_kernel_mac80211_hwsim()
    try:
      self.__get_available_phy_device(docker_node)
      self.__phy_namespace_setup(docker_node)
      if docker_node.type != "wifi_ap":
        self.start_wpa_supplicant_service(docker_node)
    except Exception as e:
      self.logger.exception("{!r}".format(e))
      return -1
    self.logger.info("Node: {} successfully enabled wifi capability".format(
        docker_node.name))

  def disable_capability(self, docker_node):
    try:
      docker_node.container.exec_run("killall wpa_supplicant")
      self.__phy_namespace_restore(docker_node)
    except Exception as e:
      self.logger.exception("{!r}".format(e))
    self.logger.info("Node: {} successfully disabled wifi capablility".format(
        docker_node.name))

  def __get_available_phy_device(self, docker_node):
    ret = utils.host_run(self.logger, "iw dev")
    if ret.stderr != b"":

# Path: cirque/capabilities/basecapability.py
# class BaseCapability:
# 
#   @property
#   def name(self):
#     return ''
# 
#   def get_docker_run_args(self, docker_node):
#     return {}
# 
#   def enable_capability(self, docker_node):
#     pass
# 
#   def disable_capability(self, docker_node):
#     pass
# 
#   @property
#   def description(self):
#     return {}
# 
# Path: cirque/common/cirquelog.py
# class CirqueLog:
# 
#   logger = None
# 
#   @classmethod
#   def setup_cirque_logger(cls, level=logging.INFO):
#     if cls.logger:
#       return
#     cls.logger = logging.getLogger('cirque')
#     cls.logger.setLevel(level)
#     sh = logging.StreamHandler()
#     sh.setFormatter(
#         logging.Formatter('%(asctime)s [%(name)s] %(levelname)s %(message)s'))
#     cls.logger.addHandler(sh)
# 
#   @classmethod
#   def get_cirque_logger(cls, name=None):
#     name = 'cirque' if not name else 'cirque.{}'.format(name)
#     return logging.getLogger(name)
# 
# Path: cirque/common/exceptions.py
# class ConnectivityError(BaseException):
#   pass
# 
# class ContainerExecError(BaseException):
#   pass
# 
# class IpNetnsExecError(BaseException):
#   pass
# 
# class LoadKernelError(BaseException):
#   pass
# 
# class NameSpaceOperatingError(BaseException):
#   pass
# 
# class PHYDeviceError(BaseException):
#   pass


# Path: cirque/capabilities/wificapability.py
import os
import time
import cirque.common.utils as utils
from subprocess import PIPE
from pyroute2 import NetNS
from cirque.capabilities.basecapability import BaseCapability
from cirque.common.cirquelog import CirqueLog
from cirque.common.exceptions import (
    ConnectivityError,
    ContainerExecError,
    IpNetnsExecError,
    LoadKernelError,
    NameSpaceOperatingError,
    PHYDeviceError,
)

    return {
        "privileged": True,
    }

  def enable_capability(self, docker_node):
    if not WiFiCapability.is_mac80211_hwsim_loaded():
      WiFiCapability.load_kernel_mac80211_hwsim()
    try:
      self.__get_available_phy_device(docker_node)
      self.__phy_namespace_setup(docker_node)
      if docker_node.type != "wifi_ap":
        self.start_wpa_supplicant_service(docker_node)
    except Exception as e:
      self.logger.exception("{!r}".format(e))
      return -1
    self.logger.info("Node: {} successfully enabled wifi capability".format(
        docker_node.name))

  def disable_capability(self, docker_node):
    try:
      docker_node.container.exec_run("killall wpa_supplicant")
      self.__phy_namespace_restore(docker_node)
    except Exception as e:
      self.logger.exception("{!r}".format(e))
    self.logger.info("Node: {} successfully disabled wifi capablility".format(
        docker_node.name))

  def __get_available_phy_device(self, docker_node):
    ret = utils.host_run(self.logger, "iw dev")
    if ret.stderr != b"":

      raise PHYDeviceError("Error:{}".format(ret.stderr))