Browse Source

Ajout du support OpenNebula HA dans Hâpy

Ajouter la possibilité de créer une grappe haute disponibilité entre
plusieurs Hâpy (https://docs.opennebula.org/5.6/advanced_components/ha/index.html)

Pré-requis : Les datastores doivent être partagés entre tous les Hâpy
via NFS ou tout autre système de fichiers accécibles de manière
concurrente entre les serveurs (Glusterfs, Ceph, DRBD).

Pour faire ce développement nous nous sommes basés sur eole-glusterfs
qui permet de créer une grappe glusterfs (https://dev-eole.ac-dijon.fr/projects/eole-glusterfs)
Philippe Caseiro 2 months ago
parent
commit
78a27b4fdd

+ 1
- 1
diagnose/04-virtualisation View File

@@ -80,7 +80,7 @@ then
80 80
   echo ""
81 81
 else
82 82
   for VM in $VMs ; do
83
-    NAME=$( one "onevm show $VM" | grep 'NAME' | cut -d: -f2 )
83
+    NAME=$( one "onevm show $VM" | grep '^NAME' | cut -d: -f2 )
84 84
     STAT=$(one "onevm show $VM" | grep '^STATE'  | cut -d: -f2 | tr -d ' ' )
85 85
     printf ".  %${len_pf}s => " "$NAME"
86 86
     eOneStatus "$STAT"

+ 102
- 9
dicos/29_one-master.xml View File

@@ -4,10 +4,13 @@
4 4
         <!--file filelist='onesinglenode' name='/etc/one/sunstone-server.conf' rm='True' mkdir='True'/-->
5 5
         <file filelist='onesinglenode' name='/etc/one/vmm_exec/vmm_exec_kvm.conf' rm='True' mkdir='True'/>
6 6
         <file filelist='onesinglenode' name='/etc/one/oned.conf' rm='True'/>
7
+        <file filelist='onesinglenode' name='/etc/one/sched.conf' rm='True'/>
7 8
         <file filelist='onesinglenode' name='/var/lib/one/remotes/etc/vnm/OpenNebulaNetwork.conf' rm='True' mkdir='True'/>
8 9
         <file filelist='onesinglenode' name='/etc/one/auth/ldap_auth.conf'/>
10
+        <file filelist='one_ha' name='/usr/share/eole/bastion/data/60-one' mode='755'/>
9 11
 
10 12
         <service>opennebula</service>
13
+        <service>opennebula-scheduler</service>
11 14
 
12 15
         <service_access service='one-ssh'>
13 16
             <tcpwrapper>sshd</tcpwrapper>
@@ -16,6 +19,19 @@
16 19
         <service_restriction service='one-ssh'>
17 20
             <ip interface='eth0' ip_type='SymLinkOption'>adresse_ip_eth0</ip>
18 21
         </service_restriction>
22
+
23
+        <service_access service='sunstone'>
24
+            <port port_type="SymLinkOption">port_sunstone</port>
25
+            <port port_type="SymLinkOption">vnc_proxy_port_sunstone</port>
26
+        </service_access>
27
+
28
+        <service_access service='sunstone_xmlrpc'>
29
+            <port service_accesslist="sunstone_xmlrpc">2633</port>
30
+        </service_access>
31
+
32
+        <service_restriction service='sunstone_xmlrpc'>
33
+            <ip interface='one_node_int_name' interface_type='SymLinkOption' ip_type='SymLinkOption'>one_nodes</ip>
34
+        </service_restriction>
19 35
     </files>
20 36
     <variables>
21 37
         <family name='general'>
@@ -30,6 +46,25 @@
30 46
             <variable name='one_cluster_name' type='string' description="Nom de la grappe OpenNebula par défaut" mode='expert'>
31 47
                 <value>default</value>
32 48
             </variable>
49
+
50
+            <!-- Base de donnée -->
51
+            <variable name="one_database_type" description="Moteur de base de données a utiliser" type="string" mode="expert">
52
+               <value>sqlite</value>
53
+            </variable>
54
+            <variable name="one_database_host" description="Adresse du serveur de base de données (mySQL uniquement)"  mandatory="True" mode="expert"/>
55
+            <variable name="one_database_port" description="Port d'écoute du serveur de base de données" mode="expert" type="number" mandatory="True">
56
+                <value>3306</value>
57
+            </variable>
58
+            <variable name="one_database_name" description="Nom de la base de données" type="string" mandatory="True">
59
+                <value>onedb</value>
60
+            </variable>
61
+            <variable name="one_database_user" description="Utilisateur pour se connecter à la base de données" type="string" mandatory="True">
62
+                <value>one</value>
63
+            </variable>
64
+            <variable name="one_database_pass" description="Mot de passe pour se connecter à la base de données" type="password" mandatory="True"/>
65
+            <variable name="one_database_connections" description="Nombre de connection à la base de données" type="number" mandatory="True" mode="expert"><value>50</value></variable>
66
+
67
+            <!-- VNETS -->
33 68
             <variable name='vnet_pilote' type='string'  description='Pilote utilisé pour le réseau virtuel' hidden='True' />
34 69
             <variable name='vnets'             type='string'  description="Nom du réseau virtuel à plage d'adresse IP" multi='True'/>
35 70
             <variable name='vnet_range_start'  type='ip'      description='Première IP de la plage' mandatory="True"/>
@@ -68,11 +103,16 @@
68 103
             <variable name='activer_hooks' type='oui/non' description="Utiliser des hooks personnalisés" mode='expert'>
69 104
                 <value>non</value>
70 105
             </variable>
71
-            <variable name='activer_multinode' description="Activer l'intégration de plusieurs nœuds de virtualisation" mode='expert' type='oui/non'>
106
+            <variable name='activer_one_ha' type='oui/non' description="Activer le support pour la haute disponibilité OpenNebula" mode='expert'>
72 107
                 <value>non</value>
73 108
             </variable>
74
-            <variable name='one_nodes' type='string' description="Nom du nœud de virtualisation" multi='True' mandatory='True'/>
75
-            <variable name='node_ip' type='ip' description="Adresse IP du nœud de virtualisation" mandatory='True'/>
109
+            <variable name='activer_multinode' description="Activer l'intégration de plusieurs nœuds de virtualisation" mode='expert' type='oui/non'/>
110
+            <variable name='one_nodes' type='domain' description="Nom du nœud de virtualisation" multi='True' mandatory='True'/>
111
+            <variable name="one_ha_server_index" description="Index du serveur dans la liste des nœuds de virtualisation" type="number" mandatory="True"/>
112
+            <variable name='one_node_int' type='domain' description="Interface de communication des nœuds" mandatory='True'/>
113
+            <variable name='one_node_int_name' type='domain' description="Nom de l'interface de communication des nœuds"/>
114
+            <variable name="one_vip" description="Adresse IP de la VIP OpenNebula" type="ip" mandatory="True"/>
115
+            <variable name="one_vip_mask" description="Masque de sous-réseau de la VIP OpenNebula" type="netmask" mandatory="True"/>
76 116
         </family>
77 117
         <family name='Modèle' icon='cloud'>
78 118
             <variable name='hapy_init_master' type='oui/non' description="Activer l'auto-création du modèle de machine virtuelle pour installer un module EOLE">
@@ -106,9 +146,10 @@
106 146
             <variable name='hapy_user_hook_arguments' type='string' description="Arguments à passer au script (arguments)" mode='expert'/>
107 147
         </family>
108 148
         <separators>
149
+            <separator name="one_database_type">Configuration de la base de données</separator>
109 150
             <separator name='vnet_pilote'>Configuration des réseaux de l'orchestrateur</separator>
110 151
             <separator name='one_ds_system_prefix'>Configuration de l'orchestrateur</separator>
111
-            <separator name='activer_multinode'>Configuration des nœuds de virtualisation</separator>
152
+            <separator name='activer_one_ha'>Configuration des nœuds de virtualisation</separator>
112 153
         </separators>
113 154
     </variables>
114 155
 
@@ -121,6 +162,10 @@
121 162
             <param type="eole" name="condition_1">vnet_pilote</param>
122 163
         </auto>
123 164
 
165
+        <check name="valid_enum" target="one_database_type">
166
+            <param>['sqlite','mysql']</param>
167
+        </check>
168
+
124 169
         <check name='valid_enum' target='one_video_driver'>
125 170
             <param>['qxl','vga','std','cirrus']</param>
126 171
             <param name='checkval'>False</param>
@@ -151,12 +196,61 @@
151 196
             <target type='variable'>arp_cache_poisoning</target>
152 197
         </condition>
153 198
 
199
+        <condition name="disabled_if_in" source="one_database_type">
200
+            <param>sqlite</param>
201
+            <target type="variable">one_database_host</target>
202
+            <target type="variable">one_database_port</target>
203
+            <target type="variable">one_database_name</target>
204
+            <target type="variable">one_database_user</target>
205
+            <target type="variable">one_database_pass</target>
206
+            <target type="variable">one_database_connections</target>
207
+        </condition>
208
+
209
+        <check name="valid_enum" target="one_node_int">
210
+            <param>['0','1','2','3','4']</param>
211
+        </check>
212
+        <auto name='concat' target='one_node_int_name'>
213
+            <param>eth</param>
214
+            <param type='eole'>one_node_int</param>
215
+        </auto>
216
+
154 217
         <condition name='disabled_if_in' source='activer_multinode'>
155 218
             <param>non</param>
156 219
             <target type='variable'>one_nodes</target>
157
-            <target type='variable'>node_ip</target>
220
+            <target type='variable'>one_node_int</target>
221
+            <target type='variable'>one_node_int_name</target>
222
+        </condition>
223
+        <fill name='calc_val' target='activer_multinode'>
224
+            <param type='eole' name='valeur'>activer_one_ha</param>
225
+        </fill>
226
+        <condition name='frozen_if_in' source='activer_one_ha'>
227
+            <param>oui</param>
228
+            <target type='variable'>activer_multinode</target>
229
+        </condition>
230
+
231
+        <condition name='disabled_if_in' source='activer_one_ha'>
232
+            <param>non</param>
233
+            <target type='variable'>one_ha_server_index</target>
234
+            <target type='variable'>one_vip</target>
235
+            <target type='variable'>one_vip_mask</target>
236
+            <target type='service_accesslist'>sunstone_xmlrpc</target>
237
+            <target type='filelist'>one_ha</target>
158 238
         </condition>
159 239
 
240
+        <fill name='calc_val' target='one_vip_mask'>
241
+            <param type='eole' name='valeur'>adresse_netmask_eth0</param>
242
+        </fill>
243
+
244
+        <check name="valid_differ" target="adresse_ip_eth0">
245
+            <param type='eole' hidden='False'>one_vip</param>
246
+        </check>
247
+        <check name="valid_differ" target="adresse_ip_gw">
248
+            <param type='eole' hidden='False'>one_vip</param>
249
+        </check>
250
+        <check name="valid_ipnetmask" target="one_vip_mask" level="warning">
251
+            <param type='eole'>one_vip</param>
252
+        </check>
253
+
160 254
         <group master='vnets'>
161 255
             <slave>vnet_range_start</slave>
162 256
             <slave>vnet_range_size</slave>
@@ -175,10 +269,6 @@
175 269
             <slave>l2_vnet_vlan_trunk</slave>
176 270
         </group>
177 271
 
178
-        <group master='one_nodes'>
179
-            <slave>node_ip</slave>
180
-        </group>
181
-
182 272
         <check name='valid_enum' target='vnets'>
183 273
             <param>['internet','admin','pedago','dmzpub','dmzpriv','wifi']</param>
184 274
             <param name='checkval'>False</param>
@@ -286,5 +376,8 @@
286 376
         <variable name='hapy_init_master_iso_version'>Version de l'ISO EOLE à télécharger lors de l'initialisation</variable>
287 377
         <variable name='vnets'>Réseau de type IPv4 (niveau 3 du modèle OSI)</variable>
288 378
         <variable name='l2_vnets'>Réseau de type ethernet (niveau 2 du modèle OSI)</variable>
379
+        <variable name='one_ha_server_index'>Le leader à l'index 0, les followers commencent à 1</variable>
380
+        <variable name='activer_one_ha'>Active la possibilité d'intégrer Hâpy dans une grappe de haute disponibilité OpenNebula</variable>
381
+        <variable name="one_vip">Adresse IP virtuelle (VIP) utilisée pour joindre le "Leader" de la grappe, les usagés utiliseront cette IP pour contacter la grappe</variable>
289 382
     </help>
290 383
 </creole>

+ 52
- 19
postservice/30-one-mng View File

@@ -69,6 +69,21 @@ function check_host()
69 69
     return ${res}
70 70
 }
71 71
 
72
+# Fix host creation error from 5.6.1 with sync methode rsync
73
+function sync_host()
74
+{
75
+    CMD="onehost"
76
+    OPT="sync -f --rsync"
77
+    AUTH=$(get_one_auth)
78
+    res=$(su - oneadmin -c "${CMD} ${OPT} --user ${AUTH%:*} --password ${AUTH#*:}")
79
+    if [[ ${?} -ne 0  ]]
80
+    then
81
+        error "Hosts sync failed"
82
+    else
83
+        echo "Hosts sync OK"
84
+    fi
85
+}
86
+
72 87
 function manage_host()
73 88
 {
74 89
     NAME=${1}
@@ -185,9 +200,9 @@ function attach_host()
185 200
 {
186 201
     HOST=${1}
187 202
     CLST=${2}
188
-	# ref https://dev-eole.ac-dijon.fr/issues/16797
203
+    # ref https://dev-eole.ac-dijon.fr/issues/16797
189 204
     #CLST_ID=$(get_cluster_id_by_name ${CLST})
190
-	CLST_ID=0
205
+    CLST_ID=0
191 206
     HST_ID=$(get_host_id_by_name ${HOST})
192 207
     AUTH=$(get_one_auth)
193 208
     CMD="onecluster"
@@ -249,10 +264,11 @@ function create_datastore()
249 264
 {
250 265
     ds_type="${1}"
251 266
     ds_name="${2}"
252
-	# ref https://dev-eole.ac-dijon.fr/issues/16797
267
+	local ha=$(CreoleGet activer_one_ha)
268
+    # ref https://dev-eole.ac-dijon.fr/issues/16797
253 269
     #ds_cluster="${3}"
254 270
 
255
-    if [[ $(CreoleGet activer_multinode 2>&1) == 'oui' ]]
271
+    if [[ $(CreoleGet activer_multinode 2>&1) == 'oui' ]] && [[ ${ha} == "non" ]]
256 272
     then
257 273
       SYS_TM_MAD='ssh'
258 274
       ISO_TM_MAD='ssh'
@@ -300,7 +316,7 @@ __EOF__
300 316
     RUN=$(${cmd} ${opt})
301 317
     if [[ ${?} -eq 0 ]]
302 318
     then
303
-		# ref https://dev-eole.ac-dijon.fr/issues/16797
319
+        # ref https://dev-eole.ac-dijon.fr/issues/16797
304 320
         #attach_ds_to_cluster ${ds_name} ${ds_cluster}
305 321
         rm ${TMPL_FILE}
306 322
         return 0
@@ -316,13 +332,14 @@ function update_datastore()
316 332
   local cmd="onedatastore"
317 333
   local opt="show"
318 334
   local multinode=$(CreoleGet activer_multinode 2>&1)
335
+  local ha=$(CreoleGet activer_one_ha)
319 336
   ds_type=""
320 337
   ds_mad=""
321 338
   ds_name=""
322 339
 
323 340
   TMPL_FILE=$(mktemp)
324 341
 
325
-  if [[ ${multinode}  == 'oui' ]]
342
+  if [[ ${multinode}  == 'oui' ]] && [[ ${ha} == "non" ]]
326 343
   then
327 344
     SYS_TM_MAD='ssh'
328 345
     ISO_TM_MAD='ssh'
@@ -384,11 +401,11 @@ __EOF__
384 401
 
385 402
 function manage_datastores()
386 403
 {
387
-	# ref https://dev-eole.ac-dijon.fr/issues/16797
404
+    # ref https://dev-eole.ac-dijon.fr/issues/16797
388 405
     #cluster=${1}
389 406
     AUTH=$(get_one_auth)
390 407
 
391
-	# ref https://dev-eole.ac-dijon.fr/issues/16797
408
+    # ref https://dev-eole.ac-dijon.fr/issues/16797
392 409
     #SYSTEM_DS="$(CreoleGet 'one_ds_system_prefix')${cluster}"
393 410
     SYSTEM_DS="$(CreoleGet 'one_ds_system_prefix')default"
394 411
     ISO_DS=$(CreoleGet 'one_ds_iso_name')
@@ -398,7 +415,7 @@ function manage_datastores()
398 415
     sid=$(get_ds_id_by_name ${SYSTEM_DS})
399 416
     if [[ ${sid} = "ERR" ]]
400 417
     then
401
-	  # ref https://dev-eole.ac-dijon.fr/issues/16797
418
+      # ref https://dev-eole.ac-dijon.fr/issues/16797
402 419
       #create_datastore "SYSTEM" "${SYSTEM_DS}" "${cluster}"
403 420
       create_datastore "SYSTEM" "${SYSTEM_DS}"
404 421
     else
@@ -408,7 +425,7 @@ function manage_datastores()
408 425
     imgid=$(get_ds_id_by_name ${IMAGE_DS})
409 426
     if [[ ${imgid} = "ERR" ]]
410 427
     then
411
-	  # ref https://dev-eole.ac-dijon.fr/issues/16797
428
+      # ref https://dev-eole.ac-dijon.fr/issues/16797
412 429
       #create_datastore "IMAGE" "${IMAGE_DS}" "${cluster}"
413 430
       create_datastore "IMAGE" "${IMAGE_DS}"
414 431
     else
@@ -418,7 +435,7 @@ function manage_datastores()
418 435
     isoid=$(get_ds_id_by_name ${ISO_DS})
419 436
     if [[ ${isoid} = "ERR" ]]
420 437
     then
421
-	  # ref https://dev-eole.ac-dijon.fr/issues/16797
438
+      # ref https://dev-eole.ac-dijon.fr/issues/16797
422 439
       #create_datastore "ISO" "${ISO_DS}" "${cluster}"
423 440
       create_datastore "ISO" "${ISO_DS}"
424 441
     else
@@ -430,22 +447,30 @@ function manage_datastores()
430 447
 function main()
431 448
 {
432 449
     wait_true_retcode "Wait for oned to be started" "onecluster show 0 > /dev/null"
450
+    if [ "$(CreoleGet activer_one_ha)" = "oui" ]; then
451
+        if [ "$(CreoleGet one_ha_server_index)" != "0" ]; then
452
+            # ne pas faire sur les followers
453
+            return
454
+        fi
455
+    fi
433 456
     #
434 457
     # Rename default cluster
435 458
     clst_name=$(CreoleGet one_cluster_name)
436 459
     rename_default_cluster "${clst_name}"
437 460
 
438
-	# Wait 4 seconds for service (ref #16848)
439
-	sleep 4
461
+    # Wait 4 seconds for service (ref #16848)
462
+    sleep 4
440 463
 
441 464
     #
442 465
     # Creating Host
443 466
     #
444
-	if [[ $(CreoleGet eole_module non) != 'hapy-master' ]]
445
-	then
446
-		host=$(CreoleGet nom_machine)
447
-		manage_host ${host}
448
-	fi
467
+    if [ ! "$(CreoleGet activer_one_ha)" = "oui" ]; then
468
+        if [[ $(CreoleGet eole_module non) != 'hapy-master' ]]
469
+        then
470
+            host=$(CreoleGet nom_machine)
471
+            manage_host ${host}
472
+        fi
473
+    fi
449 474
 
450 475
     #
451 476
     # Attaching Host to the Cluster
@@ -453,9 +478,17 @@ function main()
453 478
     attach_host ${host} "${clst_name}"
454 479
 
455 480
     #
481
+    # Force host synchronisation
482
+    #
483
+    sync_host
484
+
485
+    #
456 486
     # Création des Datastores
457 487
     #
458 488
     manage_datastores "${clst_name}"
489
+
459 490
 }
460 491
 
461
-main
492
+main $@
493
+
494
+exit 0

+ 8
- 0
postservice/31-one-netmng View File

@@ -303,6 +303,14 @@ def main():
303 303
     logger.debug(u"Configure OpenNebula networks")
304 304
 
305 305
     client = CreoleClient()
306
+    
307
+    mode_ha = client.get_creole('activer_one_ha')
308
+    if mode_ha == "oui":
309
+        indx = client.get_creole('one_ha_server_index')
310
+        if indx != 0:
311
+            # Mode HA is on and we are not in the Leader
312
+            exit(0)
313
+
306 314
     one_client = OneClient('oneadmin')
307 315
     networks = []
308 316
     cluster = client.get_creole('one_cluster_name')

+ 15
- 0
postservice/99-z-ha View File

@@ -0,0 +1,15 @@
1
+#!/bin/bash
2
+
3
+ha=$(CreoleGet activer_one_ha non)
4
+if [[ ${ha} == "oui" ]]
5
+then
6
+   indx=$(CreoleGet one_ha_server_index)
7
+else
8
+   indx="0"
9
+fi
10
+
11
+if [[ ${1} == "instance" ]] && [[ ${indx} == "0" ]]
12
+then
13
+   /usr/share/eole/sbin/onehost_create_all
14
+fi
15
+exit 0

+ 62
- 27
posttemplate/90-one-db View File

@@ -6,44 +6,79 @@
6 6
 #
7 7
 
8 8
 . /usr/lib/eole/ihm.sh
9
+script="$1"
9 10
 
10 11
 function clean_backups()
11 12
 {
12
-	file=${1}
13
-	bcks=($(ls ${file}_*))
14
-	nbbck=$(expr ${#bcks[@]} - 2)
15
-
16
-
17
-	if [[ ${nbbck} -gt 1 ]]
18
-	then
19
-		EchoGras "Cleaning up old backups !"
20
-		for idx in `seq 0 ${nbbck}`
21
-		do
22
-			rm -f ${bcks[${idx}]}
23
-		done
24
-	fi
13
+    file=${1}
14
+    ls ${file}_* > /dev/null 2>&1
15
+    if [ $? = 0 ]; then
16
+        bcks=($(ls ${file}_*))
17
+        nbbck=$(expr ${#bcks[@]} - 2)
18
+
19
+
20
+        if [[ ${nbbck} -gt 1 ]]
21
+        then
22
+            EchoGras "Cleaning up old backups !"
23
+            for idx in `seq 0 ${nbbck}`
24
+            do
25
+                rm -f ${bcks[${idx}]}
26
+            done
27
+        fi
28
+    fi
25 29
 }
26 30
 
27 31
 function updateDB()
28 32
 {
29
-	local dbfile='/var/lib/one/one.db'
30
-	local cmd="onedb"
31
-	local res=0
32
-
33
-	if [[ -f ${dbfile} ]]
34
-	then
35
-		$cmd upgrade -f -s ${dbfile}
36
-		res=${?}
37
-		clean_backups ${dbfile}
38
-		return ${res}
39
-	else
40
-		return 0
41
-	fi
33
+    local dbfile='/var/lib/one/one.db'
34
+    local cmd="onedb"
35
+    local res=0
36
+
37
+    if [[ -f ${dbfile} ]]
38
+    then
39
+        if [ $(CreoleGet one_database_type) = "mysql" ]; then
40
+            if [ $(CreoleGet one_ha_server_index 0) = "0" ]; then
41
+                HOST=$(CreoleGet one_database_host)
42
+                DB=$(CreoleGet one_database_name)
43
+                USER=$(CreoleGet one_database_user)
44
+                PASS=$(CreoleGet one_database_pass)
45
+                $cmd upgrade -f -u $USER -p $PASS -d $DB -S $HOST
46
+            fi
47
+        else
48
+            $cmd upgrade -f -s ${dbfile}
49
+        fi
50
+        res=${?}
51
+        clean_backups ${dbfile}
52
+        return ${res}
53
+    else
54
+        return 0
55
+    fi
42 56
 }
43 57
 
58
+function to_mysql() {
59
+    if [ "$script" = 'instance' ] && [ $(CreoleGet one_database_type) = "mysql" ] && [ $(CreoleGet one_ha_server_index 0) = "0" ]; then
60
+        Question_ouinon "Voulez-vous migrer de SQLite à Mysql ?" "True" "oui" "warn"
61
+        rep=$(echo "$?")
62
+        if [ "$rep" == "0" ]; then
63
+            # do not recover db on follower
64
+            HOST=$(CreoleGet one_database_host)
65
+            DB=$(CreoleGet one_database_name)
66
+            USER=$(CreoleGet one_database_user)
67
+            PASS=$(CreoleGet one_database_pass)
68
+            cp -a /etc/one/oned.conf /etc/one/oned.conf.ori
69
+            # HA ne doit pas être activer pour la migration
70
+            CreoleCat -s /usr/share/eole/creole/distrib/oned-ha-mysql.conf -o /etc/one/oned.conf
71
+            oned -i
72
+            onedb sqlite2mysql -s /var/lib/one/one.db -u $USER -p $PASS -d $DB -S $HOST
73
+            cp -a /etc/one/oned.conf.ori /etc/one/oned.conf
74
+        fi
75
+    fi
76
+}
77
+
78
+echo
79
+to_mysql
44 80
 echo
45 81
 EchoGras "Mise à jour de la base de données ONE"
46 82
 echo
47 83
 updateDB
48
-echo
49 84
 exit ${?}

+ 7
- 0
preservice/30-one-auth View File

@@ -8,3 +8,10 @@ if [ -z "${auth_mode}" ]; then
8 8
 else
9 9
     ln -s /var/lib/one/remotes/auth/{${auth_mode},default}
10 10
 fi
11
+
12
+# creation de la base /var/lib/one/one.db
13
+if [ ! -e /var/lib/one/one.db ]; then
14
+    systemctl daemon-reload
15
+    systemctl start opennebula.service
16
+fi
17
+exit 0

+ 26
- 0
preservice/31-one-ha View File

@@ -0,0 +1,26 @@
1
+#!/bin/bash
2
+
3
+HA=$(CreoleGet activer_one_ha non)
4
+DBMODE=$(CreoleGet one_database_type "none")
5
+LEADER_DB_FILE="/var/lib/one/one.db.leader"
6
+DBFILE="/var/lib/one/one.db"
7
+
8
+# If HA is enabled and a leader database file is present
9
+# we restore the leader database.
10
+
11
+if [[ ${HA} == "oui" ]] && [[ ${DBMODE} == "sqlite" ]]
12
+then
13
+   if [[ -f ${LEADER_DB_FILE} ]]
14
+   then
15
+	   if [[ $(CreoleGet one_ha_server_index) != "0" ]]
16
+	   then
17
+         onedb restore --sqlite ${DBFILE} ${LEADER_DB_FILE} -f
18
+         if [[ $? -eq 0 ]]
19
+         then
20
+            rm ${LEADER_DB_FILE}
21
+            exit ${?}
22
+         fi
23
+      fi
24
+   fi
25
+fi
26
+exit 0

+ 135
- 35
scripts/onehost_create_all View File

@@ -7,24 +7,73 @@
7 7
 . /usr/lib/eole/ihm.sh
8 8
 
9 9
 #
10
-# NAME: copy_ssh_id 
10
+# NAME: copy_ssh_id
11 11
 # AIM: Copy the ssh key on the host
12
-# PARAM: the hostname of the node 
12
+# PARAM: the hostname of the node
13 13
 #
14 14
 function copy_ssh_id()
15 15
 {
16
-    local ip=${1}
16
+    local host=${1}
17 17
 
18
-    ssh ${ip} bash -s <<EOF
19
-echo $(cat ~oneadmin/.ssh/id_rsa.pub) > /tmp/one-master.key.pub
20
-if ! grep -qs /tmp/one-master.key.pub ~oneadmin/.ssh/authorized_keys
21
-then
22
-	cat /tmp/one-master.key.pub >> ~oneadmin/.ssh/authorized_keys
23
-	chown oneadmin:oneadmin ~oneadmin/.ssh/authorized_keys
18
+    CLEF=$(cat ~oneadmin/.ssh/id_rsa.pub)
19
+    ssh ${host} bash <<EOF
20
+if ! grep -qs "$CLEF" ~oneadmin/.ssh/authorized_keys; then
21
+    echo "$CLEF" >> ~oneadmin/.ssh/authorized_keys
22
+    chown oneadmin:oneadmin ~oneadmin/.ssh/authorized_keys
23
+    su - oneadmin -c "ssh-keyscan $host"
24
+    cat ~oneadmin/.ssh/id_rsa.pub >> ~oneadmin/.ssh/authorized_keys
24 25
 fi
25
-rm -f /tmp/one-master.key.pub
26 26
 EOF
27
-	return ${?}
27
+    [[ ${?} -ne 0 ]] && EchoRouge "Erreur lors de l'échange de clés SSH avec le noeud ${host}"
28
+    REMOTEKEY=$(su - oneadmin -c "ssh ${host} 'cat ~oneadmin/.ssh/id_rsa.pub'")
29
+    if ! grep -qs "$REMOTEKEY" ~oneadmin/.ssh/authorized_keys; then
30
+        su - oneadmin -c "echo ${REMOTEKEY} >> ~oneadmin/.ssh/authorized_keys"
31
+        su - oneadmin -c "ssh-keyscan $host"
32
+    fi
33
+}
34
+
35
+function copy_files()
36
+{
37
+    local host=${1}
38
+    su - oneadmin -c "scp .one/* ${host}:.one/"
39
+}
40
+
41
+
42
+#
43
+# NAME: sync_db
44
+# AIM: Sync onedb in HA and sqlite mode
45
+# PARAM: the hostname of the node
46
+#
47
+function sync_db()
48
+{
49
+    local ip=${1}
50
+    local user="oneadmin"
51
+    local DBFILE="/var/lib/one/one.db"
52
+    local DBBCK="/tmp/one.db.bck"
53
+    local ret=0
54
+
55
+    if [[ ! -f ${DBBCK} ]]
56
+    then
57
+        cmd="onedb backup --sqlite ${DBFILE} ${DBBCK}"
58
+        ret=$(su - ${user} -c -- "${cmd}")
59
+    fi
60
+
61
+    cmd2="scp ${DBBCK} ${ip}:${DBFILE}.leader"
62
+    ret=$(su - ${user} -c -- "${cmd2}")
63
+    return ${?}
64
+}
65
+
66
+#
67
+# NAME: sync_nodes
68
+# AIM: force nodes sync with rsync (ONE 5.6.1 bug)
69
+# PARAM: none
70
+#
71
+function sync_nodes()
72
+{
73
+    # Need to sync hosts with rsync after creation, ONE 5.6.1 bug
74
+    cmd2="onehost sync -f --rsync"
75
+    ret2=$(su - ${ONEUSER} -c -- "${cmd2}")
76
+    return ${?}
28 77
 }
29 78
 
30 79
 #
@@ -35,21 +84,28 @@ EOF
35 84
 function register_node()
36 85
 {
37 86
     cmd="onehost create -i kvm -v kvm -c 0 ${1}"
87
+
38 88
     ret=$(su - ${ONEUSER} -c -- "${cmd}")
39
-    return $?
89
+    if [[ ${?} -ne 0  ]]
90
+    then
91
+        EchoRouge "Hosts register failed $res"
92
+    else
93
+        EchoVert "Hosts register OK"
94
+    fi
40 95
 }
41 96
 
97
+
42 98
 #
43 99
 # NAME: wait_node_ok
44 100
 # AIM: Wait until the node is OK or ERROR
45
-# PARAM: The node name 
101
+# PARAM: The node name
46 102
 #
47 103
 function wait_node_ok()
48 104
 {
49
-    local RET=0
50 105
     local cmd="onehost show ${1} | awk '/^STATE/ {print \$3}'"
51 106
     local spinstr='|/-\'
52 107
     local delay=0.75
108
+    local cnt=0
53 109
 
54 110
     while [ 1 ]
55 111
     do
@@ -58,8 +114,10 @@ function wait_node_ok()
58 114
         [[ ${st} == '' ]] && break
59 115
         if [[ ${st} == "ERROR" ]]
60 116
         then
61
-            RET=2
62
-            break
117
+            if [ $cnt -gt 160 ]; then
118
+                EchoRouge "Erreur lors de l'enregistrement du noeud ${host} !"
119
+                break
120
+            fi
63 121
         fi
64 122
 
65 123
         local temp=${spinstr#?}
@@ -67,10 +125,20 @@ function wait_node_ok()
67 125
         local spinstr=$temp${spinstr%"$temp"}
68 126
         sleep $delay
69 127
         printf "\b\b\b\b\b\b"
70
-
128
+        cnt=$((cnt+1))
71 129
     done
72 130
     printf "    \b\b\b\b"
73
-    return ${RET}
131
+}
132
+
133
+function init_ha_leader() {
134
+    # server with index 1 exists if already instanciate
135
+    onezone show 0 | grep -A 3 ^"HA & FEDERATION SYNC STATUS" | tail -n 1 | grep -q ^" 1 "
136
+    if [ ! $? = 0 ]; then
137
+        FOLLOWER=$(CreoleGet one_nodes)
138
+        for follower in $FOLLOWER; do
139
+            onezone server-add 0 --name $follower --rpc http://$follower:2633/RPC2
140
+        done
141
+    fi
74 142
 }
75 143
 
76 144
 #
@@ -79,21 +147,35 @@ function wait_node_ok()
79 147
 HAPY_ACTIF=$(echo $(CreoleGet activer_onesinglenode))
80 148
 if [[ $HAPY_ACTIF == "non" ]]
81 149
 then
82
-	EchoRouge "Le serveur de virtualisation n'est pas activé dans l'interface de configuration du module"
83
-	exit 1
150
+    EchoRouge "Le serveur de virtualisation n'est pas activé dans l'interface de configuration du module"
151
+    exit 1
84 152
 fi
85 153
 
86 154
 HAPY_NODE_SUPPORT=$(echo $(CreoleGet activer_multinode))
87 155
 if [[ $HAPY_NODE_SUPPORT == "non" ]]
88 156
 then
89
-	EchoRouge "Le mode multi-noeuds n'est pas activé dans l'interface de configuration du module"
90
-	exit 1
157
+    EchoRouge "Le mode multi-noeuds n'est pas activé dans l'interface de configuration du module"
158
+    exit 1
91 159
 fi
160
+
161
+HAPY_HA=$(CreoleGet activer_one_ha "non")
162
+
163
+master=1
164
+if [[ ${HAPY_HA} == "oui" ]]; then
165
+    idx=$(CreoleGet one_ha_server_index)
166
+    if [[ ${idx} != "0" ]]; then
167
+        EchoBleu "Mode HA: (on) Index : [${idx}]"
168
+        echo -e "\t$(basename ${0}) doit être lancé uniquement sur le leader (index 0)"
169
+        exit 0
170
+    else
171
+        master=0
172
+    fi
173
+fi
174
+
92 175
 declare -a HAPY_SLV=('')
93
-declare -a HAPY_SLV_IP=('')
94 176
 ONEUSER=$(CreoleGet virt_user)
95 177
 HAPY_SLV=$(echo $(CreoleGet one_nodes) | sed -e "s/\n/ /g")
96
-HAPY_SLV_IP=$(echo $(CreoleGet node_ip) | sed -e "s/\n/ /g")
178
+DBMODE=$(CreoleGet one_database_type "none")
97 179
 
98 180
 echo -e "\n"
99 181
 EchoBleu "Vous allez inscrire un noeud dans une grappe Hâpy"
@@ -101,28 +183,46 @@ EchoBleu "Pour ce faire vous devez vous munir du mot de passe de l'utilisateur '
101 183
 Question_ouinon  "Voulez-vous commencer ?" 'True' "oui"
102 184
 if [[ $? -ne 0 ]]
103 185
 then
104
-	EchoOrange "Abandon de l'enregistrement"
105
-	exit 1
186
+    EchoOrange "Abandon de l'enregistrement"
187
+    exit 1
106 188
 fi
107 189
 
108
-for ((i = 0; i < ${#HAPY_SLV[*]}; i +=1))
109
-do
190
+
191
+for host in ${HAPY_SLV}; do
110 192
     echo -e "\n"
111
-    EchoOrange "Traitement du noeud ${HAPY_SLV[${i}]}"
193
+    EchoOrange "Traitement du noeud ${host}"
112 194
     echo
113 195
     EchoVert " * Gestion des clés SSH"
114 196
     echo
115
-    copy_ssh_id ${HAPY_SLV_IP[${i}]}
116
-	[[ ${?} -ne 0 ]] && EchoRouge "Erreur lors de l'échange de clés SSH avec le noeud ${HAPY_SLV[${i}]}}"
197
+    copy_ssh_id ${host}
198
+    if [ $master = 0 ]; then
199
+        copy_files ${host}
200
+    fi
117 201
 
118 202
     EchoVert " * Enregistrement du noeud"
119
-    register_node ${HAPY_SLV[${i}]}
120
-    wait_node_ok ${HAPY_SLV[${i}]}
121
-    if [[ ${?} -ne 0 ]]
203
+    register_node ${host}
204
+    if [[ ${HAPY_HA} == "oui" ]]
122 205
     then
123
-        EchoRouge "Erreur lors de l'enregistrement du noeud ${HAPY_SLV[${i}]} !"
206
+        if [[ $DBMODE == "sqlite" ]]
207
+        then
208
+            if [[ $(CreoleGet one_ha_server_index) == "0" ]]
209
+            then
210
+                sync_db ${host}
211
+            fi
212
+        fi
213
+    fi
214
+    sync_nodes
215
+    if [[ ${HAPY_HA} != "oui" ]]
216
+        wait_node_ok ${HAPY_SLV[${i}]}
217
+        if [[ ${?} -ne 0 ]]
218
+        then
219
+            EchoRouge "Erreur lors de l'enregistrement du noeud ${HAPY_SLV[${i}]} !"
220
+        fi
124 221
     fi
125 222
 done
126 223
 
224
+if [ $master = 0 ]; then
225
+    init_ha_leader
226
+fi
127 227
 echo -e "\n"
128 228
 EchoVert "Enregistrement des noeuds terminé"

+ 5
- 0
tmpl/60-one View File

@@ -0,0 +1,5 @@
1
+#!/bin/bash
2
+
3
+%for %%host in %%one_nodes
4
+/sbin/iptables -A eth%%{one_node_int}-root -s %%host -p tcp --syn -j ACCEPT
5
+%end for

+ 2
- 0
tmpl/oned-ha-mysql.conf View File

@@ -0,0 +1,2 @@
1
+%set global %%activer_one_ha='non'
2
+%include '/var/lib/creole/oned.conf'

+ 26
- 16
tmpl/oned.conf View File

@@ -78,18 +78,22 @@ SCRIPTS_REMOTE_DIR=/var/tmp/one
78 78
 
79 79
 PORT = 2633
80 80
 
81
+%if %%activer_one_ha == 'non'
81 82
 LISTEN_ADDRESS = "127.0.0.1"
83
+%end if
82 84
 
85
+%if %%one_database_type == "sqlite"
83 86
 DB = [ BACKEND = "sqlite" ]
84
-
87
+%else
85 88
 # Sample configuration for MySQL
86
-# DB = [ BACKEND = "mysql",
87
-#        SERVER  = "localhost",
88
-#        PORT    = 0,
89
-#        USER    = "oneadmin",
90
-#        PASSWD  = "oneadmin",
91
-#        DB_NAME = "opennebula",
92
-#        CONNECTIONS = 50 ]
89
+DB = [ BACKEND = "mysql",
90
+       SERVER  = "%%one_database_host",
91
+       PORT    = %%one_database_port,
92
+       USER    = "%%one_database_user",
93
+       PASSWD  = "%%one_database_pass",
94
+       DB_NAME = "%%one_database_name",
95
+       CONNECTIONS = %%one_database_connections ]
96
+%end if
93 97
 
94 98
 VNC_PORTS = [
95 99
     START    = 5900
@@ -151,7 +155,11 @@ VNC_PORTS = [
151 155
 FEDERATION = [
152 156
     MODE          = "STANDALONE",
153 157
     ZONE_ID       = 0,
158
+%if %%activer_one_ha == 'oui'
159
+    SERVER_ID     = %%one_ha_server_index,
160
+%else
154 161
     SERVER_ID     = -1,
162
+%end if
155 163
     MASTER_ONED   = ""
156 164
 ]
157 165
 
@@ -164,17 +172,19 @@ RAFT = [
164 172
     XMLRPC_TIMEOUT_MS    = 450
165 173
 ]
166 174
 
175
+%if %%activer_one_ha == 'oui'
167 176
 # Executed when a server transits from follower->leader
168
-# RAFT_LEADER_HOOK = [
169
-#     COMMAND = "raft/vip.sh",
170
-#     ARGUMENTS = "leader <interface> <ip_cidr>"
171
-# ]
177
+RAFT_LEADER_HOOK = [
178
+    COMMAND = "raft/vip.sh",
179
+    ARGUMENTS = "leader %%nom_zone_eth0 %%one_vip/%%calc_classe(%%one_vip_mask)"
180
+]
172 181
 
173 182
 # Executed when a server transits from leader->follower
174
-# RAFT_FOLLOWER_HOOK = [
175
-#     COMMAND = "raft/vip.sh",
176
-#     ARGUMENTS = "follower <interface> <ip_cidr>"
177
-# ]
183
+RAFT_FOLLOWER_HOOK = [
184
+    COMMAND = "raft/vip.sh",
185
+    ARGUMENTS = "follower %%nom_zone_eth0 %%one_vip/%%calc_classe(%%one_vip_mask)"
186
+]
187
+%end if
178 188
 
179 189
 #*******************************************************************************
180 190
 # Default showback cost

+ 110
- 0
tmpl/sched.conf View File

@@ -0,0 +1,110 @@
1
+#*******************************************************************************
2
+#                       OpenNebula Configuration file
3
+#*******************************************************************************
4
+
5
+#*******************************************************************************
6
+# Daemon configuration attributes
7
+#-------------------------------------------------------------------------------
8
+#  MESSAGE_SIZE: Buffer size in bytes for XML-RPC responses.
9
+#
10
+#  XMLRPC_TIMEOUT: Seconds to timeout XML-RPC calls to oned
11
+#
12
+#  ONE_XMLRPC: URL to connect to the OpenNebula daemon (oned)
13
+#
14
+#  SCHED_INTERVAL: Seconds between two scheduling actions
15
+#
16
+#  MAX_VM: Maximum number of Virtual Machines scheduled in each scheduling
17
+#          action. Use 0 to schedule all pending VMs each time.
18
+#
19
+#  MAX_DISPATCH: Maximum number of Virtual Machines actually dispatched to a
20
+#                host in each scheduling action
21
+#
22
+#  MAX_HOST: Maximum number of Virtual Machines dispatched to a given host in
23
+#            each scheduling action
24
+#
25
+#  LIVE_RESCHEDS: Perform live (1) or cold migrations (0) when rescheduling a VM
26
+#
27
+#  DEFAULT_SCHED: Definition of the default scheduling algorithm
28
+#    - policy:
29
+#      0 = Packing. Heuristic that minimizes the number of hosts in use by
30
+#          packing the VMs in the hosts to reduce VM fragmentation
31
+#      1 = Striping. Heuristic that tries to maximize resources available for
32
+#          the VMs by spreading the VMs in the hosts
33
+#      2 = Load-aware. Heuristic that tries to maximize resources available for
34
+#          the VMs by using those nodes with less load
35
+#      3 = Custom.
36
+#    - rank: Custom arithmetic expression to rank suitable hosts based in their
37
+#            attributes
38
+#      4 = Fixed. Hosts will be ranked according to the PRIORITY attribute found
39
+#          in the Host or Cluster template.
40
+#
41
+#  DEFAULT_DS_SCHED: Definition of the default storage scheduling algorithm
42
+#    - policy:
43
+#      0 = Packing. Tries to optimize storage usage by selecting the DS with
44
+#          less free space
45
+#      1 = Striping. Tries to optimize I/O by distributing the VMs across
46
+#          datastores.
47
+#      2 = Custom.
48
+#    - rank: Custom arithmetic exprission to rank suitable datastores based on
49
+#          their attributes
50
+#      3 = Fixed. Datastores will be ranked according to the PRIORITY attribute
51
+#          found in the Datastore template.
52
+#
53
+#
54
+#  LOG: Configuration for the logging system
55
+#    - system: defines the logging system:
56
+#          file      to log in the sched.log file
57
+#          syslog    to use the syslog facilities
58
+#    - debug_level:
59
+#           0 = ERROR
60
+#           1 = WARNING
61
+#           2 = INFO
62
+#           3 = DEBUG   Includes general scheduling information (default)
63
+#           4 = DDEBUG  Includes time taken for each step
64
+#           5 = DDDEBUG Includes detailed information about the scheduling
65
+#                       decision, such as VM requirements, Host ranking for
66
+#                       each VM, etc. This will impact the performance
67
+#
68
+#  MEMORY_SYSTEM_DS_SCALE: This factor scales the VM usage of the system DS with
69
+#  the memory size. This factor can be use to make the scheduler consider the
70
+#  overhead of checkpoint files:
71
+#       system_ds_usage = system_ds_usage + memory_system_ds_scale * memory
72
+#
73
+#*******************************************************************************
74
+
75
+MESSAGE_SIZE = 1073741824
76
+TIMEOUT      = 60 
77
+
78
+%if %%activer_one_ha == 'oui'
79
+ONE_XMLRPC = "http://%%adresse_ip_eth0:2633/RPC2"
80
+%else
81
+ONE_XMLRPC = "http://localhost:2633/RPC2"
82
+%end if
83
+
84
+SCHED_INTERVAL = 30
85
+
86
+MAX_VM       = 5000
87
+MAX_DISPATCH = 30
88
+MAX_HOST     = 1
89
+
90
+LIVE_RESCHEDS  = 0
91
+
92
+MEMORY_SYSTEM_DS_SCALE = 0
93
+
94
+DEFAULT_SCHED = [
95
+    policy = 1
96
+]
97
+
98
+DEFAULT_DS_SCHED = [
99
+   policy = 1
100
+]
101
+
102
+#DEFAULT_SCHED = [
103
+#   policy = 3,
104
+#   rank   = "- (RUNNING_VMS * 50  + FREE_CPU)"
105
+#]
106
+
107
+LOG = [
108
+  system      = "file",
109
+  debug_level = 3
110
+]