Exemplo n.º 1
0
def _switching_main(args):
    if args.debug:
        debug = True
    else:
        debug = False

    config = ConfigParser.ConfigParser()
    assert config.read(args.ini), 'could not read config file {}'.format(
        args.ini)

    configuration = Configuration()
    configuration.host = config.get('nsxv', 'nsx_manager')
    configuration.username = config.get('nsxv', 'nsx_username')
    configuration.password = config.get('nsxv', 'nsx_password')
    configuration.verify_ssl = False
    client = ApiClient(configuration)

    try:
        command_selector = {
            'create': _create_switch,
        }
        command_selector[args.command](client,
                                       transport_zone=args.transport_zone,
                                       name=args.name,
                                       vlan=args.vlan,
                                       verbose=args.verbose)
    except KeyError:
        print('Unknown command')
Exemplo n.º 2
0
def _switching_main(args):
    if args.debug:
        debug = True
    else:
        debug = False

    config = ConfigParser.ConfigParser()
    assert config.read(args.ini), 'could not read config file {}'.format(
        args.ini)

    configuration = Configuration()
    configuration.host = config.get('nsxv', 'nsx_manager')
    configuration.username = config.get('nsxv', 'nsx_username')
    configuration.password = config.get('nsxv', 'nsx_password')
    configuration.verify_ssl = False
    client = ApiClient(configuration)

    try:
        command_selector = {
            'create_ip_block': _create_ip_block,
            'create_ip_pool': _create_ip_pool,
        }
        command_selector[args.command](client,
                                       cidr=args.cidr,
                                       name=args.name,
                                       tag=args.tag,
                                       start=args.start,
                                       end=args.end,
                                       external=args.external,
                                       verbose=args.verbose)
    except KeyError:
        print('Unknown command')
Exemplo n.º 3
0
def _routing_main(args):
    if args.debug:
        debug = True
    else:
        debug = False

    config = ConfigParser.ConfigParser()
    assert config.read(args.ini), 'could not read config file {}'.format(
        args.ini)

    configuration = Configuration()
    configuration.host = config.get('nsxv', 'nsx_manager')
    configuration.username = config.get('nsxv', 'nsx_username')
    configuration.password = config.get('nsxv', 'nsx_password')
    configuration.verify_ssl = False
    client = ApiClient(configuration)

    try:
        command_selector = {
            'create_router': _create_router,
            'create_router_port': _create_router_port,
            'create_static_route': _create_static_route,
            'create_nat_rule': _create_nat_rule
        }
        command_selector[args.command](client,
                                       router_type=args.router_type,
                                       name=args.name,
                                       edge_cluster=args.edge_cluster,
                                       router_port_type=args.router_port_type,
                                       logical_switch=args.logical_switch,
                                       logical_router=args.logical_router,
                                       ip_address=args.ip_address,
                                       mask=args.mask,
                                       network=args.network,
                                       next_hop=args.next_hop,
                                       original_ip=args.original_ip,
                                       translated_ip=args.translated_ip,
                                       action=args.action,
                                       t0=args.t0,
                                       tag=args.tag,
                                       verbose=args.verbose)
    except KeyError:
        print('Unknown command')
Exemplo n.º 4
0
def main(argv):
    logging.getLogger("urllib3").setLevel(logging.ERROR)
    root_dir, tar_file_name, blocks_to_mine, version = read_argv(argv)
    curr_dir = os.getcwd()
    temp_dir_dev1 = os.path.join(root_dir, "node1")
    os.makedirs(temp_dir_dev1)

    temp_dir_dev2 = os.path.join(root_dir, "node2")
    temp_dir_dev3 = os.path.join(root_dir, "node3")

    print("Tar name: " + tar_file_name)
    extract_tarball(tar_file_name, temp_dir_dev1)
    shutil.copytree(temp_dir_dev1, temp_dir_dev2)
    shutil.copytree(temp_dir_dev1, temp_dir_dev3)

    node_names = ["node1", "node2", "node3"]
    node_dirs = [temp_dir_dev1, temp_dir_dev2, temp_dir_dev3]
    [
        setup_node(n, d, curr_dir, version)
        for n, d in zip(node_names, node_dirs)
    ]
    [start_node(d) for d in node_dirs]

    empty_config = Configuration()
    node_objs = []
    for n in node_names:
        empty_config.host = SETUP[n]["host"]
        node_objs.append(ExternalApi(ApiClient(configuration=empty_config)))

    wait_all_nodes_are_online(node_objs, 30)

    top = node_objs[0].get_current_key_block()
    height = top.height
    max_height = blocks_to_mine + height
    test_failed = False
    try:
        print("Will mine till block " + str(max_height))
        while height < max_height:
            time.sleep(1)  # check every second
            for name, node in zip(node_names, node_objs):
                top = node.get_current_key_block()  # node is alive and mining
                print("[" + name + "] height=" + str(top.height))
                height = max(height, top.height)
            print("")
    except ApiException as e:
        test_failed = True
        print("node died")
    except urllib3.exceptions.MaxRetryError as e:
        test_failed = True
        print("node died")
    [stop_node(d) for d in node_dirs]

    if not test_failed:
        print(
            "Checking that nodes are able to start with persisted non-empty DB"
        )
        [start_node(d) for d in node_dirs]
        wait_all_nodes_are_online(node_objs, 60)
        [stop_node(d) for d in node_dirs]

    if test_failed:
        for name, node_dir in zip(node_names, node_dirs):
            print(name + " logs:")
            print(tail_logs(node_dir, "epoch.log"))
            print("\n")
    if test_failed:
        sys.exit("FAILED")
