DEBIAN_FRONTEND=noninteractive apt-get -y install python-argcomplete python-bottle python-cffi python-packaging python-paramiko python-pkgconfig libmysqlclient-dev libssl-dev libffi-dev python-mysqldb && \
DEBIAN_FRONTEND=noninteractive apt-get -y install python-logutils python-openstackclient python-openstacksdk && \
DEBIAN_FRONTEND=noninteractive pip install untangle && \
+ DEBIAN_FRONTEND=noninteractive pip install pyone && \
DEBIAN_FRONTEND=noninteractive pip install -e git+https://github.com/python-oca/python-oca#egg=oca
function upgrade_to_23(){
# echo " upgrade database from version 0.22 to version 0.23"
echo " add column 'availability_zone' at table 'vms'"
- sql "ALTER TABLE mano_db.vms ADD COLUMN availability_zone VARCHAR(255) NULL AFTER modified_at;"
+ sql "ALTER TABLE vms ADD COLUMN availability_zone VARCHAR(255) NULL AFTER modified_at;"
sql "INSERT INTO schema_version (version_int, version, openmano_ver, comments, date) VALUES (23, '0.23', '0.5.20',"\
"'Changed type of ram in flavors from SMALLINT to MEDIUMINT', '2017-08-29');"
}
function downgrade_from_23(){
# echo " downgrade database from version 0.23 to version 0.22"
echo " remove column 'availability_zone' from table 'vms'"
- sql "ALTER TABLE mano_db.vms DROP COLUMN availability_zone;"
+ sql "ALTER TABLE vms DROP COLUMN availability_zone;"
sql "DELETE FROM schema_version WHERE version_int='23';"
}
"CHANGE COLUMN status status ENUM('SCHEDULED','BUILD','DONE','FAILED','SUPERSEDED') " \
"NOT NULL DEFAULT 'SCHEDULED' AFTER item_id;"
echo " Remove related from instance_xxxx"
- for table in instance_classifications instance_nets instance_wim_netsinstance_sfis instance_sfps instance_sfs \
+ for table in instance_classifications instance_nets instance_wim_nets instance_sfis instance_sfps instance_sfs \
instance_vms
do
sql "ALTER TABLE $table DROP COLUMN related;"
if [[ -z "$DATABASE_PROCESS" ]] ; then # migration a non empty database
check_migration_needed || exit 0
# Create a backup database content
- [[ -n "$BACKUP_DIR" ]] && BACKUP_FILE="$(mktemp -q "${BACKUP_DIR}/backupdb.XXXXXX.sql")"
- [[ -z "$BACKUP_DIR" ]] && BACKUP_FILE="$(mktemp -q --tmpdir "backupdb.XXXXXX.sql")"
+ [[ -n "$BACKUP_DIR" ]] && BACKUP_FILE=$(mktemp -q "${BACKUP_DIR}/backupdb.XXXXXX.sql")
+ [[ -z "$BACKUP_DIR" ]] && BACKUP_FILE=$(mktemp -q --tmpdir "backupdb.XXXXXX.sql")
mysqldump $DEF_EXTRA_FILE_PARAM --add-drop-table --add-drop-database --routines --databases $DBNAME > $BACKUP_FILE ||
! echo "Cannot create Backup file '$BACKUP_FILE'" >&2 || exit 1
echo " Backup file '$BACKUP_FILE' created"
-from ubuntu:xenial
+##
+# Copyright {yyyy} {name of copyright owner}
+#
+# 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.
+##
+
+########################################################################
+
+from ubuntu:18.04
LABEL authors="Gennadiy Dubina, Alfonso Tierno, Gerardo Garcia"
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get -y install software-properties-common && \
- DEBIAN_FRONTEND=noninteractive add-apt-repository -y cloud-archive:queens && \
- apt-get update && \
+ DEBIAN_FRONTEND=noninteractive apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get -y install git python python-pip && \
DEBIAN_FRONTEND=noninteractive apt-get -y install wget tox && \
DEBIAN_FRONTEND=noninteractive pip2 install pip==9.0.3 && \
DEBIAN_FRONTEND=noninteractive apt-get -y install python-networkx && \
DEBIAN_FRONTEND=noninteractive apt-get -y install genisoimage && \
DEBIAN_FRONTEND=noninteractive pip2 install untangle && \
+ DEBIAN_FRONTEND=noninteractive pip2 install pyone && \
DEBIAN_FRONTEND=noninteractive pip2 install -e git+https://github.com/python-oca/python-oca#egg=oca && \
DEBIAN_FRONTEND=noninteractive apt-get -y install mysql-client
__author__ = "Alfonso Tierno, Gerardo Garcia, Pablo Montes"
__date__ = "$26-aug-2014 11:09:29$"
-__version__ = "0.6.20"
-version_date = "May 2019"
+__version__ = "6.0.2.post2"
+version_date = "Sep 2019"
database_version = 39 # expected database schema version
global global_config
return client_data, used_schema
except (TypeError, ValueError, yaml.YAMLError) as exc:
error_text += str(exc)
- logger.error(error_text, exc_info=True)
+ logger.error(error_text)
bottle.abort(httperrors.Bad_Request, error_text)
except js_e.ValidationError as exc:
logger.error(
- "validate_in error, jsonschema exception", exc_info=True)
+ "validate_in error, jsonschema exception")
error_pos = ""
if len(exc.path)>0: error_pos=" at " + ":".join(map(json.dumps, exc.path))
bottle.abort(httperrors.Bad_Request, error_text + exc.message + error_pos)
try:
flavor_vim_id = None
flavor_vim_id=vim.get_flavor_id_from_data(flavor_dict)
- flavor_create="false"
+ flavor_created="false"
except vimconn.vimconnException as e:
pass
try:
# connection points vaiable declaration
cp_name2iface_uuid = {}
+ cp_name2vdu_id = {}
cp_name2vm_uuid = {}
cp_name2db_interface = {}
vdu_id2cp_name = {} # stored only when one external connection point is presented at this VDU
# table vms (vdus)
vdu_id2uuid = {}
vdu_id2db_table_index = {}
+ mgmt_access = {}
for vdu in vnfd.get("vdu").itervalues():
for vdu_descriptor in vnfd_descriptor["vdu"]:
cp = vnfd.get("connection-point")[iface.get("external-connection-point-ref")]
db_interface["external_name"] = get_str(cp, "name", 255)
cp_name2iface_uuid[db_interface["external_name"]] = iface_uuid
+ cp_name2vdu_id[db_interface["external_name"]] = vdu_id
cp_name2vm_uuid[db_interface["external_name"]] = vm_uuid
cp_name2db_interface[db_interface["external_name"]] = db_interface
for cp_descriptor in vnfd_descriptor["connection-point"]:
numa["threads"] = max(db_flavor["vcpus"], 1)
epa_vcpu_set = True
if vdu["guest-epa"].get("cpu-quota") and not epa_vcpu_set:
- extended["cpu-quota"] = get_resource_allocation_params(vdu["guest-epa"].get("cpu-quota"))
+ cpuquota = get_resource_allocation_params(vdu["guest-epa"].get("cpu-quota"))
+ if cpuquota:
+ extended["cpu-quota"] = cpuquota
if vdu["guest-epa"].get("mem-quota"):
- extended["mem-quota"] = get_resource_allocation_params(vdu["guest-epa"].get("mem-quota"))
+ vduquota = get_resource_allocation_params(vdu["guest-epa"].get("mem-quota"))
+ if vduquota:
+ extended["mem-quota"] = vduquota
if vdu["guest-epa"].get("disk-io-quota"):
- extended["disk-io-quota"] = get_resource_allocation_params(vdu["guest-epa"].get("disk-io-quota"))
+ diskioquota = get_resource_allocation_params(vdu["guest-epa"].get("disk-io-quota"))
+ if diskioquota:
+ extended["disk-io-quota"] = diskioquota
if vdu["guest-epa"].get("vif-quota"):
- extended["vif-quota"] = get_resource_allocation_params(vdu["guest-epa"].get("vif-quota"))
+ vifquota = get_resource_allocation_params(vdu["guest-epa"].get("vif-quota"))
+ if vifquota:
+ extended["vif-quota"] = vifquota
if numa:
extended["numas"] = [numa]
if extended:
# if pg.get("strategy") == "ISOLATION":
# VNF mgmt configuration
- mgmt_access = {}
if vnfd["mgmt-interface"].get("vdu-id"):
mgmt_vdu_id = get_str(vnfd["mgmt-interface"], "vdu-id", 255)
if mgmt_vdu_id not in vdu_id2uuid:
vnf=vnfd_id, vdu=mgmt_vdu_id),
httperrors.Bad_Request)
mgmt_access["vm_id"] = vdu_id2uuid[vnfd["mgmt-interface"]["vdu-id"]]
+ mgmt_access["vdu-id"] = vnfd["mgmt-interface"]["vdu-id"]
# if only one cp is defined by this VDU, mark this interface as of type "mgmt"
if vdu_id2cp_name.get(mgmt_vdu_id):
if cp_name2db_interface[vdu_id2cp_name[mgmt_vdu_id]]:
httperrors.Bad_Request)
mgmt_access["vm_id"] = cp_name2vm_uuid[vnfd["mgmt-interface"]["cp"]]
mgmt_access["interface_id"] = cp_name2iface_uuid[vnfd["mgmt-interface"]["cp"]]
+ mgmt_access["vdu-id"] = cp_name2vdu_id[vnfd["mgmt-interface"]["cp"]]
# mark this interface as of type mgmt
if cp_name2db_interface[vnfd["mgmt-interface"]["cp"]]:
cp_name2db_interface[vnfd["mgmt-interface"]["cp"]]["type"] = "mgmt"
default_user = get_str(vnfd.get("vnf-configuration", {}).get("config-access", {}).get("ssh-access", {}),
"default-user", 64)
-
if default_user:
mgmt_access["default_user"] = default_user
+
required = get_str(vnfd.get("vnf-configuration", {}).get("config-access", {}).get("ssh-access", {}),
"required", 6)
if required:
mgmt_access["required"] = required
+ password_ = get_str(vnfd.get("vnf-configuration", {}).get("config-access", {}),
+ "password", 64)
+ if password_:
+ mgmt_access["password"] = password_
+
if mgmt_access:
db_vnf["mgmt_access"] = yaml.safe_dump(mgmt_access, default_flow_style=True, width=256)
cloud_config_vm = unify_cloud_config({"key-pairs": params["instance_parameters"]["mgmt_keys"]},
cloud_config_vm)
- if vm.get("instance_parameters") and vm["instance_parameters"].get("mgmt_keys"):
- cloud_config_vm = unify_cloud_config({"key-pairs": vm["instance_parameters"]["mgmt_keys"]},
- cloud_config_vm)
- # if ssh_access and ssh_access['required'] and ssh_access['default-user'] and tenant[0].get('RO_pub_key'):
- # RO_key = {"key-pairs": [tenant[0]['RO_pub_key']]}
- # cloud_config_vm = unify_cloud_config(cloud_config_vm, RO_key)
+ if vm.get("instance_parameters") and "mgmt_keys" in vm["instance_parameters"]:
+ if vm["instance_parameters"]["mgmt_keys"]:
+ cloud_config_vm = unify_cloud_config({"key-pairs": vm["instance_parameters"]["mgmt_keys"]},
+ cloud_config_vm)
+ if RO_pub_key:
+ cloud_config_vm = unify_cloud_config(cloud_config_vm, {"key-pairs": RO_pub_key})
if vm.get("boot_data"):
cloud_config_vm = unify_cloud_config(vm["boot_data"], cloud_config_vm)
for vm in sce_vnf['vms']:
if not action_over_all and sce_vnf['uuid'] not in input_vnfs and sce_vnf['vnf_name'] not in input_vnfs and \
sce_vnf['member_vnf_index'] not in input_vnfs and \
- vm['uuid'] not in input_vms and vm['name'] not in input_vms:
+ vm['uuid'] not in input_vms and vm['name'] not in input_vms and \
+ sce_vnf['member_vnf_index'] + "-" + vm['vdu_osm_id'] not in input_vms: # TODO conside vm_count_index
continue
try:
if "add_public_key" in action_dict:
- mgmt_access = {}
if sce_vnf.get('mgmt_access'):
mgmt_access = yaml.load(sce_vnf['mgmt_access'])
- ssh_access = mgmt_access['config-access']['ssh-access']
+ if not input_vms and mgmt_access.get("vdu-id") != vm['vdu_osm_id']:
+ continue
+ default_user = mgmt_access.get("default-user")
+ password = mgmt_access.get("password")
+ if mgmt_access.get(vm['vdu_osm_id']):
+ default_user = mgmt_access[vm['vdu_osm_id']].get("default-user", default_user)
+ password = mgmt_access[vm['vdu_osm_id']].get("password", password)
+
tenant = mydb.get_rows_by_id('nfvo_tenants', nfvo_tenant)
try:
- if ssh_access['required'] and ssh_access['default-user']:
- if 'ip_address' in vm:
+ if 'ip_address' in vm:
mgmt_ip = vm['ip_address'].split(';')
- password = mgmt_access['config-access'].get('password')
priv_RO_key = decrypt_key(tenant[0]['encrypted_RO_priv_key'], tenant[0]['uuid'])
- myvim.inject_user_key(mgmt_ip[0], ssh_access['default-user'],
+ myvim.inject_user_key(mgmt_ip[0], action_dict.get('user', default_user),
action_dict['add_public_key'],
password=password, ro_key=priv_RO_key)
- else:
- raise NfvoException("Unable to inject ssh key in vm: {} - Aborting".format(vm['uuid']),
- httperrors.Internal_Server_Error)
except KeyError:
raise NfvoException("Unable to inject ssh key in vm: {} - Aborting".format(vm['uuid']),
httperrors.Internal_Server_Error)
#get datacenter info
datacenter_id, myvim = get_datacenter_by_name_uuid(mydb, tenant_id, datacenter)
- if 'net-update' in action_dict:
+ if 'check-connectivity' in action_dict:
+ try:
+ myvim.check_vim_connectivity()
+ except vimconn.vimconnException as e:
+ #logger.error("nfvo.datacenter_action() Not possible to get_network_list from VIM: %s ", str(e))
+ raise NfvoException(str(e), e.http_code)
+ elif 'net-update' in action_dict:
try:
nets = myvim.get_network_list(filter_dict={'shared': True, 'admin_state_up': True, 'status': 'ACTIVE'})
#print content
"$schema": "http://json-schema.org/draft-04/schema#",
"type":"object",
"properties":{
- "net-update":{"type":"null",},
- "net-edit":{
+ "check-connectivity": {"type": "null"},
+ "net-update": {"type": "null"},
+ "net-edit": {
"type":"object",
"properties":{
"net": name_schema, #name or uuid of net to change
"type": ["object", "null"],
},
"add_public_key": description_schema,
+ "user": nameshort_schema,
"console": {"type": ["string", "null"], "enum": ["novnc", "xvpvnc", "rdp-html5", "spice-html5", None]},
"vdu-scaling": {
"type": "array",
import unittest
-from ..utils import get_arg, inject_args
+from ..utils import (
+ get_arg,
+ inject_args,
+ remove_extra_items,
+)
class TestUtils(unittest.TestCase):
def test_inject_args_curries_arguments(self):
- fn = inject_args(lambda a=None, b=None: a+b, a=3, b=5)
+ fn = inject_args(lambda a=None, b=None: a + b, a=3, b=5)
self.assertEqual(fn(), 8)
def test_inject_args_doesnt_add_arg_if_not_needed(self):
def _fn(x, y, z):
return x + y + z
- x = get_arg('x', _fn, (1, 3, 4), {})
+ x = get_arg("x", _fn, (1, 3, 4), {})
self.assertEqual(x, 1)
- y = get_arg('y', _fn, (1, 3, 4), {})
+ y = get_arg("y", _fn, (1, 3, 4), {})
self.assertEqual(y, 3)
- z = get_arg('z', _fn, (1, 3, 4), {})
+ z = get_arg("z", _fn, (1, 3, 4), {})
self.assertEqual(z, 4)
def test_get_arg__keyword(self):
def _fn(x, y, z=5):
return x + y + z
- z = get_arg('z', _fn, (1, 2), {'z': 3})
+ z = get_arg("z", _fn, (1, 2), {"z": 3})
self.assertEqual(z, 3)
-if __name__ == '__main__':
+
+ def test_remove_extra_items__keep_aditional_properties(self):
+ schema = {
+ "type": "object",
+ "properties": {
+ "a": {
+ "type": "object",
+ "properties": {
+ "type": "object",
+ "properties": {"b": "string"},
+ },
+ "additionalProperties": True,
+ }
+ },
+ }
+
+ example = {"a": {"b": 1, "c": 2}, "d": 3}
+ deleted = remove_extra_items(example, schema)
+ self.assertIn("d", deleted)
+ self.assertIs(example.get("d"), None)
+ self.assertEqual(example["a"]["c"], 2)
+
+
+if __name__ == "__main__":
unittest.main()
return False, ("validate_in error, jsonschema exception ", exc.message, "at", exc.path)
def remove_extra_items(data, schema):
- deleted=[]
+ deleted = []
if type(data) is tuple or type(data) is list:
for d in data:
- a= remove_extra_items(d, schema['items'])
- if a is not None: deleted.append(a)
+ a = remove_extra_items(d, schema['items'])
+ if a is not None:
+ deleted.append(a)
elif type(data) is dict:
- #TODO deal with patternProperties
+ # TODO deal with patternProperties
if 'properties' not in schema:
return None
for k in data.keys():
- if k not in schema['properties'].keys():
+ if k in schema['properties'].keys():
+ a = remove_extra_items(data[k], schema['properties'][k])
+ if a is not None:
+ deleted.append({k: a})
+ elif not schema.get('additionalProperties'):
del data[k]
deleted.append(k)
- else:
- a = remove_extra_items(data[k], schema['properties'][k])
- if a is not None: deleted.append({k:a})
- if len(deleted) == 0: return None
- elif len(deleted) == 1: return deleted[0]
- else: return deleted
+ if len(deleted) == 0:
+ return None
+ elif len(deleted) == 1:
+ return deleted[0]
+
+ return deleted
#def format_html2text(http_content):
# soup=BeautifulSoup(http_content)
# task of creation must be the first in the list of related_task
assert(related_tasks[0]["action"] in ("CREATE", "FIND"))
+ task["params"] = None
if task["extra"]:
extra = yaml.load(task["extra"])
else:
task["error_msg"] = related_tasks[0]["error_msg"]
task["vim_id"] = related_tasks[0]["vim_id"]
extra = yaml.load(related_tasks[0]["extra"])
- task["extra"]["vim_status"] = extra["vim_status"]
+ task["extra"]["vim_status"] = extra.get("vim_status")
next_refresh = related_tasks[0]["modified_at"] + 0.001
database_update = {"status": task["extra"].get("vim_status", "VIM_ERROR"),
"error_msg": task["error_msg"]}
UPDATE={("number_failed" if task["status"] == "FAILED" else "number_done"): {"INCREMENT": 1}},
WHERE={"uuid": task["instance_action_id"]})
if database_update:
+ where_filter = {"related": task["related"]}
+ if task["item"] == "instance_nets" and task["datacenter_vim_id"]:
+ where_filter["datacenter_tenant_id"] = task["datacenter_vim_id"]
self.db.update_rows(table=task["item"],
UPDATE=database_update,
- WHERE={"related": task["related"]})
+ WHERE=where_filter)
except db_base_Exception as e:
self.logger.error("task={} Error updating database {}".format(task_id, e), exc_info=True)
if wim_account_name and self.vim.config["wim_external_ports"]:
# add external port to connect WIM. Try with compute node __WIM:wim_name and __WIM
action_text = "attaching external port to ovim network"
- sdn_port_name = sdn_net_id + "." + task["vim_id"]
- sdn_port_name = sdn_port_name[:63]
+ sdn_port_name = "external_port"
sdn_port_data = {
"compute_node": "__WIM:" + wim_account_name[0:58],
"pci": None,
net_vim_id = task["vim_id"]
sdn_net_id = task["extra"].get("sdn_net_id")
try:
+ if net_vim_id:
+ self.vim.delete_network(net_vim_id, task["extra"].get("created_items"))
if sdn_net_id:
# Delete any attached port to this sdn network. There can be ports associated to this network in case
# it was manually done using 'openmano vim-net-sdn-attach'
for port in port_list:
self.ovim.delete_port(port['uuid'], idempotent=True)
self.ovim.delete_network(sdn_net_id, idempotent=True)
- if net_vim_id:
- self.vim.delete_network(net_vim_id, task["extra"].get("created_items"))
task["status"] = "FINISHED" # with FINISHED instead of DONE it will not be refreshing
task["error_msg"] = None
return None
vimconn implement an Abstract class for the vim connector plugins
with the definition of the method to be implemented.
"""
-__author__="Alfonso Tierno, Igor D.C."
-__date__ ="$14-aug-2017 23:59:59$"
import logging
import paramiko
import sys
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
+from utils import deprecated
+
+__author__ = "Alfonso Tierno, Igor D.C."
+__date__ = "$14-aug-2017 23:59:59$"
#Error variables
HTTP_Bad_Request = 400
HTTP_Service_Unavailable = 503
HTTP_Internal_Server_Error = 500
+
class vimconnException(Exception):
"""Common and base class Exception for all vimconnector exceptions"""
def __init__(self, message, http_code=HTTP_Bad_Request):
Exception.__init__(self, message)
self.http_code = http_code
+
class vimconnConnectionException(vimconnException):
"""Connectivity error with the VIM"""
def __init__(self, message, http_code=HTTP_Service_Unavailable):
vimconnException.__init__(self, message, http_code)
-
+
+
class vimconnUnexpectedResponse(vimconnException):
"""Get an wrong response from VIM"""
def __init__(self, message, http_code=HTTP_Service_Unavailable):
vimconnException.__init__(self, message, http_code)
+
class vimconnAuthException(vimconnException):
"""Invalid credentials or authorization to perform this action over the VIM"""
def __init__(self, message, http_code=HTTP_Unauthorized):
vimconnException.__init__(self, message, http_code)
+
class vimconnNotFoundException(vimconnException):
"""The item is not found at VIM"""
def __init__(self, message, http_code=HTTP_Not_Found):
vimconnException.__init__(self, message, http_code)
+
class vimconnConflictException(vimconnException):
"""There is a conflict, e.g. more item found than one"""
def __init__(self, message, http_code=HTTP_Conflict):
vimconnException.__init__(self, message, http_code)
+
class vimconnNotSupportedException(vimconnException):
"""The request is not supported by connector"""
def __init__(self, message, http_code=HTTP_Service_Unavailable):
vimconnException.__init__(self, message, http_code)
+
class vimconnNotImplemented(vimconnException):
"""The method is not implemented by the connected"""
def __init__(self, message, http_code=HTTP_Not_Implemented):
"""
def __init__(self, uuid, name, tenant_id, tenant_name, url, url_admin=None, user=None, passwd=None, log_level=None,
config={}, persitent_info={}):
- """Constructor of VIM
- Params:
- 'uuid': id asigned to this VIM
- 'name': name assigned to this VIM, can be used for logging
- 'tenant_id', 'tenant_name': (only one of them is mandatory) VIM tenant to be used
- 'url_admin': (optional), url used for administrative tasks
- 'user', 'passwd': credentials of the VIM user
- 'log_level': provider if it should use a different log_level than the general one
- 'config': dictionary with extra VIM information. This contains a consolidate version of general VIM config
- at creation and particular VIM config at teh attachment
- 'persistent_info': dict where the class can store information that will be available among class
+ """
+ Constructor of VIM. Raise an exception is some needed parameter is missing, but it must not do any connectivity
+ checking against the VIM
+ :param uuid: internal id of this VIM
+ :param name: name assigned to this VIM, can be used for logging
+ :param tenant_id: 'tenant_id': (only one of them is mandatory) VIM tenant to be used
+ :param tenant_name: 'tenant_name': (only one of them is mandatory) VIM tenant to be used
+ :param url: url used for normal operations
+ :param url_admin: (optional), url used for administrative tasks
+ :param user: user to access
+ :param passwd: password
+ :param log_level: provided if it should use a different log_level than the general one
+ :param config: dictionary with extra VIM information. This contains a consolidate version of VIM config
+ at VIM_ACCOUNT (attach)
+ :param persitent_info: dict where the class can store information that will be available among class
destroy/creation cycles. This info is unique per VIM/credential. At first call it will contain an
empty dict. Useful to store login/tokens information for speed up communication
- Returns: Raise an exception is some needed parameter is missing, but it must not do any connectivity
- check against the VIM
"""
- self.id = uuid
- self.name = name
- self.url = url
+ self.id = uuid
+ self.name = name
+ self.url = url
self.url_admin = url_admin
self.tenant_id = tenant_id
self.tenant_name = tenant_name
- self.user = user
- self.passwd = passwd
- self.config = config
+ self.user = user
+ self.passwd = passwd
+ self.config = config or {}
self.availability_zone = None
self.logger = logging.getLogger('openmano.vim')
if log_level:
- self.logger.setLevel( getattr(logging, log_level) )
- if not self.url_admin: #try to use normal url
+ self.logger.setLevel(getattr(logging, log_level))
+ if not self.url_admin: # try to use normal url
self.url_admin = self.url
- def __getitem__(self,index):
- if index=='tenant_id':
+ def __getitem__(self, index):
+ if index == 'tenant_id':
return self.tenant_id
- if index=='tenant_name':
+ if index == 'tenant_name':
return self.tenant_name
- elif index=='id':
+ elif index == 'id':
return self.id
- elif index=='name':
+ elif index == 'name':
return self.name
- elif index=='user':
+ elif index == 'user':
return self.user
- elif index=='passwd':
+ elif index == 'passwd':
return self.passwd
- elif index=='url':
+ elif index == 'url':
return self.url
- elif index=='url_admin':
+ elif index == 'url_admin':
return self.url_admin
- elif index=="config":
+ elif index == "config":
return self.config
else:
- raise KeyError("Invalid key '%s'" %str(index))
+ raise KeyError("Invalid key '{}'".format(index))
- def __setitem__(self,index, value):
- if index=='tenant_id':
+ def __setitem__(self, index, value):
+ if index == 'tenant_id':
self.tenant_id = value
- if index=='tenant_name':
+ if index == 'tenant_name':
self.tenant_name = value
- elif index=='id':
+ elif index == 'id':
self.id = value
- elif index=='name':
+ elif index == 'name':
self.name = value
- elif index=='user':
+ elif index == 'user':
self.user = value
- elif index=='passwd':
+ elif index == 'passwd':
self.passwd = value
- elif index=='url':
+ elif index == 'url':
self.url = value
- elif index=='url_admin':
+ elif index == 'url_admin':
self.url_admin = value
else:
- raise KeyError("Invalid key '%s'" %str(index))
+ raise KeyError("Invalid key '{}'".format(index))
@staticmethod
def _create_mimemultipart(content_list):
combined_message = MIMEMultipart()
for content in content_list:
if content.startswith('#include'):
- format = 'text/x-include-url'
+ mime_format = 'text/x-include-url'
elif content.startswith('#include-once'):
- format = 'text/x-include-once-url'
+ mime_format = 'text/x-include-once-url'
elif content.startswith('#!'):
- format = 'text/x-shellscript'
+ mime_format = 'text/x-shellscript'
elif content.startswith('#cloud-config'):
- format = 'text/cloud-config'
+ mime_format = 'text/cloud-config'
elif content.startswith('#cloud-config-archive'):
- format = 'text/cloud-config-archive'
+ mime_format = 'text/cloud-config-archive'
elif content.startswith('#upstart-job'):
- format = 'text/upstart-job'
+ mime_format = 'text/upstart-job'
elif content.startswith('#part-handler'):
- format = 'text/part-handler'
+ mime_format = 'text/part-handler'
elif content.startswith('#cloud-boothook'):
- format = 'text/cloud-boothook'
+ mime_format = 'text/cloud-boothook'
else: # by default
- format = 'text/x-shellscript'
- sub_message = MIMEText(content, format, sys.getdefaultencoding())
+ mime_format = 'text/x-shellscript'
+ sub_message = MIMEText(content, mime_format, sys.getdefaultencoding())
combined_message.attach(sub_message)
return combined_message.as_string()
else:
for u in cloud_config["user-data"]:
userdata_list.append(u)
- if cloud_config.get("boot-data-drive") != None:
+ if cloud_config.get("boot-data-drive") is not None:
config_drive = cloud_config["boot-data-drive"]
if cloud_config.get("config-files") or cloud_config.get("users") or cloud_config.get("key-pairs"):
userdata_dict = {}
def check_vim_connectivity(self):
"""Checks VIM can be reached and user credentials are ok.
- Returns None if success or raised vimconnConnectionException, vimconnAuthException, ...
+ Returns None if success or raises vimconnConnectionException, vimconnAuthException, ...
"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ # by default no checking until each connector implements it
+ return None
- def new_tenant(self,tenant_name,tenant_description):
+ def new_tenant(self, tenant_name, tenant_description):
"""Adds a new tenant to VIM with this name and description, this is done using admin_url if provided
"tenant_name": string max lenght 64
"tenant_description": string max length 256
returns the tenant identifier or raise exception
"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
- def delete_tenant(self,tenant_id,):
+ def delete_tenant(self, tenant_id):
"""Delete a tenant from VIM
tenant_id: returned VIM tenant_id on "new_tenant"
Returns None on success. Raises and exception of failure. If tenant is not found raises vimconnNotFoundException
"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def get_tenant_list(self, filter_dict={}):
"""Obtain tenants of VIM
Returns the tenant list of dictionaries, and empty list if no tenant match all the filers:
[{'name':'<name>, 'id':'<id>, ...}, ...]
"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def new_network(self, net_name, net_type, ip_profile=None, shared=False, vlan=None):
"""Adds a tenant network to VIM
Format is vimconnector dependent, but do not use nested dictionaries and a value of None should be the same
as not present.
"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def get_network_list(self, filter_dict={}):
"""Obtain tenant networks of VIM
List can be empty if no network map the filter_dict. Raise an exception only upon VIM connectivity,
authorization, or some other unspecific error
"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def get_network(self, net_id):
"""Obtain network details from the 'net_id' VIM network
other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param
Raises an exception upon error or when network is not found
"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def delete_network(self, net_id, created_items=None):
"""
:param created_items: dictionary with extra items to be deleted. provided by method new_network
Returns the network identifier or raises an exception upon error or when network is not found
"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def refresh_nets_status(self, net_list):
"""Get the status of the networks
vim_info: #Text with plain information obtained from vim (yaml.safe_dump)
'net_id2': ...
"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def get_flavor(self, flavor_id):
"""Obtain flavor details from the VIM
Returns the flavor dict details {'id':<>, 'name':<>, other vim specific }
Raises an exception upon error or if not found
"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def get_flavor_id_from_data(self, flavor_dict):
"""Obtain flavor id that match the flavor description
#TODO: complete parameters for EPA
Returns the flavor_id or raises a vimconnNotFoundException
"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def new_flavor(self, flavor_data):
"""Adds a tenant flavor to VIM
is_public:
#TODO to concrete
Returns the flavor identifier"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def delete_flavor(self, flavor_id):
"""Deletes a tenant flavor from VIM identify by its id
Returns the used id or raise an exception"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def new_image(self, image_dict):
""" Adds a tenant image to VIM
Returns the image id or raises an exception if failed
"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def delete_image(self, image_id):
"""Deletes a tenant image from VIM
Returns the image_id if image is deleted or raises an exception on error"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def get_image_id_from_path(self, path):
"""Get the image id from image path in the VIM database.
Returns the image_id or raises a vimconnNotFoundException
"""
- raise vimconnNotImplemented( "Should have implemented this" )
+ raise vimconnNotImplemented("Should have implemented this")
def get_image_list(self, filter_dict={}):
"""Obtain tenant images from VIM
"""
raise vimconnNotImplemented( "Should have implemented this" )
+ def inject_user_key(self, ip_addr=None, user=None, key=None, ro_key=None, password=None):
+ """
+ Inject a ssh public key in a VM
+ Params:
+ ip_addr: ip address of the VM
+ user: username (default-user) to enter in the VM
+ key: public key to be injected in the VM
+ ro_key: private key of the RO, used to enter in the VM if the password is not provided
+ password: password of the user to enter in the VM
+ The function doesn't return a value:
+ """
+ if not ip_addr or not user:
+ raise vimconnNotSupportedException("All parameters should be different from 'None'")
+ elif not ro_key and not password:
+ raise vimconnNotSupportedException("All parameters should be different from 'None'")
+ else:
+ commands = {'mkdir -p ~/.ssh/', 'echo "%s" >> ~/.ssh/authorized_keys' % key,
+ 'chmod 644 ~/.ssh/authorized_keys', 'chmod 700 ~/.ssh/'}
+ client = paramiko.SSHClient()
+ try:
+ if ro_key:
+ pkey = paramiko.RSAKey.from_private_key(StringIO.StringIO(ro_key))
+ else:
+ pkey = None
+ client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+ client.connect(ip_addr, username=user, password=password, pkey=pkey, timeout=10)
+ for command in commands:
+ (i, o, e) = client.exec_command(command, timeout=10)
+ returncode = o.channel.recv_exit_status()
+ output = o.read()
+ outerror = e.read()
+ if returncode != 0:
+ text = "run_command='{}' Error='{}'".format(command, outerror)
+ raise vimconnUnexpectedResponse("Cannot inject ssh key in VM: '{}'".format(text))
+ return
+ except (socket.error, paramiko.AuthenticationException, paramiko.SSHException) as message:
+ raise vimconnUnexpectedResponse(
+ "Cannot inject ssh key in VM: '{}' - {}".format(ip_addr, str(message)))
+ return
+
+# Optional methods
+
+ def new_tenant(self,tenant_name,tenant_description):
+ """Adds a new tenant to VIM with this name and description, this is done using admin_url if provided
+ "tenant_name": string max lenght 64
+ "tenant_description": string max length 256
+ returns the tenant identifier or raise exception
+ """
+ raise vimconnNotImplemented( "Should have implemented this" )
+
+ def delete_tenant(self,tenant_id,):
+ """Delete a tenant from VIM
+ tenant_id: returned VIM tenant_id on "new_tenant"
+ Returns None on success. Raises and exception of failure. If tenant is not found raises vimconnNotFoundException
+ """
+ raise vimconnNotImplemented( "Should have implemented this" )
+
+ def get_tenant_list(self, filter_dict=None):
+ """Obtain tenants of VIM
+ filter_dict dictionary that can contain the following keys:
+ name: filter by tenant name
+ id: filter by tenant uuid/id
+ <other VIM specific>
+ Returns the tenant list of dictionaries, and empty list if no tenant match all the filers:
+ [{'name':'<name>, 'id':'<id>, ...}, ...]
+ """
+ raise vimconnNotImplemented( "Should have implemented this" )
+
def new_classification(self, name, ctype, definition):
"""Creates a traffic classification in the VIM
Params:
"""
raise vimconnNotImplemented( "SFC support not implemented" )
-
def new_sfp(self, name, classifications, sfs, sfc_encap=True, spi=None):
"""Creates a service function path
Params:
"""
raise vimconnNotImplemented( "SFC support not implemented" )
- def inject_user_key(self, ip_addr=None, user=None, key=None, ro_key=None, password=None):
- """
- Inject a ssh public key in a VM
- Params:
- ip_addr: ip address of the VM
- user: username (default-user) to enter in the VM
- key: public key to be injected in the VM
- ro_key: private key of the RO, used to enter in the VM if the password is not provided
- password: password of the user to enter in the VM
- The function doesn't return a value:
- """
- if not ip_addr or not user:
- raise vimconnNotSupportedException("All parameters should be different from 'None'")
- elif not ro_key and not password:
- raise vimconnNotSupportedException("All parameters should be different from 'None'")
- else:
- commands = {'mkdir -p ~/.ssh/', 'echo "%s" >> ~/.ssh/authorized_keys' % key,
- 'chmod 644 ~/.ssh/authorized_keys', 'chmod 700 ~/.ssh/'}
- client = paramiko.SSHClient()
- try:
- if ro_key:
- pkey = paramiko.RSAKey.from_private_key(StringIO.StringIO(ro_key))
- else:
- pkey = None
- client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- client.connect(ip_addr, username=user, password=password, pkey=pkey, timeout=10)
- for command in commands:
- (i, o, e) = client.exec_command(command, timeout=10)
- returncode = o.channel.recv_exit_status()
- output = o.read()
- outerror = e.read()
- if returncode != 0:
- text = "run_command='{}' Error='{}'".format(command, outerror)
- raise vimconnUnexpectedResponse("Cannot inject ssh key in VM: '{}'".format(text))
- return
- except (socket.error, paramiko.AuthenticationException, paramiko.SSHException) as message:
- raise vimconnUnexpectedResponse(
- "Cannot inject ssh key in VM: '{}' - {}".format(ip_addr, str(message)))
- return
-
-
-#NOT USED METHODS in current version
+# NOT USED METHODS in current version. Deprecated
+ @deprecated
def host_vim2gui(self, host, server_dict):
"""Transform host dictionary from VIM format to GUI format,
and append to the server_dict
"""
raise vimconnNotImplemented( "Should have implemented this" )
+ @deprecated
def get_hosts_info(self):
"""Get the information of deployed hosts
Returns the hosts content"""
raise vimconnNotImplemented( "Should have implemented this" )
+ @deprecated
def get_hosts(self, vim_tenant):
"""Get the hosts and deployed instances
Returns the hosts content"""
raise vimconnNotImplemented( "Should have implemented this" )
+ @deprecated
def get_processor_rankings(self):
"""Get the processor rankings in the VIM database"""
raise vimconnNotImplemented( "Should have implemented this" )
+ @deprecated
def new_host(self, host_data):
"""Adds a new host to VIM"""
"""Returns status code of the VIM response"""
raise vimconnNotImplemented( "Should have implemented this" )
+ @deprecated
def new_external_port(self, port_data):
"""Adds a external port to VIM"""
"""Returns the port identifier"""
raise vimconnNotImplemented( "Should have implemented this" )
+ @deprecated
def new_external_network(self,net_name,net_type):
"""Adds a external network to VIM (shared)"""
"""Returns the network identifier"""
raise vimconnNotImplemented( "Should have implemented this" )
+ @deprecated
+ @deprecated
def connect_port_network(self, port_id, network_id, admin=False):
"""Connects a external port to a network"""
"""Returns status code of the VIM response"""
raise vimconnNotImplemented( "Should have implemented this" )
+ @deprecated
def new_vminstancefromJSON(self, vm_data):
"""Adds a VM instance to VIM"""
"""Returns the instance identifier"""
import untangle
import math
import random
-
+import pyone
class vimconnector(vimconn.vimconnector):
def __init__(self, uuid, name, tenant_id, tenant_name, url, url_admin=None, user=None, passwd=None,
log_level="DEBUG", config={}, persistent_info={}):
+
+ """Constructor of VIM
+ Params:
+ 'uuid': id asigned to this VIM
+ 'name': name assigned to this VIM, can be used for logging
+ 'tenant_id', 'tenant_name': (only one of them is mandatory) VIM tenant to be used
+ 'url_admin': (optional), url used for administrative tasks
+ 'user', 'passwd': credentials of the VIM user
+ 'log_level': provider if it should use a different log_level than the general one
+ 'config': dictionary with extra VIM information. This contains a consolidate version of general VIM config
+ at creation and particular VIM config at teh attachment
+ 'persistent_info': dict where the class can store information that will be available among class
+ destroy/creation cycles. This info is unique per VIM/credential. At first call it will contain an
+ empty dict. Useful to store login/tokens information for speed up communication
+
+ Returns: Raise an exception is some needed parameter is missing, but it must not do any connectivity
+ check against the VIM
+ """
+
vimconn.vimconnector.__init__(self, uuid, name, tenant_id, tenant_name, url, url_admin, user, passwd, log_level,
config)
- self.tenant = None
- self.headers_req = {'content-type': 'application/json'}
- self.logger = logging.getLogger('openmano.vim.opennebula')
- self.persistent_info = persistent_info
- if tenant_id:
- self.tenant = tenant_id
-
- def __setitem__(self, index, value):
- """Set individuals parameters
- Throw TypeError, KeyError
- """
- if index == 'tenant_id':
- self.tenant = value
- elif index == 'tenant_name':
- self.tenant = None
- vimconn.vimconnector.__setitem__(self, index, value)
+
+ def _new_one_connection(self):
+ return pyone.OneServer(self.url, session=self.user + ':' + self.passwd)
def new_tenant(self, tenant_name, tenant_description):
# '''Adds a new tenant to VIM with this name and description, returns the tenant identifier'''
self.logger.error("Create new tenant error: " + str(e))
raise vimconn.vimconnException(e)
- def _add_secondarygroup(self, id_user, id_group):
- # change secondary_group to primary_group
- params = '<?xml version="1.0"?> \
- <methodCall>\
- <methodName>one.user.addgroup</methodName>\
- <params>\
- <param>\
- <value><string>{}:{}</string></value>\
- </param>\
- <param>\
- <value><int>{}</int></value>\
- </param>\
- <param>\
- <value><int>{}</int></value>\
- </param>\
- </params>\
- </methodCall>'.format(self.user, self.passwd, (str(id_user)), (str(id_group)))
- requests.post(self.url, params)
-
def delete_tenant(self, tenant_id):
"""Delete a tenant from VIM. Returns the old tenant identifier"""
try:
self.logger.error("Delete tenant " + str(tenant_id) + " error: " + str(e))
raise vimconn.vimconnException(e)
- # to be used in future commits
+ def _add_secondarygroup(self, id_user, id_group):
+ # change secondary_group to primary_group
+ params = '<?xml version="1.0"?> \
+ <methodCall>\
+ <methodName>one.user.addgroup</methodName>\
+ <params>\
+ <param>\
+ <value><string>{}:{}</string></value>\
+ </param>\
+ <param>\
+ <value><int>{}</int></value>\
+ </param>\
+ <param>\
+ <value><int>{}</int></value>\
+ </param>\
+ </params>\
+ </methodCall>'.format(self.user, self.passwd, (str(id_user)), (str(id_group)))
+ requests.post(self.url, params)
+
def _delete_secondarygroup(self, id_user, id_group):
params = '<?xml version="1.0"?> \
<methodCall>\
</methodCall>'.format(self.user, self.passwd, (str(id_user)), (str(id_group)))
requests.post(self.url, params)
- # to be used in future commits
- # def get_tenant_list(self, filter_dict={}):
- # return ["tenant"]
-
- # to be used in future commits
- # def _check_tenant(self):
- # try:
- # client = oca.Client(self.user + ':' + self.passwd, self.url)
- # group_list = oca.GroupPool(client)
- # user_list = oca.UserPool(client)
- # group_list.info()
- # user_list.info()
- # for group in group_list:
- # if str(group.name) == str(self.tenant_name):
- # for user in user_list:
- # if str(user.name) == str(self.user):
- # self._add_secondarygroup(user.id, group.id)
- # user.chgrp(group.id)
- # except vimconn.vimconnException as e:
- # self.logger.error(e)
-
- # to be used in future commits, needs refactor to manage networks
- # def _create_bridge_host(self, vlan):
- # file = open('manage_bridge_OSM', 'w')
- # # password_path = self.config["password"]["path"]
- # a = "#! /bin/bash\nsudo brctl addbr br_osm_{vlanused}\n" \
- # "sudo ip link add link veth1 name veth1.{vlanused} type vlan id {vlanused}\n" \
- # "sudo brctl addif br_osm_{vlanused} veth1.{vlanused}\n" \
- # "sudo ip link set dev br_osm_{vlanused} up\n" \
- # "sudo ip link set dev veth1.{vlanused} up\n".format(vlanused=vlan)
- # # a = "#! /bin/bash\nsudo brctl addbr br_osm\nsudo ip link set dev br_osm up\n"
- # file.write(a)
- # file.close()
- # for host in self.config["cluster"]["ip"]:
- # file_scp = "/usr/bin/scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {} manage_bridge_OSM {}@{}:/home/{}".format(
- # self.config["cluster"]["password_path"][host], self.config["cluster"]["login"][host],
- # self.config["cluster"]["ip"][host], self.config["cluster"]["login"][host])
- # os.system(file_scp)
- # file_permissions = "/usr/bin/ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {} {}@{} sudo chmod 700 manage_bridge_OSM".format(
- # self.config["cluster"]["password_path"][host], self.config["cluster"]["login"][host],
- # self.config["cluster"]["ip"][host])
- # os.system(file_permissions)
- # exec_script = "/usr/bin/ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i {} {}@{} sudo ./manage_bridge_OSM".format(
- # self.config["cluster"]["password_path"][host], self.config["cluster"]["login"][host],
- # self.config["cluster"]["ip"][host])
- # os.system(exec_script)
- # os.remove("manage_bridge_OSM")
-
- # to be used to manage networks with vlan
- # def delete_bridge_host(self, vlan):
- # file = open('manage_bridge_OSM', 'w')
- # a = "#! /bin/bash\nsudo ip link set dev veth1.3142 down\nsudo ip link set dev br_3142 down\nsudo brctl delbr br_3142\n"
- # file.write(a)
- # file.close()
- # os.system("/usr/bin/scp -i onlife manage_bridge_OSM sysadmin@10.95.84.12:/home/sysadmin")
- # os.system("/usr/bin/ssh -i onlife sysadmin@10.95.84.12 sudo chmod 700 manage_bridge_OSM")
- # os.system("/usr/bin/ssh -i onlife sysadmin@10.95.84.12 sudo ./manage_bridge_OSM")
- # os.remove("manage_bridge_OSM")
-
def new_network(self, net_name, net_type, ip_profile=None, shared=False, vlan=None): # , **vim_specific):
"""Adds a tenant network to VIM
Params:
# oca library method cannot be used in this case (problem with cluster parameters)
try:
created_items = {}
- # vlan = str(random.randint(self.config["vlan"]["start-range"], self.config["vlan"]["finish-range"]))
- # self.create_bridge_host(vlan)
- bridge_config = self.config["bridge_service"]
- ip_version = "IP4"
- size = "256"
+ one = self._new_one_connection()
+ size = "254"
if ip_profile is None:
- random_number_ipv4 = random.randint(1, 255)
- ip_start = "192.168." + str(random_number_ipv4) + ".1" # random value
+ subnet_rand = random.randint(0, 255)
+ ip_start = "192.168.{}.1".format(subnet_rand)
else:
index = ip_profile["subnet_address"].find("/")
ip_start = ip_profile["subnet_address"][:index]
if "dhcp_start_address" in ip_profile.keys() and ip_profile["dhcp_start_address"] is not None:
ip_start = str(ip_profile["dhcp_start_address"])
if ip_profile["ip_version"] == "IPv6":
- ip_version = "IP6"
- if ip_version == "IP6":
- config = "NAME = {}\
- BRIDGE = {}\
- VN_MAD = dummy\
- AR = [TYPE = {}, GLOBAL_PREFIX = {}, SIZE = {}]".format(net_name, bridge_config, ip_version,
- ip_start, size)
+ ip_prefix_type = "GLOBAL_PREFIX"
+
+ if vlan is not None:
+ vlan_id = vlan
else:
- config = 'NAME = "{}"\
- BRIDGE = {}\
- VN_MAD = dummy\
- AR = [TYPE = {}, IP = {}, SIZE = {}]'.format(net_name, bridge_config, ip_version, ip_start,
- size)
-
- params = '<?xml version="1.0"?> \
- <methodCall>\
- <methodName>one.vn.allocate</methodName>\
- <params>\
- <param>\
- <value><string>{}:{}</string></value>\
- </param>\
- <param>\
- <value><string>{}</string></value>\
- </param>\
- <param>\
- <value><int>{}</int></value>\
- </param>\
- </params>\
- </methodCall>'.format(self.user, self.passwd, config, self.config["cluster"]["id"])
- r = requests.post(self.url, params)
- obj = untangle.parse(str(r.content))
- return obj.methodResponse.params.param.value.array.data.value[1].i4.cdata.encode('utf-8'), created_items
+ vlan_id = str(random.randint(100, 4095))
+ #if "internal" in net_name:
+ # OpenNebula not support two networks with same name
+ random_net_name = str(random.randint(1, 1000000))
+ net_name = net_name + random_net_name
+ net_id = one.vn.allocate({
+ 'NAME': net_name,
+ 'VN_MAD': '802.1Q',
+ 'PHYDEV': self.config["network"]["phydev"],
+ 'VLAN_ID': vlan_id
+ }, self.config["cluster"]["id"])
+ arpool = {'AR_POOL': {
+ 'AR': {
+ 'TYPE': 'IP4',
+ 'IP': ip_start,
+ 'SIZE': size
+ }
+ }
+ }
+ one.vn.add_ar(net_id, arpool)
+ return net_id, created_items
except Exception as e:
self.logger.error("Create new network error: " + str(e))
raise vimconn.vimconnException(e)
def get_network_list(self, filter_dict={}):
"""Obtain tenant networks of VIM
- Filter_dict can be:
- name: network name
- id: network uuid
- public: boolean
- tenant_id: tenant
- admin_state_up: boolean
- status: 'ACTIVE'
- Returns the network list of dictionaries
+ Params:
+ 'filter_dict' (optional) contains entries to return only networks that matches ALL entries:
+ name: string => returns only networks with this name
+ id: string => returns networks with this VIM id, this imply returns one network at most
+ shared: boolean >= returns only networks that are (or are not) shared
+ tenant_id: sting => returns only networks that belong to this tenant/project
+ ,#(not used yet) admin_state_up: boolean => returns only networks that are (or are not) in admin state active
+ #(not used yet) status: 'ACTIVE','ERROR',... => filter networks that are on this status
+ Returns the network list of dictionaries. each dictionary contains:
+ 'id': (mandatory) VIM network id
+ 'name': (mandatory) VIM network name
+ 'status': (mandatory) can be 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER'
+ 'network_type': (optional) can be 'vxlan', 'vlan' or 'flat'
+ 'segmentation_id': (optional) in case network_type is vlan or vxlan this field contains the segmentation id
+ 'error_msg': (optional) text that explains the ERROR status
+ other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param
+ List can be empty if no network map the filter_dict. Raise an exception only upon VIM connectivity,
+ authorization, or some other unspecific error
"""
+
try:
- client = oca.Client(self.user + ':' + self.passwd, self.url)
- networkList = oca.VirtualNetworkPool(client)
- networkList.info()
+ one = self._new_one_connection()
+ net_pool = one.vnpool.info(-2, -1, -1).VNET
response = []
if "name" in filter_dict.keys():
network_name_filter = filter_dict["name"]
network_id_filter = filter_dict["id"]
else:
network_id_filter = None
- for network in networkList:
- match = False
- if network.name == network_name_filter and str(network.id) == str(network_id_filter):
- match = True
- if network_name_filter is None and str(network.id) == str(network_id_filter):
- match = True
- if network_id_filter is None and network.name == network_name_filter:
- match = True
- if match:
- net_dict = {"name": network.name, "id": str(network.id)}
+ for network in net_pool:
+ if network.NAME == network_name_filter or str(network.ID) == str(network_id_filter):
+ net_dict = {"name": network.NAME, "id": str(network.ID), "status": "ACTIVE"}
response.append(net_dict)
return response
except Exception as e:
raise vimconn.vimconnException(e)
def get_network(self, net_id):
- """Obtain network details of network id"""
+ """Obtain network details from the 'net_id' VIM network
+ Return a dict that contains:
+ 'id': (mandatory) VIM network id, that is, net_id
+ 'name': (mandatory) VIM network name
+ 'status': (mandatory) can be 'ACTIVE', 'INACTIVE', 'DOWN', 'BUILD', 'ERROR', 'VIM_ERROR', 'OTHER'
+ 'error_msg': (optional) text that explains the ERROR status
+ other VIM specific fields: (optional) whenever possible using the same naming of filter_dict param
+ Raises an exception upon error or when network is not found
+ """
try:
- client = oca.Client(self.user + ':' + self.passwd, self.url)
- networkList = oca.VirtualNetworkPool(client)
- networkList.info()
+ one = self._new_one_connection()
+ net_pool = one.vnpool.info(-2, -1, -1).VNET
net = {}
- for network in networkList:
- if str(network.id) == str(net_id):
- net['id'] = net_id
- net['name'] = network.name
+ for network in net_pool:
+ if str(network.ID) == str(net_id):
+ net['id'] = network.ID
+ net['name'] = network.NAME
net['status'] = "ACTIVE"
break
if net:
else:
raise vimconn.vimconnNotFoundException("Network {} not found".format(net_id))
except Exception as e:
- self.logger.error("Get network " + str(net_id) + " error): " + str(e))
- raise vimconn.vimconnException(e)
+ self.logger.error("Get network " + str(net_id) + " error): " + str(e))
+ raise vimconn.vimconnException(e)
def delete_network(self, net_id, created_items=None):
"""
Returns the network identifier or raises an exception upon error or when network is not found
"""
try:
- # self.delete_bridge_host()
- client = oca.Client(self.user + ':' + self.passwd, self.url)
- networkList = oca.VirtualNetworkPool(client)
- networkList.info()
- network_deleted = False
- for network in networkList:
- if str(network.id) == str(net_id):
- oca.VirtualNetwork.delete(network)
- network_deleted = True
- if network_deleted:
- return net_id
- else:
- raise vimconn.vimconnNotFoundException("Network {} not found".format(net_id))
+
+ one = self._new_one_connection()
+ one.vn.delete(int(net_id))
+ return net_id
except Exception as e:
- self.logger.error("Delete network " + str(net_id) + "error: " + str(e))
- raise vimconn.vimconnException(e)
+ self.logger.error("Delete network " + str(net_id) + "error: network not found" + str(e))
+ raise vimconn.vimconnException(e)
+
+ def refresh_nets_status(self, net_list):
+ """Get the status of the networks
+ Params:
+ 'net_list': a list with the VIM network id to be get the status
+ Returns a dictionary with:
+ 'net_id': #VIM id of this network
+ status: #Mandatory. Text with one of:
+ # DELETED (not found at vim)
+ # VIM_ERROR (Cannot connect to VIM, authentication problems, VIM response error, ...)
+ # OTHER (Vim reported other status not understood)
+ # ERROR (VIM indicates an ERROR status)
+ # ACTIVE, INACTIVE, DOWN (admin down),
+ # BUILD (on building process)
+ error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR
+ vim_info: #Text with plain information obtained from vim (yaml.safe_dump)
+ 'net_id2': ...
+ """
+ net_dict = {}
+ try:
+ for net_id in net_list:
+ net = {}
+ try:
+ net_vim = self.get_network(net_id)
+ net["status"] = net_vim["status"]
+ net["vim_info"] = None
+ except vimconn.vimconnNotFoundException as e:
+ self.logger.error("Exception getting net status: {}".format(str(e)))
+ net['status'] = "DELETED"
+ net['error_msg'] = str(e)
+ except vimconn.vimconnException as e:
+ self.logger.error(e)
+ net["status"] = "VIM_ERROR"
+ net["error_msg"] = str(e)
+ net_dict[net_id] = net
+ return net_dict
+ except vimconn.vimconnException as e:
+ self.logger.error(e)
+ for k in net_dict:
+ net_dict[k]["status"] = "VIM_ERROR"
+ net_dict[k]["error_msg"] = str(e)
+ return net_dict
def get_flavor(self, flavor_id): # Esta correcto
- """Obtain flavor details from the VIM"""
+ """Obtain flavor details from the VIM
+ Returns the flavor dict details {'id':<>, 'name':<>, other vim specific }
+ Raises an exception upon error or if not found
+ """
try:
- client = oca.Client(self.user + ':' + self.passwd, self.url)
- listaTemplate = oca.VmTemplatePool(client)
- listaTemplate.info()
- for template in listaTemplate:
- if str(template.id) == str(flavor_id):
- return {'id': template.id, 'name': template.name}
+
+ one = self._new_one_connection()
+ template = one.template.info(int(flavor_id))
+ if template is not None:
+ return {'id': template.ID, 'name': template.NAME}
raise vimconn.vimconnNotFoundException("Flavor {} not found".format(flavor_id))
except Exception as e:
self.logger.error("get flavor " + str(flavor_id) + " error: " + str(e))
def new_flavor(self, flavor_data):
"""Adds a tenant flavor to VIM
- Returns the flavor identifier"""
+ flavor_data contains a dictionary with information, keys:
+ name: flavor name
+ ram: memory (cloud type) in MBytes
+ vpcus: cpus (cloud type)
+ extended: EPA parameters
+ - numas: #items requested in same NUMA
+ memory: number of 1G huge pages memory
+ paired-threads|cores|threads: number of paired hyperthreads, complete cores OR individual threads
+ interfaces: # passthrough(PT) or SRIOV interfaces attached to this numa
+ - name: interface name
+ dedicated: yes|no|yes:sriov; for PT, SRIOV or only one SRIOV for the physical NIC
+ bandwidth: X Gbps; requested guarantee bandwidth
+ vpci: requested virtual PCI address
+ disk: disk size
+ is_public:
+ #TODO to concrete
+ Returns the flavor identifier"""
+
+ disk_size = str(int(flavor_data["disk"])*1024)
+
try:
- client = oca.Client(self.user + ':' + self.passwd, self.url)
- template_name = flavor_data["name"][:-4]
- name = 'NAME = "{}" '.format(template_name)
- cpu = 'CPU = "{}" '.format(flavor_data["vcpus"])
- vcpu = 'VCPU = "{}" '.format(flavor_data["vcpus"])
- memory = 'MEMORY = "{}" '.format(flavor_data["ram"])
- context = 'CONTEXT = [NETWORK = "YES",SSH_PUBLIC_KEY = "$USER[SSH_PUBLIC_KEY]" ] '
- graphics = 'GRAPHICS = [ LISTEN = "0.0.0.0", TYPE = "VNC" ] '
- sched_requeriments = 'CLUSTER_ID={}'.format(self.config["cluster"]["id"])
- template = name + cpu + vcpu + memory + context + graphics + sched_requeriments
- template_id = oca.VmTemplate.allocate(client, template)
+ one = self._new_one_connection()
+ template_id = one.template.allocate({
+ 'TEMPLATE': {
+ 'NAME': flavor_data["name"],
+ 'CPU': flavor_data["vcpus"],
+ 'VCPU': flavor_data["vcpus"],
+ 'MEMORY': flavor_data["ram"],
+ 'DISK': {
+ 'SIZE': disk_size
+ },
+ 'CONTEXT': {
+ 'NETWORK': "YES",
+ 'SSH_PUBLIC_KEY': '$USER[SSH_PUBLIC_KEY]'
+ },
+ 'GRAPHICS': {
+ 'LISTEN': '0.0.0.0',
+ 'TYPE': 'VNC'
+ },
+ 'CLUSTER_ID': self.config["cluster"]["id"]
+ }
+ })
return template_id
+
except Exception as e:
self.logger.error("Create new flavor error: " + str(e))
raise vimconn.vimconnException(e)
Returns the old flavor_id
"""
try:
- client = oca.Client(self.user + ':' + self.passwd, self.url)
- listaTemplate = oca.VmTemplatePool(client)
- listaTemplate.info()
- self.logger.info("Deleting VIM flavor DELETE {}".format(self.url))
- for template in listaTemplate:
- if str(template.id) == str(flavor_id):
- template.delete()
- return template.id
- raise vimconn.vimconnNotFoundException("Flavor {} not found".format(flavor_id))
+ one = self._new_one_connection()
+ one.template.delete(int(flavor_id), False)
+ return flavor_id
except Exception as e:
- self.logger.error("Delete flavor " + str(flavor_id) + " error: " + str(e))
+ self.logger.error("Error deleting flavor " + str(flavor_id) + ". Flavor not found")
raise vimconn.vimconnException(e)
def get_image_list(self, filter_dict={}):
[{<the fields at Filter_dict plus some VIM specific>}, ...]
List can be empty
"""
- # IMPORTANT!!!!! Modify python oca library path pool.py line 102
-
try:
- client = oca.Client(self.user + ':' + self.passwd, self.url)
- image_pool = oca.ImagePool(client)
- image_pool.info()
+ one = self._new_one_connection()
+ image_pool = one.imagepool.info(-2, -1, -1).IMAGE
images = []
if "name" in filter_dict.keys():
image_name_filter = filter_dict["name"]
else:
image_id_filter = None
for image in image_pool:
- match = False
- if str(image_name_filter) == str(image.name) and str(image.id) == str(image_id_filter):
- match = True
- if image_name_filter is None and str(image.id) == str(image_id_filter):
- match = True
- if image_id_filter is None and str(image_name_filter) == str(image.name):
- match = True
- if match:
- images_dict = {"name": image.name, "id": str(image.id)}
+ if str(image_name_filter) == str(image.NAME) or str(image.ID) == str(image_id_filter):
+ images_dict = {"name": image.NAME, "id": str(image.ID)}
images.append(images_dict)
return images
except Exception as e:
def new_vminstance(self, name, description, start, image_id, flavor_id, net_list, cloud_config=None, disk_list=None,
availability_zone_index=None, availability_zone_list=None):
+
"""Adds a VM instance to VIM
- Params:
- start: indicates if VM must start or boot in pause mode. Ignored
- image_id,flavor_id: image and flavor uuid
- net_list: list of interfaces, each one is a dictionary with:
- name:
- net_id: network uuid to connect
- vpci: virtual vcpi to assign
- model: interface model, virtio, e1000, ...
- mac_address:
- use: 'data', 'bridge', 'mgmt'
- type: 'virtual', 'PF', 'VF', 'VFnotShared'
- vim_id: filled/added by this function
- #TODO ip, security groups
- Returns the instance identifier
- """
+ Params:
+ 'start': (boolean) indicates if VM must start or created in pause mode.
+ 'image_id','flavor_id': image and flavor VIM id to use for the VM
+ 'net_list': list of interfaces, each one is a dictionary with:
+ 'name': (optional) name for the interface.
+ 'net_id': VIM network id where this interface must be connect to. Mandatory for type==virtual
+ 'vpci': (optional) virtual vPCI address to assign at the VM. Can be ignored depending on VIM capabilities
+ 'model': (optional and only have sense for type==virtual) interface model: virtio, e1000, ...
+ 'mac_address': (optional) mac address to assign to this interface
+ 'ip_address': (optional) IP address to assign to this interface
+ #TODO: CHECK if an optional 'vlan' parameter is needed for VIMs when type if VF and net_id is not provided,
+ the VLAN tag to be used. In case net_id is provided, the internal network vlan is used for tagging VF
+ 'type': (mandatory) can be one of:
+ 'virtual', in this case always connected to a network of type 'net_type=bridge'
+ 'PCI-PASSTHROUGH' or 'PF' (passthrough): depending on VIM capabilities it can be connected to a data/ptp network ot it
+ can created unconnected
+ 'SR-IOV' or 'VF' (SRIOV with VLAN tag): same as PF for network connectivity.
+ 'VFnotShared'(SRIOV without VLAN tag) same as PF for network connectivity. VF where no other VFs
+ are allocated on the same physical NIC
+ 'bw': (optional) only for PF/VF/VFnotShared. Minimal Bandwidth required for the interface in GBPS
+ 'port_security': (optional) If False it must avoid any traffic filtering at this interface. If missing
+ or True, it must apply the default VIM behaviour
+ After execution the method will add the key:
+ 'vim_id': must be filled/added by this method with the VIM identifier generated by the VIM for this
+ interface. 'net_list' is modified
+ 'cloud_config': (optional) dictionary with:
+ 'key-pairs': (optional) list of strings with the public key to be inserted to the default user
+ 'users': (optional) list of users to be inserted, each item is a dict with:
+ 'name': (mandatory) user name,
+ 'key-pairs': (optional) list of strings with the public key to be inserted to the user
+ 'user-data': (optional) can be a string with the text script to be passed directly to cloud-init,
+ or a list of strings, each one contains a script to be passed, usually with a MIMEmultipart file
+ 'config-files': (optional). List of files to be transferred. Each item is a dict with:
+ 'dest': (mandatory) string with the destination absolute path
+ 'encoding': (optional, by default text). Can be one of:
+ 'b64', 'base64', 'gz', 'gz+b64', 'gz+base64', 'gzip+b64', 'gzip+base64'
+ 'content' (mandatory): string with the content of the file
+ 'permissions': (optional) string with file permissions, typically octal notation '0644'
+ 'owner': (optional) file owner, string with the format 'owner:group'
+ 'boot-data-drive': boolean to indicate if user-data must be passed using a boot drive (hard disk)
+ 'disk_list': (optional) list with additional disks to the VM. Each item is a dict with:
+ 'image_id': (optional). VIM id of an existing image. If not provided an empty disk must be mounted
+ 'size': (mandatory) string with the size of the disk in GB
+ availability_zone_index: Index of availability_zone_list to use for this this VM. None if not AV required
+ availability_zone_list: list of availability zones given by user in the VNFD descriptor. Ignore if
+ availability_zone_index is None
+ Returns a tuple with the instance identifier and created_items or raises an exception on error
+ created_items can be None or a dictionary where this method can include key-values that will be passed to
+ the method delete_vminstance and action_vminstance. Can be used to store created ports, volumes, etc.
+ Format is vimconnector dependent, but do not use nested dictionaries and a value of None should be the same
+ as not present.
+ """
self.logger.debug(
"new_vminstance input: image='{}' flavor='{}' nics='{}'".format(image_id, flavor_id, str(net_list)))
try:
- client = oca.Client(self.user + ':' + self.passwd, self.url)
- listaTemplate = oca.VmTemplatePool(client)
- listaTemplate.info()
- for template in listaTemplate:
- if str(template.id) == str(flavor_id):
- cpu = ' CPU = "{}"'.format(template.template.cpu)
- vcpu = ' VCPU = "{}"'.format(template.template.cpu)
- memory = ' MEMORY = "{}"'.format(template.template.memory)
- context = ' CONTEXT = [NETWORK = "YES",SSH_PUBLIC_KEY = "$USER[SSH_PUBLIC_KEY]" ]'
- graphics = ' GRAPHICS = [ LISTEN = "0.0.0.0", TYPE = "VNC" ]'
- disk = ' DISK = [ IMAGE_ID = {}]'.format(image_id)
- template_updated = cpu + vcpu + memory + context + graphics + disk
- networkListVim = oca.VirtualNetworkPool(client)
- networkListVim.info()
- network = ""
- for net in net_list:
- network_found = False
- for network_existingInVim in networkListVim:
- if str(net["net_id"]) == str(network_existingInVim.id):
- net["vim_id"] = network_existingInVim["id"]
- network = 'NIC = [NETWORK = "{}",NETWORK_UNAME = "{}" ]'.format(
- network_existingInVim.name, network_existingInVim.uname)
- network_found = True
- break
- if not network_found:
- raise vimconn.vimconnNotFoundException("Network {} not found".format(net["net_id"]))
- template_updated += network
- if isinstance(cloud_config, dict):
- if cloud_config.get("user-data"):
- if isinstance(cloud_config["user-data"], str):
- template_updated += cloud_config["user-data"]
- else:
- for u in cloud_config["user-data"]:
- template_updated += u
- oca.VmTemplate.update(template, template_updated)
- self.logger.info(
- "Instanciating in OpenNebula a new VM name:{} id:{}".format(template.name, template.id))
- vminstance_id = template.instantiate(name=name)
- return str(vminstance_id), None
- raise vimconn.vimconnNotFoundException("Flavor {} not found".format(flavor_id))
+ one = self._new_one_connection()
+ template_vim = one.template.info(int(flavor_id), True)
+ disk_size = str(template_vim.TEMPLATE["DISK"]["SIZE"])
+
+ one = self._new_one_connection()
+ template_updated = ""
+ for net in net_list:
+ net_in_vim = one.vn.info(int(net["net_id"]))
+ net["vim_id"] = str(net_in_vim.ID)
+ network = 'NIC = [NETWORK = "{}",NETWORK_UNAME = "{}" ]'.format(
+ net_in_vim.NAME, net_in_vim.UNAME)
+ template_updated += network
+
+ template_updated += "DISK = [ IMAGE_ID = {},\n SIZE = {}]".format(image_id, disk_size)
+
+ if isinstance(cloud_config, dict):
+ if cloud_config.get("key-pairs"):
+ context = 'CONTEXT = [\n NETWORK = "YES",\n SSH_PUBLIC_KEY = "'
+ for key in cloud_config["key-pairs"]:
+ context += key + '\n'
+ # if False:
+ # context += '"\n USERNAME = '
+ context += '"]'
+ template_updated += context
+
+ vm_instance_id = one.template.instantiate(int(flavor_id), name, False, template_updated)
+ self.logger.info(
+ "Instanciating in OpenNebula a new VM name:{} id:{}".format(name, flavor_id))
+ return str(vm_instance_id), None
+ except pyone.OneNoExistsException as e:
+ self.logger.error("Network with id " + str(e) + " not found: " + str(e))
+ raise vimconn.vimconnNotFoundException(e)
except Exception as e:
self.logger.error("Create new vm instance error: " + str(e))
raise vimconn.vimconnException(e)
+ def get_vminstance(self, vm_id):
+ """Returns the VM instance information from VIM"""
+ try:
+ one = self._new_one_connection()
+ vm = one.vm.info(int(vm_id))
+ return vm
+ except Exception as e:
+ self.logger.error("Getting vm instance error: " + str(e) + ": VM Instance not found")
+ raise vimconn.vimconnException(e)
+
def delete_vminstance(self, vm_id, created_items=None):
- """Removes a VM instance from VIM, returns the deleted vm_id"""
+ """
+ Removes a VM instance from VIM and its associated elements
+ :param vm_id: VIM identifier of the VM, provided by method new_vminstance
+ :param created_items: dictionary with extra items to be deleted. provided by method new_vminstance and/or method
+ action_vminstance
+ :return: None or the same vm_id. Raises an exception on fail
+ """
try:
- client = oca.Client(self.user + ':' + self.passwd, self.url)
- vm_pool = oca.VirtualMachinePool(client)
- vm_pool.info()
- vm_exist = False
- for i in vm_pool:
- if str(i.id) == str(vm_id):
- vm_exist = True
+ one = self._new_one_connection()
+ one.vm.recover(int(vm_id), 3)
+ vm = None
+ while True:
+ if vm is not None and vm.LCM_STATE == 0:
break
- if not vm_exist:
- self.logger.info("The vm " + str(vm_id) + " does not exist or is already deleted")
- raise vimconn.vimconnNotFoundException("The vm {} does not exist or is already deleted".format(vm_id))
- params = '<?xml version="1.0"?> \
- <methodCall>\
- <methodName>one.vm.recover</methodName>\
- <params>\
- <param>\
- <value><string>{}:{}</string></value>\
- </param>\
- <param>\
- <value><int>{}</int></value>\
- </param>\
- <param>\
- <value><int>{}</int></value>\
- </param>\
- </params>\
- </methodCall>'.format(self.user, self.passwd, str(vm_id), str(3))
- r = requests.post(self.url, params)
- obj = untangle.parse(str(r.content))
- response_success = obj.methodResponse.params.param.value.array.data.value[0].boolean.cdata.encode('utf-8')
- response = obj.methodResponse.params.param.value.array.data.value[1].i4.cdata.encode('utf-8')
- # response can be the resource ID on success or the error string on failure.
- response_error_code = obj.methodResponse.params.param.value.array.data.value[2].i4.cdata.encode('utf-8')
- if response_success.lower() == "true":
- return response
- else:
- raise vimconn.vimconnException("vm {} cannot be deleted with error_code {}: {}".format(vm_id, response_error_code, response))
+ else:
+ vm = one.vm.info(int(vm_id))
+
+ except pyone.OneNoExistsException as e:
+ self.logger.info("The vm " + str(vm_id) + " does not exist or is already deleted")
+ raise vimconn.vimconnNotFoundException("The vm {} does not exist or is already deleted".format(vm_id))
except Exception as e:
self.logger.error("Delete vm instance " + str(vm_id) + " error: " + str(e))
raise vimconn.vimconnException(e)
def refresh_vms_status(self, vm_list):
- """Refreshes the status of the virtual machines"""
+ """Get the status of the virtual machines and their interfaces/ports
+ Params: the list of VM identifiers
+ Returns a dictionary with:
+ vm_id: #VIM id of this Virtual Machine
+ status: #Mandatory. Text with one of:
+ # DELETED (not found at vim)
+ # VIM_ERROR (Cannot connect to VIM, VIM response error, ...)
+ # OTHER (Vim reported other status not understood)
+ # ERROR (VIM indicates an ERROR status)
+ # ACTIVE, PAUSED, SUSPENDED, INACTIVE (not running),
+ # BUILD (on building process), ERROR
+ # ACTIVE:NoMgmtIP (Active but any of its interface has an IP address
+ #
+ error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR
+ vim_info: #Text with plain information obtained from vim (yaml.safe_dump)
+ interfaces: list with interface info. Each item a dictionary with:
+ vim_info: #Text with plain information obtained from vim (yaml.safe_dump)
+ mac_address: #Text format XX:XX:XX:XX:XX:XX
+ vim_net_id: #network id where this interface is connected, if provided at creation
+ vim_interface_id: #interface/port VIM id
+ ip_address: #null, or text with IPv4, IPv6 address
+ compute_node: #identification of compute node where PF,VF interface is allocated
+ pci: #PCI address of the NIC that hosts the PF,VF
+ vlan: #physical VLAN used for VF
+ """
vm_dict = {}
try:
- client = oca.Client(self.user + ':' + self.passwd, self.url)
- vm_pool = oca.VirtualMachinePool(client)
- vm_pool.info()
for vm_id in vm_list:
- vm = {"interfaces": []}
- vm_exist = False
- vm_element = None
- for i in vm_pool:
- if str(i.id) == str(vm_id):
- vm_exist = True
- vm_element = i
- break
- if not vm_exist:
+ vm = {}
+ if self.get_vminstance(vm_id) is not None:
+ vm_element = self.get_vminstance(vm_id)
+ else:
self.logger.info("The vm " + str(vm_id) + " does not exist.")
vm['status'] = "DELETED"
vm['error_msg'] = ("The vm " + str(vm_id) + " does not exist.")
continue
- vm_element.info()
vm["vim_info"] = None
- VMstatus = vm_element.str_lcm_state
- if VMstatus == "RUNNING":
+ vm_status = vm_element.LCM_STATE
+ if vm_status == 3:
vm['status'] = "ACTIVE"
- elif "FAILURE" in VMstatus:
+ elif vm_status == 36:
vm['status'] = "ERROR"
vm['error_msg'] = "VM failure"
else:
vm['status'] = "BUILD"
- try:
- for red in vm_element.template.nics:
- interface = {'vim_info': None, "mac_address": str(red.mac), "vim_net_id": str(red.network_id),
- "vim_interface_id": str(red.network_id)}
- # maybe it should be 2 different keys for ip_address if an interface has ipv4 and ipv6
- if hasattr(red, 'ip'):
- interface["ip_address"] = str(red.ip)
- if hasattr(red, 'ip6_global'):
- interface["ip_address"] = str(red.ip6_global)
- vm["interfaces"].append(interface)
- except Exception as e:
- self.logger.error("Error getting vm interface_information " + type(e).__name__ + ":" + str(e))
- vm["status"] = "VIM_ERROR"
- vm["error_msg"] = "Error getting vm interface_information " + type(e).__name__ + ":" + str(e)
+
+ if vm_element is not None:
+ interfaces = self._get_networks_vm(vm_element)
+ vm["interfaces"] = interfaces
vm_dict[vm_id] = vm
return vm_dict
except Exception as e:
vm_dict[k]["error_msg"] = str(e)
return vm_dict
- def refresh_nets_status(self, net_list):
- """Get the status of the networks
- Params: the list of network identifiers
- Returns a dictionary with:
- net_id: #VIM id of this network
- status: #Mandatory. Text with one of:
- # DELETED (not found at vim)
- # VIM_ERROR (Cannot connect to VIM, VIM response error, ...)
- # OTHER (Vim reported other status not understood)
- # ERROR (VIM indicates an ERROR status)
- # ACTIVE, INACTIVE, DOWN (admin down),
- # BUILD (on building process)
- #
- error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR
- vim_info: #Text with plain information obtained from vim (yaml.safe_dump)
- """
- net_dict = {}
+ def _get_networks_vm(self, vm_element):
+ interfaces = []
try:
- for net_id in net_list:
- net = {}
- try:
- net_vim = self.get_network(net_id)
- net["status"] = net_vim["status"]
- net["vim_info"] = None
- except vimconn.vimconnNotFoundException as e:
- self.logger.error("Exception getting net status: {}".format(str(e)))
- net['status'] = "DELETED"
- net['error_msg'] = str(e)
- except vimconn.vimconnException as e:
- self.logger.error(e)
- net["status"] = "VIM_ERROR"
- net["error_msg"] = str(e)
- net_dict[net_id] = net
- return net_dict
- except vimconn.vimconnException as e:
- self.logger.error(e)
- for k in net_dict:
- net_dict[k]["status"] = "VIM_ERROR"
- net_dict[k]["error_msg"] = str(e)
- return net_dict
-
- # to be used and fixed in future commits... not working properly
- # def action_vminstance(self, vm_id, action_dict):
- # """Send and action over a VM instance from VIM
- # Returns the status"""
- # try:
- # if "console" in action_dict:
- # console_dict = {"protocol": "http",
- # "server": "10.95.84.42",
- # "port": "29876",
- # "suffix": "?token=4hsb9cu9utruakon4p3z"
- # }
- # return console_dict
- # except vimconn.vimconnException as e:
- # self.logger.error(e)
-
+ if isinstance(vm_element.TEMPLATE["NIC"], list):
+ for net in vm_element.TEMPLATE["NIC"]:
+ interface = {'vim_info': None, "mac_address": str(net["MAC"]), "vim_net_id": str(net["NETWORK_ID"]),
+ "vim_interface_id": str(net["NETWORK_ID"])}
+ # maybe it should be 2 different keys for ip_address if an interface has ipv4 and ipv6
+ if u'IP' in net:
+ interface["ip_address"] = str(net["IP"])
+ if u'IP6_GLOBAL' in net:
+ interface["ip_address"] = str(net["IP6_GLOBAL"])
+ interfaces.append(interface)
+ else:
+ net = vm_element.TEMPLATE["NIC"]
+ interface = {'vim_info': None, "mac_address": str(net["MAC"]), "vim_net_id": str(net["NETWORK_ID"]),
+ "vim_interface_id": str(net["NETWORK_ID"])}
+ # maybe it should be 2 different keys for ip_address if an interface has ipv4 and ipv6
+ if u'IP' in net:
+ interface["ip_address"] = str(net["IP"])
+ if u'IP6_GLOBAL' in net:
+ interface["ip_address"] = str(net["IP6_GLOBAL"])
+ interfaces.append(interface)
+ return interfaces
+ except Exception as e:
+ self.logger.error("Error getting vm interface_information of vm_id: " + str(vm_element.ID))
self.security_groups_id = None
raise vimconn.vimconnConnectionException("Not found security group {} for this tenant".format(sg))
+ def check_vim_connectivity(self):
+ # just get network list to check connectivity and credentials
+ self.get_network_list(filter_dict={})
+
def get_tenant_list(self, filter_dict={}):
'''Obtain tenants of VIM
filter_dict can contain the following keys:
extended = flavor_dict.get("extended", {})
if extended:
#TODO
- raise vimconn.vimconnNotFoundException("Flavor with EPA still not implemted")
+ raise vimconn.vimconnNotFoundException("Flavor with EPA still not implemented")
# if len(numas) > 1:
# raise vimconn.vimconnNotFoundException("Cannot find any flavor with more than one numa")
# numa=numas[0]
if 'memory' in numa:
ram = numa['memory']*1024
#See for reference: https://specs.openstack.org/openstack/nova-specs/specs/mitaka/implemented/virt-driver-cpu-thread-pinning.html
+ extra_specs["hw:cpu_sockets"] = 1
if 'paired-threads' in numa:
vcpus = numa['paired-threads']*2
#cpu_thread_policy "require" implies that the compute node must have an STM architecture
INTERVAL_TIME = 5
MAX_WAIT_TIME = 1800
-API_VERSION = '31.0'
+API_VERSION = '27.0'
__author__ = "Mustafa Bayramov, Arpita Kate, Sachin Bhangare, Prakash Kasar"
__date__ = "$09-Mar-2018 11:09:29$"
media_upload_href = match.group(1)
else:
raise Exception('Could not parse the upload URL for the media file from the last response')
-
+ upload_iso_task = self.get_task_from_response(response.content)
headers['Content-Type'] = 'application/octet-stream'
response = self.perform_request(req_type='PUT',
url=media_upload_href,
if response.status_code != 200:
raise Exception('PUT request to "{}" failed'.format(media_upload_href))
+ result = self.client.get_task_monitor().wait_for_success(task=upload_iso_task)
+ if result.get('status') != 'success':
+ raise Exception('The upload iso task failed with status {}'.format(result.get('status')))
def get_vcd_availibility_zones(self,respool_href, headers):
""" Method to find presence of av zone is VIM resource pool
namespaces["xmlns"] = "http://www.vmware.com/vcloud/v1.5"
nwcfglist = newelem.findall(".//xmlns:NetworkConfig", namespaces)
+ # VCD 9.7 returns an incorrect parentnetwork element. Fix it before PUT operation
+ parentnetworklist = newelem.findall(".//xmlns:ParentNetwork", namespaces)
+ if parentnetworklist:
+ for pn in parentnetworklist:
+ if "href" not in pn.keys():
+ id_val = pn.get("id")
+ href_val = "{}/api/network/{}".format(self.url, id_val)
+ pn.set("href", href_val)
+
newstr = """<NetworkConfig networkName="{}">
<Configuration>
<ParentNetwork href="{}/api/network/{}"/>
self.org_name))
host = self.url
client = Client(host, verify_ssl_certs=False)
+ client.set_highest_supported_version()
client.set_credentials(BasicLoginCredentials(self.user, self.org_name, self.passwd))
# connection object
self.client = client
'sce_net_id': sce_net_id,
'wim_id': wim_id,
'wim_account_id': account['uuid'],
- related: related
+ 'related': related
}
def derive_wan_links(self, wim_usage, networks, tenant=None):
if num_changes is None:
raise UnexpectedDatabaseError(
- 'Impossible to update wim_port_mappings %s:\n%s\n',
- id, _serialize(properties))
+ 'Impossible to update wim_port_mappings {}:\n{}\n'.format(
+ id, _serialize(properties))
+ )
return num_changes
"type": "object",
"properties": wim_schema_properties,
"required": ["name", "type", "wim_url"],
- "additionalProperties": True
}
},
"required": ["wim"],
- "additionalProperties": False
}
wim_edit_schema = {
"wim": {
"type": "object",
"properties": wim_schema_properties,
- "additionalProperties": False
}
},
"required": ["wim"],
- "additionalProperties": False
}
wim_account_schema = {
"password": nameshort_schema,
"config": {"type": "object"}
},
- "additionalProperties": True
}
},
"required": ["wim_account"],
- "additionalProperties": False
}
wim_port_mapping_schema = {
class DynpacConnector(WimConnector):
- __supported_service_types = ["ELINE (L2)"]
+ __supported_service_types = ["ELINE (L2)", "ELINE"]
__supported_encapsulation_types = ["dot1q"]
__WIM_LOGGER = 'openmano.wimconn.dynpac'
__ENCAPSULATION_TYPE_PARAM = "service_endpoint_encapsulation_type"
if enc_type not in self.__supported_encapsulation_types:
self.__exception(WimError.ENCAPSULATION_TYPE, http_code=400)
- bandwidth = kwargs.get(self.__BANDWIDTH_PARAM)
- if not isinstance(bandwidth, int):
- self.__exception(WimError.BANDWIDTH, http_code=400)
+ # Commented out for as long as parameter isn't implemented
+ # bandwidth = kwargs.get(self.__BANDWIDTH_PARAM)
+ # if not isinstance(bandwidth, int):
+ # self.__exception(WimError.BANDWIDTH, http_code=400)
- backup = kwargs.get(self.__BACKUP_PARAM)
- if not isinstance(backup, bool):
- self.__exception(WimError.BACKUP, http_code=400)
+ # Commented out for as long as parameter isn't implemented
+ # backup = kwargs.get(self.__BACKUP_PARAM)
+ # if not isinstance(backup, bool):
+ # self.__exception(WimError.BACKUP, http_code=400)
def __get_body(self, service_type, connection_points, kwargs):
- port_mapping = self.__config.get("port_mapping")
+ port_mapping = self.__config.get("service_endpoint_mapping")
selected_ports = []
for connection_point in connection_points:
endpoint_id = connection_point.get(self.__SERVICE_ENDPOINT_PARAM)
port = filter(lambda x: x.get(self.__WAN_SERVICE_ENDPOINT_PARAM) == endpoint_id, port_mapping)[0]
- wsmpi_json = port.get(self.__WAN_MAPPING_INFO_PARAM)
- port_info = json.loads(wsmpi_json)
+ port_info = port.get(self.__WAN_MAPPING_INFO_PARAM)
selected_ports.append(port_info)
- if service_type == "ELINE (L2)":
+ if service_type == "ELINE (L2)" or service_type == "ELINE":
service_type = "L2"
body = {
"connection_points": [{
"wan_switch_port": selected_ports[1].get(self.__SW_PORT_PARAM),
"wan_vlan": connection_points[1].get(self.__ENCAPSULATION_INFO_PARAM).get(self.__VLAN_PARAM)
}],
- "bandwidth": kwargs.get(self.__BANDWIDTH_PARAM),
+ "bandwidth": 100, # Hardcoded for as long as parameter isn't implemented
"service_type": service_type,
- "backup": kwargs.get(self.__BACKUP_PARAM)
+ "backup": False # Hardcoded for as long as parameter isn't implemented
}
return "body={}".format(json.dumps(body))
vpn_service["customer-name"] = "osm"
vpn_service_list = []
vpn_service_list.append(vpn_service)
- vpn_service_l = {"vpn-service": vpn_service_list}
+ vpn_service_l = {"ietf-l2vpn-svc:vpn-service": vpn_service_list}
response_service_creation = None
conn_info = []
self.logger.info("Sending vpn-service :{}".format(vpn_service_l))
self.logger.info("Sending vpn-attachement :{}".format(vpn_attach))
uuid_sna = str(uuid.uuid4())
site_network_access["network-access-id"] = uuid_sna
+ site_network_access["bearer"] = connection_point_wan_info["wan_service_mapping_info"]["bearer"]
site_network_accesses = {}
site_network_access_list = []
site_network_access_list.append(site_network_access)
- site_network_accesses["site-network-access"] = site_network_access_list
+ site_network_accesses["ietf-l2vpn-svc:site-network-access"] = site_network_access_list
conn_info_d = {}
- conn_info_d["site"] = connection_point_wan_info["site-id"]
+ conn_info_d["site"] = connection_point_wan_info["wan_service_mapping_info"]["site-id"]
conn_info_d["site-network-access-id"] = site_network_access["network-access-id"]
conn_info_d["mapping"] = None
conn_info.append(conn_info_d)
try:
endpoint_site_network_access_creation = \
"{}/restconf/data/ietf-l2vpn-svc:l2vpn-svc/sites/site={}/site-network-accesses/".format(
- self.wim["wim_url"], connection_point_wan_info["site-id"])
+ self.wim["wim_url"], connection_point_wan_info["wan_service_mapping_info"]["site-id"])
response_endpoint_site_network_access_creation = requests.post(
endpoint_site_network_access_creation,
headers=self.headers,
elif response_endpoint_site_network_access_creation.status_code == 400:
self.delete_connectivity_service(vpn_service["vpn-id"])
- raise WimConnectorError("Site {} does not exist".format(connection_point_wan_info["site-id"]),
- http_code=response_endpoint_site_network_access_creation.status_code)
+ raise WimConnectorError("Site {} does not exist".format(
+ connection_point_wan_info["wan_service_mapping_info"]["site-id"]),
+ http_code=response_endpoint_site_network_access_creation.status_code)
elif response_endpoint_site_network_access_creation.status_code != requests.codes.created and \
response_endpoint_site_network_access_creation.status_code != requests.codes.no_content:
site_network_access = {}
connection_point_wan_info = self.search_mapp(connection_point)
params_site = {}
- params_site["site-id"] = connection_point_wan_info["site-id"]
+ params_site["site-id"] = connection_point_wan_info["wan_service_mapping_info"]["site-id"]
params_site["site-vpn-flavor"] = "site-vpn-flavor-single"
device_site = {}
device_site["device-id"] = connection_point_wan_info["device-id"]
site_network_access["vpn-attachment"] = vpn_attach
uuid_sna = conn_info[counter]["site-network-access-id"]
site_network_access["network-access-id"] = uuid_sna
+ site_network_access["bearer"] = connection_point_wan_info["wan_service_mapping_info"]["bearer"]
site_network_accesses = {}
site_network_access_list = []
site_network_access_list.append(site_network_access)
- site_network_accesses["site-network-access"] = site_network_access_list
+ site_network_accesses["ietf-l2vpn-svc:site-network-access"] = site_network_access_list
try:
endpoint_site_network_access_edit = \
"{}/restconf/data/ietf-l2vpn-svc:l2vpn-svc/sites/site={}/site-network-accesses/".format(
- self.wim["wim_url"], connection_point_wan_info["site-id"]) # MODIF
+ self.wim["wim_url"], connection_point_wan_info["wan_service_mapping_info"]["site-id"])
response_endpoint_site_network_access_creation = requests.put(endpoint_site_network_access_edit,
headers=self.headers,
json=site_network_accesses,
boto
genisoimage
untangle
+pyone
oca
azure
db_version=$6 # minimun database version
if mysqlshow -h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" | grep -v Wildcard | grep -q -e "$db_name" ; then
- if echo "SELECT * FROM schema_version WHERE version='0'" |
+ if echo "SELECT comments FROM schema_version WHERE version_int=0;" |
mysql -h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" "$db_name" |
grep -q -e "init" ; then
- echo " DB $db_name exists BUT failed in previous init"
+ echo " DB $db_name exists BUT failed in previous init" >&2
return 1
- elif echo "SELECT * FROM schema_version WHERE version='$db_version'" |
+ elif echo "SELECT * FROM schema_version WHERE version_int=$db_version;" |
mysql -h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" "$db_name" |
grep -q -e "$db_version" ; then
- echo " DB $db_name exists and inited"
+ echo " DB $db_name exists and inited" >&2
return 0
else
- echo " DB $db_name exists BUT not inited"
+ echo " DB $db_name exists BUT not inited" >&2
return 1
fi
fi
- echo " DB $db_name does not exist"
+ echo " DB $db_name does not exist" >&2
return 1
}
#wait 120 sec
if [ $attempt -ge $max_attempts ]; then
echo
- echo "Cannot connect to database ${db_host}:${db_port} during $max_attempts sec"
+ echo "Cannot connect to database ${db_host}:${db_port} during $max_attempts sec" >&2
return 1
fi
attempt=$[$attempt+1]
echo "3/4 Init database"
RO_PATH=`python -c 'import osm_ro; print(osm_ro.__path__[0])'`
echo "RO_PATH: $RO_PATH"
-if ! is_db_created "$RO_DB_HOST" "$RO_DB_PORT" "$RO_DB_USER" "$RO_DB_PASSWORD" "$RO_DB_NAME" "0.27"
+if ! is_db_created "$RO_DB_HOST" "$RO_DB_PORT" "$RO_DB_USER" "$RO_DB_PASSWORD" "$RO_DB_NAME" "27"
then
if [ -n "$RO_DB_ROOT_PASSWORD" ] ; then
mysqladmin -h"$RO_DB_HOST" -uroot -p"$RO_DB_ROOT_PASSWORD" create "$RO_DB_NAME"
OVIM_PATH=`python -c 'import lib_osm_openvim; print(lib_osm_openvim.__path__[0])'`
echo "OVIM_PATH: $OVIM_PATH"
if ! is_db_created "$RO_DB_OVIM_HOST" "$RO_DB_OVIM_PORT" "$RO_DB_OVIM_USER" "$RO_DB_OVIM_PASSWORD" "$RO_DB_OVIM_NAME" \
- "0.22"
+ "22"
then
if [ -n "$RO_DB_OVIM_ROOT_PASSWORD" ] ; then
mysqladmin -h"$RO_DB_OVIM_HOST" -uroot -p"$RO_DB_OVIM_ROOT_PASSWORD" create "$RO_DB_OVIM_NAME"
# required for OpenNebula connector
pip2 install untangle || exit 1
+ pip2 install pyone || exit 1
pip2 install -e git+https://github.com/python-oca/python-oca#egg=oca || exit 1
# required for AWS connector
pip2 install --upgrade pyvmomi
pip2 install --upgrade pyang pyangbind
pip2 install untangle
+pip2 install pyone
pip2 install -e git+https://github.com/python-oca/python-oca#egg=oca
pip2 install azure
# contact with: nfvlabs@tid.es
##
---
-schema_version: 2
-scenario:
- name: simple
- description: Simple network scenario consisting of a single VNF connected to an external network
- vnfs:
- linux1: # vnf/net name in the scenario
- vnf_name: linux # VNF name as introduced in OPENMANO DB
- networks:
- mgmt: # provide a name for this net or connection
- external: true
- interfaces:
- - linux1: eth0 # Node and its interface
+nsd:nsd-catalog:
+ nsd:
+ - id: simple
+ name: simple
+ vendor: OSM
+ version: '1.0'
+ description: Simple network scenario consisting of a single VNF connected to an external network
+ constituent-vnfd:
+ # The member-vnf-index needs to be unique, starting from 1
+ # vnfd-id-ref is the id of the VNFD
+ # Multiple constituent VNFDs can be specified
+ - member-vnf-index: 1
+ vnfd-id-ref: linux
+ vld:
+ # Networks for the VNFs
+ - id: vld1
+ name: mgmt
+ short-name: vld1-sname
+ type: ELAN
+ mgmt-network: 'true'
+ vnfd-connection-point-ref:
+ - member-vnf-index-ref: 1
+ vnfd-id-ref: linux
+ vnfd-connection-point-ref: eth0
# contact with: nfvlabs@tid.es
##
---
-vnf:
- name: linux
- description: Single-VM VNF with a traditional cloud VM based on generic Linux OS
- external-connections:
- - name: eth0
- type: bridge
- VNFC: linux-VM
- local_iface_name: eth0
- description: General purpose interface
- VNFC:
- - name: linux-VM
- description: Generic Linux Virtual Machine
- #Copy the image to a compute path and edit this path
- image name: image_name.qcow2
- vcpus: 1 # Only for traditional cloud VMs. Number of virtual CPUs (oversubscription is allowed).
- ram: 1024 # Only for traditional cloud VMs. Memory in MBytes (not from hugepages, oversubscription is allowed)
- disk: 10
- bridge-ifaces:
- - name: eth0
- vpci: "0000:00:11.0"
- numas: []
+vnfd-catalog:
+ vnfd:
+ - id: linux
+ name: linux
+ description: Single-VM VNF with a traditional cloud VM based on generic Linux OS
+ connection-point:
+ - name: eth0
+ type: VPORT
+ vdu:
+ - id: linux-VM
+ name: linux-VM
+ description: Generic Linux Virtual Machine
+ #Copy the image to a compute path and edit this path
+ image: image_name.qcow2
+ vm-flavor:
+ memory-mb: '1024'
+ storage-gb: '10'
+ vcpu-count: '1'
+ interface:
+ - name: eth0
+ type: EXTERNAL
+ virtual-interface:
+ type: VIRTIO
+ vpci: "0000:00:11.0"
+ external-connection-point-ref: eth0
# contact with: nfvlabs@tid.es
##
---
-schema_version: 2
-scenario:
- name: simple_multi_vnfc
- description: Simple network scenario consisting of a multi VNFC VNF connected to an external network
- vnfs:
- linux1: # vnf/net name in the scenario
- vnf_name: linux_2VMs_v02 # VNF name as introduced in OPENMANO DB
- networks:
- mgmt: # provide a name for this net or connection
- external: true
- interfaces:
- - linux1: control0 # Node and its interface
- - linux1: control1 # Node and its interface
+nsd:nsd-catalog:
+ nsd:
+ - id: simple_multi_vnfc
+ name: simple_multi_vnfc
+ vendor: OSM
+ version: '1.0'
+ description: Simple network scenario consisting of a multi VNFC VNF connected to an external network
+ constituent-vnfd:
+ # The member-vnf-index needs to be unique, starting from 1
+ # vnfd-id-ref is the id of the VNFD
+ # Multiple constituent VNFDs can be specified
+ - member-vnf-index: 1
+ vnfd-id-ref: linux_2VMs_v02
+ vld:
+ # Networks for the VNFs
+ - id: vld1
+ name: mgmt
+ short-name: vld1-sname
+ type: ELAN
+ mgmt-network: 'true'
+ vnfd-connection-point-ref:
+ - member-vnf-index-ref: 1
+ vnfd-id-ref: linux_2VMs_v02
+ vnfd-connection-point-ref: eth0
+ - member-vnf-index-ref: 1
+ vnfd-id-ref: linux_2VMs_v02
+ vnfd-connection-point-ref: xe1
# contact with: nfvlabs@tid.es
##
---
-schema_version: "0.2"
-vnf:
- name: linux_2VMs_v02
- description: "Example of a linux VNF consisting of two VMs with one internal network"
- # class: parent # Optional. Used to organize VNFs
- internal-connections:
- - name: internalnet
- description: internalnet
- type: e-lan
- implementation: overlay
- ip-profile:
- ip-version: IPv4
- subnet-address: 192.168.1.0/24
+vnfd-catalog:
+ vnfd:
+ - id: linux_2VMs_v02
+ name: linux_2VMs_v02
+ description: "Example of a linux VNF consisting of two VMs with one internal network"
+ connection-point:
+ - id: eth0
+ name: eth0
+ short-name: eth0
+ type: VPORT
+ - id: xe1
+ name: xe1
+ short-name: xe1
+ type: VPORT
+ internal-vld:
+ - id: internalnet
+ name: internalnet
+ short-name: internalnet
+ ip-profile-ref: ip-prof1
+ type: ELAN
+ internal-connection-point:
+ - id-ref: VM1-xe0
+ - id-ref: VM2-xe0
+ ip-profiles:
+ - name: ip-prof1
+ description: IP profile
gateway-address: 192.168.1.1
- dns-address: 8.8.8.8
- dhcp:
+ dns-address: 8.8.8.8
+ #- address: 8.8.8.8
+ ip-profile-params:
+ ip-version: ipv4
+ subnet-address: 192.168.1.0/24
+ dhcp-params:
enabled: true
start-address: 192.168.1.100
count: 100
- elements:
- - VNFC: linux_2VMs-VM1
- local_iface_name: xe0
- ip_address: 192.168.1.2
- - VNFC: linux_2VMs-VM2
- local_iface_name: xe0
- ip_address: 192.168.1.3
- external-connections:
- - name: control0
- type: mgmt
- VNFC: linux_2VMs-VM1
- local_iface_name: eth0
- description: control interface VM1
- - name: control1
- type: mgmt
- VNFC: linux_2VMs-VM2
- local_iface_name: eth0
- description: control interface VM2
- - name: in
- type: bridge
- VNFC: linux_2VMs-VM1
- local_iface_name: xe1
- description: data interface input
- - name: out
- type: bridge
- VNFC: linux_2VMs-VM2
- local_iface_name: xe1
- description: data interface output
- VNFC:
- - name: linux_2VMs-VM1
- description: "Linux VM1 with 4 CPUs, 2 GB RAM and 3 bridge interfaces"
- #Copy the image to a compute path and edit this path
- image name: TestVM
- disk: 10
- vcpus: 4
- ram: 2048
- bridge-ifaces:
- - name: eth0
- vpci: "0000:00:09.0"
- bandwidth: 1 Mbps # Optional, informative only
- - name: xe0
- vpci: "0000:00:11.0"
- bandwidth: 1 Mbps
- - name: xe1
- vpci: "0000:00:12.0"
- bandwidth: 1 Mbps
- - name: linux_2VMs-VM2
- description: "Linux VM2 with 2 CPUs, 2 GB RAM and 3 bridge interfaces"
- #Copy the image to a compute path and edit this path
- image name: TestVM
- disk: 10
- vcpus: 2
- ram: 2048
- bridge-ifaces:
- - name: eth0
- vpci: "0000:00:09.0"
- bandwidth: 1 Mbps # Optional, informative only
- - name: xe0
- vpci: "0000:00:11.0"
- bandwidth: 1 Mbps
- - name: xe1
- vpci: "0000:00:12.0"
- bandwidth: 1 Mbps
-
+ vdu:
+ - id: linux_2VMs-VM1
+ name: linux_2VMs-VM1
+ description: Generic Linux Virtual Machine
+ #Copy the image to a compute path and edit this path
+ image: TestVM
+ vm-flavor:
+ memory-mb: '2048'
+ storage-gb: '10'
+ vcpu-count: '4'
+ interface:
+ - name: eth0
+ type: EXTERNAL
+ virtual-interface:
+ type: VIRTIO
+ vpci: "0000:00:09.0"
+ external-connection-point-ref: eth0
+ - name: xe0
+ type: INTERNAL
+ virtual-interface:
+ type: VIRTIO
+ vpci: "0000:00:11.0"
+ internal-connection-point-ref: VM1-xe0
+ - name: xe1
+ type: EXTERNAL
+ virtual-interface:
+ type: VIRTIO
+ vpci: "0000:00:12.0"
+ external-connection-point-ref: xe1
+ internal-connection-point:
+ - id: VM1-xe0
+ name: VM1-xe0
+ short-name: VM1-xe0
+ type: VPORT
+ - id: linux_2VMs-VM2
+ name: linux_2VMs-VM2
+ description: Generic Linux Virtual Machine
+ #Copy the image to a compute path and edit this path
+ image: TestVM
+ vm-flavor:
+ memory-mb: '2048'
+ storage-gb: '10'
+ vcpu-count: '4'
+ interface:
+ - name: eth0
+ type: EXTERNAL
+ virtual-interface:
+ type: VIRTIO
+ vpci: "0000:00:09.0"
+ external-connection-point-ref: eth0
+ - name: xe0
+ type: INTERNAL
+ virtual-interface:
+ type: VIRTIO
+ vpci: "0000:00:11.0"
+ internal-connection-point-ref: VM2-xe0
+ - name: xe1
+ type: EXTERNAL
+ virtual-interface:
+ type: VIRTIO
+ vpci: "0000:00:12.0"
+ external-connection-point-ref: xe1
+ internal-connection-point:
+ - id: VM2-xe0
+ name: VM2-xe0
+ short-name: VM2-xe0
+ type: VPORT
##
# DEBUG WITH PDB
-import os
-if os.getenv('OSMRO_PDB_DEBUG'):
+from os import getenv
+if getenv('OSMRO_PDB_DEBUG'):
import sys
print(sys.path)
import pdb
flavor_id = test_config["vim_conn"].new_flavor(flavor_data)
# get flavor by id
result = test_config["vim_conn"].get_flavor(flavor_id)
-
- if test_config['vimtype'] != 'azure':
- self.assertEqual(ram, result['ram'])
- self.assertEqual(vcpus, result['vcpus'])
- self.assertEqual(disk, result['disk'])
- else:
- self.assertTrue(ram <= result['ram'])
- self.assertTrue(vcpus <= result['vcpus'])
- self.assertTrue(disk <= result['disk'])
+ self.assertEqual(ram, result['ram'])
+ self.assertEqual(vcpus, result['vcpus'])
+ self.assertEqual(disk, result['disk'])
# delete flavor
- if test_config['vimtype'] != 'azure':
- result = test_config["vim_conn"].delete_flavor(flavor_id)
- if result:
- logger.info("Flavor id {} sucessfully deleted".format(result))
- else:
- logger.info("Failed to delete flavor id {}".format(result))
+ result = test_config["vim_conn"].delete_flavor(flavor_id)
+ if result:
+ logger.info("Flavor id {} sucessfully deleted".format(result))
+ else:
+ logger.info("Failed to delete flavor id {}".format(result))
def test_010_get_flavor_negative(self):
Non_exist_flavor_id = str(uuid.uuid4())
with self.assertRaises(Exception) as context:
test_config["vim_conn"].new_flavor(Invalid_flavor_data)
- if test_config['vimtype'] == 'azure':
- self.assertEqual((context.exception).http_code, 404)
- else:
- self.assertEqual((context.exception).http_code, 400)
+ self.assertEqual((context.exception).http_code, 400)
def test_030_delete_flavor_negative(self):
Non_exist_flavor_id = str(uuid.uuid4())
with self.assertRaises(Exception) as context:
test_config["vim_conn"].delete_flavor(Non_exist_flavor_id)
- if test_config['vimtype'] == 'azure':
- self.assertEqual((context.exception).http_code, 401)
- else:
- self.assertEqual((context.exception).http_code, 404)
-
-class test_vimconn_new_image(test_base):
-
- def test_000_new_image(self):
- self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
- self.__class__.test_index,
- inspect.currentframe().f_code.co_name)
- self.__class__.test_index += 1
-
- image_path = test_config['image_path']
- if image_path:
- self.__class__.image_id = test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : image_path,
- 'metadata': {'upload_location':None} })
- time.sleep(20)
-
- self.assertIsInstance(self.__class__.image_id, (str, unicode))
- self.assertIsInstance(uuid.UUID(self.__class__.image_id), uuid.UUID)
- else:
- self.skipTest("Skipping test as image file not present at RO container")
-
- def test_010_new_image_negative(self):
- Non_exist_image_path = '/temp1/cirros.ovf'
-
- self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
- self.__class__.test_index,
- inspect.currentframe().f_code.co_name)
- self.__class__.test_index += 1
-
- with self.assertRaises(Exception) as context:
- test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : Non_exist_image_path})
-
- self.assertEqual((context.exception).http_code, 400)
-
- def test_020_delete_image(self):
- self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
- self.__class__.test_index,
- inspect.currentframe().f_code.co_name)
- self.__class__.test_index += 1
-
- image_id = test_config["vim_conn"].delete_image(self.__class__.image_id)
-
- self.assertIsInstance(image_id, (str, unicode))
-
- def test_030_delete_image_negative(self):
- Non_exist_image_id = str(uuid.uuid4())
-
- self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
- self.__class__.test_index,
- inspect.currentframe().f_code.co_name)
- self.__class__.test_index += 1
-
- with self.assertRaises(Exception) as context:
- test_config["vim_conn"].delete_image(Non_exist_image_id)
-
self.assertEqual((context.exception).http_code, 404)
-class test_vimconn_get_image_id_from_path(test_base):
-
- def test_000_get_image_id_from_path(self):
- self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
- self.__class__.test_index,
- inspect.currentframe().f_code.co_name)
- self.__class__.test_index += 1
-
- image_path = test_config['image_path']
- if image_path:
- image_id = test_config["vim_conn"].get_image_id_from_path( image_path )
- self.assertEqual(type(image_id),str)
- else:
- self.skipTest("Skipping test as image file not present at RO container")
-
- def test_010_get_image_id_from_path_negative(self):
- Non_exist_image_path = '/temp1/cirros.ovf'
-
- self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
- self.__class__.test_index,
- inspect.currentframe().f_code.co_name)
- self.__class__.test_index += 1
-
- with self.assertRaises(Exception) as context:
- test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : Non_exist_image_path })
+# class test_vimconn_new_image(test_base):
+#
+# def test_000_new_image(self):
+# self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+# self.__class__.test_index,
+# inspect.currentframe().f_code.co_name)
+# self.__class__.test_index += 1
+#
+# image_path = test_config['image_path']
+# if image_path:
+# self.__class__.image_id = test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : image_path, 'metadata': {'upload_location':None} })
+# time.sleep(20)
+#
+# self.assertIsInstance(self.__class__.image_id, (str, unicode))
+# self.assertIsInstance(uuid.UUID(self.__class__.image_id), uuid.UUID)
+# else:
+# self.skipTest("Skipping test as image file not present at RO container")
+#
+# def test_010_new_image_negative(self):
+# Non_exist_image_path = '/temp1/cirros.ovf'
+#
+# self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+# self.__class__.test_index,
+# inspect.currentframe().f_code.co_name)
+# self.__class__.test_index += 1
+#
+# with self.assertRaises(Exception) as context:
+# test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : Non_exist_image_path})
+#
+# self.assertEqual((context.exception).http_code, 400)
+#
+# def test_020_delete_image(self):
+# self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+# self.__class__.test_index,
+# inspect.currentframe().f_code.co_name)
+# self.__class__.test_index += 1
+#
+# image_id = test_config["vim_conn"].delete_image(self.__class__.image_id)
+#
+# self.assertIsInstance(image_id, (str, unicode))
+#
+# def test_030_delete_image_negative(self):
+# Non_exist_image_id = str(uuid.uuid4())
+#
+# self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+# self.__class__.test_index,
+# inspect.currentframe().f_code.co_name)
+# self.__class__.test_index += 1
+#
+# with self.assertRaises(Exception) as context:
+# test_config["vim_conn"].delete_image(Non_exist_image_id)
+#
+# self.assertEqual((context.exception).http_code, 404)
- self.assertEqual((context.exception).http_code, 400)
+# class test_vimconn_get_image_id_from_path(test_base):
+#
+# def test_000_get_image_id_from_path(self):
+# self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+# self.__class__.test_index,
+# inspect.currentframe().f_code.co_name)
+# self.__class__.test_index += 1
+#
+# image_path = test_config['image_path']
+# if image_path:
+# image_id = test_config["vim_conn"].get_image_id_from_path( image_path )
+# self.assertEqual(type(image_id),str)
+# else:
+# self.skipTest("Skipping test as image file not present at RO container")
+#
+# def test_010_get_image_id_from_path_negative(self):
+# Non_exist_image_path = '/temp1/cirros.ovf'
+#
+# self.__class__.test_text = "{}.{}. TEST {}".format(test_config["test_number"],
+# self.__class__.test_index,
+# inspect.currentframe().f_code.co_name)
+# self.__class__.test_index += 1
+#
+# with self.assertRaises(Exception) as context:
+# test_config["vim_conn"].new_image({ 'name': 'TestImage', 'location' : Non_exist_image_path })
+#
+# self.assertEqual((context.exception).http_code, 400)
class test_vimconn_get_image_list(test_base):
image_name = None
inspect.currentframe().f_code.co_name)
self.__class__.test_index += 1
- if test_config['image_name']:
- image_list = test_config['vim_conn'].get_image_list({'name': test_config['image_name']})
- else:
- image_list = test_config["vim_conn"].get_image_list()
+ # if test_config['image_name']:
+ # image_list = test_config['vim_conn'].get_image_list({'name': test_config['image_name']})
+ # else:
+ image_list = test_config["vim_conn"].get_image_list()
for item in image_list:
if 'name' in item:
for action in action_list:
# sleep for sometime till status is changed
time.sleep(25)
- instance_id = test_config["vim_conn"].action_vminstance(new_instance_id, {action: None})
+ instance_id = test_config["vim_conn"].action_vminstance(new_instance_id,
+ { action: None})
self.assertTrue(instance_id is None)
- #Deleting created vm instance
+ # Deleting created vm instance
logger.info("Deleting created vm intance")
test_config["vim_conn"].delete_vminstance(new_instance_id)
time.sleep(10)
with self.assertRaises(Exception) as context:
test_config["vim_conn"].delete_tenant(Non_exist_tenant_name)
- if test_config['vimtype'] != 'azure':
- self.assertEqual((context.exception).http_code, 404)
- else:
- self.assertEqual((context.exception).http_code, 401)
+ self.assertEqual((context.exception).http_code, 404)
def get_image_id():
'port_security': True, 'type': 'virtual', 'net_id': net_id})
c = c+1
- instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', description='', start=False,
- image_id=image_id, flavor_id=flavor_id, net_list=net_list)
+ instance_id, _ = test_config["vim_conn"].new_vminstance(name='Test1_vm', image_id=image_id,
+ flavor_id=flavor_id, net_list=net_list)
self.assertEqual(type(instance_id),str)
logger.info("Deleting created vm instance")