Example #1
0
    def _parse_config_file(self, config_file):
        ''' Config file has general configuration, such as href prefix.
            Config file has information for Switches
             - Name
             - Connection info 
             - List of reserved bridge numbers
             - Neighbors
        '''
        with open(config_file) as data_file:
            data = json.load(data_file)

        self.base_url = data['adaptor-href-base']

        for switch in data['switches']:
            switch_name = switch['name']
            connection_info = switch['connection-info']
            reserved_bridges = switch['reserved-bridges']
            neighbors = switch['neighbors']

            # Determine the correct href for the switch we're creating
            switch_href = self.base_url + "switches/" + switch_name

            # Create Switch object
            switch = Switch(switch_name, switch_href, self.no_switch)

            # Create the ConnectionInfo object and add it to the switch
            cxn_info_object = ConnectionInfo(connection_info['address'],
                                             connection_info['rest_key'])
            switch.set_connection_info(cxn_info_object)

            # Add list of reserved bridges
            switch.set_reserved_bridges(reserved_bridges)

            # Create all the neighbors and add them to the switch object
            for neighbor in neighbors:
                neighbor_name = neighbor['name']
                neighbor_type = neighbor['type']
                neighbor_physport = neighbor['port']
                neighbor_vlans = neighbor['vlans']
                neighbor_href = switch_href + "/neighbors/" + neighbor_name
                neighbor_object = Neighbor(neighbor_name, neighbor_href,
                                           neighbor_vlans, neighbor_physport,
                                           neighbor_type)

                switch.add_neighbor(neighbor_object)
            # Save off switch
            self.switches[switch_name] = switch