예제 #1
0
 def init(self, conf, force_deploy=False):
     LOGGER.info("Vagrant provider")
     enoslib_conf = _build_enoslib_conf(conf)
     _conf = Configuration.from_dictionnary(enoslib_conf)
     vagrant = enoslib_vagrant.Enos_vagrant(_conf)
     roles, networks = vagrant.init(force_deploy)
     return roles, networks
예제 #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"
예제 #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
예제 #4
0
파일: step2.py 프로젝트: Prygan/enoslib
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
예제 #5
0
 def test_from_dictionnary_custom_backend(self):
     d = {
         "backend": "virtualbox",
         "resources": {
             "machines": [],
             "networks": []
         }
     }
     conf = Configuration.from_dictionnary(d)
     self.assertEqual("virtualbox", conf.backend)
예제 #6
0
 def test_missing_flavour_and_flavour_desc(self):
     d = {
         "backend": "virtualbox",
         "resources": {
             "machines": [{
                 "roles": ["role1"]
             }],
             "networks": []
         },
     }
     with self.assertRaises(ValidationError) as e:
         conf = Configuration.from_dictionnary(d)
예제 #7
0
    def test_programmatic(self):
        conf = Configuration()
        conf.add_machine_conf(MachineConfiguration(roles=["r1"],
                                                   flavour=FLAVOURS["large"],
                                                   number=10))\
            .add_network_conf(NetworkConfiguration(roles=["net1"], cidr="192.168.2.1/24"))

        conf.finalize()
        self.assertEqual(1, len(conf.machines))
예제 #8
0
from typing import List

from enoslib.host import Host
from enoslib.api import run as run_command
from enoslib.infra.enos_vagrant.configuration import Configuration

from utils import infra, LOG


# Fig Code
def contextualize(hosts: List[Host]):
    '''Fig1. Install MariaDB and Galera on a list of `hosts`.

    A `Host` is an abstract notion of unit of computation that can be
    bound to bare-metal machines, virtual machines or containers.

    '''
    run_command("apt install -y mariadb-server galera", hosts)


# Test it!

# Define the infrastructure: 2 machines
CONF = (Configuration().from_settings(backend="virtualbox").add_machine(
    flavour="tiny", number=2, roles=["database"]).finalize())

# Setup the infra and call the `contextualize` function
with infra(CONF) as (hosts, _, _):
    LOG.info(inspect.getsource(contextualize))
    contextualize(hosts)
예제 #9
0
파일: step1.py 프로젝트: msimonin/enoslib
            "networks": ["n1"]
        }]
    }
}

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
예제 #10
0
 def test_programmatic_missing_keys(self):
     conf = Configuration()
     conf.add_machine_conf(MachineConfiguration())
     with self.assertRaises(jsonschema.exceptions.ValidationError) as _:
         conf.finalize()
예제 #11
0
from enoslib.api import generate_inventory, discover_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()

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

# generate an inventory compatible with ansible
discover_networks(roles, networks)
generate_inventory(roles, networks, inventory, check_networks=True)
예제 #12
0
    This function builds a specific `filter` with the CIDR of the
    `net` and prints TCP `packets` that are related to the Galera
    communications.

    '''
    LOG.info(f'Listen packet on {ifname(net)}...')
    scapy.sniff(
        iface=ifname(net),
        count=10,  # Stop analysis after 10 packets
        filter=f'net {net["cidr"]} and tcp and port 4567',
        prn=lambda packet: packet.summary())


# Test it!

# Define the infrastructure: 2 machines, 1 net
CONF = (Configuration().from_settings(backend="libvirt").add_machine(
    flavour="tiny",
    number=2, roles=["database"]).add_network(cidr="192.168.42.0/24",
                                              roles=["database"]).finalize())

# Setup the infra and call the `analyze_galera` function
with infra(CONF) as (hosts, roles, networks):
    # First, install and configure active/active Galera
    setup_galera(roles, networks)

    # Then, analyze
    LOG.info(inspect.getsource(analyze_galera))
    analyze_galera(lookup_net(networks, "database"))
예제 #13
0
# -*- coding: utf-8 -*-

# Imports
import os
from pprint import pformat
import yaml

from enoslib.infra.enos_vagrant.configuration import Configuration

from utils import infra, LOG


# Fig Code (Load the yaml file)
YAML_PATH = 'fig5.yaml'
YAML_DICT = None
with open(YAML_PATH) as yaml_file:
    YAML_DICT = yaml.safe_load(yaml_file)


# Test It!

# Define the infrastructure: 2 database machines, 2
# database/client machines, 1 net
CONF = Configuration.from_dictionnary(YAML_DICT)

# Setup the infra and call the `contextualize` function
LOG.info(f'Provisionning of {YAML_PATH}:\n{pformat(CONF.to_dict())}')
with infra(CONF):
    pass
예제 #14
0
            body_format="json", method="POST",
            status_code=[200], # 409 for already added
            src="misc/grafana-dashboard.json")

    # Display UI URLs to view metrics
    ui_urls = map(lambda h: f'http://{h.extra["monitor_ip"]}:3000', rs['aggregator'])
    LOG.info(f'View UI on {list(ui_urls)}')
    LOG.info('Connect with `admin` as login and password, '
             'then skip the change password, '
             'and finally select `Host Dashboard`.')


# Test it!

# Define the infrastructure: 2 database/monitored machines, 2
# database/client/monitored machines, 1 aggregator machine, 1 net for
# database, 1 net for monitoring.
CONF = (Configuration()
        .from_settings(backend="virtualbox")
        .add_machine(flavour='tiny', number=2, roles=['database', 'monitored'])
        .add_machine(flavour='tiny', number=2, roles=['database', 'client', 'monitored'])
        .add_machine(flavour='tiny', number=1, roles=['aggregator'])
        .add_network(cidr='192.168.43.0/24', roles=['database'])
        .add_network(cidr='192.168.44.0/24', roles=['monitor'])
        .finalize())

# Setup the infra and call the `monitor` function
with infra(CONF) as (_, roles, networks):
    LOG.info(inspect.getsource(monitor))
    monitor(roles, networks)
예제 #15
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],
        })
예제 #16
0
 def test_from_dictionnary_minimal(self):
     d = {"resources": {"machines": [], "networks": []}}
     conf = Configuration.from_dictionnary(d)
     self.assertEqual(constants.DEFAULT_BACKEND, conf.backend)
     self.assertEqual(constants.DEFAULT_BOX, conf.box)
     self.assertEqual(constants.DEFAULT_USER, conf.user)
예제 #17
0
파일: flent_on.py 프로젝트: Prygan/enoslib
from enoslib.infra.enos_vagrant.provider import Enos_vagrant
from enoslib.infra.enos_vagrant.configuration import Configuration

import logging


logging.basicConfig(level=logging.DEBUG)

# The conf let us define the resources wanted.
# This is provider specific
conf = Configuration.from_settings(backend="libvirt",
                                   box="generic/debian9")\
                    .add_machine(roles=["server"],
                                 flavour="tiny",
                                 number=1)\
                    .add_machine(roles=["client"],
                                 flavour="tiny",
                                 number=1)\
                    .add_network(roles=["mynetwork"],
                                 cidr="192.168.42.0/24")\
                    .finalize()

provider = Enos_vagrant(conf)

# The code below is intended to be provider agnostic

# Start the resources
roles, networks = provider.init()

# Add some specific knowledge to the returned roles (e.g on the server the ip
# for mynetwork is 192.168.42.254)