def _simulate_state_changes(self, node: Node, final_state: str): """ Simulate the node transitioning through multiple states by firing state change events. :param Node node: the node to transition through the state changes :param str final_state: the final state the node must reach in the simulation """ initial_state_found = False for state in self.STATE_TRANSITIONS: # # Find the current node state in the list of transitions # if not initial_state_found: if state == node.state: initial_state_found = True continue # # Fire a state change event to get to the next state # previous_state = node.state node.state = state self.fire_state_change_event(node, previous_state) # # If this is the final state, exit the loop # if state == final_state: break
def setNodeForNetworkBoot(self, session: Session, dbNode: Node) -> None: \ # pylint: disable=unused-argument # Update node status to "Expired" and boot from network dbNode.state = state.NODE_STATE_EXPIRED dbNode.bootFrom = 0 self.deletePuppetNodeCert(dbNode.name)
def primeDb(session: Session, settings: Dict[str, Any]): """ Prime database with initial data """ # Create node entry for installer node = Node(name=settings['fqdn']) node.state = state.NODE_STATE_INSTALLED node.lockedState = 'HardLocked' node.lastUpdate = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) node.bootFrom = 1 node.isIdle = False # Create Installer Software Profile node.softwareprofile = SoftwareProfile( name=settings['installer_software_profile'], description='Installer software profile', type='installer', minNodes=1, maxNodes=1, lockedState='HardLocked', ) node.softwareprofile.os = OperatingSystem( name=settings['osInfo'].getName(), version=settings['osInfo'].getVersion(), arch=settings['osInfo'].getArch()) node.softwareprofile.os.family = OperatingSystemFamily( name=settings['osInfo'].getOsFamilyInfo().getName(), version=settings['osInfo'].getOsFamilyInfo().getVersion(), arch=settings['osInfo'].getOsFamilyInfo().getArch()) # Create Installer Hardware Profile node.hardwareprofile = HardwareProfile( name=settings['installer_hardware_profile']) node.hardwareprofile.description = 'Installer hardware profile' node.hardwareprofile.nameFormat = 'installer' node.hardwareprofile.installType = 'package' node.hardwareprofile.setLocation = 'local' node.hardwareprofile.mappedsoftwareprofiles.append(node.softwareprofile) session.add(node)
def start(self, addNodesRequest: dict, dbSession: Session, dbHardwareProfile: HardwareProfile, dbSoftwareProfile: Optional[SoftwareProfile] = None): """ Create nodes """ # # Load resource adapter settings # config = self.getResourceAdapterConfig( sectionName=addNodesRequest.get( 'resource_adapter_configuration', 'default') ) nodes = [] for _ in range(addNodesRequest['count']): random_host_name_suffix = get_random_host_name_suffix() node = Node(name='compute-{}'.format(random_host_name_suffix)) node.softwareprofile = dbSoftwareProfile node.hardwareprofile = dbHardwareProfile node.isIdle = False node.state = self.STATE_TRANSITIONS[0] # create dummy nic nic = Nic(boot=True, ip=generate_fake_ip()) node.nics.append(nic) self._simulate_state_changes( node, config.get('state', self.settings['state'].default) ) nodes.append(node) return nodes
def setNodeForNetworkBoot(self, session: Session, dbNode: Node): \ # pylint: disable=unused-argument dbNode.state = state.NODE_STATE_EXPIRED