Mentions légales du service

Skip to content
Snippets Groups Projects
Verified Commit c6fb86ad authored by SIMONIN Matthieu's avatar SIMONIN Matthieu
Browse files

Introduce a configuration object

```
from enoslib.infra.enos_g5k.provider import G5k
from enoslib.infra.enos_g5k.configuration import Configuration

conf = Configuration.from_dictionnary(provider_conf)
provider = G5k(conf)
roles, networks = provider.init()
```
Note: Validation is done in the class method from_dictionnary.

Additionnaly a programmatic way of creating configuration is provided :

```
conf = Configuration()
network = NetworkConfiguration(id="id",
                               roles=["my_network"],
                               type="prod",
                               site="rennes")

conf.add_network_conf(network)\
        .add_machine_conf(MachineConfiguration(roles=["r1"],
                     cluster="paravance",
                     primary_network=network))\
        .add_machine_conf(MachineConfiguration(roles=["r2"],
                     cluster="parapluie",
                     primary_network=network,
                     nodes=10))\
       .finalize()
```

```
conf = Configuration()
network = NetworkConfiguration(id="id",
                               roles=["my_network"],
                               type="prod",
                               site="rennes")

conf.add_network_conf(network)\
        .add_machine(roles=["r1"],
                     cluster="paravance",
                     primary_network=network)\
        .add_machine(roles=["r2"],
                     cluster="parapluie",
                     primary_network=network,
                     nodes=10)\
       .finalize()
```

In this case validation is done when calling finalize.

Refactor each provider code to split the configuration from the Provider
object. This object is then passed to the provider which only read it and
proceed with the deployment of the infrastructure.

In each provider:
- add a `configuration.py` which contains the definition of Configuration
- add a `schema.py` which contains the schema
- add a `constants.py` which contains the constants

- Unit testing has been added as well as
- functionnal tests adapted to the new API (mostly located in `docs/tutorials`)

