[docs]classPlugin(AbstractPlugin):""" Connect all VMs in the experiment to a single :py:class:`Switch <base_objects.Switch>`. This is for testing connectivity, NIC creation, and IP address assignment. """
[docs]defrun(self,num_nets="1",ipv6="False"):""" Connect all VMs in the experiment to a single :py:class:`Switch <base_objects.Switch>`. The number of connections depends on the number of networks passed into the plugin. An error will be thrown if there are more than 255 networks. Args: num_nets (str): The number of networks to connect. ipv6 (str): A string representing whether or not to use IPv6 networking. Raises: RuntimeError: If ``num_nets`` is less than or equal to 0 or greater than 255. """num_nets=int(num_nets)ipv6=strtobool(ipv6)ifnum_nets>=255ornum_nets<=0:raiseRuntimeError("The number of networks must be between [1-254].")ifnum_nets>=10:scaling_factor=num_nets//20+1forvinself.g.get_vertices():ifv.is_decorated_by(VMEndpoint):try:v.vm["mem"]=1024*scaling_factorv.vm["vcpu"]={"sockets":4,"cores":1,"threads":1}exceptAttributeError:v.vm={"mem":1024*scaling_factor}v.vm["vcpu"]={"sockets":4,"cores":1,"threads":1}fornetinrange(1,num_nets+1):# Create our switchswitch=Vertex(self.g,f"switch-{net}")switch.decorate(Switch)# Create an IP Addressifipv6:network=netaddr.IPNetwork(f"{net}::/16")else:network=netaddr.IPNetwork(f"{net}.0.0.0/8")ips=network.iter_hosts()forvinself.g.get_vertices():ifv.is_decorated_by(VMEndpoint):v.connect(switch,next(ips),network.netmask)