--- /dev/null
+# Copyright (c) 2017 SONATA-NFV and Paderborn University
+# ALL RIGHTS RESERVED.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Neither the name of the SONATA-NFV, Paderborn University
+# nor the names of its contributors may be used to endorse or promote
+# products derived from this software without specific prior written
+# permission.
+#
+# This work has been performed in the framework of the SONATA project,
+# funded by the European Commission under Grant number 671517 through
+# the Horizon 2020 and 5G-PPP programmes. The authors would like to
+# acknowledge the contributions of their colleagues of the SONATA
+# partner consortium (www.sonata-nfv.eu).
+
+FROM ubuntu:xenial
+
+ENV SON_EMU_IN_DOCKER 1
+ENV PIP_DEFAULT_TIMEOUT=100
+
+# install required packages
+RUN apt-get clean
+RUN apt-get update \
+ && apt-get install -y git \
+ net-tools \
+ aptitude \
+ apt-utils \
+ build-essential \
+ libevent-dev \
+ software-properties-common \
+ ansible \
+ curl \
+ iptables \
+ iputils-ping \
+ sudo \
+ vim \
+ nano \
+ wget
+
+RUN add-apt-repository ppa:jonathonf/python-3.6
+RUN apt-get update
+RUN apt install -y python3.6
+RUN apt install -y python3.6-dev
+RUN apt install -y python3.6-venv
+RUN wget https://bootstrap.pypa.io/get-pip.py
+RUN python3.6 get-pip.py
+RUN ln -s /usr/bin/python3.6 /usr/local/bin/python3
+
+# install containernet (using its Ansible playbook)
+#RUN git clone https://github.com/containernet/containernet.git && \
+# (cd containernet && git checkout 6fcee82e192c8c0e6447650d6f512842185529ee)
+RUN git clone https://github.com/RafaelSche/containernet.git
+WORKDIR /containernet/ansible
+RUN ansible-playbook -i "localhost," -c local --skip-tags "notindocker" install_py3.yml
+
+# install emulator (using its Ansible playbook)
+COPY . /son-emu
+WORKDIR /son-emu/ansible
+RUN ansible-playbook -i "localhost," -c local --skip-tags "notindocker" install_py3.yml
+WORKDIR /son-emu
+RUN python3 setup.py develop
+
+# Hotfix: https://github.com/pytest-dev/pytest/issues/4770
+RUN pip3 install "more-itertools<=5.0.0"
+
+# Hotfix: Do not use latest tinyrpc lib, since it breaks Ryu
+RUN pip3 install "tinyrpc==1.0.3"
+
+RUN pip3 install wheel --upgrade
+
+# Important: This entrypoint is required to start the OVS service
+ENTRYPOINT ["/son-emu/utils/docker/entrypoint.sh"]
+CMD ["python3", "examples/default_single_dc_topology.py"]
+
+# open ports for emulator APIs
+# SONATA GK
+EXPOSE 5000
+# EMU REST API
+EXPOSE 5001
+# Monitoring (Prometheus)
+EXPOSE 8081
+# Monitoring (GW)
+EXPOSE 9091
+# OpenStack-fake
+EXPOSE 4000
+# OpenStack-fake
+EXPOSE 10243
+# OpenStack-fake
+EXPOSE 9005
+# OpenStack-fake (Keystone)
+EXPOSE 6001
+# OpenStack-fake
+EXPOSE 9775
+# OpenStack-fake
+EXPOSE 10697
- name: install pip
apt: pkg=python-pip state=installed
+ - name: install libevent-dev
+ apt: pkg=libevent-dev state=installed
+
+ - name: install libevent-dev
+ apt: pkg=python-all-dev state=installed
+
+ - name: find pip executable
+ shell: "which pip"
+ register: pip_path
+
- name: install setuptools
- pip: name=setuptools state=latest
+ pip: name=setuptools state=latest executable={{pip_path.stdout}}
- name: install tabulate
- pip: name=tabulate state=latest
+ pip: name=tabulate state=latest executable={{pip_path.stdout}}
- name: install argparse
- pip: name=argparse state=latest
+ pip: name=argparse state=latest executable={{pip_path.stdout}}
- name: install networkx
- pip: name=networkx version=1.11
+ pip: name=networkx version=1.11 executable={{pip_path.stdout}}
- name: install six
- pip: name=six state=latest
+ pip: name=six state=latest executable={{pip_path.stdout}}
- name: install tinyrpc (fixed version to not break ryu)
- pip: name=tinyrpc version=1.0.3
+ pip: name=tinyrpc version=1.0.3 executable={{pip_path.stdout}}
- name: install ryu
- pip: name=ryu state=latest
+ pip: name=ryu state=latest executable={{pip_path.stdout}}
- name: install oslo.config
- pip: name=oslo.config state=latest
+ pip: name=oslo.config state=latest executable={{pip_path.stdout}}
- name: install pytest
- pip: name=pytest version=4.6.4
+ pip: name=pytest version=4.6.4 executable={{pip_path.stdout}}
- name: install Flask
- pip: name=Flask state=latest
+ pip: name=Flask executable={{pip_path.stdout}}
- name: install flask_restful
- pip: name=flask_restful state=latest
+ pip: name=flask_restful state=latest executable={{pip_path.stdout}}
- name: install requests
- pip: name=requests state=latest
+ pip: name=requests state=latest executable={{pip_path.stdout}}
- name: install docker
- pip: name=docker version=2.0.2
+ pip: name=docker version=2.0.2 executable={{pip_path.stdout}}
- name: install prometheus_client
- pip: name=prometheus_client state=latest
+ pip: name=prometheus_client state=latest executable={{pip_path.stdout}}
- name: install latest urllib3 (fix error urllib3.connection.match_hostname = match_hostname)
- pip: name=urllib3 version=1.21.1
+ pip: name=urllib3 version=1.21.1 executable={{pip_path.stdout}}
- name: install iptc
- pip: name=python-iptables state=latest
+ pip: name=python-iptables state=latest executable={{pip_path.stdout}}
- name: install ipaddress
- pip: name=ipaddress state=latest
+ pip: name=ipaddress state=latest executable={{pip_path.stdout}}
- name: install gevent
- pip: name=gevent state=latest
-
- #- name: install urllib
- # pip: name=urllib state=latest
-
+ pip: name=gevent executable={{pip_path.stdout}}
--- /dev/null
+# Copyright (c) 2015 SONATA-NFV and Paderborn University
+# ALL RIGHTS RESERVED.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Neither the name of the SONATA-NFV, Paderborn University
+# nor the names of its contributors may be used to endorse or promote
+# products derived from this software without specific prior written
+# permission.
+#
+# This work has been performed in the framework of the SONATA project,
+# funded by the European Commission under Grant number 671517 through
+# the Horizon 2020 and 5G-PPP programmes. The authors would like to
+# acknowledge the contributions of their colleagues of the SONATA
+# partner consortium (www.sonata-nfv.eu).
+
+- hosts: localhost
+ tasks:
+ - name: updates apt
+ apt: update_cache=yes
+
+ - name: install python3-dev
+ apt: pkg=python3-dev state=installed
+
+ - name: install libffi-dev
+ apt: pkg=libffi-dev state=installed
+
+ - name: install libssl-dev
+ apt: pkg=libssl-dev state=installed
+
+ - name: install pip3
+ apt: pkg=python3-pip state=installed
+
+ - name: install libevent-dev
+ apt: pkg=libevent-dev state=installed
+
+ - name: install libevent-dev
+ apt: pkg=python-all-dev state=installed
+
+ - name: find pip executable
+ shell: "which pip3"
+ register: pip_path
+
+ - name: install setuptools
+ pip: name=setuptools state=latest executable={{pip_path.stdout}}
+
+ - name: install tabulate
+ pip: name=tabulate state=latest executable={{pip_path.stdout}}
+
+ - name: install argparse
+ pip: name=argparse state=latest executable={{pip_path.stdout}}
+
+ - name: install networkx
+ pip: name=networkx version=1.11 executable={{pip_path.stdout}}
+
+ - name: install six
+ pip: name=six state=latest executable={{pip_path.stdout}}
+
+ - name: install tinyrpc (fixed version to not break ryu)
+ pip: name=tinyrpc version=1.0.3 executable={{pip_path.stdout}}
+
+ - name: install ryu
+ pip: name=ryu state=latest executable={{pip_path.stdout}}
+
+ - name: install oslo.config
+ pip: name=oslo.config state=latest executable={{pip_path.stdout}}
+
+ - name: install pytest
+ pip: name=pytest version=4.6.4 executable={{pip_path.stdout}}
+
+ - name: install Flask
+ pip: name=Flask executable={{pip_path.stdout}}
+
+ - name: install flask_restful
+ pip: name=flask_restful state=latest executable={{pip_path.stdout}}
+
+ - name: install requests
+ pip: name=requests state=latest executable={{pip_path.stdout}}
+
+ - name: install docker
+ pip: name=docker version=2.0.2 executable={{pip_path.stdout}}
+
+ - name: install prometheus_client
+ pip: name=prometheus_client state=latest executable={{pip_path.stdout}}
+
+ - name: install latest urllib3 (fix error urllib3.connection.match_hostname = match_hostname)
+ pip: name=urllib3 version=1.21.1 executable={{pip_path.stdout}}
+
+ - name: install iptc
+ pip: name=python-iptables state=latest executable={{pip_path.stdout}}
+
+ - name: install ipaddress
+ pip: name=ipaddress state=latest executable={{pip_path.stdout}}
+
+ - name: install gevent
+ pip: name=gevent executable={{pip_path.stdout}}
+
+
+
+
# search for related OpenStackAPIs
api_src = None
api_dst = None
- from openstack_api_endpoint import OpenstackApiEndpoint
+ from emuvim.api.openstack.openstack_api_endpoint import OpenstackApiEndpoint
for api in OpenstackApiEndpoint.dc_apis:
if api.compute.dc == dc_src:
api_src = api
dc_real = self.api.manage.net.dcs[dc]
# search for related OpenStackAPIs
api_real = None
- from openstack_api_endpoint import OpenstackApiEndpoint
+ from emuvim.api.openstack.openstack_api_endpoint import OpenstackApiEndpoint
for api in OpenstackApiEndpoint.dc_apis:
if api.compute.dc == dc_real:
api_real = api
# partner consortium (www.sonata-nfv.eu).
from mininet.link import Link
-from resources.instance_flavor import InstanceFlavor
-from resources.net import Net
-from resources.port import Port
-from resources.port_pair import PortPair
-from resources.port_pair_group import PortPairGroup
-from resources.flow_classifier import FlowClassifier
-from resources.port_chain import PortChain
-from resources.server import Server
-from resources.image import Image
+from emuvim.api.openstack.resources.instance_flavor import InstanceFlavor
+from emuvim.api.openstack.resources.net import Net
+from emuvim.api.openstack.resources.port import Port
+from emuvim.api.openstack.resources.port_pair import PortPair
+from emuvim.api.openstack.resources.port_pair_group import PortPairGroup
+from emuvim.api.openstack.resources.flow_classifier import FlowClassifier
+from emuvim.api.openstack.resources.port_chain import PortChain
+from emuvim.api.openstack.resources.server import Server
+from emuvim.api.openstack.resources.image import Image
from docker import DockerClient
import logging
import threading
import uuid
import time
-import ip_handler as IP
+import emuvim.api.openstack.ip_handler as IP
import hashlib
for server in self.stacks[stack_id].servers.values():
self.stop_compute(server)
self.delete_server(server)
- for net in self.stacks[stack_id].nets.values():
- self.delete_network(net.id)
+ stack = list(self.stacks[stack_id].nets.values())
+ while stack:
+ id = stack.pop().id
+ self.delete_network(id)
+ # for net in self.stacks[stack_id].nets.values():
+ # self.delete_network(net.id)
for port in self.stacks[stack_id].ports.values():
self.delete_port(port.id)
"""
if len(name) > char_limit:
# construct a short name
- h = hashlib.sha224(name).hexdigest()
+ h = hashlib.sha224(name.encode()).hexdigest()
h = h[0:char_limit]
LOG.debug("Shortened server name '%s' to '%s'" % (name, h))
return name
"""
if name_or_id in self.nets:
return self.nets[name_or_id]
+ print("name_or_id: ", name_or_id)
for net in self.nets.values():
if net.name == name_or_id:
return net
if name_or_id in self.ports:
return self.ports[name_or_id]
# find by name
- matching_ports = filter(
+ matching_ports = list(filter(
lambda port: port.name == name_or_id or port.template_name == name_or_id,
self.ports.values()
- )
+ ))
matching_ports_count = len(matching_ports)
if matching_ports_count == 1:
return matching_ports[0]
# the Horizon 2020 and 5G-PPP programmes. The authors would like to
# acknowledge the contributions of their colleagues of the SONATA
# partner consortium (www.sonata-nfv.eu).
-from __future__ import print_function # TODO remove when print is no longer needed for debugging
-from resources.router import Router
+# TODO remove when print is no longer needed for debugging
+from __future__ import print_function
+from emuvim.api.openstack.resources.router import Router
from datetime import datetime
import re
import sys
import uuid
import logging
-import ip_handler as IP
+import emuvim.api.openstack.ip_handler as IP
LOG = logging.getLogger("api.openstack.heat.parser")
net_name, True)
except Exception as e:
- LOG.warning('Could not create Net: ' + e.message)
+ LOG.warning('Could not create Net: ' + str(e))
return
if 'OS::Neutron::Subnet' in resource['type'] and "Net" not in resource['type']:
if not stack_update:
net.set_cidr(IP.get_new_cidr(net.subnet_id))
except Exception as e:
- LOG.warning('Could not create Subnet: ' + e.message)
+ LOG.warning('Could not create Subnet: ' + str(e))
return
if 'OS::Neutron::Port' in resource['type']:
port.ip_address = net.get_new_ip_address(port.name)
return
except Exception as e:
- LOG.warning('Could not create Port: ' + e.message)
+ LOG.warning('Could not create Port: ' + str(e))
self.bufferResource.append(resource)
return
server.port_names.append(port_name)
return
except Exception as e:
- LOG.warning('Could not create Server: ' + e.message)
+ LOG.warning('Could not create Server: ' + str(e))
return
if 'OS::Neutron::RouterInterface' in resource['type']:
stack.ports[port_name].floating_ip = floating_network_id
except Exception as e:
- LOG.warning('Could not create FloatingIP: ' + e.message)
+ LOG.warning('Could not create FloatingIP: ' + str(e))
return
if 'OS::Neutron::Router' in resource['type']:
if name not in stack.routers:
stack.routers[name] = Router(name)
except Exception as e:
- print('Could not create Router: ' + e.message)
+ print('Could not create Router: ' + str(e))
return
if 'OS::Heat::ResourceGroup' in resource['type']:
self.handle_resource(
embedded_resource, stack, dc_label, stack_update)
except Exception as e:
- print('Could not create Router: ' + e.message)
+ print('Could not create Router: ' + str(e))
return
LOG.warning(
# the Horizon 2020 and 5G-PPP programmes. The authors would like to
# acknowledge the contributions of their colleagues of the SONATA
# partner consortium (www.sonata-nfv.eu).
-from urlparse import urlparse
+try:
+ from urllib.parse import urlparse
+except ImportError:
+ from urlparse import urlparse
import logging
LOG = logging.getLogger("api.openstack.helper")
# the Horizon 2020 and 5G-PPP programmes. The authors would like to
# acknowledge the contributions of their colleagues of the SONATA
# partner consortium (www.sonata-nfv.eu).
-from resources.net import Net
+from emuvim.api.openstack.resources.net import Net
import threading
lock = threading.Lock()
import threading
import uuid
import networkx as nx
-import chain_api
+import emuvim.api.openstack.chain_api as chain_api
import json
import random
from emuvim.api.openstack.resources.net import Net
port.ip_address = root_ip
# floating ip network setup
# wierd way of getting a datacenter object
- first_dc = self.net.dcs.values()[0]
+ first_dc = list(self.net.dcs.values())[0]
# set a dpid for the switch. for this we have to get the id of the
# next possible dc
self.floating_switch = self.net.addSwitch(
# the Horizon 2020 and 5G-PPP programmes. The authors would like to
# acknowledge the contributions of their colleagues of the SONATA
# partner consortium (www.sonata-nfv.eu).
-from manage import OpenstackManage
+from emuvim.api.openstack.manage import OpenstackManage
-from openstack_dummies.glance_dummy_api import GlanceDummyApi
-from openstack_dummies.heat_dummy_api import HeatDummyApi
-from openstack_dummies.keystone_dummy_api import KeystoneDummyApi
-from openstack_dummies.neutron_dummy_api import NeutronDummyApi
-from openstack_dummies.nova_dummy_api import NovaDummyApi
+from emuvim.api.openstack.openstack_dummies.glance_dummy_api import \
+ GlanceDummyApi
+from emuvim.api.openstack.openstack_dummies.heat_dummy_api import \
+ HeatDummyApi
+from emuvim.api.openstack.openstack_dummies.keystone_dummy_api import \
+ KeystoneDummyApi
+from emuvim.api.openstack.openstack_dummies.neutron_dummy_api import \
+ NeutronDummyApi
+from emuvim.api.openstack.openstack_dummies.nova_dummy_api import \
+ NovaDummyApi
import logging
-import compute
+import emuvim.api.openstack.compute as compute
import socket
import time
except Exception as ex:
LOG.exception(
u"%s: Could not retrieve the list of images." % __name__)
- return ex.message, 500
+ return str(ex), 500
def post(self):
"""
except Exception as ex:
LOG.exception(
u"%s: Could not retrieve image with id %s." % (__name__, id))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
def put(self, id):
except Exception as ex:
logging.exception(
u"%s: Could not retrieve image with id %s." % (__name__, id))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
reader = HeatParser(self.api.compute)
if isinstance(stack_dict['template'], str) or isinstance(
- stack_dict['template'], unicode):
+ stack_dict['template'], bytes):
stack_dict['template'] = json.loads(stack_dict['template'])
if not reader.parse_input(
stack_dict['template'], stack, self.api.compute.dc.label):
except Exception as ex:
LOG.exception("Heat: Create Stack exception.")
- return ex.message, 500
+ return str(ex), 500
def get(self, tenant_id):
"""
status=200, mimetype="application/json")
except Exception as ex:
LOG.exception("Heat: List Stack exception.")
- return ex.message, 500
+ return str(ex), 500
class HeatShowStack(Resource):
except Exception as ex:
LOG.exception("Heat: Show stack exception.")
- return ex.message, 500
+ return str(ex), 500
class HeatShowStackTemplate(Resource):
except Exception as ex:
LOG.exception("Heat: Show stack template exception.")
- return ex.message, 500
+ return str(ex), 500
class HeatShowStackResources(Resource):
except Exception as ex:
LOG.exception("Heat: Show stack template exception.")
- return ex.message, 500
+ return str(ex), 500
class HeatUpdateStack(Resource):
reader = HeatParser(self.api.compute)
if isinstance(stack_dict['template'], str) or isinstance(
- stack_dict['template'], unicode):
+ stack_dict['template'], bytes):
stack_dict['template'] = json.loads(stack_dict['template'])
if not reader.parse_input(
stack_dict['template'], stack, self.api.compute.dc.label, stack_update=True):
except Exception as ex:
LOG.exception("Heat: Update Stack exception")
- return ex.message, 500
+ return str(ex), 500
class HeatDeleteStack(Resource):
except Exception as ex:
LOG.exception("Heat: Delete Stack exception")
- return ex.message, 500
+ return str(ex), 500
except Exception as ex:
logging.exception("Keystone: Get token failed.")
- return ex.message, 500
+ return str(ex), 500
class KeystoneGetTokenv3(Resource):
except Exception as ex:
logging.exception("Keystone: Get token failed.")
- return ex.message, 500
+ return str(ex), 500
# partner consortium (www.sonata-nfv.eu).
from flask_restful import Resource
from flask import request, Response
-from emuvim.api.openstack.openstack_dummies.base_openstack_dummy import BaseOpenstackDummy
+from emuvim.api.openstack.openstack_dummies.base_openstack_dummy import \
+ BaseOpenstackDummy
from datetime import datetime
-import neutron_sfc_dummy_api as SFC
+import emuvim.api.openstack.openstack_dummies.neutron_sfc_dummy_api as SFC
import logging
import json
import uuid
except Exception as ex:
LOG.exception("Neutron: List networks exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron: Show network exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
{"network": net.create_network_dict()}), status=201, mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Create network excepiton.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Show networks exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
return Response('', status=204, mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Delete network exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: List subnets exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Show subnet exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Create network excepiton.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Show networks exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
status=404, mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Delete subnet exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
), ports)
port_dict = dict()
- port_dict["ports"] = map(lambda x: x.create_port_dict(self.api.compute), ports)
+ port_dict["ports"] = list(map(lambda x: x.create_port_dict(self.api.compute), ports))
return Response(json.dumps(port_dict), status=200,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: List ports exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Show port exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Show port exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Update port exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Delete port exception.")
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
mimetype='application/json')
except Exception as ex:
LOG.exception("Neutron: Create FloatingIP exception %s.", ex)
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
id = request.args.get('id')
if id and any(id):
port_pairs = filter(lambda port_pair: port_pair.id == id, port_pairs)
- resp = {"port_pairs": map(lambda port_pair: port_pair.create_dict(self.api.compute), port_pairs)}
+ resp = {"port_pairs": list(map(lambda port_pair: port_pair.create_dict(self.api.compute), port_pairs))}
return Response(json.dumps(resp), status=200,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
logging.exception("Neutron SFC: %s Exception." %
str(self.__class__.__name__))
- return Response(ex.message, status=500,
+ return Response(str(ex), status=500,
mimetype='application/json')
except Exception as ex:
LOG.exception(u"%s: Could not show list of versions." % __name__)
- return ex.message, 500
+ return str(ex), 500
class NovaVersionShow(Resource):
except Exception as ex:
LOG.exception(u"%s: Could not show list of versions." % __name__)
- return ex.message, 500
+ return str(ex), 500
class NovaListServersApi(Resource):
except Exception as ex:
LOG.exception(
u"%s: Could not retrieve the list of servers." % __name__)
- return ex.message, 500
+ return str(ex), 500
def post(self, id):
"""
except Exception as ex:
LOG.exception(u"%s: Could not create the server." % __name__)
- return ex.message, 500
+ return str(ex), 500
class NovaListServersAndPortsApi(Resource):
except Exception as ex:
LOG.exception(
u"%s: Could not retrieve the list of servers." % __name__)
- return ex.message, 500
+ return str(ex), 500
class NovaListServersDetailed(Resource):
except Exception as ex:
LOG.exception(
u"%s: Could not retrieve the list of servers." % __name__)
- return ex.message, 500
+ return str(ex), 500
class NovaListFlavors(Resource):
except Exception as ex:
LOG.exception(
u"%s: Could not retrieve the list of servers." % __name__)
- return ex.message, 500
+ return str(ex), 500
def post(self, id):
LOG.debug("API CALL: %s POST" % str(self.__class__.__name__))
except Exception as ex:
LOG.exception(
u"%s: Could not retrieve the list of servers." % __name__)
- return ex.message, 500
+ return str(ex), 500
def post(self, id):
LOG.debug("API CALL: %s POST" % str(self.__class__.__name__))
except Exception as ex:
LOG.exception(u"%s: Could not retrieve flavor with id %s" %
(__name__, flavorid))
- return ex.message, 500
+ return str(ex), 500
def delete(self, id, flavorid):
"""
except Exception as ex:
LOG.exception(
u"%s: Could not retrieve the list of images." % __name__)
- return ex.message, 500
+ return str(ex), 500
class NovaListImagesDetails(Resource):
except Exception as ex:
LOG.exception(
u"%s: Could not retrieve the list of images." % __name__)
- return ex.message, 500
+ return str(ex), 500
class NovaListImageById(Resource):
except Exception as ex:
LOG.exception(u"%s: Could not retrieve image with id %s." %
(__name__, imageid))
- return ex.message, 500
+ return str(ex), 500
def delete(self, id, imageid):
"""
except Exception as ex:
LOG.exception(
u"%s: Could not retrieve the server details." % __name__)
- return ex.message, 500
+ return str(ex), 500
def delete(self, id, serverid):
"""
except Exception as ex:
LOG.exception(u"%s: Could not create the server." % __name__)
- return ex.message, 500
+ return str(ex), 500
class NovaInterfaceToServer(Resource):
except Exception as ex:
LOG.exception(
u"%s: Could not add interface to the server." % __name__)
- return ex.message, 500
+ return str(ex), 500
class NovaShowAndDeleteInterfaceAtServer(Resource):
except Exception as ex:
LOG.exception(
u"%s: Could not detach interface from the server." % __name__)
- return ex.message, 500
+ return str(ex), 500
class NovaLimits(Resource):
except Exception as ex:
LOG.exception(
u"%s: Could not retrieve the list of images." % __name__)
- return ex.message, 500
+ return str(ex), 500
# acknowledge the contributions of their colleagues of the SONATA
# partner consortium (www.sonata-nfv.eu).
import re
+from json import dumps
class Net:
:return: IP address as int.
:rtype: ``int``
"""
- o = map(int, ip.split('.'))
+ o = list(map(int, ip.split('.')))
res = (16777216 * o[0]) + (65536 * o[1]) + (256 * o[2]) + o[3]
return res
self.gateway_ip,
self.segmentation_id,
self._cidr,
- self.start_end_dict))
+ dumps(self.start_end_dict)))
port_pair_chain = map(lambda port_pair_group_id: self._get_port_pair(port_pair_group_id, compute),
self.port_pair_groups)
- ingress_ports = map(lambda port_pair: port_pair.ingress, port_pair_chain)
- egress_ports = map(lambda port_pair: port_pair.ingress, port_pair_chain)
+ ingress_ports = list(map(lambda port_pair: port_pair.ingress, port_pair_chain))
+ egress_ports = list(map(lambda port_pair: port_pair.ingress, port_pair_chain))
chain_start = ingress_ports[0]
chain_rest = ingress_ports[1:]
port = compute.find_port_by_name_or_id(flow_classifier.logical_source_port)
- chain = [(port, chain_start)] + zip(egress_ports, chain_rest)
+ chain = [(port, chain_start)] + list(zip(egress_ports, chain_rest))
for (egress_port, ingress_port) in chain:
server_egress = None
c.start()
except Exception as ex:
logging.warning("Couldn't run Docker entry point VIM_EMU_CMD")
- logging.exception("Exception:")
+ logging.exception(
+ "Exception: " + str(ex) + "; " + str(type(ex))
+ )
# return docker inspect dict
return c.getStatus(), 200, CORS_HEADER
except Exception as ex:
if dc_label is None or dc_label == 'None':
# return list with all compute nodes in all DCs
all_containers = []
- for dc in dcs.itervalues():
+ for dc in dcs.values():
all_containers += dc.listCompute()
container_list = [(c.name, c.getStatus())
for c in all_containers]
def get(self):
logging.debug("API CALL: datacenter list")
try:
- return [d.getStatus() for d in dcs.itervalues()], 200, CORS_HEADER
+ return [d.getStatus() for d in dcs.values()], 200, CORS_HEADER
except Exception as ex:
logging.exception("API error.")
return ex.message, 500, CORS_HEADER
return str(c), 200, CORS_HEADER
except Exception as ex:
logging.exception("API error.")
- return ex.message, 500, CORS_HEADER
+ return str(ex), 500, CORS_HEADER
class DrawD3jsgraph(Resource):
from gevent.pywsgi import WSGIServer
# need to import total module to set its global variable dcs
-import compute
-from compute import ComputeList, Compute, ComputeResources, DatacenterList, DatacenterStatus
+from emuvim.api.rest import compute
+from emuvim.api.rest.compute import ComputeList, Compute, ComputeResources, DatacenterList, DatacenterStatus
# need to import total module to set its global variable net
-import network
-from network import NetworkAction, DrawD3jsgraph
+from emuvim.api.rest import network
+from emuvim.api.rest.network import NetworkAction, DrawD3jsgraph
-import monitor
-from monitor import MonitorInterfaceAction, MonitorFlowAction, MonitorLinkAction, MonitorSkewAction, MonitorTerminal
+from emuvim.api.rest import monitor
+from emuvim.api.rest.monitor import MonitorInterfaceAction, MonitorFlowAction, MonitorLinkAction, MonitorSkewAction, MonitorTerminal
import pkg_resources
from os import path
r = list()
for net in range(base, base + subnet_size):
subnet = "{0}.{1}.0/{2}".format(prefix, net, mask)
- r.append(ipaddress.ip_network(unicode(subnet)))
+ r.append(ipaddress.ip_network(subnet))
return r
# partner consortium (www.5gtango.eu).
import logging
import threading
-import llcm
+from emuvim.api.tango import llcm
LOG = logging.getLogger("5gtango.llcm")
Get all URLs to pre-build docker images in some repo.
:return:
"""
- for vnf_id, v in self.vnfds.iteritems():
+ for vnf_id, v in list(self.vnfds.items()):
for vu in v.get("virtual_deployment_units", []):
vnf_container_name = get_container_name(vnf_id, vu.get("id"))
if vu.get("vm_image_format") == "docker":
dc = DockerClient()
LOG.info("Building %d Docker images (this may take several minutes) ..." % len(
self.local_docker_files))
- for k, v in self.local_docker_files.iteritems():
+ for k, v in list(self.local_docker_files.items()):
for line in dc.build(path=v.replace(
"Dockerfile", ""), tag=k, rm=False, nocache=False):
LOG.debug("DOCKER BUILD: %s" % line)
If the package contains URLs to pre-build Docker images, we download them with this method.
"""
dc = DockerClient()
- for url in self.remote_docker_image_urls.itervalues():
+ for url in list(self.remote_docker_image_urls.values()):
# only pull if not present (speedup for development)
if not FORCE_PULL:
if len(dc.images.list(name=url)) > 0:
"""
def place(self, dcs, vnfd, vnfid, vdu, ssiid, cname):
- return list(dcs.itervalues())[0]
+ return list(dcs.values())[0]
class RoundRobinDcPlacement(object):
self.count = 0
def place(self, dcs, vnfd, vnfid, vdu, ssiid, cname):
- dcs_list = list(dcs.itervalues())
+ dcs_list = list(dcs.values())
rdc = dcs_list[self.count % len(dcs_list)]
self.count += 1 # inc. count to use next DC
return rdc
if cname not in self.static_placement:
LOG.error("Coudn't find {} in placement".format(cname))
LOG.error("Using first DC as fallback!")
- return list(dcs.itervalues())[0]
+ return list(dcs.values())[0]
# lookup
candidate_dc = self.static_placement.get(cname)
# check if DC exsits
if candidate_dc not in dcs:
LOG.error("Coudn't find DC {}".format(candidate_dc))
LOG.error("Using first DC as fallback!")
- return list(dcs.itervalues())[0]
+ return list(dcs.values())[0]
# return correct DC
return dcs.get(candidate_dc)
"error": "upload failed. file not found."}, 500
# generate a uuid to reference this package
service_uuid = str(uuid.uuid4())
- file_hash = hashlib.sha1(str(son_file)).hexdigest()
+ file_hash = str(son_file)
+ file_hash = hashlib.sha1(file_hash.encode())
+ file_hash = file_hash.hexdigest()
# ensure that upload folder exists
ensure_dir(UPLOAD_FOLDER)
- upload_path = os.path.join(UPLOAD_FOLDER, "%s.tgo" % service_uuid)
+ upload_path = os.path.\
+ join(UPLOAD_FOLDER, "%s.tgo" % service_uuid)
# store *.son file to disk
if is_file_object:
son_file.save(upload_path)
"""
LOG.info("GET /packages")
result = list()
- for suuid, sobj in GK.services.iteritems():
+ for suuid, sobj in GK.services.items():
pkg = dict()
pkg["pd"] = dict()
pkg["uuid"] = suuid
"""
LOG.info("GET /services")
result = list()
- for suuid, sobj in GK.services.iteritems():
+ for suuid, sobj in GK.services.items():
service = dict()
service["nsd"] = dict()
service["uuid"] = suuid
service_name = service_uuid
# first try to find by service_name
if service_name is not None:
- for s_uuid, s in GK.services.iteritems():
+ for s_uuid, s in GK.services.items():
if s.manifest.get("name") == service_name:
LOG.info("Searched for: {}. Found service w. UUID: {}"
.format(service_name, s_uuid))
"latest") and len(GK.services) > 0:
# if we don't get a service uuid, we simple start the first service
# in the list
- service_uuid = list(GK.services.iterkeys())[0]
+ service_uuid = list(GK.services.keys())[0]
if service_uuid in GK.services:
# ok, we have a service uuid, lets start the service
service_instance_uuid = GK.services.get(
"""
LOG.debug("GET /instantiations or /api/v3/records/services")
# return {"service_instantiations_list": [
- # list(s.instances.iterkeys()) for s in GK.services.itervalues()]}
+ # list(s.instances.keys()) for s in GK.services.values()]}
result = list()
- for suuid, sobj in GK.services.iteritems():
- for iuuid, iobj in sobj.instances.iteritems():
+ for suuid, sobj in GK.services.items():
+ for iuuid, iobj in sobj.instances.items():
inst = dict()
inst["uuid"] = iobj.get("uuid")
inst["instance_name"] = "{}-inst.{}".format(
# try to be fuzzy
if service_uuid_input is None:
# if we don't get a service uuid we stop all services
- service_uuid_list = list(GK.services.iterkeys())
+ service_uuid_list = list(GK.services.keys())
LOG.info("No service_uuid given, stopping all.")
else:
service_uuid_list = [service_uuid_input]
for service_uuid in service_uuid_list:
if instance_uuid_input is None:
instance_uuid_list = list(
- GK.services[service_uuid].instances.iterkeys())
+ GK.services[service_uuid].instances.keys())
else:
instance_uuid_list = [instance_uuid_input]
# for all service instances
r = list()
for net in range(base, base + subnet_size):
subnet = "{0}.{1}.0/{2}".format(prefix, net, mask)
- r.append(ipaddress.ip_network(unicode(subnet)))
+ try:
+ r.append(ipaddress.ip_network(subnet))
+ except ValueError:
+ r.append(ipaddress.ip_network(unicode(subnet)))
return r
:return:
"""
assert (len(GK.dcs) > 0)
- return GK.dcs.values()[0].net
+ return list(GK.dcs.values())[0].net
def parse_interface(interface_name):
def _offset(p):
return p + MULTI_INSTANCE_PORT_OFFSET * ssiid
- port_bindings = {k: _offset(v) for k, v in port_bindings.iteritems()}
+ port_bindings = {k: _offset(v) for k, v in port_bindings.items()}
return port_bindings
'stats/flow', dpid=flow_dict['switch_dpid'], data=data)\r
if isinstance(ret, dict):\r
flow_stat_dict = ret\r
- elif isinstance(ret, basestring):\r
+ elif isinstance(ret, str):\r
flow_stat_dict = ast.literal_eval(ret.rstrip())\r
else:\r
flow_stat_dict = None\r
ret = self.net.ryu_REST('stats/port', dpid=dpid)\r
if isinstance(ret, dict):\r
port_stat_dict = ret\r
- elif isinstance(ret, basestring):\r
+ elif isinstance(ret, str):\r
port_stat_dict = ast.literal_eval(ret.rstrip())\r
else:\r
port_stat_dict = None\r
self.DCNetwork_graph = nx.MultiDiGraph()
# initialize pool of vlan tags to setup the SDN paths
- self.vlans = range(1, 4095)[::-1]
+ self.vlans = list(range(1, 4095))[::-1]
# link to Ryu REST_API
ryu_ip = 'localhost'
assert node2 is not None
# ensure type of node1
- if isinstance(node1, basestring):
+ if isinstance(node1, str):
if node1 in self.dcs:
node1 = self.dcs[node1].switch
if isinstance(node1, Datacenter):
node1 = node1.switch
# ensure type of node2
- if isinstance(node2, basestring):
+ if isinstance(node2, str):
if node2 in self.dcs:
node2 = self.dcs[node2].switch
if isinstance(node2, Datacenter):
'dst_port_name': node2_port_name}
attr_dict2.update(attr_dict)
self.DCNetwork_graph.add_edge(
- node1.name, node2.name, attr_dict=attr_dict2)
+ node1.name, node2.name, **attr_dict2)
attr_dict2 = {'src_port_id': node2_port_id, 'src_port_nr': node2.ports[link.intf2],
'src_port_name': node2_port_name,
'dst_port_name': node1_port_name}
attr_dict2.update(attr_dict)
self.DCNetwork_graph.add_edge(
- node2.name, node1.name, attr_dict=attr_dict2)
+ node2.name, node1.name, **attr_dict2)
LOG.debug("addLink: n1={0} intf1={1} -- n2={2} intf2={3}".format(
str(node1), node1_port_name, str(node2), node2_port_name))
Returns a list with all containers within all data centers.
"""
all_containers = []
- for dc in self.dcs.itervalues():
+ for dc in self.dcs.values():
all_containers += dc.listCompute()
return all_containers
def start(self):
# start
- for dc in self.dcs.itervalues():
+ for dc in self.dcs.values():
dc.start()
Containernet.start(self)
# check if port is specified (vnf:port)
if vnf_src_interface is None:
# take first interface by default
- connected_sw = self.DCNetwork_graph.neighbors(vnf_src_name)[0]
+ connected_sw = list(self.DCNetwork_graph.neighbors(vnf_src_name))[0]
link_dict = self.DCNetwork_graph[vnf_src_name][connected_sw]
vnf_src_interface = link_dict[0]['src_port_id']
if vnf_dst_interface is None:
# take first interface by default
- connected_sw = self.DCNetwork_graph.neighbors(vnf_dst_name)[0]
+ connected_sw = list(self.DCNetwork_graph.neighbors(vnf_dst_name))[0]
link_dict = self.DCNetwork_graph[connected_sw][vnf_dst_name]
vnf_dst_interface = link_dict[0]['dst_port_id']
Return a list of all running containers assigned to this
data center.
"""
- return list(self.containers.itervalues())
+ return list(self.containers.values())
def listExtSAPs(self):
"""
Return a list of all external SAPs assigned to this
data center.
"""
- return list(self.extSAPs.itervalues())
+ return list(self.extSAPs.values())
def getStatus(self):
"""
List of registered resource models
:return:
"""
- return list(self._resource_models.itervalues())
+ return list(self._resource_models.values())
@property
def num_dcs_with_rms(self):
:return:
"""
return sum([len(rm.dcs)
- for rm in list(self._resource_models.itervalues())])
+ for rm in list(self._resource_models.values())])
class ResourceFlavor(object):
We have to recalculate for all containers to allow e.g. over provisioning models.
:return:
"""
- for d in self._allocated_compute_instances.itervalues():
+ for d in self._allocated_compute_instances.values():
if not self.deactivate_cpu_limit:
self._apply_cpu_limits(d)
if not self.deactivate_mem_limit:
# check status
# check get status
s1 = self.dc[0].containers.get("vnf1").getStatus()
- print s1
+ print(s1)
self.assertTrue(s1["name"] == "vnf1")
self.assertTrue(s1["state"]["Running"])
self.assertTrue(s1["network"][0]['intf_name'] == 'intf1')
self.assertTrue(s1["network"][0]['ip'] == '10.0.10.1/24')
s2 = self.dc[1].containers.get("vnf2").getStatus()
- print s2
+ print(s2)
self.assertTrue(s2["name"] == "vnf2")
self.assertTrue(s2["state"]["Running"])
self.assertTrue(s2["network"][0]['intf_name'] == 'intf2')
# check status
# check get status
s1 = self.dc[0].containers.get("vnf1").getStatus()
- print s1
+ print(s1)
self.assertTrue(s1["name"] == "vnf1")
self.assertTrue(s1["state"]["Running"])
self.assertTrue(s1["network"][0]['intf_name'] == 'intf1')
self.assertTrue(s1["network"][0]['ip'] == '10.0.10.1/24')
s2 = self.dc[1].containers.get("vnf2").getStatus()
- print s2
+ print(s2)
self.assertTrue(s2["name"] == "vnf2")
self.assertTrue(s2["state"]["Running"])
self.assertTrue(s2["network"][0]['intf_name'] == 'intf2')
self.assertEqual(network_resp.status_code, 200)
network_id = json.loads(network_resp.content)["networks"][0]["id"]
- port_responses = map(lambda name: requests.post("http://0.0.0.0:19696/v2.0/ports",
- data='{"port": {"name": "%s", "network_id": "%s"}}' %
- (name, network_id),
- headers=headers),
- ["p1", "p2", "p3", "p4", "p5", "p6"])
+ port_responses = list(map(lambda name: requests.post("http://0.0.0.0:19696/v2.0/ports",
+ data='{"port": {"name": "%s", "network_id": "%s"}}' %
+ (name, network_id),
+ headers=headers),
+ ["p1", "p2", "p3", "p4", "p5", "p6"]))
for port in port_responses:
self.assertEqual(port.status_code, 201)
- port_ids = map(lambda response: json.loads(response.content)["port"]["id"], port_responses)
+ port_ids = list(map(lambda response: json.loads(response.content)["port"]["id"], port_responses))
listflavorsresponse = requests.get("http://0.0.0.0:18774/v2.1/id_bla/flavors", headers=headers)
self.assertEqual(listflavorsresponse.status_code, 200)
flavors = json.loads(listflavorsresponse.content)["flavors"]
- m1_tiny_flavor = filter(lambda flavor: flavor["name"] == "m1.tiny", flavors)[0]
+ m1_tiny_flavor = list(filter(lambda flavor: flavor["name"] == "m1.tiny", flavors))[0]
listimagesdetailsresponse = requests.get("http://0.0.0.0:18774/v2.1/id_bla/images/detail", headers=headers)
self.assertEqual(listimagesdetailsresponse.status_code, 200)
images = json.loads(listimagesdetailsresponse.content)["images"]
- ubuntu_image = filter(lambda image: image["name"] == "ubuntu:trusty", images)[0]
+ ubuntu_image = list(filter(lambda image: image["name"] == "ubuntu:trusty", images))[0]
server_url = "http://0.0.0.0:18774/v2.1/id_bla/servers"
server_template = \
rm.allocate(c8) # calculate allocation
rm.allocate(c9) # calculate allocation
except NotEnoughResourcesAvailable as e:
- self.assertIn("Not enough compute", e.message)
+ self.assertIn("Not enough compute", str(e))
exception = True
self.assertTrue(exception)
rm.allocate(c7) # calculate allocation
rm.allocate(c8) # calculate allocation
except NotEnoughResourcesAvailable as e:
- self.assertIn("Not enough memory", e.message)
+ self.assertIn("Not enough memory", str(e))
exception = True
self.assertTrue(exception)
print('->>>>>>> checking running nodes, compute list, and connectivity >>>>>>>>>>')
# check number of running nodes
- self.assertTrue(len(self.getContainernetContainers()) == 3)
- self.assertTrue(len(self.net.hosts) == 5)
- self.assertTrue(len(self.net.switches) == 2)
+ self.assertEqual(len(self.getContainernetContainers()), 3)
+ self.assertEqual(len(self.net.hosts), 5)
+ self.assertEqual(len(self.net.switches), 2)
# check compute list result
- self.assertTrue(len(self.dc[0].listCompute()) == 2)
- self.assertTrue(len(self.dc[1].listCompute()) == 1)
+ self.assertEqual(len(self.dc[0].listCompute()), 2)
+ self.assertEqual(len(self.dc[1].listCompute()), 1)
self.assertTrue(isinstance(
self.dc[0].listCompute()[0], EmulatorCompute))
self.assertTrue(isinstance(
self.dc[0].listCompute()[1], EmulatorCompute))
self.assertTrue(isinstance(
self.dc[1].listCompute()[0], EmulatorCompute))
- self.assertTrue(self.dc[0].listCompute()[1].name == "vnf1")
- self.assertTrue(self.dc[0].listCompute()[0].name == "vnf2")
- self.assertTrue(self.dc[1].listCompute()[0].name == "vnf3")
+ print("dc1: ", self.dc[0].listCompute())
+ print("dc2: ", self.dc[1].listCompute())
+ self.assertIn("vnf1", list(map(lambda x: x.name, self.dc[0].listCompute())))
+ self.assertIn("vnf2", list(map(lambda x: x.name, self.dc[0].listCompute())))
+ self.assertIn("vnf3", list(map(lambda x: x.name, self.dc[1].listCompute())))
# check connectivity by using ping
self.assertTrue(self.net.ping(
print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
output = subprocess.check_output(
"vim-emu network add -src vnf1 -dst vnf2 -b -c 10", shell=True)
- self.assertTrue("add-flow" in output)
- self.assertTrue("success" in output)
+ print("output: ", output)
+ print("type: ", type(output))
+ self.assertIn("add-flow", output.decode())
+ self.assertIn("success", output.decode())
print('network remove vnf1 vnf2->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
output = subprocess.check_output(
"vim-emu network remove -src vnf1 -dst vnf2 -b", shell=True)
- self.assertTrue("del-flows" in output)
- self.assertTrue("success" in output)
+ self.assertIn("del-flows", output.decode())
+ self.assertIn("success", output.decode())
print('>>>>> checking --> vim-emu compute stop -d datacenter0 -n vnf2 ->>>>>>')
print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
"vim-emu compute stop -d datacenter0 -n vnf2", shell=True)
# check number of running nodes
- self.assertTrue(len(self.getContainernetContainers()) == 2)
- self.assertTrue(len(self.net.hosts) == 4)
- self.assertTrue(len(self.net.switches) == 2)
+ self.assertEqual(len(self.getContainernetContainers()), 2)
+ self.assertEqual(len(self.net.hosts), 4)
+ self.assertEqual(len(self.net.switches), 2)
# check compute list result
- self.assertTrue(len(self.dc[0].listCompute()) == 1)
- self.assertTrue(len(self.dc[1].listCompute()) == 1)
+ self.assertEqual(len(self.dc[0].listCompute()), 1)
+ self.assertEqual(len(self.dc[1].listCompute()), 1)
print('>>>>> checking --> vim-emu compute list ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
output = subprocess.check_output("vim-emu compute list", shell=True)
# check datacenter list result
- self.assertTrue("datacenter0" in output)
+ self.assertIn("datacenter0", output.decode())
print('>>>>> checking --> vim-emu compute status -d datacenter0 -n vnf1 ->>>>')
print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
output = subprocess.check_output(
"vim-emu compute status -d datacenter0 -n vnf1", shell=True)
- output = ast.literal_eval(output)
+ output = ast.literal_eval(output.decode())
# check compute status result
- self.assertTrue(output["name"] == "vnf1")
+ self.assertEqual(output["name"], "vnf1")
self.assertTrue(output["state"]["Running"])
print('>>>>> checking --> vim-emu datacenter list ->>>>>>>>>>>>>>>>>>>>>>>>>>')
print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
output = subprocess.check_output("vim-emu datacenter list", shell=True)
# check datacenter list result
- self.assertTrue("datacenter0" in output)
+ self.assertIn("datacenter0", output.decode())
print('->>>>> checking --> vim-emu datacenter status -d datacenter0 ->>>>>>>>')
print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
output = subprocess.check_output(
"vim-emu datacenter status -d datacenter0", shell=True)
# check datacenter status result
- self.assertTrue("datacenter0" in output)
+ self.assertIn("datacenter0", output.decode())
self.stopApi()
self.stopNet()
from emuvim.api.tango.llcm import initialize_GK, parse_interface
from ipaddress import ip_network
+
PACKAGE_PATH = "misc/eu.5gtango.emulator-example-service.0.1.tgo"
for link in self.net.deployed_elines:
vnf_src, intf_src = parse_interface(
link['connection_points_reference'][0])
- print vnf_src, intf_src
+ print(vnf_src, intf_src)
src = self.net.getNodeByName(vnf_src)
if not src:
continue
dst_mask = [intf['netmask']
for intf in network_list if intf['intf_name'] == intf_dst][0]
- print "src = {0}:{1} ip={2} ".format(
- vnf_src, intf_src, src_ip, src_mask)
- print "dst = {0}:{1} ip={2} ".format(
- vnf_dst, intf_dst, dst_ip, dst_mask)
+ print("src = {0}:{1} ip={2} ".format(
+ vnf_src, intf_src, src_ip, src_mask))
+ print("dst = {0}:{1} ip={2} ".format(
+ vnf_dst, intf_dst, dst_ip, dst_mask))
# check if the E-Line IP's are in the same subnet
ret = ip_network(u'{0}'.format(src_ip, src_mask), strict=False)\
self.assertTrue(len(mgmt_ip) > 0)
ip_address = mgmt_ip[0]
ELAN_list.append(ip_address)
- print ip_address
+ print(ip_address)
# check ELAN connection by ping over the mgmt network (needs to be
# configured as ELAN in the test service)
for intf in network_list if intf['intf_name'] == 'mgmt']
self.assertTrue(len(mgmt_ip) > 0)
ip_address = mgmt_ip[0]
- print ELAN_list
- print ip_address
+ print(ELAN_list)
+ print(ip_address)
test_ip_list = list(ELAN_list)
test_ip_list.remove(ip_address)
for ip in test_ip_list:
# only take ip address, without netmask
p = self.net.ping([vnf], manualdestip=ip.split('/')[0])
- print p
+ print(p)
self.assertTrue(p <= 0.0)
# stop Mininet network
self.startNet()
time.sleep(3)
- print "starting tests"
+ print("starting tests")
# board package
files = {"package": open(PACKAGE_PATH, "rb")}
r = requests.post("http://127.0.0.1:56001/packages", files=files)