def _mount_cluster_nics(self, conf, cluster, nodes, kavlan_nodes, vlans): """Get the NIC devices of the reserved cluster. :param nodes: List of hostnames unmodified by the vlan """ provider_conf = conf['provider'] # XXX: this only works if all nodes are on the same cluster, # or if nodes from different clusters have the same devices site = EX5.get_cluster_site(cluster) nics = EX5.get_resource_attributes( "/sites/%s/clusters/%s/nodes" % (site, cluster) )['items'][0]['network_adapters'] interfaces = [nic['device'] for nic in nics if nic['mountable'] and nic['interface'] == 'Ethernet'] network_interface = str(interfaces[0]) external_interface = None if len(interfaces) > 1 and not provider_conf['single_interface']: external_interface = str(interfaces[1]) _, vlan = self._get_primary_vlan(vlans) api.set_nodes_vlan(site, map(lambda d: EX.Host(d), nodes), external_interface, vlan) self._exec_command_on_nodes( kavlan_nodes, "ifconfig %s up && dhclient -nw %s" % ( external_interface, external_interface), 'mounting secondary interface') else: # TODO(msimonin) fix the network in this case as well. external_interface = 'veth0' if provider_conf['single_interface']: logging.warning("Forcing the use of a one network interface") else: logging.warning("%s has only one NIC. The same interface " "will be used for network_interface and " "neutron_external_interface." % conf['resources'].keys()[0]) self._exec_command_on_nodes( kavlan_nodes, 'ip link show veth0 || ip link add type veth peer', 'Creating a veth') return (network_interface, external_interface)
def _mount_secondary_nics(desc, networks): cluster = desc["cluster"] # get only the secondary interfaces nics = get_cluster_interfaces(cluster, lambda nic: not nic['mounted']) idx = 0 desc["_c_nics"] = desc.get("_c_nics") or [] for network_id in desc.get("secondary_networks", []): net = lookup_networks(network_id, networks) if net["type"] == PROD: # nothing to do continue nic_device, nic_name = nics[idx] nodes_to_set = [Host(n) for n in desc["_c_nodes"]] vlan_id = net["_c_network"]["vlan_id"] logger.info("Put %s, %s in vlan id %s for nodes %s" % (nic_device, nic_name, vlan_id, nodes_to_set)) api.set_nodes_vlan(net["site"], nodes_to_set, nic_device, vlan_id) # recording the mapping, just in case desc["_c_nics"].append((nic_name, get_roles_as_list(net))) idx = idx + 1