示例#1
0
    def initialize(self):
        """Initialize this instance and make it go"""
        cpn_dir_name = os.getenv('FORCH_CONFIG_DIR')
        cpn_file_name = os.path.join(cpn_dir_name, 'cpn.yaml')
        current_time = datetime.now().isoformat()
        self._logger.info("Reading CPN config file: %s", cpn_file_name)
        try:
            cpn_data = yaml_proto(cpn_file_name, CpnConfig)
            cpn_nodes = cpn_data.cpn_nodes

            for node, attr_map in cpn_nodes.items():
                node_state_map = self._node_states.setdefault(node, {})
                node_state_map[NODE_ATTRIBUTES] = attr_map
                self._hosts_ip[node] = attr_map.cpn_ip

            if not self._hosts_ip:
                raise Exception('No CPN components defined in file')

            self._ping_manager = PingManager(self._hosts_ip,
                                             self.ping_interval)
            self._update_cpn_state(current_time, State.initializing,
                                   "Initializing")
        except Exception as e:
            self._logger.error('Could not load config file: %s', e)
            self._node_states.clear()
            self._update_cpn_state(current_time, State.broken, str(e))

        if self._ping_manager:
            self._ping_manager.start_loop(self._handle_ping_result)
示例#2
0
def load_network_state(base_dir_name):
    """Load network state file"""
    file = os.path.join(base_dir_name, 'network_state.yaml')
    LOGGER.info('Loading network state file %s', file)
    network_state = yaml_proto(file, NetworkState)
    LOGGER.info('Loaded %d devices', len(network_state.device_mac_behaviors))
    return network_state
示例#3
0
 def _reload_static_device_placement(self, file_path):
     if self._faucetizer:
         self._faucetizer.clear_static_placements()
     devices_state = yaml_proto(file_path, DevicesState)
     for eth_src, device_placement in devices_state.device_mac_placements.items(
     ):
         self._process_device_placement(eth_src,
                                        device_placement,
                                        static=True)
示例#4
0
def load_devices():
    """Load a device specification file"""
    base_dir_name = os.getenv('FORCH_CONFIG_DIR')
    building_schema_file_name = os.path.join(base_dir_name, 'building_schema.yaml')
    LOGGER.info('Loading device spec file %s', building_schema_file_name)
    building_schema = yaml_proto(building_schema_file_name, BuildingSchema)
    loaded_macs = list(building_schema.mac_addrs.keys())
    loaded_macs.sort()
    LOGGER.info('Loaded device spec for devices: %s', loaded_macs)
    sys.stdout.write(str(loaded_macs) + '\n')
示例#5
0
    def reload_segments_to_vlans(self, file_path):
        """Reload file that contains the mappings from segments to vlans"""
        self._segments_to_vlans = yaml_proto(file_path, SegmentsToVlans).segments_to_vlans

        operational_vlans = set(self._segments_to_vlans.values())
        if self._all_testing_vlans and self._all_testing_vlans & operational_vlans:
            self._logger.error(
                'Testing VLANs has intersection with operational VLANs: %s',
                self._all_testing_vlans & operational_vlans)

        self.flush_behavioral_config()
示例#6
0
def load_config():
    """Load configuration from the configuration file"""
    config_root = os.getenv('FORCH_CONFIG_DIR', '.')
    config_file = os.getenv('FORCH_CONFIG_FILE', _FORCH_CONFIG_DEFAULT)
    config_path = os.path.join(config_root, config_file)
    LOGGER.info('Reading config file %s', os.path.abspath(config_path))
    try:
        return yaml_proto(config_path, ForchConfig)
    except Exception as e:
        LOGGER.error('Cannot load config: %s', e)
        return None
示例#7
0
    def _reload_static_device_behavior(self, file_path):
        self._port_state_manager.clear_static_device_behaviors()

        try:
            devices_state = yaml_proto(file_path, DevicesState)
        except Exception as error:
            msg = f'Authentication disabled: could not load static behavior file {file_path}'
            LOGGER.error('%s: %s', msg, error)
            with self._lock:
                self._config_errors[STATIC_BEHAVIORAL_FILE] = msg
                self._should_ignore_auth_result = True
            return

        with self._lock:
            self._config_errors.pop(STATIC_BEHAVIORAL_FILE, None)
            self._should_ignore_auth_result = False

        LOGGER.info('Authentication resumed')

        for mac, device_behavior in devices_state.device_mac_behaviors.items():
            self._port_state_manager.handle_static_device_behavior(mac, device_behavior)
示例#8
0
def load_orch_config(file):
    """Load forch config and return orchestration config"""
    forch_config = yaml_proto(file, ForchConfig)
    return forch_config.orchestration
示例#9
0
def load_segments_to_vlans(file):
    """Load segments to vlans mapping from file"""
    segments_to_vlans = yaml_proto(file, SegmentsToVlans)
    return segments_to_vlans
示例#10
0
def load_devices_state(file):
    """Load devices state file"""
    LOGGER.info('Loading network state file %s', file)
    devices_state = yaml_proto(file, DevicesState)
    LOGGER.info('Loaded %d devices', len(devices_state.device_mac_behaviors))
    return devices_state