# 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,
)
          self.RUNTIME_NAMESPACE))

    pid = docker_node.get_container_pid()
    sym_src = "/proc/{}/ns/net".format(pid)
    sym_dst = "/var/run/netns/{}".format(docker_node.name)
    os.symlink(sym_src, sym_dst)
    if not os.path.isfile(sym_dst):
      raise NameSpaceOperatingError(
          "unable mounting container namespace: {} to host".format(
              docker_node.name))

  def __add_phy_device_to_container_namespace(self, docker_node):
    ret = utils.host_run(
        docker_node.logger,
        "iw phy {} set netns name {}".format(docker_node.wlan_phy_device,
                                             docker_node.name))
    if ret.returncode != 0:
      raise NameSpaceOperatingError(
          "failed adding {} to container namespace: {}".format(
              docker_node.wlan_phy_device, docker_node.name))

  def __bring_up_wifi_interface(self, docker_node):
    commands = [
        "ip link set {} down".format(docker_node.wlan_interface),
        "ip link set {} name wlan0".format(docker_node.wlan_interface),
        "ip link set wlan0 up",
    ]
    for command in commands:
      ret = utils.netns_run(docker_node.logger, command, docker_node.name)
      if ret.returncode != 0:

# 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,
)

          self.RUNTIME_NAMESPACE))

    pid = docker_node.get_container_pid()
    sym_src = "/proc/{}/ns/net".format(pid)
    sym_dst = "/var/run/netns/{}".format(docker_node.name)
    os.symlink(sym_src, sym_dst)
    if not os.path.isfile(sym_dst):
      raise NameSpaceOperatingError(
          "unable mounting container namespace: {} to host".format(
              docker_node.name))

  def __add_phy_device_to_container_namespace(self, docker_node):
    ret = utils.host_run(
        docker_node.logger,
        "iw phy {} set netns name {}".format(docker_node.wlan_phy_device,
                                             docker_node.name))
    if ret.returncode != 0:
      raise NameSpaceOperatingError(
          "failed adding {} to container namespace: {}".format(
              docker_node.wlan_phy_device, docker_node.name))

  def __bring_up_wifi_interface(self, docker_node):
    commands = [
        "ip link set {} down".format(docker_node.wlan_interface),
        "ip link set {} name wlan0".format(docker_node.wlan_interface),
        "ip link set wlan0 up",
    ]
    for command in commands:
      ret = utils.netns_run(docker_node.logger, command, docker_node.name)
      if ret.returncode != 0:

        raise IpNetnsExecError("Error: {} on command: {}".format(