def up(force, env=None, **kwargs): """Starts a new experiment using vagrant""" inventory = os.path.join(os.getcwd(), "hosts") provider = Enos_vagrant(provider_conf) roles, networks = provider.init(force_deploy=force) generate_inventory(roles, networks, inventory, check_networks=True) env["roles"] = roles env["networks"] = networks env["inventory"] = inventory
def up(force=True, env=None, **kwargs): "Starts a new experiment" inventory = os.path.join(os.getcwd(), "hosts") conf = Configuration.from_dictionnary(provider_conf) provider = Enos_vagrant(conf) roles, networks = provider.init() check_networks(roles, networks) env["roles"] = roles env["networks"] = networks
def up(force, env=None, **kwargs): """Starts a new experiment using vagrant""" inventory = os.path.join(os.getcwd(), "hosts") conf = Configuration.from_dictionnary(provider_conf) provider = Enos_vagrant(conf) roles, networks = provider.init(force_deploy=force) discover_networks(roles, networks) env["roles"] = roles env["networks"] = networks
def vagrant(config, force, env=None, **kwargs): conf = VagrantConf.from_dictionnary(config["vagrant"]) provider = Enos_vagrant(conf) roles, networks = provider.init(force_deploy=force) env["config"] = config env["roles"] = roles env["networks"] = networks env["context"] = "vagrant" env["provider"] = provider
def infra(conf: Configuration): 'Provision and remove a `conf` infrastructure from Vagrant.' # Get the Vagrant provider vagrant_provider = Enos_vagrant(conf) # Setup the infra LOG.info("Provisioning machines...") roles, networks = vagrant_provider.init() # Extract the list of Hosts from Roles hosts = set([h for hs in roles.values() for h in hs]) LOG.info("Provisioning finished") try: # Let the user does it stuff # yield: Tuple[List[Host], Roles, List[Network]] yield hosts, roles, networks LOG.info('You can SSH on Hosts from another terminal with:') for h in hosts: LOG.info(f'- vagrant ssh {h.alias}') input('Press Enter to finish...') except Exception as e: LOG.error(f'Unexpected error: {e}') finally: # Tear down the infra LOG.info('Finished!') LOG.info('Destroying machines...') vagrant_provider.destroy() tmp_enoslib_path = '_tmp_enos_' LOG.info(f'Removing cache {tmp_enoslib_path}...') if os.path.isdir(tmp_enoslib_path): shutil.rmtree(tmp_enoslib_path)
"roles": ["compute"], "flavour": "tiny", "number": 1 }, ], "networks": [{ "cidr": "192.168.20.0/24", "roles": ["mynetwork"] }], } } tc = {"enable": True, "default_delay": "20ms", "default_rate": "1gbit"} inventory = os.path.join(os.getcwd(), "hosts") print("Starting ressources with the provider vagrant") provider = Enos_vagrant(VagrantConf.from_dictionnary(provider_conf)) roles, networks = provider.init() print("Building the machine list") resources = {"machines": [], "networks": []} for role, machines in roles.items(): for machine in machines: resources["machines"].append({ "address": machine.address, "alias": machine.alias, "user": machine.user, "port": int(machine.port), "keyfile": machine.keyfile, "roles": [role], })
"box": "debian/jessie64", "resources": { "machines": [{ "role": "control1", "flavor": "tiny", "number": 1, "networks": ["n1", "n2"] }, { "role": "control2", "flavor": "tiny", "number": 1, "networks": ["n1", "n3"] }] } } tc = { "enable": True, "default_delay": "20ms", "default_rate": "1gbit", } inventory = os.path.join(os.getcwd(), "hosts") provider = Enos_vagrant(provider_conf) roles, networks = provider.init() generate_inventory(roles, networks, inventory, check_networks=True) #result = run_command("control*", "ping -c 1 {{hostvars['enos-1']['ansible_' + n1].ipv4.address}}", inventory) result = run_command("control*", "date", inventory) print(result["ok"]) emulate_network(roles, inventory, tc) validate_network(roles, inventory)
def vagrant(env=None, broker=BROKER, force=False, config=None, **kwargs): provider = Enos_vagrant(config["vagrant"]) roles, networks = provider.init(force_deploy=force) env["config"] = config env["roles"] = roles env["networks"] = networks
from enoslib.infra.enos_vagrant.provider import Enos_vagrant from enoslib.infra.enos_vagrant.configuration import Configuration import logging import os logging.basicConfig(level=logging.INFO) conf = Configuration()\ .add_machine(roles=["control"], flavour="tiny", number=1)\ .add_machine(roles=["control", "compute"], flavour="tiny", number=1)\ .add_network(roles=["mynetwork"], cidr="192.168.42.0/24")\ .finalize() # claim the resources provider = Enos_vagrant(conf) roles, networks = provider.init() # generate an inventory compatible with ansible discover_networks(roles, networks) print(roles) # destroy the boxes provider.destroy()
def vagrant(config, **kwargs): return Enos_vagrant(config["vagrant"])