Exemplo n.º 5
0
from swagger_client.configuration import Configuration

from nose.tools import assert_equals
from testconfig import config
from waiting import wait

from nacl.hash import sha256

import base58
import rlp
import integration.keys

EXT_API = {}
for node, node_config in config['nodes'].iteritems():
    empty_config = Configuration()
    empty_config.host = node_config['host'] + ':' + str(node_config['ports']['external_api']) + '/v2'
    EXT_API[node] = ExternalApi(ApiClient(empty_config))

INT_API = {}
for node, node_config in config['nodes'].iteritems():
    empty_config = Configuration()
    empty_config.host = node_config['host'] + ':' + str(node_config['ports']['internal_api']) + '/v2'
    INT_API[node] = InternalApi(ApiClient(empty_config))

def external_api(name):
    return EXT_API[name]

def internal_api(name):
    return INT_API[name]

def node_online(ext_api, int_api):
Exemplo n.º 6
0
def main(argv):

    opts, args = getopt.getopt(argv, "s:", ["size="])

    FIRST_REGION_NAME = "RegionOne"
    KEYSTONE_ENDPOINT = "http://{{ ansible_eno1.ipv4.address }}/identity/v3"

    #KEYSTONE_ENDPOINT = "http://192.168.57.6/identity/v3"

    def get_session_object(auth_param):
        return session.Session(auth=auth_param)

    def get_auth_object(keystone_endpoint):
        return v3.Password(
            username="******",
            password="******",
            project_name="demo",
            auth_url=keystone_endpoint,
            user_domain_id="default",
            project_domain_id="default",
            include_catalog=True,
            # Allow fetching a new token if the current one is going to expire
            reauthenticate=True)

    auth = get_auth_object(KEYSTONE_ENDPOINT)
    sess = get_session_object(auth)

    # Authenticate
    auth.get_access(sess)
    auth_ref = auth.auth_ref
    #print("Auth token: %s" %auth_ref.auth_token)

    catalog_endpoints = auth_ref.service_catalog.catalog
    #print("Resource catalog: %s" % catalog_endpoints)

    regions_list_neu = []
    regions_list_key = []
    regions_list = []

    for obj in catalog_endpoints:

        if obj['name'] == 'neutron':
            for endpoint in obj['endpoints']:
                #print(endpoint)
                new_endpoint_obj = {
                    'region_name': endpoint["region"],
                    'neutron_url': endpoint["url"]
                }
                regions_list_neu.append(new_endpoint_obj)

        if obj['name'] == 'keystone':
            for endpoint in obj['endpoints']:
                if endpoint['interface'] == 'public':
                    new_endpoint_obj = {
                        'region_name': endpoint["region"],
                        'keystone_url': endpoint["url"]
                    }
                    regions_list_key.append(new_endpoint_obj)
                    #print(endpoint)

    print(regions_list_neu)
    print(regions_list_key)

    for i in range(len(regions_list_neu)):
        neutron_endpoint = regions_list_neu[i]
        print(neutron_endpoint)
        for j in range(len(regions_list_key)):
            keystone_endpoint = regions_list_key[j]
            print(keystone_endpoint)
            if neutron_endpoint['region_name'] == keystone_endpoint[
                    'region_name']:
                new_end = {
                    'region_name': neutron_endpoint['region_name'],
                    'keystone_url': keystone_endpoint['keystone_url'],
                    'neutron_url': neutron_endpoint['neutron_url']
                }
                regions_list.append(new_end)

    print(regions_list)

    cidrs_region_network_information = {
        '10.0.0.0/24': [],
        '10.0.1.0/24': [],
        '10.0.2.0/24': [],
        '10.0.3.0/24': [],
        '10.0.4.0/24': [],
        '10.0.5.0/24': [],
        '10.0.6.0/24': [],
        '10.0.7.0/24': [],
        '10.0.8.0/24': [],
        '10.0.9.0/24': [],
        '10.0.10.0/24': [],
        '10.0.11.0/24': [],
        '10.0.12.0/24': [],
        '10.0.13.0/24': [],
        '10.0.14.0/24': [],
        '10.0.15.0/24': [],
        '10.0.16.0/24': [],
        '10.0.17.0/24': [],
        '10.0.18.0/24': [],
        '10.0.19.0/24': [],
        '10.0.20.0/24': [],
        '10.0.21.0/24': [],
        '10.0.22.0/24': [],
        '10.0.23.0/24': [],
        '10.0.24.0/24': [],
        '10.0.25.0/24': [],
        '10.0.26.0/24': [],
        '10.0.27.0/24': [],
        '10.0.28.0/24': [],
        '10.0.29.0/24': [],
        '10.0.30.0/24': [],
        '10.0.31.0/24': [],
        '10.0.32.0/24': [],
        '10.0.33.0/24': [],
        '10.0.34.0/24': [],
        '10.0.35.0/24': [],
        '10.0.36.0/24': [],
        '10.0.37.0/24': [],
        '10.0.38.0/24': [],
        '10.0.39.0/24': [],
        '10.0.40.0/24': [],
        '10.0.41.0/24': [],
        '10.0.42.0/24': [],
        '10.0.43.0/24': [],
        '10.0.44.0/24': [],
        '10.0.45.0/24': [],
        '10.0.46.0/24': [],
        '10.0.47.0/24': [],
        '10.0.48.0/24': []
    }
    #cidrs_region_network_information = {'10.0.0.0/24': [], '20.0.0.0/24': []}

    # For every region find the networks created with heat
    for i in range(len(regions_list)):
        region_name, region_auth_endpoint, region_neutron_endpoint = regions_list[
            i]['region_name'], regions_list[i][
                'keystone_url'] + '/v3', regions_list[i]['neutron_url']
        auth = get_auth_object(region_auth_endpoint)
        sess = get_session_object(auth)
        print('Getting information from region ' + str(region_name))
        # Authenticate
        auth.get_access(sess)
        auth_ref = auth.auth_ref

        net_adap = Adapter(auth=auth,
                           session=sess,
                           service_type='network',
                           interface='public',
                           region_name=region_name)

        per_region_net_list = net_adap.get('/v2.0/networks').json()
        region_network = per_region_net_list['networks']

        # For every network find the cidr of the subnetwork it has
        for index in range(len(region_network)):
            net_ID = region_network[index]['id']
            subnet_ID = region_network[index]['subnets'][0]

            per_net_subnet = net_adap.get('/v2.0/subnets/' + subnet_ID).json()
            subnet_cidr = per_net_subnet['subnet']['cidr']
            #print(subnet_cidr)
            test_object = {
                'region_name': region_name,
                'net_uuid': net_ID,
            }
            cidrs_region_network_information[subnet_cidr].append(test_object)

    #print(cidrs_region_network_information)

    test_type1 = "L3"
    test_type2 = "L2"
    print('starting tests')
    test_sizes_temps = (opts[0][1])
    test_sizes = test_sizes_temps.split(',')
    test_number = 100
    configuration = Configuration()

    for elem in test_sizes:
        test_size = int(elem)
        if (test_type1 == "L3"):
            file_results = open(
                "results/Results_" + test_type1 + "_" + str(test_size) + "_" +
                str(datetime.datetime.now().strftime("%H:%M:%S")), "w+")
            #file_results.write("L3\n")
            #file_results.write(str(test_size)+"\n")
            #file_results.write(str(test_number)+"\n")
            for i in range(test_number):
                seed(datetime.datetime.now())
                selected_index = randint(1, len(regions_list))
                host = regions_list[selected_index - 1]
                #print(host['region_name'])
                configuration.host = host['neutron_url'][0:-5] + "7575/api"
                api_instance = swagger_client.ResourcesApi(
                    swagger_client.ApiClient(configuration))

                resource = swagger_client.Resource(
                )  # Resource | data for inter-site creation
                resource.type = "L3"
                resource.name = "Inter-site network test " + str(i)

                condition = True
                keys = []
                regions = []
                subresources = []

                while (condition):
                    seed(datetime.datetime.now())
                    key = random.choice(list(cidrs_region_network_information))
                    condition1 = True
                    while (condition1):
                        seed(datetime.datetime.now())
                        second_element = random.randint(
                            1, len(cidrs_region_network_information[key]))
                        element = cidrs_region_network_information[key][
                            second_element - 1]
                        if element['region_name'] == host['region_name']:
                            #print(key)
                            #print(element)
                            keys.append(key)
                            regions.append(element['region_name'])
                            subresources.append(element['region_name'] + "," +
                                                element['net_uuid'])
                            condition = False
                            condition1 = False
                            break

                for j in range(test_size - 1):
                    #print(j)
                    condition = True
                    condition1 = True
                    while (condition and condition1):
                        seed(datetime.datetime.now())
                        key = random.choice(
                            list(cidrs_region_network_information))
                        seed(datetime.datetime.now())
                        second_element = random.randint(
                            1, len(cidrs_region_network_information[key]))
                        element = cidrs_region_network_information[key][
                            second_element - 1]
                        if element[
                                'region_name'] not in regions and key not in keys:
                            #print(key)
                            #print(element)
                            keys.append(key)
                            regions.append(element['region_name'])
                            subresources.append(element['region_name'] + "," +
                                                element['net_uuid'])
                            condition = False
                            condition1 = False
                            break

                print(i)
                print(subresources)
                print(regions)
                print(keys)

                resource.subresources = subresources
                api_response = ''
                #start = time.clock()
                start = time.time()
                try:
                    # Horizontal request to create an inter-site Resource POST
                    api_response = api_instance.vertical_create_resource(
                        resource)
                    #print(api_response['resource_global'])
                except ApiException as e:
                    print(
                        "Exception when calling VerticalApi->vertical_create_resource: %s\\n"
                        % e)

                #end = time.clock()
                end = time.time()

                print(api_response["resource_global"])
                print(start)
                print(end)
                print(end - start)
                file_results.write(str(end - start) + "\n")

                try:
                    delete_resource = api_instance.vertical_delete_resource(
                        api_response['resource_global'])
                except ApiException as e:
                    print(
                        "Exception when calling VerticalApi->vertical_create_resource: %s\n"
                        % e)

            file_results.close()

        if (test_type2 == "L2"):
            file_results = open(
                "results/Results_" + test_type2 + "_" + str(test_size) + "_" +
                str(datetime.datetime.now().strftime("%H:%M:%S")), "w+")
            for i in range(test_number):
                seed(datetime.datetime.now())
                selected_index = randint(1, len(regions_list))
                host = regions_list[selected_index - 1]
                #print(host['region_name'])
                configuration.host = host['neutron_url'][0:-5] + "7575/api"
                api_instance = swagger_client.ResourcesApi(
                    swagger_client.ApiClient(configuration))

                resource = swagger_client.Resource(
                )  # Resource | data for inter-site creation
                resource.type = "L2"
                resource.name = "Inter-site network test " + str(i)

                condition = True
                regions = []
                subresources = []

                while (condition):
                    seed(datetime.datetime.now())
                    key = random.choice(list(cidrs_region_network_information))
                    condition1 = True
                    while (condition1):
                        second_element = random.randint(
                            1, len(cidrs_region_network_information[key]))
                        element = cidrs_region_network_information[key][
                            second_element - 1]
                        if element['region_name'] == host['region_name']:

                            regions.append(element['region_name'])
                            subresources.append(element['region_name'] + "," +
                                                element['net_uuid'])
                            condition = False
                            condition1 = False
                            break

                for j in range(test_size - 1):
                    #print(j)
                    condition = True
                    while (condition):
                        seed(datetime.datetime.now())
                        new_index = randint(1, len(regions_list))
                        new_host = regions_list[new_index - 1]
                        #print(host['region_name'])
                        if new_host['region_name'] not in regions:
                            regions.append(new_host['region_name'])
                            subresources.append(new_host['region_name'] + ",")
                            condition = False
                            break

                print(i)
                print(subresources)
                print(regions)

                resource.subresources = subresources
                api_response = ""
                start = time.time()
                try:
                    # Horizontal request to create an inter-site Resource POST
                    api_response = api_instance.vertical_create_resource(
                        resource)
                    #print(api_response['resource_global'])
                except ApiException as e:
                    print(
                        "Exception when calling VerticalApi->vertical_create_resource: %s\n"
                        % e)

                end = time.time()
                print(api_response["resource_global"])
                print(end - start)
                file_results.write(str(end - start) + "\n")

                try:
                    delete_resource = api_instance.vertical_delete_resource(
                        api_response['resource_global'])
                except ApiException as e:
                    print(
                        "Exception when calling VerticalApi->vertical_create_resource: %s\n"
                        % e)

            file_results.close()
