From: Paolo Lungaroni Date: Wed, 14 Feb 2018 17:05:02 +0000 (+0100) Subject: Bug 462 (Enhancement) - Add support for Xen and Unikernels X-Git-Tag: v3.1.0 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=50557c2e90ad65d8d9459063bd83d5e0b2e02f37;p=osm%2Fopenvim.git Bug 462 (Enhancement) - Add support for Xen and Unikernels Change-Id: I1ea87eccb96d43f52e43a6e4c4232a82c24a8c46 Signed-off-by: Paolo Lungaroni --- diff --git a/database_utils/migrate_vim_db.sh b/database_utils/migrate_vim_db.sh index e8415e4..9d59b2b 100755 --- a/database_utils/migrate_vim_db.sh +++ b/database_utils/migrate_vim_db.sh @@ -33,7 +33,7 @@ DBPORT="3306" DBNAME="vim_db" QUIET_MODE="" #TODO update it with the last database version -LAST_DB_VERSION=22 +LAST_DB_VERSION=23 # Detect paths MYSQL=$(which mysql) @@ -190,6 +190,7 @@ fi #[ $OPENVIM_VER_NUM -ge 5017 ] && DATABASE_TARGET_VER_NUM=20 #0.5.17 => 20 #[ $OPENVIM_VER_NUM -ge 5018 ] && DATABASE_TARGET_VER_NUM=21 #0.5.18 => 21 #[ $OPENVIM_VER_NUM -ge 5021 ] && DATABASE_TARGET_VER_NUM=22 #0.5.21 => 22 +#[ $OPENVIM_VER_NUM -ge 5024 ] && DATABASE_TARGET_VER_NUM=23 #0.5.24 => 23 # TODO ... put next versions here function upgrade_to_1(){ @@ -770,6 +771,25 @@ function downgrade_from_22(){ sql "DELETE FROM schema_version WHERE version_int = '22';" } +function upgrade_to_23(){ + echo " Add 'hypervisor' and 'os_type' column to 'instances' table" + sql "ALTER TABLE instances ADD COLUMN hypervisor enum('kvm','xen-unik','xenhvm') NOT NULL DEFAULT 'kvm' AFTER flavor_id;" + sql "ALTER TABLE instances ADD COLUMN os_image_type VARCHAR(24) NOT NULL DEFAULT 'other' AFTER hypervisor;" + echo " Add 'hypervisors' column to 'hosts' table" + sql "ALTER TABLE hosts ADD COLUMN hypervisors VARCHAR(255) NOT NULL DEFAULT 'kvm' AFTER features;" + sql "INSERT INTO schema_version (version_int, version, openvim_ver, comments, date) "\ + "VALUES (23, '0.23', '0.5.24', 'Add hypervisor, os_type to instances and add hypervisors to hosts', '2018-03-20');" +} + +function downgrade_from_23(){ + echo " Remove 'hypervisor' and 'os_type' column from 'instances' table" + sql "ALTER TABLE instances DROP COLUMN hypervisor;" + sql "ALTER TABLE instances DROP COLUMN os_image_type;" + echo " Remove 'hypervisors' column from 'hosts' table" + sql "ALTER TABLE hosts DROP COLUMN hypervisors;" + sql "DELETE FROM schema_version WHERE version_int = '23';" +} + # TODO ... put functions here # echo "db version = "${DATABASE_VER_NUM} diff --git a/osm_openvim/host_thread.py b/osm_openvim/host_thread.py index 78be1c9..34e8f07 100644 --- a/osm_openvim/host_thread.py +++ b/osm_openvim/host_thread.py @@ -50,7 +50,7 @@ class host_thread(threading.Thread): lvirt_module = None def __init__(self, name, host, user, db, db_lock, test, image_path, host_id, version, develop_mode, - develop_bridge_iface, password=None, keyfile = None, logger_name=None, debug=None): + develop_bridge_iface, password=None, keyfile = None, logger_name=None, debug=None, hypervisors=None): """Init a thread to communicate with compute node or ovs_controller. :param host_id: host identity :param name: name of the thread @@ -99,6 +99,14 @@ class host_thread(threading.Thread): self.pending_terminate_server =[] #list with pairs (time,server_uuid) time to send a terminate for a server being destroyed self.next_update_server_status = 0 #time when must be check servers status +####### self.hypervisor = "kvm" #hypervisor flag (default: kvm) + if hypervisors: + self.hypervisors = hypervisors + else: + self.hypervisors = "kvm" + + self.xen_hyp = True if "xen" in self.hypervisors else False + self.hostinfo = None self.queueLock = threading.Lock() @@ -107,10 +115,16 @@ class host_thread(threading.Thread): self.run_command_session = None self.error = None self.localhost = True if host == 'localhost' else False - self.lvirt_conn_uri = "qemu+ssh://{user}@{host}/system?no_tty=1&no_verify=1".format( - user=self.user, host=self.host) + + if self.xen_hyp: + self.lvirt_conn_uri = "xen+ssh://{user}@{host}/?no_tty=1&no_verify=1".format( + user=self.user, host=self.host) + else: + self.lvirt_conn_uri = "qemu+ssh://{user}@{host}/system?no_tty=1&no_verify=1".format( + user=self.user, host=self.host) if keyfile: self.lvirt_conn_uri += "&keyfile=" + keyfile + self.remote_ip = None self.local_ip = None @@ -488,8 +502,13 @@ class host_thread(threading.Thread): bus_ide = True if bus=='ide' else False self.xml_level = 0 + hypervisor = server.get('hypervisor', 'kvm') + os_type_img = server.get('os_image_type', 'other') - text = "" + if hypervisor[:3] == 'xen': + text = "" + else: + text = "" #get topology topo = server_metadata.get('topology', None) if topo == None and 'metadata' in dev_list[0]: @@ -563,12 +582,26 @@ class host_thread(threading.Thread): if dev['type']=='cdrom' : boot_cdrom = True break - text += self.tab()+ '' + \ - self.inc_tab() + "hvm" - if boot_cdrom: - text += self.tab() + "" - text += self.tab() + "" + \ - self.dec_tab()+'' + if hypervisor == 'xenhvm': + text += self.tab()+ '' + \ + self.inc_tab() + "hvm" + text += self.tab() + "/usr/lib/xen/boot/hvmloader" + if boot_cdrom: + text += self.tab() + "" + text += self.tab() + "" + \ + self.dec_tab()+'' + elif hypervisor == 'xen-unik': + text += self.tab()+ '' + \ + self.inc_tab() + "xen" + text += self.tab() + "" + str(dev_list[0]['source file']) + "" + \ + self.dec_tab()+'' + else: + text += self.tab()+ '' + \ + self.inc_tab() + "hvm" + if boot_cdrom: + text += self.tab() + "" + text += self.tab() + "" + \ + self.dec_tab()+'' #features text += self.tab()+''+\ self.inc_tab()+'' +\ @@ -587,14 +620,29 @@ class host_thread(threading.Thread): self.tab() + "preserve" + \ self.tab() + "restart" + \ self.tab() + "restart" - text += self.tab() + "" + \ - self.inc_tab() + "/usr/libexec/qemu-kvm" + \ - self.tab() + "" +\ - self.inc_tab() + "" + \ - self.dec_tab() + "" +\ - self.tab() + "" + \ - self.inc_tab()+ "" + \ - self.dec_tab()+'' + if hypervisor == 'xenhvm': + text += self.tab() + "" + \ + self.inc_tab() + "/usr/bin/qemu-system-i386" + \ + self.tab() + "" +\ + self.inc_tab() + "" + \ + self.dec_tab() + "" +\ + self.tab() + "" + \ + self.inc_tab()+ "" + \ + self.dec_tab()+'' #In some libvirt version may be: /usr/lib64/xen/bin/qemu-dm (depends on distro) + elif hypervisor == 'xen-unik': + text += self.tab() + "" + \ + self.tab() + "" + \ + self.inc_tab()+ "" + \ + self.dec_tab()+'' + else: + text += self.tab() + "" + \ + self.inc_tab() + "/usr/libexec/qemu-kvm" + \ + self.tab() + "" +\ + self.inc_tab() + "" + \ + self.dec_tab() + "" +\ + self.tab() + "" + \ + self.inc_tab()+ "" + \ + self.dec_tab()+'' if windows_os: text += self.tab() + "" + \ self.tab() + "" + \ @@ -605,6 +653,15 @@ class host_thread(threading.Thread): self.dec_tab() + "" + \ self.tab() + "" + \ self.tab() + "" #TODO revisar + elif hypervisor == 'xen-unik': + pass + else: + text += self.tab() + "" + \ + self.tab() + "" + \ + self.tab() + "" + \ + self.tab() + "" #> self.tab()+'\n' +\ #> self.dec_tab()+'\n' +\ @@ -621,7 +678,7 @@ class host_thread(threading.Thread): vd_index = 'a' for dev in dev_list: bus_ide_dev = bus_ide - if dev['type']=='cdrom' or dev['type']=='disk': + if (dev['type']=='cdrom' or dev['type']=='disk') and hypervisor != 'xen-unik': if dev['type']=='cdrom': bus_ide_dev = True text += self.tab() + "" @@ -656,6 +713,8 @@ class host_thread(threading.Thread): dev_text = dev_text.replace('__dev__', vd_index) vd_index = chr(ord(vd_index)+1) text += dev_text + elif hypervisor == 'xen-unik': + pass else: return -1, 'Unknown device type ' + dev['type'] @@ -696,6 +755,8 @@ class host_thread(threading.Thread): vlan = content[0]['provider'].replace('OVS:', '') text += self.tab() + "" + \ self.inc_tab() + "" + if hypervisor == 'xenhvm' or hypervisor == 'xen-unik': + text += self.tab() + "