DBHOST="localhost"
DBPORT="3306"
DBNAME="mano_db"
+CREATEDB=""
# Detect paths
MYSQL=$(which mysql)
echo -e " -h HOST database host. '$DBHOST' by default"
echo -e " -d NAME database name. '$DBNAME' by default. Prompts if DB access fails"
echo -e " --help shows this help"
+ echo -e " --createdb forces the deletion and creation of the database"
}
while getopts ":u:p:P:d:h:-:" o; do
DBHOST="$OPTARG"
;;
-)
- [ "${OPTARG}" == "help" ] && usage && exit 0
- echo "Invalid option: --$OPTARG" >&2 && usage >&2
- exit 1
+ if [ "${OPTARG}" == "help" ]; then
+ usage && exit 0
+ elif [ "${OPTARG}" == "createdb" ]; then
+ CREATEDB="yes"
+ else
+ echo "Invalid option: --$OPTARG" >&2 && usage >&2
+ exit 1
+ fi
;;
\?)
echo "Invalid option: -$OPTARG" >&2 && usage >&2
echo
done
-#${DIRNAME}/quick_delete_db.sh $MUSER $MPASS $MDB $HOST $PORT
+if [ -n "${CREATEDB}" ]; then
+ echo " deleting previous database ${DBNAME}"
+ echo "DROP DATABASE IF EXISTS ${DBNAME}" | mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_
+ echo " creating database ${DBNAME}"
+ mysqladmin $DBUSER_ $DBPASS_ -s create ${DBNAME} || exit 1
+fi
+
echo " loading ${DIRNAME}/${DBNAME}_structure.sql"
mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME < ${DIRNAME}/mano_db_structure.sql
[ $OPENMANO_VER_NUM -ge 4033 ] && DATABASE_TARGET_VER_NUM=9 #0.4.33=> 9
[ $OPENMANO_VER_NUM -ge 4036 ] && DATABASE_TARGET_VER_NUM=10 #0.4.36=> 10
[ $OPENMANO_VER_NUM -ge 4043 ] && DATABASE_TARGET_VER_NUM=11 #0.4.43=> 11
+[ $OPENMANO_VER_NUM -ge 4046 ] && DATABASE_TARGET_VER_NUM=12 #0.4.46=> 12
#TODO ... put next versions here
echo "DELETE FROM schema_version WHERE version_int='11';" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
}
+function upgrade_to_12(){
+ echo " upgrade database from version 0.11 to version 0.12"
+ echo " create ip_profiles table, with foreign keys to all nets tables, and add ip_address column to 'interfaces' and 'sce_interfaces'"
+ echo "CREATE TABLE ip_profiles (
+ id INT(11) NOT NULL AUTO_INCREMENT,
+ net_id VARCHAR(36) NULL DEFAULT NULL,
+ sce_net_id VARCHAR(36) NULL DEFAULT NULL,
+ instance_net_id VARCHAR(36) NULL DEFAULT NULL,
+ ip_version ENUM('IPv4','IPv6') NOT NULL DEFAULT 'IPv4',
+ subnet_address VARCHAR(64) NULL DEFAULT NULL,
+ gateway_address VARCHAR(64) NULL DEFAULT NULL,
+ security_group VARCHAR(255) NULL DEFAULT NULL,
+ dns_address VARCHAR(64) NULL DEFAULT NULL,
+ dhcp_enabled ENUM('true','false') NOT NULL DEFAULT 'true',
+ dhcp_start_address VARCHAR(64) NULL DEFAULT NULL,
+ dhcp_count INT(11) NULL DEFAULT NULL,
+ PRIMARY KEY (id),
+ CONSTRAINT FK_ipprofiles_nets FOREIGN KEY (net_id) REFERENCES nets (uuid) ON DELETE CASCADE,
+ CONSTRAINT FK_ipprofiles_scenets FOREIGN KEY (sce_net_id) REFERENCES sce_nets (uuid) ON DELETE CASCADE,
+ CONSTRAINT FK_ipprofiles_instancenets FOREIGN KEY (instance_net_id) REFERENCES instance_nets (uuid) ON DELETE CASCADE )
+ COMMENT='Table containing the IP parameters of a network, either a net, a sce_net or and instance_net.'
+ COLLATE='utf8_general_ci'
+ ENGINE=InnoDB;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+ echo "ALTER TABLE interfaces ADD COLUMN ip_address VARCHAR(64) NULL DEFAULT NULL AFTER mac;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+ echo "ALTER TABLE sce_interfaces ADD COLUMN ip_address VARCHAR(64) NULL DEFAULT NULL AFTER interface_id;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+ echo "INSERT INTO schema_version (version_int, version, openmano_ver, comments, date) VALUES (12, '0.12', '0.4.46', 'create ip_profiles table, with foreign keys to all nets tables, and add ip_address column to interfaces and sce_interfaces', '2016-07-18');" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+}
+function downgrade_from_12(){
+ echo " downgrade database from version 0.12 to version 0.11"
+ echo " delete ip_profiles table, and remove ip_address column in 'interfaces' and 'sce_interfaces'"
+ echo "DROP TABLE ip_profiles;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+ echo "ALTER TABLE interfaces DROP COLUMN ip_address;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+ echo "ALTER TABLE sce_interfaces DROP COLUMN ip_address;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+ echo "DELETE FROM schema_version WHERE version_int='12';" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+}
+
function upgrade_to_X(){
echo " change 'datacenter_nets'"
echo "ALTER TABLE datacenter_nets ADD COLUMN vim_tenant_id VARCHAR(36) NOT NULL AFTER datacenter_id, DROP INDEX name_datacenter_id, ADD UNIQUE INDEX name_datacenter_id (name, datacenter_id, vim_tenant_id);" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
from jsonschema import validate as js_v, exceptions as js_e
from openmano_schemas import vnfd_schema_v01, vnfd_schema_v02, \
nsd_schema_v01, nsd_schema_v02, scenario_edit_schema, \
- scenario_action_schema, instance_scenario_action_schema, instance_scenario_create_schema, \
+ scenario_action_schema, instance_scenario_action_schema, instance_scenario_create_schema_v01, \
tenant_schema, tenant_edit_schema,\
datacenter_schema, datacenter_edit_schema, datacenter_action_schema, datacenter_associate_schema,\
object_schema, netmap_new_schema, netmap_edit_schema
if tenant_id != "any":
nfvo.check_tenant(mydb, tenant_id)
#parse input data
- http_content,used_schema = format_in( instance_scenario_create_schema)
+ http_content,used_schema = format_in( instance_scenario_create_schema_v01)
r = utils.remove_extra_items(http_content, used_schema)
if r is not None: print "http_post_instances: Warning: remove extra items ", r
data = nfvo.create_instance(mydb, tenant_id, http_content["instance"])
def create_instance(mydb, tenant_id, instance_dict):
#print "Checking that nfvo_tenant_id exists and getting the VIM URI and the VIM tenant_id"
+ logger.debug("Creating instance...")
scenario = instance_dict["scenario"]
datacenter_id = None
datacenter_name=None
for vm in vnf['vms']:
vm_manage_iface_list=[]
#instance_interfaces
- cmd = "SELECT vim_interface_id, instance_net_id, internal_name,external_name, mac_address, ip_address, vim_info, i.type as type "\
+ cmd = "SELECT vim_interface_id, instance_net_id, internal_name,external_name, mac_address, ii.ip_address as ip_address, vim_info, i.type as type "\
" FROM instance_interfaces as ii join interfaces as i on ii.interface_id=i.uuid "\
" WHERE instance_vm_id='{}' ORDER BY created_at".format(vm['uuid'])
self.logger.debug(cmd)
"properties":{
"VNFC": name_schema,
"local_iface_name": name_schema,
- "ip-address": ip_schema
+ "ip_address": ip_schema
}
}
"$schema": "http://json-schema.org/draft-04/schema#",
"type":"object",
"properties":{
- "schema_version": {"type": "string", "enum": ["0.2"]},
+ "schema_version": schema_version_2,
"scenario":{
"type":"object",
"properties":{
"tenant_id": id_schema, #only valid for admin
"public": {"type": "boolean"},
"cloud-config": cloud_config_schema, #common for all vnfs in the scenario
- #"site": name_schema,
+ #"datacenter": name_schema,
"vnfs": {
"type":"object",
"patternProperties":{
"vnf_id": id_schema,
"graph": graph_schema,
"vnf_name": name_schema,
- "cloud-config": cloud_config_schema, #particular for a vnf
- #"site": name_schema,
+ #"cloud-config": cloud_config_schema, #particular for a vnf
+ #"datacenter": name_schema,
"internal-connections": {
"type": "object",
"patternProperties": {
"properties":{
"VNFC": name_schema,
"local_iface_name": name_schema,
- "ip-address": ip_schema
+ "ip_address": ip_schema
},
"required": ["VNFC", "local_iface_name"],
}
"items":{
"type":"object",
"properties":{
- "ip-address": ip_schema
+ "ip_address": ip_schema
},
"patternProperties":{
".": {"type": "string"}
"properties":{
"name":name_schema,
"description":description_schema,
- "site": name_schema,
+ "datacenter": name_schema,
+ "scenario" : name_schema, #can be an UUID or name
"action":{"enum": ["deploy","reserve","verify" ]},
"connect_mgmt_interfaces": {"oneOf": [{"type":"boolean"}, {"type":"object"}]},# can be true or a dict with datacenter: net_name
"cloud-config": cloud_config_schema, #common to all vnfs in the instance scenario
"type": "object",
"properties":{
"name": name_schema, #override vnf name
- "site": name_schema,
+ "datacenter": name_schema,
#"metadata": {"type": "object"},
#"user_data": {"type": "string"}
- "cloud-config": cloud_config_schema, #particular for a vnf
+ #"cloud-config": cloud_config_schema, #particular for a vnf
"external-connections": {
"type": "object",
"patternProperties": {
"type": "object",
"properties": {
"vim-network-name": name_schema,
- "ip-address": ip_schema
+ "ip_address": ip_schema
}
}
}
"properties":{
"VNFC": name_schema,
"local_iface_name": name_schema,
- "ip-address": ip_schema
+ "ip_address": ip_schema
},
"required": ["VNFC", "local_iface_name"],
}
"items":{
"type":"object",
"properties":{
- "ip-address": ip_schema
+ "ip_address": ip_schema
},
"patternProperties":{
".": {"type": "string"}
},
"netmap-create": {"oneOf":[name_schema,{"type": "null"}]}, #datacenter network to use. Null if must be created as an internal net
"netmap-use": name_schema,
- "name": name_schema, #override network name
+ #"name": name_schema, #override network name
"ip-profile": ip_profile_schema,
- #"site": name_schema,
+ #"datacenter": name_schema,
"vim-network-name": name_schema
}
}
'''
__author__="Alfonso Tierno, Gerardo Garcia, Pablo Montes"
__date__ ="$26-aug-2014 11:09:29$"
-__version__="0.4.45-r484"
+__version__="0.4.46-r485"
version_date="Aug 2016"
-database_version="0.11" #expected database schema version
+database_version="0.12" #expected database schema version
import httpserver
import time
echo "Stopping openmano"
$DIRscript/service-openmano.sh mano stop
echo "Initializing openmano database"
- $DIRmano/database_utils/init_mano_db.sh -u mano -p manopw
+ $DIRmano/database_utils/init_mano_db.sh -u mano -p manopw --createdb
echo "Starting openmano"
$DIRscript/service-openmano.sh mano start
echo