- Drop py27
- In configuration schema, drop `role` keyword (keep only `roles`)
- update doc
parent 6e2c1ee5
Branches to_2_configuration
Tags
No related merge requests found
Showing
with 392 additions and 101 deletions
......@@ -18,13 +18,6 @@ python3.5:
- pip install tox
- tox -e py35 pep8
python2.7:
image: python:2.7
stage: test
script:
- pip install tox
- tox -e py27 pep8
python3.6:
image: python:3.6
stage: test
......
sudo: false
language: python
python:
- "2.7"
- "3.5"
- "3.6"
install: pip install tox-travis
......
......@@ -9,52 +9,106 @@ Base Provider Class
:undoc-members:
:show-inheritance:
Vagrant
-------
Vagrant Provider Class
----------------------
^^^^^^^^^^^^^^^^^^^^^^
.. automodule:: enoslib.infra.enos_vagrant.provider
:members:
:undoc-members:
:show-inheritance:
.. autodata:: FLAVORS
Vagrant Schema
^^^^^^^^^^^^^^
.. literalinclude:: ../../enoslib/infra/enos_vagrant/schema.py
Grid5000 Provider Class
-----------------------
Grid5000 (G5k)
--------------
G5k Provider Class
^^^^^^^^^^^^^^^^^^
.. automodule:: enoslib.infra.enos_g5k.provider
:members:
:undoc-members:
:show-inheritance:
Grid5000 API
^^^^^^^^^^^^
G5k Schema
^^^^^^^^^^
.. literalinclude:: ../../enoslib/infra/enos_g5k/schema.py
G5k API
^^^^^^^
.. automodule:: enoslib.infra.enos_g5k.api
:members:
:undoc-members:
:show-inheritance:
Static
------
Static Provider Class
^^^^^^^^^^^^^^^^^^^^^
.. automodule:: enoslib.infra.enos_static.provider
:members:
:undoc-members:
:show-inheritance:
Static Schema
^^^^^^^^^^^^^
.. literalinclude:: ../../enoslib/infra/enos_static/schema.py
Openstack
---------
Openstack Provider Class
------------------------
^^^^^^^^^^^^^^^^^^^^^^^^
.. automodule:: enoslib.infra.enos_openstack.provider
:members:
:undoc-members:
:show-inheritance:
Openstack Schema
^^^^^^^^^^^^^^^^
.. literalinclude:: ../../enoslib/infra/enos_openstack/schema.py
Chameleon
---------
Chameleon(kvm) Provider Class
-----------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automodule:: enoslib.infra.enos_chameleonkvm.provider
:members:
:undoc-members:
:show-inheritance:
Chameleon(kvm) Schema
^^^^^^^^^^^^^^^^^^^^^
.. literalinclude:: ../../enoslib/infra/enos_chameleonkvm/schema.py
Chameleon(bare metal) Provider Class
------------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automodule:: enoslib.infra.enos_chameleonbaremetal.provider
:members:
:undoc-members:
:show-inheritance:
Chameleon(bare metal) schema
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. literalinclude:: ../../enoslib/infra/enos_chameleonbaremetal/schema.py
......@@ -15,10 +15,29 @@ Installation
It's a good practice to use a virtualenv or a python version manager like `pyenv`.
Alternatively you can also install from sources:
Basic example
-------------
The following reserve 2 nodes on the chameleon baremetal infrastructure.
Prior to the execution you must source your openrc file:
.. code-block:: bash
$ pip install -U git+https://github.com/BeyondTheClouds/enoslib/enoslib#egg=enoslib[chameleon]
..
$ source CH-XXXXX.sh
You must also configure an access key in you project and replace with its name
in the following.
.. literalinclude:: chameleon/tuto_chameleonbaremetal.py
:language: python
:linenos:
.. note::
Similarly to other provider the configuration can be generated
programmatically instead of using a dict.
from enoslib.api import generate_inventory, emulate_network, validate_network
from enoslib.infra.enos_chameleonbaremetal.provider import Chameleonbaremetal
from enoslib.infra.enos_chameleonbaremetal.configuration import Configuration
import logging
import os
logging.basicConfig(level=logging.INFO)
provider_conf = {
"key_name": "enos_matt",
"resources": {
"machines": [{
"roles": ["control"],
"flavour": "compute_skylake",
"number": 1,
},{
"roles": ["compute"],
"flavour": "compute_skylake",
"number": 1,
}],
"networks": ["network_interface"]
}
}
tc = {
"enable": True,
"default_delay": "20ms",
"default_rate": "1gbit",
}
inventory = os.path.join(os.getcwd(), "hosts")
conf = Configuration.from_dictionnary(provider_conf)
provider = Chameleonbaremetal(conf)
# provider.destroy()
roles, networks = provider.init()
generate_inventory(roles, networks, inventory, check_networks=True)
emulate_network(roles, inventory, tc)
validate_network(roles, inventory)
provider.destroy()
Tutorial 2 - Working with Grid'5000
===================================
This tutorial illustrate the use of EnOSlib to interact with Grid'5000. For a
This tutorial illustrates the use of EnOSlib to interact with Grid'5000. For a
full description of the API and the available options, please refer to the API
documentation of the Grid'5000 provider.
......@@ -21,8 +21,13 @@ On Grid'5000, you can go with a virtualenv :
Basic example
-------------
The following ``tuto_grid5000.py`` implements a basic workflow where 2 nodes are
reserved and 2 roles are described. Nodes are here put in a dedicated vlan.
We'll implement a basic workflow where 2 nodes are reserved and 2 roles are
described. Nodes are here put in a dedicated vlan.
Build the configuration from a dictionnary
******************************************
.. literalinclude:: grid5000/tuto_grid5000.py
:language: python
......@@ -45,31 +50,65 @@ reserved and 2 roles are described. Nodes are here put in a dedicated vlan.
Compared to the vagrant provider, Grid'5000 requires a more precise
network description that should map what is available on the platform.
Build the configuration programmatically
****************************************
The above script can be rewritten using the programmatc API.
.. literalinclude:: grid5000/tuto_grid5000_p.py
:language: python
:linenos:
.. note::
Here we first create a network and pass its reference to each group of
machine to configure the first interface of the Grid'5000 nodes.
Subnet reservation
------------------
The following ``tuto_grid5000_subnet.py`` shows how to deal with a subnet reservation.
This shows how to deal with a subnet reservation
Build the configuration from a dictionnary
******************************************
.. literalinclude:: grid5000/tuto_grid5000_subnet.py
:language: python
:linenos:
Build the configuration programmatically
****************************************
.. literalinclude:: grid5000/tuto_grid5000_subnet_p.py
:language: python
:linenos:
Non deploy reservation
----------------------
The following ``tuto_grid5000_non_deploy.py`` shows how to deal with a non
deploy reservation. Root ssh access will be granted to the nodes. For this
purpose you must have a ``~/.ssh/id_rsa.pub`` file available. All the
connections will be done as root user allowing to mimic the behaviour of deploy
jobs (without the kadeploy3 step). This is particularly interesting if your
deployment does't require more than one network interface.
The following shows how to deal with a non deploy reservation. Root ssh access
will be granted to the nodes. For this purpose you must have a
``~/.ssh/id_rsa.pub`` file available. All the connections will be done as root
user allowing to mimic the behaviour of deploy jobs (without the kadeploy3
step). This is particularly interesting if your deployment does't require more
than one network interface.
Build the configuration from a dictionnary
******************************************
.. literalinclude:: grid5000/tuto_grid5000_non_deploy.py
:language: python
:linenos:
Build the configuration programmatically
****************************************
.. literalinclude:: grid5000/tuto_grid5000_non_deploy_p.py
:language: python
:linenos:
More complete example
---------------------
......
[control]
paravance-9-kavlan-4.rennes.grid5000.fr ansible_host=paravance-9-kavlan-4.rennes.grid5000.fr ansible_ssh_user=root ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' enos_devices="['eth0']" my_network=eth0
parasilo-7-kavlan-4.rennes.grid5000.fr ansible_host=parasilo-7-kavlan-4.rennes.grid5000.fr ansible_ssh_user=root ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' enos_devices="['eth0']" my_network=eth0
paravance-49-kavlan-8.rennes.grid5000.fr ansible_host=paravance-49-kavlan-8.rennes.grid5000.fr ansible_ssh_user=root ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' enos_devices="['eno1']" my_network=eno1
paravance-51-kavlan-8.rennes.grid5000.fr ansible_host=paravance-51-kavlan-8.rennes.grid5000.fr ansible_ssh_user=root ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' enos_devices="['eno1']" my_network=eno1
[compute]
parasilo-7-kavlan-4.rennes.grid5000.fr ansible_host=parasilo-7-kavlan-4.rennes.grid5000.fr ansible_ssh_user=root ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' enos_devices="['eth0']" my_network=eth0%
paravance-51-kavlan-8.rennes.grid5000.fr ansible_host=paravance-51-kavlan-8.rennes.grid5000.fr ansible_ssh_user=root ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' enos_devices="['eno1']" my_network=eno1
\ No newline at end of file
from enoslib.api import generate_inventory, emulate_network, validate_network
from enoslib.infra.enos_g5k.provider import G5k
from enoslib.infra.enos_g5k.configuration import Configuration
import logging
import os
......@@ -9,23 +10,28 @@ logging.basicConfig(level=logging.INFO)
provider_conf = {
"resources": {
"machines": [{
"role": "control",
"roles": ["control"],
"cluster": "paravance",
"nodes": 1,
"primary_network": "n1",
"secondary_networks": []
"secondary_networks": ["n2"]
},{
"roles": ["control", "compute"],
"cluster": "parasilo",
"nodes": 1,
"primary_network": "n1",
"secondary_networks": []
"secondary_networks": ["n2"]
}],
"networks": [{
"id": "n1",
"type": "kavlan",
"role": "my_network",
"roles": ["my_network"],
"site": "rennes",
}, {
"id": "n2",
"type": "kavlan",
"roles": ["my_second_network"],
"site": "rennes",
}]
}
......@@ -35,11 +41,11 @@ provider_conf = {
inventory = os.path.join(os.getcwd(), "hosts")
# claim the resources
provider = G5k(provider_conf)
conf = Configuration.from_dictionnary(provider_conf)
provider = G5k(conf)
roles, networks = provider.init()
# generate an inventory compatible with ansible
generate_inventory(roles, networks, inventory, check_networks=True)
# destroy the reservation
provider.destroy()
from enoslib.api import generate_inventory
from enoslib.infra.enos_g5k.provider import G5k
from enoslib.infra.enos_g5k.configuration import Configuration
import logging
import os
......@@ -11,7 +12,7 @@ provider_conf = {
"job_name": "test-non-deploy",
"resources": {
"machines": [{
"role": "control",
"roles": ["control"],
"cluster": "parapluie",
"nodes": 1,
"primary_network": "n1",
......@@ -27,7 +28,7 @@ provider_conf = {
"networks": [{
"id": "n1",
"type": "prod",
"role": "my_network",
"roles": ["my_network"],
"site": "rennes",
}]
}
......@@ -37,7 +38,9 @@ provider_conf = {
inventory = os.path.join(os.getcwd(), "hosts")
# claim the resources
provider = G5k(provider_conf)
conf = Configuration.from_dictionnary(provider_conf)
provider = G5k(conf)
roles, networks = provider.init()
# generate an inventory compatible with ansible
......
from enoslib.api import generate_inventory
from enoslib.infra.enos_g5k.provider import G5k
from enoslib.infra.enos_g5k.configuration import (Configuration,
NetworkConfiguration)
import logging
import os
logging.basicConfig(level=logging.INFO)
# path to the inventory
inventory = os.path.join(os.getcwd(), "hosts")
# claim the resources
conf = Configuration.from_settings(job_type="allow_classic_ssh",
job_name="test-non-deploy")
network = NetworkConfiguration(id="n1",
type="prod",
roles=["my_network"],
site="rennes")
conf.add_network_conf(network)\
.add_machine(roles=["control"],
cluster="parapluie",
nodes=1,
primary_network=network)\
.add_machine(roles=["control", "network"],
cluster="parapluie",
nodes=1,
primary_network=network)\
.finalize()
provider = G5k(conf)
roles, networks = provider.init()
# generate an inventory compatible with ansible
generate_inventory(roles, networks, inventory, check_networks=True)
# destroy the reservation
provider.destroy()
from enoslib.api import generate_inventory, emulate_network, validate_network
from enoslib.infra.enos_g5k.provider import G5k
from enoslib.infra.enos_g5k.configuration import Configuration, NetworkConfiguration
import logging
import os
logging.basicConfig(level=logging.INFO)
# path to the inventory
inventory = os.path.join(os.getcwd(), "hosts")
# claim the resources
network = NetworkConfiguration(id="n1",
type="kavlan",
roles=["my_network"],
site="rennes")
conf = Configuration.from_settings(job_name="test-enoslib")\
.add_network_conf(network)\
.add_machine(roles=["control"],
cluster="paravance",
nodes=1,
primary_network=network)\
.add_machine(roles=["control", "compute"],
cluster="paravance",
nodes=1,
primary_network=network)\
.finalize()
provider = G5k(conf)
roles, networks = provider.init()
# generate an inventory compatible with ansible
generate_inventory(roles, networks, inventory, check_networks=True)
# destroy the reservation
provider.destroy()
from enoslib.api import generate_inventory, emulate_network, validate_network
from enoslib.infra.enos_g5k.provider import G5k
from enoslib.infra.enos_g5k.configuration import Configuration
import logging
import os
......@@ -9,7 +10,7 @@ logging.basicConfig(level=logging.INFO)
provider_conf = {
"resources": {
"machines": [{
"role": "control",
"roles": ["control"],
"cluster": "parapluie",
"nodes": 1,
"primary_network": "n1",
......@@ -19,13 +20,13 @@ provider_conf = {
{
"id": "n1",
"type": "prod",
"role": "my_network",
"roles": ["my_network"],
"site": "rennes"
},
{
"id": "not_linked_to_any_machine",
"type": "slash_22",
"role": "my_subnet",
"roles": ["my_subnet"],
"site": "rennes",
}]
}
......@@ -35,7 +36,8 @@ provider_conf = {
inventory = os.path.join(os.getcwd(), "hosts")
# claim the resources
provider = G5k(provider_conf)
conf = Configuratin.from_dictionnary(provider_conf)
provider = G5k(conf)
roles, networks = provider.init()
# Retrieving subnet
......
from enoslib.api import generate_inventory
from enoslib.infra.enos_g5k.provider import G5k
from enoslib.infra.enos_g5k.configuration import (Configuration,
NetworkConfiguration)
import logging
import os
logging.basicConfig(level=logging.INFO)
# path to the inventory
inventory = os.path.join(os.getcwd(), "hosts")
# claim the resources
conf = Configuration.from_settings(job_type="allow_classic_ssh")
prod_network = NetworkConfiguration(id="n1",
type="prod",
roles=["my_network"],
site="rennes")
conf.add_network_conf(prod_network)\
.add_network(id="not_linked_to_any_machine",
type="slash_22",
roles=["my_subnet"],
site="rennes")\
.add_machine(roles=["control"],
cluster="parapluie",
nodes=1,
primary_network=prod_network)\
.finalize()
provider = G5k(conf)
roles, networks = provider.init()
# Retrieving subnet
subnet = [n for n in networks if "my_subnet" in n["roles"]]
logging.info(subnet)
# This returns the subnet information
# {
# 'roles': ['my_subnet'],
# 'start': '10.158.0.1',
# 'dns': '131.254.203.235',
# 'end': '10.158.3.254',
# 'cidr': '10.158.0.0/22',
# 'gateway': '10.159.255.254'
# 'mac_end': '00:16:3E:9E:03:FE',
# 'mac_start': '00:16:3E:9E:00:01',
# }
# generate an inventory compatible with ansible
generate_inventory(roles, networks, inventory, check_networks=True)
# destroy the reservation
provider.destroy()
from enoslib.api import generate_inventory, run_ansible
from enoslib.infra.enos_g5k.provider import G5k
from enoslib.infra.enos_g5k.configuration import (Configuration,
NetworkConfiguration)
import logging
from netaddr import EUI
import os
......@@ -19,39 +22,31 @@ def range_mac(mac_start, mac_end, step=1):
ip = ['10'] + [str(int(i, 2)) for i in mac.bits().split('-')[-3:]]
yield str(mac).replace('-', ':'), '.'.join(ip)
provider_conf = {
"job_type": "allow_classic_ssh",
"job_name": "test-non-deploy",
"walltime": "1:00:00",
"resources": {
"machines": [{
"role": "compute",
"cluster": "parasilo",
"nodes": PMS,
"primary_network": "n1",
"secondary_networks": []
}],
"networks": [{
"id": "n1",
"type": "prod",
"role": "my_network",
"site": "rennes",
}, {
"id": "not_linked_to_any_machine",
"type": "slash_22",
"role": "my_subnet",
"site": "rennes",
}]
}
}
# claim the resources
prod = NetworkConfiguration(id="n1",
type="prod",
roles=["my_network"],
site="rennes")
conf = Configuration.from_settings(job_type="allow_classic_ssh",
job_name="enoslib-virt",
walltime="01:00:00")\
.add_network_conf(prod)\
.add_network(id="_subnet_network",
type="slash_22",
roles=["my_subnet"],
site="rennes")\
.add_machine(roles=["compute"],
cluster="parasilo",
nodes=PMS,
primary_network=prod)\
.finalize()
provider = G5k(conf)
roles, networks = provider.init()
# path to the inventory
inventory = os.path.join(os.getcwd(), "hosts")
# claim the resources
provider = G5k(provider_conf)
roles, networks = provider.init()
# generate an inventory compatible with ansible
generate_inventory(roles, networks, inventory, check_networks=True)
......
192.168.142.245 : 0.03 0.04 0.04 0.04 0.04
192.168.142.244 : 41.50 41.55 41.63 42.50 41.43
192.168.142.244 : 40.48 40.40 40.42 40.43 40.35 40.36 40.36 40.44 40.27 40.34
192.168.142.245 : 0.02 0.02 0.03 0.02 0.03 0.03 0.03 0.02 0.03 0.02
2 targets
2 alive
......@@ -7,12 +7,12 @@
0 unknown addresses
0 timeouts (waiting for response)
10 ICMP Echos sent
10 ICMP Echo Replies received
20 ICMP Echos sent
20 ICMP Echo Replies received
0 other ICMP received
0.03 ms (min round trip time)
20.8 ms (avg round trip time)
42.5 ms (max round trip time)
4.075 sec (elapsed real time)
0.02 ms (min round trip time)
20.2 ms (avg round trip time)
40.4 ms (max round trip time)
9.042 sec (elapsed real time)
[control]
enos-0 ansible_host=127.0.0.1 ansible_ssh_user=root ansible_port=2222 ansible_ssh_private_key_file=/Users/msimonin/sed/discovery/openstack/enoslib/docs/tutorials/using-tasks/.vagrant/machines/enos-0/virtualbox/private_key ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' n1=eth1 enos_devices="['eth1']"
enos-0 ansible_host=192.168.121.70 ansible_ssh_user=root ansible_port=22 ansible_ssh_private_key_file=/home/msimonin/workspace/repos/enoslib/docs/tutorials/using-tasks/.vagrant/machines/enos-0/libvirt/private_key ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' n3=eth1 enos_devices="['eth1']"
[compute]
enos-1 ansible_host=127.0.0.1 ansible_ssh_user=root ansible_port=2201 ansible_ssh_private_key_file=/Users/msimonin/sed/discovery/openstack/enoslib/docs/tutorials/using-tasks/.vagrant/machines/enos-1/virtualbox/private_key ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' n1=eth1 enos_devices="['eth1']"
\ No newline at end of file
enos-1 ansible_host=192.168.121.170 ansible_ssh_user=root ansible_port=22 ansible_ssh_private_key_file=/home/msimonin/workspace/repos/enoslib/docs/tutorials/using-tasks/.vagrant/machines/enos-1/libvirt/private_key ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' n3=eth1 enos_devices="['eth1']"
\ No newline at end of file
from enoslib.api import generate_inventory, emulate_network,\
validate_network, reset_network
from enoslib.infra.enos_vagrant.provider import Enos_vagrant
from enoslib.infra.enos_vagrant.configuration import Configuration
import logging
import os
......@@ -10,12 +11,12 @@ logging.basicConfig(level=logging.INFO)
provider_conf = {
"resources": {
"machines": [{
"role": "control",
"roles": ["control"],
"flavor": "tiny",
"number": 1,
"networks": ["n1"]
},{
"role": "compute",
"roles": ["compute"],
"flavor": "tiny",
"number": 1,
"networks": ["n1"]
......@@ -33,7 +34,9 @@ tc = {
inventory = os.path.join(os.getcwd(), "hosts")
# claim the resources
provider = Enos_vagrant(provider_conf)
conf = Configuration.from_dictionnary(provider_conf)
provider = Enos_vagrant(conf)
roles, networks = provider.init()
generate_inventory(roles, networks, inventory, check_networks=True)
......
from enoslib.api import generate_inventory, emulate_network, validate_network
from enoslib.task import enostask
from enoslib.infra.enos_vagrant.provider import Enos_vagrant
from enoslib.infra.enos_vagrant.configuration import Configuration
import click
import os
provider_conf = {
"backend": "virtualbox",
"user": "root",
"resources": {
"machines": [{
"role": "control",
"roles": ["control"],
"flavor": "tiny",
"number": 1,
"networks": ["n1"]
},{
"role": "compute",
"roles": ["compute"],
"flavor": "tiny",
"number": 1,
"networks": ["n1"]
......@@ -34,7 +32,8 @@ tc = {
def up(force=True, env=None, **kwargs):
"Starts a new experiment"
inventory = os.path.join(os.getcwd(), "hosts")
provider = Enos_vagrant(provider_conf)
conf = Configuration.from_dictionnary(provider_conf)
provider = Enos_vagrant(conf)
roles, networks = provider.init()
generate_inventory(roles, networks, inventory, check_networks=True)
env["roles"] = roles
......
from enoslib.api import generate_inventory, emulate_network, validate_network
from enoslib.task import enostask
from enoslib.infra.enos_vagrant.provider import Enos_vagrant
from enoslib.infra.enos_vagrant.configuration import Configuration
import os
import logging
logging.basicConfig(level=logging.INFO)
provider_conf = {
"backend": "virtualbox",
"user": "root",
"box": "debian/jessie64",
"resources": {
"machines": [{
"role": "control",
"roles": ["control"],
"flavor": "tiny",
"number": 1,
"networks": ["n1", "n2"]
},{
"role": "compute",
"roles": ["compute"],
"flavor": "tiny",
"number": 1,
"networks": ["n1", "n3"]
......@@ -44,7 +42,8 @@ def cli():
def up(force, env=None, **kwargs):
"""Starts a new experiment using vagrant"""
inventory = os.path.join(os.getcwd(), "hosts")
provider = Enos_vagrant(provider_conf)
conf = Configuration.from_dictionnary(provider_conf)
provider = Enos_vagrant(conf)
roles, networks = provider.init(force_deploy=force)
generate_inventory(roles, networks, inventory, check_networks=True)
env["roles"] = roles
......
......@@ -20,6 +20,9 @@ Installation
Using the API
-------------
From a dictionnary
******************
The following ``tuto_vagrant.py`` implements the desired workflow.
.. literalinclude:: vagrant/tuto_vagrant.py
......@@ -54,4 +57,12 @@ The following ``tuto_vagrant.py`` implements the desired workflow.
Note the extra variables concerning the network. They can be use in
your ansible playbooks to refer to a specific network.
Programmatic way
****************
.. literalinclude:: vagrant/tuto_vagrant_p.py
:language: python
:linenos:
.. _pyenv: https://github.com/pyenv/pyenv
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment