From 8008c3ab56d80d73568226a4503f0f5933c23df9 Mon Sep 17 00:00:00 2001 From: tierno Date: Thu, 13 Oct 2016 15:34:28 +0000 Subject: [PATCH] v0.5.2 enlarge vim_tenant_id to allow extra fields. Allow extra datacenter configuration at attachment Change-Id: I7a99a65be55fb7520633ceb33922c0ff2ea96c3f Signed-off-by: tierno --- database_utils/migrate_mano_db.sh | 18 ++++++++++++++++++ httpserver.py | 20 +++++++++++++++----- nfvo.py | 12 ++++++++---- openmano | 7 +++++-- openmano_schemas.py | 5 +++-- openmanod.py | 4 ++-- test/basictest.sh | 8 ++++---- 7 files changed, 55 insertions(+), 19 deletions(-) diff --git a/database_utils/migrate_mano_db.sh b/database_utils/migrate_mano_db.sh index ae1ef15c..9484131c 100755 --- a/database_utils/migrate_mano_db.sh +++ b/database_utils/migrate_mano_db.sh @@ -184,6 +184,7 @@ DATABASE_TARGET_VER_NUM=0 [ $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 @@ -665,6 +666,23 @@ function downgrade_from_15(){ 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 diff --git a/httpserver.py b/httpserver.py index cd40882f..789e0224 100644 --- a/httpserver.py +++ b/httpserver.py @@ -450,7 +450,7 @@ def http_get_datacenter_id(tenant_id, datacenter_id): 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 @@ -470,13 +470,22 @@ def http_get_datacenter_id(tenant_id, datacenter_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']) @@ -719,8 +728,9 @@ def http_associate_datacenters(tenant_id, datacenter_id): 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))) diff --git a/nfvo.py b/nfvo.py index 1d954257..e529d5f2 100644 --- a/nfvo.py +++ b/nfvo.py @@ -108,9 +108,9 @@ def get_vim(mydb, nfvo_tenant=None, datacenter_id=None, datacenter_name=None, da 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') @@ -119,8 +119,10 @@ def get_vim(mydb, nfvo_tenant=None, datacenter_id=None, datacenter_name=None, da 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: @@ -2413,7 +2415,7 @@ def delete_datacenter(mydb, datacenter): 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"] @@ -2463,6 +2465,8 @@ def associate_datacenter_to_tenant(mydb, nfvo_tenant, datacenter, vim_tenant_id= 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_ diff --git a/openmano b/openmano index 818e7173..6c546c12 100755 --- a/openmano +++ b/openmano @@ -28,8 +28,8 @@ openmano client used to interact with openmano-server (openmanod) ''' __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 @@ -889,6 +889,8 @@ def datacenter_attach(args): 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 @@ -1335,6 +1337,7 @@ if __name__=="__main__": 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") diff --git a/openmano_schemas.py b/openmano_schemas.py index e1fc2bd7..ffbacd3a 100644 --- a/openmano_schemas.py +++ b/openmano_schemas.py @@ -275,10 +275,11 @@ datacenter_associate_schema={ "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 diff --git a/openmanod.py b/openmanod.py index a76ed70f..62b83acf 100755 --- a/openmanod.py +++ b/openmanod.py @@ -33,9 +33,9 @@ It loads the configuration file and launches the http_server thread that will li ''' __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 diff --git a/test/basictest.sh b/test/basictest.sh index 5b7dca54..ba6cd97a 100755 --- a/test/basictest.sh +++ b/test/basictest.sh @@ -72,7 +72,7 @@ action_list="" 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 @@ -167,8 +167,8 @@ then [[ -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 @@ -177,7 +177,7 @@ then [[ -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 -- 2.25.1