Exemplo n.º 1
0
def vagrant(env=None, broker=BROKER, force=False, **kwargs):
    with open("confs/vagrant-%s.yaml" % broker) as f:
        vagrant_config = yaml.load(f)
        provider = Enos_vagrant(vagrant_config)
        roles, networks = provider.init(force_deploy=force)
        # saving the roles
        env["roles"] = roles
        env["networks"] = networks
Exemplo n.º 2
0
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"
Exemplo n.º 3
0
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)
    check_networks(roles, networks)
    env["roles"] = roles
    env["networks"] = networks
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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()
    discover_networks(roles, networks)
    env["roles"] = roles
    env["networks"] = networks
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
                "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],
        })
Exemplo n.º 8
0
    "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)
Exemplo n.º 9
0
    }
}

tc = {
    "enable": True,
    "default_delay": "20ms",
    "default_rate": "1gbit",
}

# path to the inventory
inventory = os.path.join(os.getcwd(), "hosts")

# claim the resources
conf = Configuration.from_dictionnary(provider_conf)

provider = Enos_vagrant(conf)
roles, networks = provider.init()
generate_inventory(roles, networks, inventory, check_networks=True)

# apply network constraints
emulate_network(roles, inventory, tc)

# validate network constraints
validate_network(roles, inventory)

# reset network constraints
reset_network(roles, inventory)

# validate network constraints and saving in an alternative
validate_network(roles, inventory, output_dir="after_reset")
Exemplo n.º 10
0
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
Exemplo n.º 11
0
def vagrant(config, **kwargs):
    return Enos_vagrant(config["vagrant"])