# 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/utils.py
# def manipulate_iptable_src_dst_rule(logger, src, dst, action, add=True):
#   chain = 'DOCKER-USER'
#   manipulate_action = '-I' if add else '-D'
#   ret = host_run(logger, 'iptables -L DOCKER-USER')
#   if b'No chain/target/match by that name' in ret.stderr:
#     chain = 'INPUT'
#   cmd = [
#       'iptables', manipulate_action, chain, '-s', src, '-d', dst, '-j', action
#   ]
#   ret = host_run(logger, cmd)
#   if ret.returncode != 0:
#     logger.error('Failed to add iptables rule %s', ' '.join(cmd))


from cirque.capabilities.basecapability import BaseCapability
from cirque.common.utils import manipulate_iptable_src_dst_rule
# Copyright 2020 Google LLC
#
# 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.



class LanAccessCapability(BaseCapability):

  def __init__(self, home_lan):
    self.__home_lan = home_lan

  @property
  def name(self):
    return 'LanAccess'

  def enable_capability(self, docker_node):
    node_address = docker_node.description['ipv4_addr']
    subnet = self.__home_lan.subnet

# 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/utils.py
# def manipulate_iptable_src_dst_rule(logger, src, dst, action, add=True):
#   chain = 'DOCKER-USER'
#   manipulate_action = '-I' if add else '-D'
#   ret = host_run(logger, 'iptables -L DOCKER-USER')
#   if b'No chain/target/match by that name' in ret.stderr:
#     chain = 'INPUT'
#   cmd = [
#       'iptables', manipulate_action, chain, '-s', src, '-d', dst, '-j', action
#   ]
#   ret = host_run(logger, cmd)
#   if ret.returncode != 0:
#     logger.error('Failed to add iptables rule %s', ' '.join(cmd))


# Path: cirque/capabilities/lanaccesscapability.py
from cirque.capabilities.basecapability import BaseCapability
from cirque.common.utils import manipulate_iptable_src_dst_rule

# Copyright 2020 Google LLC
#
# 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.



class LanAccessCapability(BaseCapability):

  def __init__(self, home_lan):
    self.__home_lan = home_lan

  @property
  def name(self):
    return 'LanAccess'

  def enable_capability(self, docker_node):
    node_address = docker_node.description['ipv4_addr']
    subnet = self.__home_lan.subnet

    manipulate_iptable_src_dst_rule(self.__home_lan.logger, node_address,