Esempio n. 1
0
    def __init__(self,
                 ip_forwarding_enabled,
                 proto_id,
                 ip_aliases,
                 target_instance_ips,
                 dhclient_script,
                 dhcp_command,
                 network_setup_enabled,
                 debug=False):
        """Constructor.

    Args:
      ip_forwarding_enabled: bool, True if ip forwarding is enabled.
      proto_id: string, the routing protocol identifier for Google IP changes.
      ip_aliases: bool, True if the guest should configure IP alias routes.
      target_instance_ips: bool, True supports internal IP load balancing.
      dhclient_script: string, the path to a dhclient script used by dhclient.
      dhcp_command: string, a command to enable Ethernet interfaces.
      network_setup_enabled: bool, True if network setup is enabled.
      debug: bool, True if debug output should write to the console.
    """
        facility = logging.handlers.SysLogHandler.LOG_DAEMON
        self.logger = logger.Logger(name='google-networking',
                                    debug=debug,
                                    facility=facility)
        self.ip_aliases = ip_aliases
        self.ip_forwarding_enabled = ip_forwarding_enabled
        self.network_setup_enabled = network_setup_enabled
        self.target_instance_ips = target_instance_ips
        self.dhclient_script = dhclient_script

        self.ip_forwarding = ip_forwarding.IpForwarding(proto_id=proto_id,
                                                        debug=debug)
        self.network_setup = network_setup.NetworkSetup(
            dhclient_script=dhclient_script,
            dhcp_command=dhcp_command,
            debug=debug)
        self.network_utils = network_utils.NetworkUtils(logger=self.logger)
        self.watcher = metadata_watcher.MetadataWatcher(logger=self.logger)
        self.distro_utils = distro_utils.Utils(debug=debug)

        try:
            with file_utils.LockFile(LOCKFILE):
                self.logger.info('Starting Google Networking daemon.')
                timeout = 60 + random.randint(0, 30)
                self.watcher.WatchMetadata(
                    self.HandleNetworkInterfaces,
                    metadata_key=self.instance_metadata_key,
                    recursive=True,
                    timeout=timeout)
        except (IOError, OSError) as e:
            self.logger.warning(str(e))
Esempio n. 2
0
  def __init__(self, dhclient_script=None, dhcp_command=None, debug=False):
    """Constructor.

    Args:
      dhclient_script: string, the path to a dhclient script used by dhclient.
      dhcp_command: string, a command to enable Ethernet interfaces.
      debug: bool, True if debug output should write to the console.
    """
    self.dhclient_script = dhclient_script or '/sbin/google-dhclient-script'
    self.dhcp_command = dhcp_command
    facility = logging.handlers.SysLogHandler.LOG_DAEMON
    self.logger = logger.Logger(
        name='network-setup', debug=debug, facility=facility)
    self.distro_utils = distro_utils.Utils(debug=debug)
  def __init__(self, debug=False):
    """Constructor.

    Args:
      debug: bool, True if debug output should write to the console.
    """
    facility = logging.handlers.SysLogHandler.LOG_DAEMON
    self.logger = logger.Logger(
        name='google-clock-skew', debug=debug, facility=facility)
    self.distro_utils = distro_utils.Utils(debug=debug)
    self.watcher = metadata_watcher.MetadataWatcher(logger=self.logger)
    try:
      with file_utils.LockFile(LOCKFILE):
        self.logger.info('Starting Google Clock Skew daemon.')
        self.watcher.WatchMetadata(
            self.HandleClockSync, metadata_key=self.drift_token,
            recursive=False)
    except (IOError, OSError) as e:
      self.logger.warning(str(e))
 def __new__(self, logger, proto_id=None):
   return distro_utils.Utils().IpForwardingUtils(logger, proto_id)