DBNAME="mano_db"
QUIET_MODE=""
#TODO update it with the last database version
-LAST_DB_VERSION=35
+LAST_DB_VERSION=36
# Detect paths
MYSQL=$(which mysql)
#[ $OPENMANO_VER_NUM -ge 5082 ] && DB_VERSION=33 #0.5.82 => 33
#[ $OPENMANO_VER_NUM -ge 6000 ] && DB_VERSION=34 #0.6.00 => 34
#[ $OPENMANO_VER_NUM -ge 6001 ] && DB_VERSION=35 #0.6.01 => 35
+#[ $OPENMANO_VER_NUM -ge 6003 ] && DB_VERSION=35 #0.6.03 => 36
#TODO ... put next versions here
function upgrade_to_1(){
script="$(find "${DBUTILS}/migrations/down" -iname "35*.sql" | tail -1)"
sql "source ${script}"
}
+function upgrade_to_36(){
+ echo " Allow null for image_id at 'vms'"
+ sql "ALTER TABLE vms ALTER image_id DROP DEFAULT;"
+ sql "ALTER TABLE vms CHANGE COLUMN image_id image_id VARCHAR(36) NULL COMMENT 'Link to image table' AFTER " \
+ "flavor_id;"
+ echo " Enlarge config at 'wims' and 'wim_accounts'"
+ sql "ALTER TABLE wims CHANGE COLUMN config config TEXT NULL DEFAULT NULL AFTER wim_url;"
+ sql "ALTER TABLE wim_accounts CHANGE COLUMN config config TEXT NULL DEFAULT NULL AFTER password;"
+ sql "INSERT INTO schema_version (version_int, version, openmano_ver, comments, date) "\
+ "VALUES (36, '0.36', '0.6.03', 'Allow vm without image_id for PDUs', '2018-12-19');"
+}
+function downgrade_from_36(){
+ echo " Force back not null for image_id at 'vms'"
+ sql "ALTER TABLE vms ALTER image_id DROP DEFAULT;"
+ sql "ALTER TABLE vms CHANGE COLUMN image_id image_id VARCHAR(36) NOT NULL COMMENT 'Link to image table' AFTER " \
+ "flavor_id;"
+ # For downgrade do not restore wims/wim_accounts config to varchar 4000
+ sql "DELETE FROM schema_version WHERE version_int='36';"
+}
+
#TODO ... put functions here
# echo "db version = "${DATABASE_VER_NUM}
__author__ = "Alfonso Tierno, Gerardo Garcia, Pablo Montes"
__date__ = "$26-aug-2014 11:09:29$"
-__version__ = "0.6.02"
+__version__ = "0.6.03"
version_date = "Dec 2018"
-database_version = 35 # expected database schema version
+database_version = 36 # expected database schema version
global global_config
global logger
image_list = []
vms = mydb.get_rows(SELECT=('image_id','image_list'), FROM='vms', WHERE={'vnf_id': vnf_id})
for vm in vms:
- if vm["image_id"] not in image_list:
+ if vm["image_id"] and vm["image_id"] not in image_list:
image_list.append(vm["image_id"])
if vm["image_list"]:
vm_image_list = yaml.load(vm["image_list"])
devices.append(device)
+ if not db_vm.get("image_id"):
+ if not db_vm["pdu_type"]:
+ raise NfvoException("Not defined image for VDU")
+ # create a fake image
+
# cloud-init
boot_data = {}
if vdu.get("cloud-init"):
else:
del vm["image_list"]
if datacenter_vim_id!=None:
- cmd = "SELECT vim_id FROM datacenters_images WHERE image_id='{}' AND datacenter_vim_id='{}'".format(vm['image_id'],datacenter_vim_id)
- self.logger.debug(cmd)
- self.cur.execute(cmd)
- if self.cur.rowcount==1:
- vim_image_dict = self.cur.fetchone()
- vm['vim_image_id']=vim_image_dict['vim_id']
- cmd = "SELECT vim_id FROM datacenters_flavors WHERE flavor_id='{}' AND datacenter_vim_id='{}'".format(vm['flavor_id'],datacenter_vim_id)
- self.logger.debug(cmd)
- self.cur.execute(cmd)
- if self.cur.rowcount==1:
- vim_flavor_dict = self.cur.fetchone()
- vm['vim_flavor_id']=vim_flavor_dict['vim_id']
+ if vm['image_id']:
+ cmd = "SELECT vim_id FROM datacenters_images WHERE image_id='{}' AND " \
+ "datacenter_vim_id='{}'".format(vm['image_id'], datacenter_vim_id)
+ self.logger.debug(cmd)
+ self.cur.execute(cmd)
+ if self.cur.rowcount==1:
+ vim_image_dict = self.cur.fetchone()
+ vm['vim_image_id']=vim_image_dict['vim_id']
+ if vm['flavor_id']:
+ cmd = "SELECT vim_id FROM datacenters_flavors WHERE flavor_id='{}' AND " \
+ "datacenter_vim_id='{}'".format(vm['flavor_id'], datacenter_vim_id)
+ self.logger.debug(cmd)
+ self.cur.execute(cmd)
+ if self.cur.rowcount==1:
+ vim_flavor_dict = self.cur.fetchone()
+ vm['vim_flavor_id']=vim_flavor_dict['vim_id']
#interfaces
cmd = "SELECT uuid,internal_name,external_name,net_id,type,vpci,mac,bw,model,ip_address," \