def populate(self): """Prepare services.""" if is_master_process(): for name in self.factories.keys(): self.populateService(name) else: for name, item in self.factories.items(): if not item["only_on_master"]: self.populateService(name)
def inner_start_up(): """Startup jobs that must run serialized w.r.t. other starting servers.""" # Register our MAC data type with psycopg. register_mac_type(connection.cursor()) # Ensure the this region is represented in the database. The first regiond # to pass through inner_start_up on this host can do this; it should NOT # be restricted to masters only. This also ensures that the MAAS ID is set # on the filesystem; it will be done in a post-commit hook and will thus # happen before `locks.startup` is released. region = RegionController.objects.get_or_create_running_controller() # Only perform the following if the master process for the # region controller. if is_master_process(): # Freshen the kms SRV records. dns_kms_setting_changed() # Add or update all builtin scripts load_builtin_scripts() # Refresh soon after this transaction is in. post_commit_do(reactor.callLater, 0, refreshRegion, region)
def register(system_id=None, hostname='', interfaces=None, url=None, is_loopback=None, create_fabrics=True, version=None): """Register a new rack controller if not already registered. Attempt to see if the rack controller was already registered as a node. This can be looked up either by system_id, hostname, or mac address. If found convert the existing node into a rack controller. If not found create a new rack controller. After the rack controller has been registered and successfully connected we will refresh all commissioning data. The parameter ``is_loopback`` is only referenced if ``url`` is not None. :return: A ``rack-controller``. """ if interfaces is None: interfaces = {} # If hostname is actually a FQDN, split the domain off and # create it as non-authoritative domain if it does not exist already. domain = Domain.objects.get_default_domain() if hostname.find('.') > 0: hostname, domainname = hostname.split('.', 1) (domain, _) = Domain.objects.get_or_create(name=domainname, defaults={'authoritative': False}) this_region = RegionController.objects.get_running_controller() node = find(system_id, hostname, interfaces) version_log = "2.2 or below" if version is None else version if node is None: node = RackController.objects.create(hostname=hostname, domain=domain) maaslog.info( "New rack controller '%s' running version %s was created by " "region '%s' upon first connection.", node.hostname, version_log, this_region.hostname) elif node.is_rack_controller: if is_master_process(): # Only the master process logs to the maaslog. maaslog.info( "Existing rack controller '%s' running version %s has " "connected to region '%s'.", node.hostname, version_log, this_region.hostname) elif node.is_region_controller: maaslog.info( "Region controller '%s' running version %s converted into a " "region and rack controller.", node.hostname, version_log) node.node_type = NODE_TYPE.REGION_AND_RACK_CONTROLLER node.pool = None node.save() else: maaslog.info( "Region controller '%s' converted '%s' running version %s into a " "rack controller.", this_region.hostname, node.hostname, version_log) node.node_type = NODE_TYPE.RACK_CONTROLLER node.pool = None node.save() if node.current_commissioning_script_set is None: # Create a ScriptSet so the rack can store its commissioning data # which is sent on connect. script_set = ScriptSet.objects.create_commissioning_script_set(node) node.current_commissioning_script_set = script_set node.save() rackcontroller = node.as_rack_controller() # Update `rackcontroller.url` from the given URL, if it has changed. update_fields = [] if url is not None: if is_loopback and rackcontroller.url != '': # There used to be a URL, and now it's localhost, set it to None. rackcontroller.url = '' update_fields.append("url") elif not is_loopback and rackcontroller.url != url.geturl(): # There is a non-loopback URL, and it's different than what the # database has. Change it. rackcontroller.url = url.geturl() update_fields.append("url") # else: # The URL is already the correct value, no need to change anything. if rackcontroller.owner is None: rackcontroller.owner = worker_user.get_worker_user() update_fields.append("owner") rackcontroller.save(update_fields=update_fields) # Update interfaces, if requested. rackcontroller.update_interfaces(interfaces, create_fabrics=create_fabrics) return rackcontroller