def is_enabled(self): # # # Make sure that this port is enabled. # if not self.query(): Log.error('{}[{}].enable : can\'t read status', self.node.name, self.index) self.active = False return False state, health = self.current['Status']['State'], self.current[ 'Status']['Health'] link_state = self.current['LinkState'] if_state = self.current['InterfaceState'] if health != 'OK': Log.error('{}[{}].enable : port health {} is bad', self.node.name, self.index, health) port.active = False return False if state != 'Enabled': Log.debug('{}[{}].enable : state not yet ready {}/{}', self.node.name, self.index, state, health) return False if if_state != 'Enabled': Log.debug('{}[{}].enable : interface not yet enabled {}', self.node.name, self.index, if_state) return False return True
def enable(self): # # # Get the current port state. # if not self.query(): Log.error('{}[{}].enable : can\'t read status', self.node.name, self.index) self.active = False return False state, health = self.current['Status']['State'], self.current[ 'Status']['Health'] link_state = self.current['LinkState'] if_state = self.current['InterfaceState'] if health != 'OK': Log.error('{}[{}].enable : port health {} is bad', self.node.name, self.index, health) port.active = False return False # # Verify that the port is in the correct state for enabling the interface. # if state == 'Enabled': Log.debug('{}[{}].enable : already enabled {}/{}', self.node.name, self.index, state, health) return True if state != 'StandbyOffline': Log.debug('{}[{}].enable : state not ready {}/{}', self.node.name, self.index, state, health) return False if link_state != 'Enabled': Log.debug('{}[{}].enable : link state not ready {}', self.node.name, self.index, link_state) return False if if_state != 'Disabled': Log.debug('{}[{}].enable : interface state not ready {}', self.node.name, self.index, if_state) return False # # If we are in StandbyOffline mode, transition to Enabled. # values = {'InterfaceState': 'Enabled'} status, _ = self.node.patch(self.name, values) if not status: Log.error('{}[{}].enable : can\'t enable interface - downing port', self.node.name, self.index) self.active = False Log.debug('{}[{}].enable : status={}', self.node.name, self.index, status) return status
def initialize(self): # # Validate the sweep type. # if self.sweep_type not in Fabric.sweep_types: Log.error('invalid sweep type {}', self.sweep_type) return False # # Read the node profiles. # self.nodes = {} for filename in self.node_file_list: Log.info('reading {}', filename) try: with open(filename) as f: node_profiles = json.load(f) for name, profile in node_profiles.items(): node_type = profile['type'] self.nodes[name] = Fabric.name_classes[node_type]( name, profile) except: Log.error('error reading {}', filename) return False # # There are 5 steps for node initialization: # 1) load the GCIDs and UID into the endpoints # 2) train the port links # 3) validate that all ports are wired correctly # 4) load the node attributes # 5) enable the port interfaces # status = True if status: status = self.init_ids() if status: status = self.train_ports() if status: status = self.validate_ports() if status: status = self.load_nodes() if status: status = self.enable_ports() # # Verify the state of all connected ports. # if status: status = self.verify_fabric_health() Log.debug('fabric initialization status = {}', status) return status
def train(self): # # # Make sure that this port is enabled. # if not self.query(): Log.error('{}[{}].train : can\'t read status', self.node.name, self.index) self.active = False return False state, health = self.current['Status']['State'], self.current[ 'Status']['Health'] link_state = self.current['LinkState'] if_state = self.current['InterfaceState'] Log.debug('{}[{}].train : S={}/{} LS={} IF={}', self.node.name, self.index, state, health, link_state, if_state) # # Check the port health. # if health != 'OK': Log.error('{}[{}].train : port health {} is bad', self.node.name, self.index, health) self.active = False return False # # Check the port state for consistency. # possible_port_states = { # Status Link Interface ('Disabled', 'Disabled', 'Disabled'): True, ('Starting', 'Disabled', 'Disabled'): False, # link != Enabled ('StandbyOffline', 'Disabled', 'Disabled'): False, # link != Enabled ('Enabled', 'Disabled', 'Disabled'): False, # link != Enabled ('Disabled', 'Disabled', 'Enabled'): False, # interface != Disabled ('Starting', 'Disabled', 'Enabled'): False, # link != Enabled ('StandbyOffline', 'Disabled', 'Enabled'): False, # link != Enabled ('Enabled', 'Disabled', 'Enabled'): False, # link != Enabled ('Disabled', 'Enabled', 'Disabled'): False, # status != Starting ('Starting', 'Enabled', 'Disabled'): True, ('StandbyOffline', 'Enabled', 'Disabled'): True, ('Enabled', 'Enabled', 'Disabled'): False, # interface != Enabled ('Disabled', 'Enabled', 'Enabled'): False, # link != Disabled ('Starting', 'Enabled', 'Enabled'): False, # interface != Disabled ('StandbyOffline', 'Enabled', 'Enabled'): True, ('Enabled', 'Enabled', 'Enabled'): True, } port_state = possible_port_states.get((state, link_state, if_state), False) if not port_state: Log.error('{}[{}].train : invalid port state {} {} {}', self.node.name, self.index, state, link_state, if_state) return False # # Only train up if we are in the correct state. # if state == 'Disabled' and link_state == 'Disabled' and if_state == 'Disabled': status, _ = self.node.patch(self.name, {'LinkState': 'Enabled'}) if not status: Log.error('{}[{}].train : can\'t set LinkState', self.node.name, self.index) self.active = False return False return True