[ $OPENMANO_VER_NUM -ge 4047 ] && DATABASE_TARGET_VER_NUM=13 #0.4.47=> 13
[ $OPENMANO_VER_NUM -ge 4057 ] && DATABASE_TARGET_VER_NUM=14 #0.4.57=> 14
[ $OPENMANO_VER_NUM -ge 4059 ] && DATABASE_TARGET_VER_NUM=15 #0.4.59=> 15
+[ $OPENMANO_VER_NUM -ge 5002 ] && DATABASE_TARGET_VER_NUM=16 #0.5.2 => 16
#TODO ... put next versions here
echo "DELETE FROM schema_version WHERE version_int='15';" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
}
+function upgrade_to_16(){
+ echo " upgrade database from version 0.15 to version 0.16"
+ echo " add column 'config' at table 'datacenter_tenants', enlarge 'vim_tenant_name/id'"
+ echo "ALTER TABLE datacenter_tenants ADD COLUMN config VARCHAR(4000) NULL DEFAULT NULL AFTER passwd;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+ echo "ALTER TABLE datacenter_tenants CHANGE COLUMN vim_tenant_name vim_tenant_name VARCHAR(256) NULL DEFAULT NULL AFTER datacenter_id;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+ echo "ALTER TABLE datacenter_tenants CHANGE COLUMN vim_tenant_id vim_tenant_id VARCHAR(256) NULL DEFAULT NULL COMMENT 'Tenant ID at VIM' AFTER vim_tenant_name;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+ echo "INSERT INTO schema_version (version_int, version, openmano_ver, comments, date) VALUES (16, '0.16', '0.5.2', 'enlarge vim_tenant_name and id. New config at datacenter_tenants', '2016-10-11');" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+}
+function downgrade_from_16(){
+ echo " downgrade database from version 0.16 to version 0.15"
+ echo " remove column 'config' at table 'datacenter_tenants', restoring lenght 'vim_tenant_name/id'"
+ echo "ALTER TABLE datacenter_tenants DROP COLUMN config" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+ echo "ALTER TABLE datacenter_tenants CHANGE COLUMN vim_tenant_name vim_tenant_name VARCHAR(64) NULL DEFAULT NULL AFTER datacenter_id;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+ echo "ALTER TABLE datacenter_tenants CHANGE COLUMN vim_tenant_id vim_tenant_id VARCHAR(36) NULL DEFAULT NULL COMMENT 'Tenant ID at VIM' AFTER vim_tenant_name;" | $DBCMD || ! echo "ERROR. Aborted!" || exit -1
+ echo "DELETE FROM schema_version WHERE version_int='16';" | $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
what = 'uuid' if utils.check_valid_uuid(datacenter_id) else 'name'
where_={}
where_[what] = datacenter_id
- select_=['uuid', 'name','vim_url', 'vim_url_admin', 'type', 'config', 'description', 'd.created_at as created_at']
+ select_=['uuid', 'name','vim_url', 'vim_url_admin', 'type', 'd.config as config', 'description', 'd.created_at as created_at']
if tenant_id != 'any':
select_.append("datacenter_tenant_id")
where_['td.nfvo_tenant_id']= tenant_id
if tenant_id != 'any':
#get vim tenant info
vim_tenants = mydb.get_rows(
- SELECT=("vim_tenant_name", "vim_tenant_id", "user"),
+ SELECT=("vim_tenant_name", "vim_tenant_id", "user", "passwd", "config"),
FROM="datacenter_tenants",
WHERE={"uuid": datacenters[0]["datacenter_tenant_id"]},
ORDER_BY=("created", ) )
del datacenter["datacenter_tenant_id"]
datacenter["vim_tenants"] = vim_tenants
-
+ for vim_tenant in vim_tenants:
+ if vim_tenant["passwd"]:
+ vim_tenant["passwd"] = "******"
+ if vim_tenant['config'] != None:
+ try:
+ config_dict = yaml.load(vim_tenant['config'])
+ vim_tenant['config'] = config_dict
+ except Exception, e:
+ logger.error("Exception '%s' while trying to load config information", str(e))
+
if datacenter['config'] != None:
try:
config_dict = yaml.load(datacenter['config'])
http_content['datacenter'].get('vim_tenant'),
http_content['datacenter'].get('vim_tenant_name'),
http_content['datacenter'].get('vim_username'),
- http_content['datacenter'].get('vim_password')
- )
+ http_content['datacenter'].get('vim_password'),
+ http_content['datacenter'].get('config')
+ )
return http_get_datacenter_id(tenant_id, id_)
except (nfvo.NfvoException, db_base_Exception) as e:
logger.error("http_associate_datacenters error {}: {}".format(e.http_code, str(e)))
if vim_tenant_name is not None: WHERE_dict['vim_tenant_name'] = vim_tenant_name
if nfvo_tenant or vim_tenant or vim_tenant_name or datacenter_tenant_id:
from_= 'tenants_datacenters as td join datacenters as d on td.datacenter_id=d.uuid join datacenter_tenants as dt on td.datacenter_tenant_id=dt.uuid'
- select_ = ('type','config','d.uuid as datacenter_id', 'vim_url', 'vim_url_admin', 'd.name as datacenter_name',
+ select_ = ('type','d.config as config','d.uuid as datacenter_id', 'vim_url', 'vim_url_admin', 'd.name as datacenter_name',
'dt.uuid as datacenter_tenant_id','dt.vim_tenant_name as vim_tenant_name','dt.vim_tenant_id as vim_tenant_id',
- 'user','passwd')
+ 'user','passwd', 'dt.config as dt_config')
else:
from_ = 'datacenters as d'
select_ = ('type','config','d.uuid as datacenter_id', 'vim_url', 'vim_url_admin', 'd.name as datacenter_name')
vim_dict={}
for vim in vims:
extra={'datacenter_tenant_id': vim.get('datacenter_tenant_id')}
- if vim["config"] != None:
+ if vim["config"]:
extra.update(yaml.load(vim["config"]))
+ if vim.get('dt_config'):
+ extra.update(yaml.load(vim["dt_config"]))
if vim["type"] not in vimconn_imported:
module_info=None
try:
mydb.delete_row_by_id("datacenters", datacenter_dict['uuid'])
return datacenter_dict['uuid'] + " " + datacenter_dict['name']
-def associate_datacenter_to_tenant(mydb, nfvo_tenant, datacenter, vim_tenant_id=None, vim_tenant_name=None, vim_username=None, vim_password=None):
+def associate_datacenter_to_tenant(mydb, nfvo_tenant, datacenter, vim_tenant_id=None, vim_tenant_name=None, vim_username=None, vim_password=None, config=None):
#get datacenter info
datacenter_id, myvim = get_datacenter_by_name_uuid(mydb, None, datacenter)
datacenter_name=myvim["name"]
datacenter_tenants_dict["user"] = vim_username
datacenter_tenants_dict["passwd"] = vim_password
datacenter_tenants_dict["datacenter_id"] = datacenter_id
+ if config:
+ datacenter_tenants_dict["config"] = yaml.safe_dump(config, default_flow_style=True, width=256)
id_ = mydb.new_row('datacenter_tenants', datacenter_tenants_dict, add_uuid=True)
datacenter_tenants_dict["uuid"] = id_
'''
__author__="Alfonso Tierno, Gerardo Garcia"
__date__ ="$09-oct-2014 09:09:48$"
-__version__="0.4.6-r500"
-version_date="Sep 2016"
+__version__="0.4.7-r511"
+version_date="Oct 2016"
from argcomplete.completers import FilesCompleter
import os
datacenter_dict['vim_username'] = args.user
if args.password != None:
datacenter_dict['vim_password'] = args.password
+ if args.config!=None:
+ datacenter_dict["config"] = _load_file_or_yaml(args.config)
payload_req = json.dumps( {"datacenter": datacenter_dict })
#print payload_req
datacenter_attach_parser.add_argument('--vim-tenant-name', action='store', help="specify a datacenter tenant name.")
datacenter_attach_parser.add_argument("--user", action="store", help="user credentials for the datacenter")
datacenter_attach_parser.add_argument("--password", action="store", help="password credentials for the datacenter")
+ datacenter_attach_parser.add_argument("--config", action="store", help="aditional configuration in json/yaml format")
datacenter_attach_parser.set_defaults(func=datacenter_attach)
datacenter_detach_parser = subparsers.add_parser('datacenter-detach', parents=[parent_parser], help="removes the association between a datacenter and the operating tenant")
"datacenter":{
"type":"object",
"properties":{
- "vim_tenant": id_schema,
- "vim_tenant_name": nameshort_schema,
+ "vim_tenant": name_schema,
+ "vim_tenant_name": name_schema,
"vim_username": nameshort_schema,
"vim_password": nameshort_schema,
+ "config": {"type": "object"}
},
# "required": ["vim_tenant"],
"additionalProperties": True
'''
__author__="Alfonso Tierno, Gerardo Garcia, Pablo Montes"
__date__ ="$26-aug-2014 11:09:29$"
-__version__="0.5.1-r508"
+__version__="0.5.2-r510"
version_date="Oct 2016"
-database_version="0.15" #expected database schema version
+database_version="0.16" #expected database schema version
import httpserver
import time
for argument in $params
do
- if [[ $argument == reset ]] || [[ $argument == create ]] || [[ $argument == delete ]]
+ if [[ $argument == reset ]] || [[ $argument == create ]] || [[ $argument == delete ]] || [[ -z "$argument" ]]
then
action_list="$action_list $argument"
continue
[[ -z $OPENVIM_HOST ]] && OPENVIM_HOST=localhost
[[ -z $OPENVIM_PORT ]] && OPENVIM_PORT=9080
URL_ADMIN_PARAM=""
- [[ -n $OPENVIM_ADMIN_PORT ]] && URL_ADMIN_PARAM="--url_admin=http://${OPENVIM_HOST}:${OPENVIM_ADMIN_PORT}/openvim"
- result=`${DIRmano}/openmano datacenter-create TEST-dc "http://${OPENVIM_HOST}:${OPENVIM_PORT}/openvim" --type=openvim $URL_ADMIN_PARAM`
+ [[ -n $OPENVIM_ADMIN_PORT ]] && URL_ADMIN_PARAM=" --url_admin=http://${OPENVIM_HOST}:${OPENVIM_ADMIN_PORT}/openvim"
+ result=`${DIRmano}/openmano datacenter-create TEST-dc "http://${OPENVIM_HOST}:${OPENVIM_PORT}/openvim" --type=openvim${URL_ADMIN_PARAM} --config="{test: no use just for test}"`
datacenter=`echo $result |gawk '{print $1}'`
#check a valid uuid is obtained
! is_valid_uuid $datacenter && echo "FAIL" && echo " $result" && $_exit 1
[[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_DATACENTER=$datacenter" >> ~/.bashrc
printf "%-50s" "Attaching openmano tenant to the datacenter:"
- result=`${DIRmano}/openmano datacenter-attach TEST-dc`
+ result=`${DIRmano}/openmano datacenter-attach TEST-dc --config="{test: no use just for test}"`
[[ $? != 0 ]] && echo "FAIL" && echo " $result" && $_exit 1
echo OK