def assign_and_configure_roles_to_node(node_fqdn, role_list, node_config=None): node = Node.get_by_name(node_fqdn) if node_config != None: for param_label, value in node_config.iteritems(): param = ConfigClassParameter.get_by_name(param_label) Override.update_or_create_override(node, param, value) roles = [Role.get_by_name(role_name) for role_name in role_list] NodeRoleAssignment.add_roles_to_node(node, roles, True)
def test_get_overrides(self): node = self._add_blank_node() d1 = {config.HAPI_USER: '******', config.HAPI_PASS: '******', config.MYSQL_USER: '******', config.MYSQL_PASS: '******', } for key, value in d1.iteritems(): Override.update_or_create_override(node, config.get_by_name(key), value) d2 = node.get_overrides_dict() self.assertDictEqual(d1, d2)
def update_related_config_params(roles, node_fqdn): """Update all config values affected by the given worker type moving to a new node. Then restart all affected services. """ affected_config_parms = [] for role in roles: if role.description: affected_config_parms.extend(RoleDesConfigParamAssignment.\ get_param_labels_by_description(role.description)) affected_config_parms = set(affected_config_parms) for param_label in affected_config_parms: ConfigClassParameter.set_config_parameter(param_label, node_fqdn) Override.update_overrides(ConfigClassParameter.\ get_by_name(param_label)) GroupOverride.update_overrides(ConfigClassParameter.\ get_by_name(param_label)) # restart appropriate services on the affected nodes or # track nodes whose CLI configuration require a refresh node_dict = {} details = ConfigClassParameter.\ get_details_for_params(affected_config_parms) for param_label in affected_config_parms: applies_to = details[param_label]['applies-to'] for role_name in applies_to: role_name = str(role_name) affected_nodes = Node.get_fqdns_by_role(role_name) for n in affected_nodes: if n in node_dict and role_name not in node_dict[n]: node_dict[n].append(role_name) elif n != node_fqdn: node_dict[n] = [role_name] affected_nodes = Node.get_fqdns_by_role(role_name, is_service=False) for n in affected_nodes: if n not in node_dict: node_dict[n] = [] svc_restart = ConfigClassParameter.\ get_by_name(ConfigClassParameter.VPX_RESTART_SERVICES) for node_fqdn, role_to_restart in node_dict.iteritems(): if len(role_to_restart) > 0: Override.update_or_create_override(Node.get_by_name(node_fqdn), svc_restart, role_to_restart, True) return node_dict.keys()
def test_copy_node_overrides(self): node_src = self._add_dummy_node('node_src') node_dst = self._add_dummy_node('node_dst') c1 = config.get_by_name('HAPI_PASS') c2 = config.get_by_name('HAPI_USER') overrides = \ [Override.\ objects.create(node=node_src, config_class_parameter=c1, value='mysecret'), Override.\ objects.create(node=node_src, config_class_parameter=c2, value='myuser'), ] Override.copy_node_overrides(node_dst, overrides) self.assertDictEqual(node_dst.get_overrides_dict(), node_src.get_overrides_dict())
def get_or_create_node(node_fqdn): try: node = Node.get_by_name(node_fqdn) except: node = Node.create(node_fqdn) # Generate and assign a Host GUID host_guid = _generate_host_guid() param = ConfigClassParameter.get_by_name( ConfigClassParameter.HOST_GUID) Override.update_or_create_override(node, param, host_guid) # Assign default roles on node creation default_roles = Role.get_default_roles() NodeRoleAssignment.add_roles_to_node(node, default_roles) # determine if we can add celeryd on each worker. This is # possible only if the DB backend is != sqlite3 if DATABASES['default']['ENGINE'] == 'django.db.backends.mysql': celery_role = Role.get_by_name(Role.CELERY_WORKER) NodeRoleAssignment.add_roles_to_node(node, [celery_role], True) return node
def create_swift_rings(hostnames): """This attempts to create the swift ring file on the master, given the specified hostnames of the swift object nodes.""" # Resolve IPs # TODO - we should have this info in the facts ips = [] for hostname in hostnames: ips.append(socket.gethostbyname(hostname)) ips_str = string.join(ips, " ") # Assign Ring Builder Role: runs on this host node_fqdn = network.get_hostname() node = Node.get_by_name(node_fqdn) Override.update_or_create_override( node, ConfigClassParameter.get_by_name(ConfigClassParameter.SWIFT_NODES_IPS), ips_str) NodeRoleAssignment.add_roles_to_node(node, [Role.get_by_name(Role.RING_BUILDER)], True) return node_fqdn
def _add_dummy_node(self, fqdn='test_fqdn', is_enabled=True): self.dummy_node_fqdn = fqdn node = Node.create(fqdn) node.enabled = is_enabled import pickle node.facts = pickle.dumps({ "geppetto_status_running_services": "openstack-nova-api,openstack-nova-compute", "geppetto_status_stopped_services": "openstack-nova-network", "host_fqdn": "test_host", "ipaddress_eth0": "169.254.0.2", "ipaddress_eth1": "127.0.0.1", "interfaces": "'eth0,eth1,eth2,lo'", }) node.save() node.joined_date = datetime.datetime(2001, 1, 1, 0, 0, 0, 0) # make the host guid predictable param = ConfigClassParameter.get_by_name( ConfigClassParameter.HOST_GUID) Override.update_or_create_override(node, param, "00:00:00:00:00:00") return node