Exemplo n.º 7
0
def main(argv):
    logging.getLogger("urllib3").setLevel(logging.ERROR)
    root_dir, package_file_name, blocks_to_mine, version = read_argv(argv)
    curr_dir = os.getcwd()
    temp_dir_dev1 = os.path.join(root_dir, "node1")
    os.makedirs(temp_dir_dev1)

    temp_dir_dev2 = os.path.join(root_dir, "node2")
    temp_dir_dev3 = os.path.join(root_dir, "node3")

    print("Package name: " + package_file_name)
    extract_package(package_file_name, temp_dir_dev1)
    shutil.copytree(temp_dir_dev1, temp_dir_dev2)
    shutil.copytree(temp_dir_dev1, temp_dir_dev3)

    node_names = ["node1", "node2", "node3"]
    node_dirs = [temp_dir_dev1, temp_dir_dev2, temp_dir_dev3]
    [
        setup_node(n, d, curr_dir, version)
        for n, d in zip(node_names, node_dirs)
    ]
    [start_node(n, d) for n, d in zip(node_names, node_dirs)]

    node_objs = []
    for n in node_names:
        empty_config = Configuration()
        empty_config.host = SETUP[n]["host"]
        node_objs.append(ExternalApi(ApiClient(configuration=empty_config)))

    wait_all_nodes_are_online(node_objs, 30)

    top = node_objs[0].get_top_block()
    height = top.key_block.height
    max_height = blocks_to_mine + height
    test_failed = False
    try:
        print("Will mine (at least) until block " + str(max_height))
        sync_height = 0
        while sync_height < max_height:
            time.sleep(1)  # check every second
            sync_height = max_height
            for name, node in zip(node_names, node_objs):
                top = node.get_top_block()  # node is alive and mining
                print("[" + name + "] height=" + str(top.key_block.height))
                sync_height = min(sync_height, top.key_block.height)
            print("")
    except ApiException as e:
        test_failed = True
        print("node died")
    except urllib3.exceptions.MaxRetryError as e:
        test_failed = True
        print("node died")

    for name, node in zip(node_names, node_objs):
        if not node_has_version(
                node):  # node does not report version and revision
            print("[" + name +
                  "] is not reporting version/revision in /getStatus")
            test_failed = True

    [stop_node(n, d) for n, d in zip(node_names, node_dirs)]
    wait_all_nodes_are_offline(node_objs, 10)

    if not test_failed:
        print(
            "Checking that nodes are able to start with persisted non-empty DB"
        )
        [start_node(n, d) for n, d in zip(node_names, node_dirs)]
        wait_all_nodes_are_online(node_objs, 60)
        [stop_node(n, d) for n, d in zip(node_names, node_dirs)]
        wait_all_nodes_are_offline(node_objs, 10)

    if test_failed:
        for name, node_dir in zip(node_names, node_dirs):
            print(name + " logs:")
            print(tail_logs(node_dir, "aeternity.log"))
            print("\n")
    if test_failed:
        sys.exit("FAILED")
Exemplo n.º 8
0
from swagger_client.api_client import ApiClient
from swagger_client.configuration import Configuration
from swagger_client.api.default_api import DefaultApi
from swagger_client.models.message import Message


# Un peu de configuration, pas besoin de toucher

config = Configuration()
config.host = 'http://supermessagerie.tech/'
client = ApiClient(configuration=config)
api = DefaultApi(api_client=client)

# Code pour envoyer des requetes
message = Message(contenu="Hello world", emetteur="Anonyme")
api.messages_post(body=message)

messages = api.messages_get()
for msg in messages:
    print(msg)